Sage: Ticket #5679: solve should convert additional args to SR
https://trac.sagemath.org/ticket/5679
<pre class="wiki">Some code that used to work in sage-3.0.6 (or something close like
3.0.3), now break with this error message:
>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)
TypeError: not all arguments converted during string formatting
BUT:
sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([{x0: 0}], [1])
The printing problem is due to the fact that Polynomials have an
implicit conversion to sequence types triggered by this code:
try:
variables = tuple(args[0])
except TypeError:
variables = args
near the start of solve(), (Hint: tuple(args[0]) works if the first
variable is a PolynomialElement and thus the rest of the vars are
ignored and you get the bogus ((1.0000000, x0),) tuple as variables)
If that is fixed, then you get this message which does not help much more:
>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/anakha/.sage/sage_notebook/worksheets/admin/12/code/55.py",
line 8, in <module>
solve(x0 == _sage_const_0 , x0, x1, x2)
File "/Volumes/Place/anakha/Applications/sage/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/",
line 1, in <module>
File "/Users/anakha/.sage/sage_notebook/worksheets/admin/12/code/54.py",
line 22, in solve
raise TypeError, "%s is not a valid variable."%v
TypeError: x0 is not a valid variable.
Furthermore, if you disable the type checking that is done on the
input variables, then it works as before:
>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)
[[x0 == 0, x1 == r10, x2 == r9]]
I don't think killing the typecheck is the way to go, but maybe
extending it to cover the polynomial elements.
Or maybe another better way to do this has come up.
Arnaud
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/5679
Trac 1.1.6kcrismanWed, 16 Mar 2011 15:52:58 GMTupstream set
https://trac.sagemath.org/ticket/5679#comment:1
https://trac.sagemath.org/ticket/5679#comment:1
<ul>
<li><strong>upstream</strong>
set to <em>N/A</em>
</li>
</ul>
<p>
In Sage 4.6.2:
{{[
sage: f = symbolic_expression(x0) == 0
sage: f.solve(x0)
</p>
<hr />
<p>
<a class="missing wiki">TypeError?</a>: x0 is not a valid variable.
sage: f.solve(symbolic_expression(x0))
[x0 == 0]
}}}
</p>
<p>
This is because
</p>
<pre class="wiki"> if not isinstance(x, Expression):
raise TypeError, "%s is not a valid variable."%x
</pre><p>
So I guess one could check whether SR(x) is a symbol?
</p>
<pre class="wiki">sage: symbolic_expression(x0)._is_symbol()
True
</pre><p>
Incidentally, we never get to the <code>args[0]</code> because you are solving a single expression, so it goes to <code>ex.solve(*args)</code>. So maybe we should check for that... But in any case the syntax is now
</p>
<pre class="wiki">sage: solve([symbolic_expression(x0) == 0, 0==0], [x0, x1, x2])
---------------------------------------------------------------------------
TypeError: x0 is not a valid variable.
</pre><p>
which <em>does</em> raise the error in question.
</p>
<p>
But
</p>
<pre class="wiki">sage: solve([symbolic_expression(x0) == 0, 0==0], [SR(x0), SR(x1), SR(x2)])
[[x0 == 0, x1 == r2, x2 == r1]]
</pre><p>
Weirdly,
</p>
<pre class="wiki">sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([x0 == 0], [1])
</pre>
TicketkcrismanTue, 13 Sep 2011 17:01:13 GMT
https://trac.sagemath.org/ticket/5679#comment:2
https://trac.sagemath.org/ticket/5679#comment:2
<blockquote class="citation">
<p>
Incidentally, we never get to the <code>args[0]</code> because you are solving a single expression, so it goes to <code>ex.solve(*args)</code>. So maybe we should check for that... But in any case the syntax is now
Weirdly,
</p>
<pre class="wiki">sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([x0 == 0], [1])
</pre></blockquote>
<p>
These (tangential) things are both addressed at <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/10750" title="defect: Fix solve so that additional args are properly handled (needs_work)">#10750</a>, as it turns out.
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/5679#comment:3
https://trac.sagemath.org/ticket/5679#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/5679#comment:4
https://trac.sagemath.org/ticket/5679#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/5679#comment:5
https://trac.sagemath.org/ticket/5679#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/5679#comment:6
https://trac.sagemath.org/ticket/5679#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
TicketrwsWed, 15 Jul 2015 07:07:48 GMTdescription, summary changed
https://trac.sagemath.org/ticket/5679#comment:7
https://trac.sagemath.org/ticket/5679#comment:7
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/5679?action=diff&version=7">diff</a>)
</li>
<li><strong>summary</strong>
changed from <em>fix a bug in solve and polynomial generators</em> to <em>solve should convert additional args to SR</em>
</li>
</ul>
Ticket