Sage: Ticket #25458: Inconsistent printing of algebraic numbers
https://trac.sagemath.org/ticket/25458
<pre class="wiki">sage: QQbar(2*I)^(1/2)
1 + 1*I
sage: type(_)
<class 'sage.rings.qqbar.AlgebraicNumber'>
sage: QQbar(I)+1
I + 1
sage: type(_)
<class 'sage.rings.qqbar.AlgebraicNumber'>
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/25458
Trac 1.1.6slabbeTue, 29 May 2018 08:26:47 GMT
https://trac.sagemath.org/ticket/25458#comment:1
https://trac.sagemath.org/ticket/25458#comment:1
<p>
Notice that:
</p>
<pre class="wiki">sage: AA.options.display_format = 'radical'
</pre><p>
recently introduced (<a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a>) fixes the problem:
</p>
<pre class="wiki">sage: QQbar(2*I)^(1/2)
I + 1
sage: QQbar(I)+1
I + 1
</pre>
TicketrwsWed, 30 May 2018 07:06:23 GMT
https://trac.sagemath.org/ticket/25458#comment:2
https://trac.sagemath.org/ticket/25458#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/25458#comment:1" title="Comment 1">slabbe</a>:
</p>
<blockquote class="citation">
<p>
Notice that:
</p>
<pre class="wiki">sage: AA.options.display_format = 'radical'
</pre><p>
recently introduced (<a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a>) fixes the problem:
</p>
</blockquote>
<p>
It is not a fix if you have to set it every time to get a consistent result. The fix would be to make it the default from the start. Until that ticket the output was consistent, so <a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a> actually introduced a bug.
</p>
TicketslabbeWed, 30 May 2018 19:01:41 GMT
https://trac.sagemath.org/ticket/25458#comment:3
https://trac.sagemath.org/ticket/25458#comment:3
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/25458#comment:2" title="Comment 2">rws</a>:
</p>
<blockquote class="citation">
<p>
It is not a fix if you have to set it every time to get a consistent result.
</p>
</blockquote>
<p>
It was not intended to be a fix, just a side note.
</p>
<blockquote class="citation">
<p>
The fix would be to make it the default from the start.
</p>
</blockquote>
<p>
This is one possibility. Maybe there is a another possibility that would fix the default display format without using the radical display format.
</p>
<blockquote class="citation">
<p>
Until that ticket the output was consistent, so <a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a> actually introduced a bug.
</p>
</blockquote>
<p>
To my knowledge (I reviewed <a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a>), the default behavior was not affected by <a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a>. Moreover, on 8.0 and on <a class="ext-link" href="http://sagecell.sagemath.org/?q=mlfmio"><span class="icon"></span>sagecell</a> currently running 8.2, I am able to reproduce the inconsistency. Therefore, it seems on the contrary that the bug was present *before* <a class="closed ticket" href="https://trac.sagemath.org/ticket/25210" title="enhancement: Add option to make QQbar / AA print using radicals (closed: fixed)">#25210</a>:
</p>
<pre class="wiki">┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.0, Release Date: 2017-07-21 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: QQbar(2*I)^(1/2)
1 + 1*I
sage: QQbar(I)+1
I + 1
</pre>
TicketslabbeThu, 05 Jul 2018 08:25:29 GMT
https://trac.sagemath.org/ticket/25458#comment:4
https://trac.sagemath.org/ticket/25458#comment:4
<p>
So do you have any idea to fix the print inconsistency?
</p>
<p>
Making
</p>
<pre class="wiki">sage: AA.options.display_format = 'radical'
</pre><p>
the default is a solution, but maybe it should be discussed on sage-devel first?
</p>
Ticketgh-mwageringelSat, 21 Dec 2019 10:48:25 GMT
https://trac.sagemath.org/ticket/25458#comment:5
https://trac.sagemath.org/ticket/25458#comment:5
<p>
The elements print differently depending on how they are represented internally (see <code>AlgebraicNumber_base._repr_</code>).
</p>
<ol><li>This element is represented exactly as an element of <code>QuadraticField(-1)</code>:
<pre class="wiki">sage: QQbar(1 + I)
I + 1
</pre></li></ol><ol start="2"><li>This element is represented implicitly as a root of a polynomial, so the <code>CIF</code> approximation is used for printing:
<pre class="wiki">sage: QQbar(2*I)^(1/2)
1 + 1*I
</pre></li></ol><ol start="3"><li>If the display format is <code>radical</code>, the representation as a radical symbolic expression in <code>SR</code> is printed instead:
<pre class="wiki">sage: (QQbar(2*I)^(1/2)).radical_expression()
I + 1
</pre>(This is rather inefficient in general, so should not become the default.)
</li></ol><p>
It is difficult to unify these three cases. It would not be too hard to change the order of real and imaginary part in (1) to appear the same as (2), but then (3) would look different. The radical expressions in <code>SR</code> in (3) are not in general written in terms of real and imaginary part, so this cannot easily be changed to look like (2); for example:
</p>
<pre class="wiki">sage: QQbar(sqrt(2) + I).radical_expression()
sqrt(2*I*sqrt(2) + 1)
</pre><p>
On the other hand, making (2) look the same as (1) is also not trivial, as it would require special cases if the imaginary part is exactly 1 or -1, and even then, there are more differences between the representations, for example:
</p>
<pre class="wiki">sage: QQbar(1 + I) * 2^60
1152921504606846976*I + 1152921504606846976
sage: QQbar(2*I)^(1/2) * 2^60
1.1529215046068470?e18 + 1.1529215046068470?e18*I
</pre>
TicketslelievreTue, 14 Apr 2020 10:29:52 GMTcomponent, milestone changed; cc set
https://trac.sagemath.org/ticket/25458#comment:6
https://trac.sagemath.org/ticket/25458#comment:6
<ul>
<li><strong>cc</strong>
<em>slelievre</em> added
</li>
<li><strong>component</strong>
changed from <em>numerical</em> to <em>number fields</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-8.3</em> to <em>sage-9.2</em>
</li>
</ul>
TicketmkoeppeSat, 29 Aug 2020 16:37:33 GMTmilestone changed
https://trac.sagemath.org/ticket/25458#comment:7
https://trac.sagemath.org/ticket/25458#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>sage-9.2</em> to <em>sage-9.3</em>
</li>
</ul>
TicketmkoeppeSat, 13 Feb 2021 20:51:01 GMTmilestone changed
https://trac.sagemath.org/ticket/25458#comment:8
https://trac.sagemath.org/ticket/25458#comment:8
<ul>
<li><strong>milestone</strong>
changed from <em>sage-9.3</em> to <em>sage-9.4</em>
</li>
</ul>
<p>
Setting new milestone based on a cursory review of ticket status, priority, and last modification date.
</p>
Ticket