Ask Your Question
1

Mathematica-like transformations rules

asked 2018-03-24 08:39:14 -0500

Peter Wildemann gravatar image

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.

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2018-03-24 09:21:07 -0500 )edit

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.

slelievre gravatar imageslelievre ( 2018-03-24 09:21:56 -0500 )edit

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?

Sébastien gravatar imageSébastien ( 2018-03-24 10:42:51 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2018-03-24 09:38:00 -0500

slelievre gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-03-24 08:39:14 -0500

Seen: 40 times

Last updated: Mar 24