First time here? Check out the FAQ!

Ask Your Question
0

What is equivalent to applyrule in Maple

asked 7 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 7 years ago

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.

Preview: (hide)
link
1

answered 7 years ago

tmonteil gravatar image

updated 7 years ago

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.

Preview: (hide)
link

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: 7 years ago

Seen: 373 times

Last updated: May 11 '17