home / skills / bdambrosio / cognitive_workbench / calculate
This skill evaluates mathematical expressions numerically using SymPy, returning precise floating-point results for reliable LLM arithmetic.
npx playbooks add skill bdambrosio/cognitive_workbench --skill calculateReview the files below or copy the command above to add this skill to your agents.
---
name: calculate
type: python
description: "Numerically evaluate mathematical expressions using SymPy"
---
# calculate
Evaluate mathematical expressions numerically using SymPy. Returns floating-point results.
## Input
- `value`: Mathematical expression as string (required)
- `variables`: Dictionary of variable substitutions (optional, numbers only)
- `precision`: Decimal places for evaluation (optional, default: 10)
## Output
Success (`status: "success"`):
- `value`: String representation of numeric result
Failure (`status: "failed"`):
- `reason`: Error description
## Behavior
- **Operators**: `+`, `-`, `*`, `/`, `**`, `%`
- **Constants**: `pi`, `E`
- **Functions**: `sin`, `cos`, `tan`, `asin`, `acos`, `atan` (radians), `sqrt`, `log`, `ln`, `exp`, `abs`, `factorial`
- **Equations**: Expressions with `=` are solved (e.g., `x**2 - 4 = 0` → `-2.0, 2.0`)
- All trig functions expect radians
## Planning Notes
- Use for reliable arithmetic (LLM arithmetic is unreliable)
- To convert result to integer, use coercion tool afterward
## Examples
```json
{"type":"calculate","value":"2 + 3 * 4","out":"$result"}
{"type":"calculate","value":"2 * v * sin(theta * pi / 180) / g","variables":{"v":20,"theta":30,"g":9.8},"out":"$time"}
{"type":"calculate","value":"x**2 - 4 = 0","out":"$roots"}
```
This skill numerically evaluates mathematical expressions using SymPy and returns floating-point results. It supports arithmetic, common mathematical functions, constants, and basic equation solving. Use it when you need reliable numeric evaluation or to offload arithmetic from an LLM.
You provide an expression string, optional numeric variable substitutions, and an optional precision (decimal places). The skill parses the expression with SymPy, substitutes variables, evaluates to the requested precision, and returns a numeric result or solved roots for equations. If parsing or evaluation fails, it returns a clear error reason.
What input formats are supported?
Provide the expression as a string. Variables are a dictionary of numeric values. Precision is an integer for decimal places.
How are equations handled?
Expressions containing '=' are treated as equations; the skill solves for variable roots and returns numeric solutions.