Symbolic simplification differences between Sage and Maxima

asked 2016-03-15 06:38:49 +0200

rtc gravatar image

I ran into some problems trying to do some symbolic manipulations in the standard sage interface versus maxima. I wan't to ask is there some way to get sage to behave the same, or do I have rely on maxima to get this substitution to work.

here my code for the sage notebook gui directly calling maxima:

x = maxima('x')

y = maxima('y:(t0*s+a0*t0)/((s^2+s*a)*(s+r1)+s0*s+s1)');

dyds0= maxima('dyds0: diff(y,s0)');

ans = maxima.ratsubst(x,y,dyds0);

the answer as expected is:

ans = -s*x/(s1+s*s0+s^3+(r1+a)*s^2+a*r1*s)

Here is the sage code from the sage notebook not calling maxima directly:

s,r1,s1,s0,t0,a,a0,y,deds0,x = var('s,r1,s1,s0,t0,a,a0,y,deds0,x')

y = (t0*s+a0*t0)/((s^2+s*a)*(s+r1)+s0*s+s1); y

d = (t0*s+a0*t0)

dyds0 = diff(y,s0);

ans = dyds0.substitute(y == x);

ans1 = dyds0.substitute(d == x);

trying to substitute in x for the expression y in the result doesn't work as the result is:

ans  =  (-(a0*t0 + s*t0)*s/((a*s + s^2)*(r1 + s) + s*s0 + s1)^2

However I try to substitute x for only the numerator in the y expressions (d), it works and the correct result is:

ans1 =  -s*x/((a*s + s^2)*(r1 + s) + s*s0 + s1)^2)

as another example:

This works as expected

Q,q,w,e = var('Q,q,w,e')
Q = q/(q+w)

But this doesn't

Q,q,w,e = var('Q,q,w,e')
Q = q/(q+w)^2

again maxima has no problem doing the substitution using ratsubst

edit retag flag offensive close merge delete


Maybe we need a wrapper for ratsubst? I'm not as familiar with that one. You may want to use "wildcards" for this in Sage proper.

kcrisman gravatar imagekcrisman ( 2016-03-15 16:18:52 +0200 )edit

in the last example I posted.

Q,q,w,e = var('Q,q,w,e')
Q = q/(q+w)^2

How would you use "wildcards" to get this to work?

rtc gravatar imagertc ( 2016-03-15 16:59:20 +0200 )edit

In principle: see = SR.wild(0) Q.subs({(1/(q+w))*w0:e*w0}) But in this case it won't work because the expression doesn't "look" like the form there. In the expression tree the squaring is at a lower level than the division, I guess. So it's back to wondering whether Sage should wrap ratsubst.

kcrisman gravatar imagekcrisman ( 2016-03-16 14:02:01 +0200 )edit
kcrisman gravatar imagekcrisman ( 2016-03-16 14:02:51 +0200 )edit

Maybe instead of just wrapping ratsubst wild cards in the substitute function need to be able to deal with division and powers? Because as you stated, in principle your should be able to do Q.subs({(1/(q+w))*w0:e*w0}) and have it work.

As an interesting example i found a way to get this example to "work"

Q,q,w,e = var('Q,q,w,e')
Q = q/(q+w)^2

The problem however is when you want to substitute an expression for something in the numerator AND the denominator there are still problems. For example this problem still doesn't work as expected:

Q,q,w,e = var('Q,q,w,e')
Q = q*w/(q+w)^2

I wonder is there anyway to get sage to interpret ...(more)

rtc gravatar imagertc ( 2016-03-16 16:58:18 +0200 )edit