ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 24 Mar 2018 10:42:51 -0500Mathematica-like transformations ruleshttp://ask.sagemath.org/question/41746/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.
Thanks in advance for any answers!
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.Sat, 24 Mar 2018 08:39:14 -0500http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/Comment by Sébastien for <p>Hey everyone!</p>
<p>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.</p>
<p>Thanks in advance for any answers!</p>
<p>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.</p>
http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41751#post-id-41751I 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?Sat, 24 Mar 2018 10:42:51 -0500http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41751#post-id-41751Comment by slelievre for <p>Hey everyone!</p>
<p>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.</p>
<p>Thanks in advance for any answers!</p>
<p>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.</p>
http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41748#post-id-41748New 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.Sat, 24 Mar 2018 09:21:56 -0500http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41748#post-id-41748Comment by slelievre for <p>Hey everyone!</p>
<p>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.</p>
<p>Thanks in advance for any answers!</p>
<p>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.</p>
http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41747#post-id-41747Welcome to Ask Sage! Thank you for your question!Sat, 24 Mar 2018 09:21:07 -0500http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?comment=41747#post-id-41747Answer by slelievre for <p>Hey everyone!</p>
<p>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.</p>
<p>Thanks in advance for any answers!</p>
<p>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.</p>
http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?answer=41749#post-id-41749You can use the `substitute` or `subs`methods:
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.Sat, 24 Mar 2018 09:38:00 -0500http://ask.sagemath.org/question/41746/mathematica-like-transformations-rules/?answer=41749#post-id-41749