Skip to main content

Documentation 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.

Calculator App exposes a curated set of mathematical functions and constants drawn from Python’s standard 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 every eval call. No import statement or prefix is needed — just use them directly in your expression.

sqrt(x)

Computes the square root of x.
x
float | int
required
A non-negative real number. Passing a negative value raises a ValueError and returns "Invalid - Value error: math domain error".
Returns: float
sqrt(25)
= 5.0
sqrt(2)
= 1.4142135623730951
sqrt(0)
= 0.0

sin(x)

Computes the sine of x, where x is expressed in radians.
x
float | int
required
Angle in radians. Use pi for degree conversions, e.g., sin(90 * pi / 180) for 90°.
Returns: float in the range [-1.0, 1.0]
sin(0)
= 0.0
sin(pi/2)
= 1.0

cos(x)

Computes the cosine of x, where x is expressed in radians.
x
float | int
required
Angle in radians.
Returns: float in the range [-1.0, 1.0]
cos(0)
= 1.0
cos(pi)
= -1.0

tan(x)

Computes the tangent of x, where x is expressed in radians.
x
float | int
required
Angle in radians. Avoid values where cosine equals zero (e.g., pi/2), as the result approaches infinity.
Returns: float
tan(0)
= 0.0
tan(pi/4)
= 0.9999999999999999

log(x)

Computes the natural logarithm (base e) of x.
x
float | int
required
A strictly positive real number. Passing zero or a negative value raises a ValueError and returns "Invalid - Value error: math domain error".
Returns: float
log(e)
= 1.0
log(1)
= 0.0
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
pi * 2
= 6.283185307179586
sin(pi)
= 1.2246467991473532e-16
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
e
= 2.718281828459045
log(e)
= 1.0

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 inputInternal representation
1/2Fraction(1, 2)
3/4Fraction(3, 4)
2 1/2Fraction(5, 2)
3 3/4Fraction(15, 4)
Result formatting rules applied after evaluation:
  • 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

The parse_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.
The five patterns are:

Pattern 1 — squared

Regex: (\d+(?:\.\d+)?)\s*squared(\1)**2Matches a number (integer or decimal) optionally followed by whitespace, then the word squared.
9 squared
= 81

Pattern 2 — cubed

Regex: (\d+(?:\.\d+)?)\s*cubed(\1)**3Matches a number optionally followed by whitespace, then the word cubed.
5 cubed
= 125

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.
sqrt of 16
= 4.0

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.
square root of 25
= 5.0

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.
sqrt 16
= 4.0
Natural language patterns only match literal numbers written in the expression. Patterns like x squared or sqrt of x will not trigger the rewrite — use x**2 or sqrt(x) instead when working with variables.

Build docs developers (and LLMs) love