expand_expression
Expand algebraic expressions including polynomial products, powers, and logarithms. Provides deterministic expansion for coefficient extraction and simplification.
Instructions
Expand algebraic expression.
═══════════════════════════════════════════════════════════════════════
🆕 PHASE 1 - NOT IN SYMPY-MCP OR NSFORGE v0.2.3!
═══════════════════════════════════════════════════════════════════════
DETERMINISTIC: Always expands products and powers (unlike `simplify()`).
Use cases:
- Expand polynomial products: (x+1)(x-1) → x²-1
- Expand powers: (x+a)² → x²+2ax+a²
- Prepare for coefficient extraction
- Expand logarithms: log(xy) → log(x)+log(y)
Args:
expression: Expression to expand
deep: Expand recursively into subexpressions (default: True)
modulus: Modular arithmetic (for finite fields)
power_base: Expand (x*y)^n → x^n*y^n (default: True)
power_exp: Expand x^(a+b) → x^a*x^b (default: True)
mul: Expand products (default: True)
log: Expand log(xy) → log(x)+log(y) (default: True)
multinomial: Use multinomial expansion (default: True)
basic: Apply basic expansion rules (default: True)
Returns:
Expanded expression with LaTeX
Examples:
# Polynomial expansion
expand_expression("(x + 1)**2")
→ {"result": "x**2 + 2*x + 1", ...}
# Product expansion
expand_expression("(x + y)*(x - y)")
→ {"result": "x**2 - y**2", ...}
# Exponential expansion
expand_expression("exp(x + y)")
→ {"result": "exp(x)*exp(y)", ...}
# Log expansion
expand_expression("log(x*y)")
→ {"result": "log(x) + log(y)", ...}
# PK model: Expand dose calculation
expand_expression("dose/(V1 + V2) * exp(-k*t)")
→ {"result": "dose*exp(-k*t)/(V1 + V2)", ...}
# Michaelis-Menten expanded
expand_expression("(V_max*S + V_max*I)/(K_m + S)")
→ {"result": "V_max*S/(K_m + S) + V_max*I/(K_m + S)", ...}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| log | No | ||
| mul | No | ||
| deep | No | ||
| basic | No | ||
| modulus | No | ||
| power_exp | No | ||
| expression | Yes | ||
| power_base | No | ||
| multinomial | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||