Ask Your Question
0

Solve() confusion...

asked 2011-02-06 22:10:35 +0100

this post is marked as community wiki

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], [1])
[[s_0 == 0, s_1 == r11, s_2 == r10]]
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-02-07 10:38:39 +0100

this post is marked as community wiki

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], [1])

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.

edit flag offensive delete link more

Comments

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.

kcrisman gravatar imagekcrisman ( 2011-09-13 14:08:58 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-02-06 22:10:35 +0100

Seen: 765 times

Last updated: Feb 07 '11