Sage: Ticket #18819: Real number fields with __cmp__ that gives a linear order induced by its real embedding
https://trac.sagemath.org/ticket/18819
<p>
It would seem to be useful to have a category of number fields whose <code>__cmp__</code> method agrees with the linear order of its embedding. (I might be using the word "category" in a non-technical sense.)
</p>
<p>
This has been the topic of past discussions and tickets (<a class="closed ticket" href="https://trac.sagemath.org/ticket/6132" title="defect: [with patch, needs work] cmp for number field elements (closed: duplicate)">#6132</a>, <a class="closed ticket" href="https://trac.sagemath.org/ticket/7160" title="defect: comparison with quadratic number field elements (closed: fixed)">#7160</a>, <a class="closed ticket" href="https://trac.sagemath.org/ticket/9752" title="defect: sorting of number field elements is broken (closed: duplicate)">#9752</a>),
and there is a conflict between at least two different desirable meanings for <code>__cmp__</code>, which could be
</p>
<ul><li>lexicographic comparison of the coordinates in the power basis of the generator;
</li><li>or, as proposed, the linear order.
</li></ul><p>
But it has not been completely resolved. The current status in Sage is inconsistent because quadratic number fields behave differently from number fields of a higher degree, due to <code>NumberFieldElement_quadratic.__cmp__</code>.
</p>
<pre class="wiki">sage: field, field_values, morphism = number_field_elements_from_algebraics((sqrt(2), sqrt(3)))
sage: field_values
[-a^3 + 3*a, -a^2 + 2]
# If I explicitly send the number field elements back into AA, I can compare them
sage: 1 < morphism(field_values[0]) < morphism(field_values[1]) < 2 < 3 * morphism(field_values[0]) < 5
True
# but the number field elements themselves do not compare according to that linear order.
sage: field_values[0] < field_values[1]
False
# and note that this is in contrast to the special case of quadratic
# extensions of the rationals, where comparisons seem to work as
# expected.
sage: from sage.rings.number_field.number_field_element_quadratic import NumberFieldElement_quadratic
K.<sqrt2> = QuadraticField(2,name='sqrt2')
sage: 1 < sqrt2 < 2 < 3 * sqrt2 < 5
True
</pre><p>
(I mentioned this to some developers during the Sage Days in Davis in 2013, but didn't follow up on it.)
</p>
<p>
An implementation of this in user code is brittle as it will depend on Sage internals. This is what I'm currently doing for my application:
<a class="ext-link" href="https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/real_number_field.sage"><span class="icon"></span>https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/real_number_field.sage</a>
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/18819
Trac 1.1.6vdelecroixMon, 29 Jun 2015 20:26:20 GMT
https://trac.sagemath.org/ticket/18819#comment:1
https://trac.sagemath.org/ticket/18819#comment:1
<p>
Duplicate of <a class="closed ticket" href="https://trac.sagemath.org/ticket/17830" title="enhancement: Comparison of number field elements dependent of real embedding (closed: fixed)">#17830</a>?
</p>
TicketmkoeppeMon, 29 Jun 2015 20:55:36 GMT
https://trac.sagemath.org/ticket/18819#comment:2
https://trac.sagemath.org/ticket/18819#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/18819#comment:1" title="Comment 1">vdelecroix</a>:
</p>
<blockquote class="citation">
<p>
Duplicate of <a class="closed ticket" href="https://trac.sagemath.org/ticket/17830" title="enhancement: Comparison of number field elements dependent of real embedding (closed: fixed)">#17830</a>?
</p>
</blockquote>
<p>
Indeed. Not sure how I managed to overlook this ticket.
</p>
TicketmkoeppeWed, 09 Mar 2016 03:19:35 GMTmilestone changed
https://trac.sagemath.org/ticket/18819#comment:3
https://trac.sagemath.org/ticket/18819#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.8</em> to <em>sage-duplicate/invalid/wontfix</em>
</li>
</ul>
<p>
Most of this is a duplicate of <a class="closed ticket" href="https://trac.sagemath.org/ticket/17830" title="enhancement: Comparison of number field elements dependent of real embedding (closed: fixed)">#17830</a>; but see <a class="closed ticket" href="https://trac.sagemath.org/ticket/20181" title="enhancement: number_field_elements_from_algebraics should create embedded number ... (closed: fixed)">#20181</a> for the remaining "wishlist item" of having <code>number_field_elements_from_algebraics</code> create embedded elements by default, or by option.
</p>
TicketmkoeppeSun, 27 Mar 2016 01:02:12 GMTstatus changed
https://trac.sagemath.org/ticket/18819#comment:4
https://trac.sagemath.org/ticket/18819#comment:4
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
Setting this to "needs_review" so that this ticket can be closed.
</p>
TicketmmezzarobbaSun, 27 Mar 2016 08:58:41 GMTstatus changed
https://trac.sagemath.org/ticket/18819#comment:5
https://trac.sagemath.org/ticket/18819#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
TicketvbraunSun, 12 Jun 2016 12:02:30 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/18819#comment:6
https://trac.sagemath.org/ticket/18819#comment:6
<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>
</ul>
Ticket