calculate
Numerically evaluate mathematical expressions via SymPy. Returns the result as a string.
Supported operations
- Operators:
+, -, *, /, **, %
- Constants:
pi, E
- Functions:
sin, cos, tan, asin, acos, atan (radians), sqrt, log, ln, exp, abs, factorial
- Equations: an expression containing
= is solved (e.g. x**2 - 4 = 0 → -2, 2). An explicit solve(...) call works too: solve(x**2 - 4, x).
All trig functions expect radians.
Exact vs floating-point results
An expression that evaluates to an exact integer or rational comes back exact —
17! returns 355687428096000, not 3.556874281e+14. precision applies only
to results that genuinely need floating-point evaluation (irrationals, trig,
logs). Asking for a small precision to get a "clean" integer is backwards and
will be rejected below 1.
Examples
{"thought": "compute the discriminant", "tool": "calculate", "expression": "b**2 - 4*a*c", "vars": "a=1, b=-5, c=6"}
{"thought": "projectile range", "tool": "calculate", "expression": "2 * v * sin(theta * pi / 180) / g", "vars": "v=20, theta=30, g=9.8"}
{"thought": "roots of a quadratic", "tool": "calculate", "expression": "x**2 - 4 = 0"}
1---2name: calculate3description: Compute the value of a math expression. Handles arithmetic, algebra, trig, calculus. Use this instead of LLM arithmetic — calculate is exact and deterministic.4---56# calculate78Numerically evaluate mathematical expressions via SymPy. Returns the result as a string.910## Supported operations1112- **Operators**: `+`, `-`, `*`, `/`, `**`, `%`13- **Constants**: `pi`, `E`14- **Functions**: `sin`, `cos`, `tan`, `asin`, `acos`, `atan` (radians), `sqrt`, `log`, `ln`, `exp`, `abs`, `factorial`15- **Equations**: an expression containing `=` is solved (e.g. `x**2 - 4 = 0` → `-2, 2`). An explicit `solve(...)` call works too: `solve(x**2 - 4, x)`.1617All trig functions expect radians.1819## Exact vs floating-point results2021An expression that evaluates to an exact integer or rational comes back exact —22`17!` returns `355687428096000`, not `3.556874281e+14`. `precision` applies only23to results that genuinely need floating-point evaluation (irrationals, trig,24logs). Asking for a small `precision` to get a "clean" integer is backwards and25will be rejected below 1.2627## Examples2829```json30{"thought": "compute the discriminant", "tool": "calculate", "expression": "b**2 - 4*a*c", "vars": "a=1, b=-5, c=6"}31```3233```json34{"thought": "projectile range", "tool": "calculate", "expression": "2 * v * sin(theta * pi / 180) / g", "vars": "v=20, theta=30, g=9.8"}35```3637```json38{"thought": "roots of a quadratic", "tool": "calculate", "expression": "x**2 - 4 = 0"}39```