# Mathematica-like transformations rules

Hey everyone!

I am currently exploring Sage's features and was wondering if there is something similar to Mathematica's replacement/transformation rules, which are (in my opinion) the strongest feature of Mathematica itself.

PS: I would have liked to link on Wolfram's documentation page on Transformation rules but my Karma is insufficient for posting links, so in case you wonder what I mean by transformation rules, just give Google a hit.

edit retag close merge delete

New users cannot post hyperlinks, which helps avoid a lot of spam.

A workaround is to introduce spaces in the url of links.

For example: https:// wiki.sagemath.org instead of https://wiki.sagemath.org.

Or put more spaces if necessary, eg https:// wiki .sagemath .org.

I think the question is more general than just substitutions in symbolics expression as I remember a course on Mathematica I saw some years ago. Can you update the question by giving an example of such typical transformation rules?

Sort by » oldest newest most voted

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)


• 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.

more