Sage: Ticket #22024: symbolic placeholder for complex root
https://trac.sagemath.org/ticket/22024
<p>
The Sage equivalent of SymPy's <code>CRootOf</code> (=<code>ComplexRootOf</code>) is missing, which is just a symbolic placeholder for a solution that cannot be displayed symbolically.
</p>
<pre class="wiki">sage: from sympy import solve as ssolve
sage: ssolve(x^6+x+1, x)
[CRootOf(x**6 + x + 1, 0),
CRootOf(x**6 + x + 1, 1),
CRootOf(x**6 + x + 1, 2),
CRootOf(x**6 + x + 1, 3),
CRootOf(x**6 + x + 1, 4),
CRootOf(x**6 + x + 1, 5)]
sage: (_[0]+1)._sage_()
...
AttributeError: 'ComplexRootOf' object has no attribute '_sage_'
</pre><p>
Defect because conversion from SymPy fails.
</p>
<p>
A possible solution for <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/11941" title="defect: Solve and assumptions too aggressive with cube root of negative numbers (needs_work)">#11941</a> depends on this.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/22024
Trac 1.1.6nbruinTue, 06 Dec 2016 20:45:15 GMT
https://trac.sagemath.org/ticket/22024#comment:1
https://trac.sagemath.org/ticket/22024#comment:1
<p>
I think it's a bit more than a symbolic placeholder. It does seem there's an embedding in CC associated with it. So conversion to sage should probably be by converting to QQbar. Something like this might work:
</p>
<pre class="wiki">QQbar.polynomial_root(ZZ['x'](c.poly.as_expr()._sage_()),CIF(c.n()._sage_()))
</pre><p>
but there will be a lot of corner cases to deal with too.
</p>
TicketrwsWed, 01 Nov 2017 14:36:22 GMT
https://trac.sagemath.org/ticket/22024#comment:2
https://trac.sagemath.org/ticket/22024#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/22024#comment:1" title="Comment 1">nbruin</a>:
</p>
<blockquote class="citation">
<p>
I think it's a bit more than a symbolic placeholder. It does seem there's an embedding in CC associated with it. So conversion to sage should probably be by converting to QQbar. Something like this might work:
</p>
<pre class="wiki">QQbar.polynomial_root(ZZ['x'](c.poly.as_expr()._sage_()),CIF(c.n()._sage_()))
</pre><p>
but there will be a lot of corner cases to deal with too.
</p>
</blockquote>
<p>
To return a QQbar element would certainly be ideal. However, we're dealing at the moment with an unnecessary error, and returning a list of objects that show the polynomial plus the float value (and from which both can be extracted) would be sufficient to fix that defect.
</p>
TicketrwsWed, 01 Nov 2017 15:06:13 GMT
https://trac.sagemath.org/ticket/22024#comment:3
https://trac.sagemath.org/ticket/22024#comment:3
<p>
To return a float with arbitrary precision we can use SymPy's <code>n()</code> as well, so we just keep the original SymPy object.
</p>
TicketrwsWed, 01 Nov 2017 16:47:50 GMTbranch set
https://trac.sagemath.org/ticket/22024#comment:4
https://trac.sagemath.org/ticket/22024#comment:4
<ul>
<li><strong>branch</strong>
set to <em>u/rws/symbolic_placeholder_for_complex_root</em>
</li>
</ul>
TicketrwsWed, 01 Nov 2017 16:49:39 GMTstatus, milestone changed; commit, dependencies, author set
https://trac.sagemath.org/ticket/22024#comment:5
https://trac.sagemath.org/ticket/22024#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>ba171aa7029e35a6c444691376cad801e082ab36</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-7.5</em> to <em>sage-8.1</em>
</li>
<li><strong>dependencies</strong>
set to <em>#24062</em>
</li>
<li><strong>author</strong>
set to <em>Ralf Stephan</em>
</li>
</ul>
TicketcharpentTue, 14 Nov 2017 15:40:22 GMTstatus changed
https://trac.sagemath.org/ticket/22024#comment:6
https://trac.sagemath.org/ticket/22024#comment:6
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
Builds, passes <code>ptestlong</code> with no error whatsoever.
</p>
<p>
I'm a bit stimyed by the usefulness of the result. If this is supposed to just allow the conversion of a SymPy computation into Sage, it does the job :
</p>
<pre class="wiki">sage: sage: from sympy import solve as ssolve
....: sage: foo=ssolve(x^6+x+1, x)
....:
sage: [t._sage_() for t in foo]
[complex_root_of(x^6 + x + 1, 0),
complex_root_of(x^6 + x + 1, 1),
complex_root_of(x^6 + x + 1, 2),
complex_root_of(x^6 + x + 1, 3),
complex_root_of(x^6 + x + 1, 4),
complex_root_of(x^6 + x + 1, 5)]
sage: [t._sage_().n() for t in foo]
[-0.790667188814418 - 0.300506920309552*I,
-0.790667188814418 + 0.300506920309552*I,
-0.154735144496843 - 1.03838075445846*I,
-0.154735144496843 + 1.03838075445846*I,
0.945402333311260 - 0.611836693781009*I,
0.945402333311260 + 0.611836693781009*I]
</pre><p>
bit, as Nil's remarked, I find that we loose the properties of an answer in <code>QQbar</code>. However, the guarantee oif a fixed order may be the key to further computations.
</p>
<p>
==><code>positive_review</code>
</p>
<p>
But see my forthcoming comment to <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/11941" title="defect: Solve and assumptions too aggressive with cube root of negative numbers (needs_work)">#11941</a> : we may have bigger fish to fry...
</p>
TicketchapotonWed, 15 Nov 2017 12:21:41 GMT
https://trac.sagemath.org/ticket/22024#comment:7
https://trac.sagemath.org/ticket/22024#comment:7
<p>
reviewer name, please
</p>
TicketcharpentWed, 15 Nov 2017 14:34:13 GMTreviewer set
https://trac.sagemath.org/ticket/22024#comment:8
https://trac.sagemath.org/ticket/22024#comment:8
<ul>
<li><strong>reviewer</strong>
set to <em>Emmanuel Charpentier</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/22024#comment:7" title="Comment 7">chapoton</a>:
</p>
<blockquote class="citation">
<p>
reviewer name, please
</p>
</blockquote>
<p>
Wups ! Fixed...
</p>
TicketrwsThu, 16 Nov 2017 09:02:34 GMT
https://trac.sagemath.org/ticket/22024#comment:9
https://trac.sagemath.org/ticket/22024#comment:9
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/22024#comment:6" title="Comment 6">charpent</a>:
</p>
<blockquote class="citation">
<p>
I'm a bit stimyed by the usefulness of the result.
</p>
</blockquote>
<p>
I like such minimal solutions. I mean if we're importing sympy we might as well use their code. Thanks for the review.
</p>
TicketvbraunMon, 11 Dec 2017 01:04:03 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/22024#comment:10
https://trac.sagemath.org/ticket/22024#comment:10
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>u/rws/symbolic_placeholder_for_complex_root</em> to <em>ba171aa7029e35a6c444691376cad801e082ab36</em>
</li>
</ul>
TicketjdemeyerFri, 15 Dec 2017 09:42:59 GMTcommit deleted
https://trac.sagemath.org/ticket/22024#comment:11
https://trac.sagemath.org/ticket/22024#comment:11
<ul>
<li><strong>commit</strong>
<em>ba171aa7029e35a6c444691376cad801e082ab36</em> deleted
</li>
</ul>
<p>
This is breaking on some patchbots: <a class="closed ticket" href="https://trac.sagemath.org/ticket/24378" title="defect: complex_root_of uses inexact index (closed: fixed)">#24378</a>
</p>
Ticket