Ask Your Question
0

What is equivalent to applyrule in Maple

asked 2017-05-11 03:01:56 +0100

I have an expression e1 and in e1 I would like to replace e2 (a sub-expression of e1) with e3 (a different expression). In Maple I use

applyrule([e2=e3,1/e2=1/e3],e1);

Is there a similar command in Sage?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2017-05-11 09:13:21 +0100

B r u n o gravatar image

You can use the method subs:

sage: e1 = cos(x) + sin(x) - exp(x) + x^2/3
sage: e2 = sin(x)
sage: e3 = 1/x + 1/x^2
sage: e1.subs({e2:e3})
1/3*x^2 + 1/x + 1/x^2 + cos(x) - e^x

Note though that it won't work with too complicated expressions for e2. For more on this, you may have a look to the documentation of subs in the reference manual.

edit flag offensive delete link more
1

answered 2017-05-11 09:16:47 +0100

tmonteil gravatar image

updated 2017-05-11 09:17:26 +0100

You can try:

sage: e1.substitute({e2:e3})

or even

sage: e1.substitute({e2:e3, 1/e2:1/e3})

if it can help.

If this does not work, please do not hesitate to provide a way to construct e1, e2 and e3 so that we can think about it.

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

Stats

Asked: 2017-05-11 03:01:56 +0100

Seen: 328 times

Last updated: May 11 '17