Calculator App exposes a curated set of mathematical functions and constants drawn from Python’s standardDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Seaus-tech/Calculator-App/llms.txt
Use this file to discover all available pages before exploring further.
math module. They are available in any expression you type at the REPL prompt. This page documents each function’s signature, behaviour, and example output, and also covers the natural language transformations that act as convenient shorthand.
Built-In Functions
These names are injected into the evaluator’s safe dictionary before everyeval call. No import statement or prefix is needed — just use them directly in your expression.
sqrt(x)
Computes the square root of x.
A non-negative real number. Passing a negative value raises a
ValueError and returns "Invalid - Value error: math domain error".float
sin(x)
Computes the sine of x, where x is expressed in radians.
Angle in radians. Use
pi for degree conversions, e.g., sin(90 * pi / 180) for 90°.float in the range [-1.0, 1.0]
cos(x)
Computes the cosine of x, where x is expressed in radians.
Angle in radians.
float in the range [-1.0, 1.0]
tan(x)
Computes the tangent of x, where x is expressed in radians.
Angle in radians. Avoid values where cosine equals zero (e.g.,
pi/2), as the result approaches infinity.float
log(x)
Computes the natural logarithm (base e) of x.
A strictly positive real number. Passing zero or a negative value raises a
ValueError and returns "Invalid - Value error: math domain error".float
log(x) is the natural logarithm (ln). To compute a base-10 logarithm, use the change-of-base formula: log(x) / log(10).Constants
Constants are resolved at the same time as functions and can appear anywhere in an expression.pi
The mathematical constant π.
Value: 3.141592653589793
Due to floating-point precision,
sin(pi) returns a very small number near zero rather than exactly 0.0. This is expected behaviour.e
Euler’s number, the base of the natural logarithm.
Value: 2.718281828459045
Fraction Arithmetic
Fraction(numerator, denominator) (internal)
Python’s fractions.Fraction class is included in the safe dictionary to support exact rational arithmetic. Users do not call Fraction() directly — the parse_fractions() pre-processor rewrites a/b and mixed-number notation into the appropriate Fraction(...) calls automatically before evaluation.
What the parser rewrites:
| User input | Internal representation |
|---|---|
1/2 | Fraction(1, 2) |
3/4 | Fraction(3, 4) |
2 1/2 | Fraction(5, 2) |
3 3/4 | Fraction(15, 4) |
- If
denominator == 1→ returned as a plain integer - If
|numerator| > denominator→ returned as a mixed number string, e.g.,"2 3/4" - Otherwise → returned as
"numerator/denominator", e.g.,"5/6"
Natural Language Transformations
Theparse_natural_language() function in parser.py runs as a pre-processing step on every expression before evaluation. It applies five regex substitutions in order, allowing you to type English phrases instead of symbolic notation.
All input is lowercased before pattern matching, so
9 Squared, 9 squared, and 9 SQUARED are all equivalent.Pattern 1 — squared
Regex:
(\d+(?:\.\d+)?)\s*squared → (\1)**2Matches a number (integer or decimal) optionally followed by whitespace, then the word squared.Pattern 2 — cubed
Regex:
(\d+(?:\.\d+)?)\s*cubed → (\1)**3Matches a number optionally followed by whitespace, then the word cubed.Pattern 3 — sqrt of
Regex:
sqrt\s*of\s*(\d+(?:\.\d+)?) → sqrt(\1)Matches the word sqrt, optional whitespace, the word of, optional whitespace, then a number.Pattern 4 — square root of
Regex:
square\s*root\s*of\s*(\d+(?:\.\d+)?) → sqrt(\1)Matches the full phrase square root of (with optional internal whitespace), then a number.Pattern 5 — sqrt (no keyword)
Regex:
sqrt\s*(\d+(?:\.\d+)?) → sqrt(\1)Matches the word sqrt followed by optional whitespace and a number, without the word of. This is the most compact form.