ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 13 Sep 2011 07:08:58 -0500Solve() confusion...http://ask.sagemath.org/question/7927/solve-confusion/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]]Sun, 06 Feb 2011 15:10:35 -0600http://ask.sagemath.org/question/7927/solve-confusion/Answer by kcrisman for <p>I've been experimenting with the <code>solve</code> 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.</p>
<p>Can someone explain what is going on in the following code and output?</p>
<pre><code>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);
</code></pre>
<p>The result:</p>
<pre><code>[[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]]
</code></pre>
http://ask.sagemath.org/question/7927/solve-confusion/?answer=12072#post-id-12072Let'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](http://trac.sagemath.org/sage_trac/ticket/10750) to track this issue.Mon, 07 Feb 2011 03:38:39 -0600http://ask.sagemath.org/question/7927/solve-confusion/?answer=12072#post-id-12072Comment by kcrisman for <p>Let's look one by one.</p>
<pre><code>print solve([],s_0,s_1,s_2)
[[s_0 == c1, s_1 == c2, s_2 == c3]]
</code></pre>
<p>Looks good - no equations, so any complex number (hence the <code>c</code>) will do for each variable.</p>
<pre><code>print solve([z==z],s_0,s_1,s_2)
({s_0: r1}, [])
</code></pre>
<p>Hmm, this must be an artifact of the difference between single-variable and multivariable solve. Here Maxima gives us a <code>r</code> as well, so real number - not really what we want, in retrospect.</p>
<pre><code>print solve([z==z,y==y],s_0,s_1,s_2)
[[s_0 == r6, s_1 == r5, s_2 == r4]]
</code></pre>
<p>Seems fine except for the real versus complex issue.</p>
<pre><code>print solve([z==z,y==y,x==x],s_0,s_1,s_2)
[[s_0 == r9, s_1 == r8, s_2 == r7]]
</code></pre>
<p>Ditto.</p>
<pre><code>print solve([s_0==0],s_0,s_1,s_2);
([s_0 == 0], [1])
</code></pre>
<p>Huh, a tuple. I wonder if this is giving multiplicity of this solution? That <em>is</em> the default, I believe. See <code>solve?</code> for details.</p>
<pre><code>print solve([s_0==0,s_1==s_1],s_0,s_1,s_2);
[[s_0 == 0, s_1 == r11, s_2 == r10]]
</code></pre>
<p>This seems fine.</p>
<p>Still, I agree that there isn't 100% uniformity here, so I'm opening <a href="http://trac.sagemath.org/sage_trac/ticket/10750">Trac 10750</a> to track this issue.</p>
http://ask.sagemath.org/question/7927/solve-confusion/?comment=21257#post-id-21257Followup - 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.Tue, 13 Sep 2011 07:08:58 -0500http://ask.sagemath.org/question/7927/solve-confusion/?comment=21257#post-id-21257