Ask Your Question

Revision history [back]

Hello,

The nearest I am able to do is

sage:  sage: x.add(10,hold=True).mul(2,hold=True).mul(1/5,hold=True)
1/5*(2*(x + 10))

The thing is that there is nothing like division with symoblic expression (but you can take inverses and use multiplication). It can be seen on

sage: ((x-1)/(x+1)).operands()
[1/(x + 1), x - 1]
sage: ((x-1)/(x+1)).operator()
<built-in function mul>

And there is a problem with the argument hold since it sometimes reorder the terms (i.e. symbolic expressions always assume that + and * are commutative)

sage: var('y')
y
sage: x.mul(y,hold=True).operands()
[x, y]
sage: y.mul(x,hold=True).operands()
[x, y]

So an expression such as (x+3) / 5 does not exist in Sage as it automatically put 1/5 as the second term

sage: (x+3).mul(1/5, hold=True).operands()
[x + 3, 1/5]
sage: SR(1/5).mul(x+3, hold=True).operands()
[x + 3, 1/5]

Good luck.

Vincent