Ask Your Question
0

SUBSTITUTIONS IN SYMBOLIC EXPRESSIONS

asked 2019-03-24 13:43:13 -0500

Hi,

I would like to know if it is possible to substitute expressions inside some equation or expression.

Consider the following expression:

$$(r+1)\cdot(r+2)+g+a$$

Then, I would like to say that I want this same expression for $c+d = 2\cdot r + a$.

Is this possible?

Can I implement something like this in SAGE?

edit retag flag offensive close merge delete

Comments

I think you should explain a bit more what you are looking for. If, for example, you only want to replace $a$ in the expression by its value from the equality, you can simply do this:

var("a,c,d,g,r")
expression = (r+1)*(r+2) + g + a
expression.subs(a=c+d-2*r)
Juanjo gravatar imageJuanjo ( 2019-03-25 13:30:45 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-25 18:22:57 -0500

Emmanuel Charpentier gravatar image

Do you mean:

sage: var("r,g,a,c,d")
(r, g, a, c, d)
sage: Exp=(r+1)*(r+2)+g+a; Exp
(r + 2)*(r + 1) + a + g
sage: Exp.expand()-(2*r+a)+(c+d)
r^2 + c + d + g + r + 2

?

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: 2019-03-24 13:43:13 -0500

Seen: 25 times

Last updated: Mar 25