Ask Your Question

Revision history [back]

You can use the substitute or subsmethods:

sage: a, b, x, y = SR.var('a b x y')
sage: expr = x^2 + sin(x) - x*y + exp(sin(y)-x)
sage: expr
x^2 - x*y + e^(-x + sin(y)) + sin(x)
sage: expr.subs({x: a, y: b})
a^2 - a*b + e^(-a + sin(b)) + sin(a)

See also:

  • expr.subs
  • expr.substitute_function
  • expr.substitute
  • expr.substitution_delayed

To get the documentation for those, define expr as above and type for example one of:

  • expr.substitute_function?
  • browse_sage_doc(expr.substitute_function)

One will give you text-mode help, and the other will render in html in a browser.