substitute_expression
Perform symbolic substitution in mathematical expressions by replacing a specified variable with another expression. Returns the resulting expression key for further use.
Instructions
Substitutes a variable in an expression with another expression using SymPy's subs method.
Args:
expr_key: The key of the expression to perform substitution on.
var_name: The name of the variable to substitute.
replacement_expr_key: The key of the expression to substitute in place of the variable.
Example:
# Create variables x and y
intro("x", [], [])
intro("y", [], [])
# Create expressions
expr1 = introduce_expression("x**2 + y**2")
expr2 = introduce_expression("sin(x)")
# Substitute y with sin(x) in x^2 + y^2
result = substitute_expression(expr1, "y", expr2)
# Results in x^2 + sin^2(x)
Returns:
A key for the resulting expression after substitution.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
expr_key | Yes | ||
replacement_expr_key | Yes | ||
var_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"expr_key": {
"title": "Expr Key",
"type": "string"
},
"replacement_expr_key": {
"title": "Replacement Expr Key",
"type": "string"
},
"var_name": {
"title": "Var Name",
"type": "string"
}
},
"required": [
"expr_key",
"var_name",
"replacement_expr_key"
],
"title": "substitute_expressionArguments",
"type": "object"
}