# Solve() confusion... This post is a wiki. Anyone with karma >750 is welcome to improve it.

I've been experimenting with the solve function, as it recently gave me unexpected results. In some instances sage outputs nonsensical solutions, but if I provide it with more information (even a trivial equation like x=x) it suddenly parametrizes and outputs correctly.

Can someone explain what is going on in the following code and output?

s=list(var('s_%d' % i) for i in range(3));
var('x y z');
print solve([],s_0,s_1,s_2)
print solve([z==z],s_0,s_1,s_2)
print solve([z==z,y==y],s_0,s_1,s_2)
print solve([z==z,y==y,x==x],s_0,s_1,s_2)
print solve([s_0==0],s_0,s_1,s_2);
print solve([s_0==0,s_1==s_1],s_0,s_1,s_2);


The result:

[[s_0 == c1, s_1 == c2, s_2 == c3]]
({s_0: r1}, [])
[[s_0 == r6, s_1 == r5, s_2 == r4]]
[[s_0 == r9, s_1 == r8, s_2 == r7]]
([s_0 == 0], )
[[s_0 == 0, s_1 == r11, s_2 == r10]]

edit retag close merge delete

Sort by » oldest newest most voted This post is a wiki. Anyone with karma >750 is welcome to improve it.

Let's look one by one.

print solve([],s_0,s_1,s_2)
[[s_0 == c1, s_1 == c2, s_2 == c3]]


Looks good - no equations, so any complex number (hence the c) will do for each variable.

print solve([z==z],s_0,s_1,s_2)
({s_0: r1}, [])


Hmm, this must be an artifact of the difference between single-variable and multivariable solve. Here Maxima gives us a r as well, so real number - not really what we want, in retrospect.

print solve([z==z,y==y],s_0,s_1,s_2)
[[s_0 == r6, s_1 == r5, s_2 == r4]]


Seems fine except for the real versus complex issue.

print solve([z==z,y==y,x==x],s_0,s_1,s_2)
[[s_0 == r9, s_1 == r8, s_2 == r7]]


Ditto.

print solve([s_0==0],s_0,s_1,s_2);
([s_0 == 0], )


Huh, a tuple. I wonder if this is giving multiplicity of this solution? That is the default, I believe. See solve? for details.

print solve([s_0==0,s_1==s_1],s_0,s_1,s_2);
[[s_0 == 0, s_1 == r11, s_2 == r10]]


This seems fine.

Still, I agree that there isn't 100% uniformity here, so I'm opening Trac 10750 to track this issue.

more

Followup - this was also noticed on sage-devel, and it turns out that we should consider these bugs. Short version - s_1 and s_2 are becoming True in Expression.solve(), which is bad.