Ask Your Question
1

SUBSTITUTIONS IN SYMBOLIC EXPRESSIONS

asked 2019-03-24 19:43:13 +0200

idriskameni gravatar image

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 19:30:45 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-26 00:22:57 +0200

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 19:43:13 +0200

Seen: 1,989 times

Last updated: Mar 26 '19