Sage: Ticket #16753: solve of equation system misses trivial simplifications
https://trac.sagemath.org/ticket/16753
<p>
Some trivial substitutions are not done by solve:
</p>
<pre class="wiki">sage: x,y=var('x,y')
sage: solve([y==exp(x),2*y-exp(x)==1],x,y)
[y == e^x, 2*y - e^x == 1]
</pre><p>
and, as reported in <a class="ext-link" href="http://ask.sagemath.org/question/23652/solve-equations-with-sinx/"><span class="icon"></span>http://ask.sagemath.org/question/23652/solve-equations-with-sinx/</a>
</p>
<pre class="wiki">sage: solve([y==sin(x),y+4*sin(x)==5],x,y)
[y == sin(x), y + 4*sin(x) == 5]
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/16753
Trac 1.1.6rwsMon, 04 Aug 2014 07:39:53 GMTpriority, description changed
https://trac.sagemath.org/ticket/16753#comment:1
https://trac.sagemath.org/ticket/16753#comment:1
<ul>
<li><strong>priority</strong>
changed from <em>major</em> to <em>critical</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/16753?action=diff&version=1">diff</a>)
</li>
</ul>
<p>
Set to critical because it makes Sage look really stupid.
</p>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/16753#comment:2
https://trac.sagemath.org/ticket/16753#comment:2
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
Ticketajagekar.akshayThu, 03 Mar 2016 05:01:09 GMT
https://trac.sagemath.org/ticket/16753#comment:3
https://trac.sagemath.org/ticket/16753#comment:3
<p>
I think it is maxima which is unable to solve the equations and returns
</p>
<pre class="wiki">%solve([y = sin(x), y + 4*sin(x) = 5],[x,y])
</pre><p>
in this case. Sage converts this to list of solutions. Can we condition sage to return "Unable to solve" instead of returning the equations? while reporting this upstream.
</p>
TicketrwsThu, 03 Mar 2016 06:47:39 GMT
https://trac.sagemath.org/ticket/16753#comment:4
https://trac.sagemath.org/ticket/16753#comment:4
<p>
You mean a general change for unsolved equations/relations? That would be a different ticket which you would have to open. I'm not against a change but I'd rather have solve return a set, and in case of unsolved an empty set.
</p>
Ticketajagekar.akshayThu, 03 Mar 2016 15:14:03 GMT
https://trac.sagemath.org/ticket/16753#comment:5
https://trac.sagemath.org/ticket/16753#comment:5
<p>
A test which returned initial function instead of solutions was failing
</p>
<pre class="wiki">solve([sin(x)==x,y^2==x],x,y)
Expected:
[sin(x) == x, y^2 == x]
Got:
[]
</pre><blockquote>
<p>
I have changed that test. Please have a look.
</p>
</blockquote>
Ticketajagekar.akshayThu, 03 Mar 2016 15:15:15 GMTbranch set
https://trac.sagemath.org/ticket/16753#comment:6
https://trac.sagemath.org/ticket/16753#comment:6
<ul>
<li><strong>branch</strong>
set to <em>u/ajagekar.akshay/Trac16753</em>
</li>
</ul>
TicketrwsThu, 03 Mar 2016 15:45:16 GMTcommit set
https://trac.sagemath.org/ticket/16753#comment:7
https://trac.sagemath.org/ticket/16753#comment:7
<ul>
<li><strong>commit</strong>
set to <em>1961f9430ee403bb5632853af3e18d2d2c858187</em>
</li>
</ul>
<p>
Your ticket branch shows <a class="missing wiki">MeatAxe?</a> changes. Probably you branched not from develop. Use <code>git trac checkout</code> to have a proper start.
</p>
TicketgitThu, 03 Mar 2016 16:03:53 GMTcommit changed
https://trac.sagemath.org/ticket/16753#comment:8
https://trac.sagemath.org/ticket/16753#comment:8
<ul>
<li><strong>commit</strong>
changed from <em>1961f9430ee403bb5632853af3e18d2d2c858187</em> to <em>88dec5a75c53522f0a24889b4e60efda0964d700</em>
</li>
</ul>
<p>
Branch pushed to git repo; I updated commit sha1. New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="http://git.sagemath.org/sage.git/commit/?id=88dec5a75c53522f0a24889b4e60efda0964d700"><span class="icon"></span>88dec5a</a></td><td><code>Trac 16753 : solve of equation system misses trivial simplifications</code>
</td></tr></table>
Ticketajagekar.akshayThu, 03 Mar 2016 16:05:43 GMT
https://trac.sagemath.org/ticket/16753#comment:9
https://trac.sagemath.org/ticket/16753#comment:9
<p>
Sorry for that mistake.
</p>
Ticketajagekar.akshayFri, 04 Mar 2016 14:03:15 GMTstatus changed; author set
https://trac.sagemath.org/ticket/16753#comment:10
https://trac.sagemath.org/ticket/16753#comment:10
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>author</strong>
set to <em>Akshay Ajagekar</em>
</li>
</ul>
TicketnbruinFri, 04 Mar 2016 16:24:37 GMTstatus changed
https://trac.sagemath.org/ticket/16753#comment:11
https://trac.sagemath.org/ticket/16753#comment:11
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
<p>
This solution doesn't fly. Presently:
</p>
<pre class="wiki">sage: solve([x==5],[x])
[x == 5]
</pre><p>
with this patch, it would return []. That's bad.
</p>
<p>
In general, I think it's bad to silently returning an empty list in a case where we know we failed to "solve" the system. An empty list can be interpreted as an inconsistent system of equations.
</p>
<p>
The original behaviour, returning the original system, indicates better a failure to solve than an empty solution list does. Therefore, I think that is preferable.
</p>
<p>
You could argue that returning the original system would be "invalid" output, because usually it means that the LH sides of the equations aren't the to-be-solved-for variables and/or the RH sides won't be free of them.
</p>
<p>
In that case, returning an error is a better solution.
</p>
<p>
I think the parsing that happens for <code>solution_dict=True</code> is definitely broken:
</p>
<pre class="wiki">sage: solve([y == sin(x), y + 4*sin(x) == 5],[x,y],solution_dict=True)
[{y: sin(x)}, {y + 4*sin(x): 5}]
</pre><p>
Compared with
</p>
<pre class="wiki">sage: solve([x^2==5,y==6],[x,y],solution_dict=True)
[{y: 6, x: -sqrt(5)}, {y: 6, x: sqrt(5)}]
</pre><p>
it's clearly very misleading output. So for <code>solution_dict=True</code> I think we have a good case for an error. Without it, I think the current output is misleading. But so is:
</p>
<pre class="wiki">sage: solve(x-1,x)
[x == 1]
sage: solve([x-1],[x])
[x == 1]
sage: solve([x-1,y-1],[x,y])
[[x == 1, y == 1]]
sage: solve([x-1],[x],solution_dict=True)
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
</pre><p>
(we'd probably be better off if also in the single-variable case we'd also return list-of-lists etc.)
</p>
<p>
Beware of legacy, though. There might be users out there that have grown fond of this bad behaviour and somehow depend on it.
</p>
Ticketajagekar.akshaySat, 05 Mar 2016 06:16:19 GMT
https://trac.sagemath.org/ticket/16753#comment:12
https://trac.sagemath.org/ticket/16753#comment:12
<pre class="wiki">sage: solve([x==5],[x])
</pre><p>
returns <code> [x == 5]</code> as expected, the changed code gets executed only for system of equations.
Even for cases like
</p>
<pre class="wiki">sage: solve([x==5,y==2],x,y)
</pre><p>
maxima returns list of list as solution <code> [[x == 5, y == 2]]</code>, so an empty set is not returned. I also think returning error would be better for unsolved equations. For <a class="missing wiki">TypeError?</a>, the parsing for <code> solution_dict = True</code>
can be fixed by checking length of variables list and adding appropriate condition.
</p>
Ticket