id summary reporter owner description type status priority milestone component resolution keywords cc merged author reviewer upstream work_issues branch commit dependencies stopgaps
18819 Real number fields with __cmp__ that gives a linear order induced by its real embedding mkoeppe "It would seem to be useful to have a category of number fields whose `__cmp__` method agrees with the linear order of its embedding. (I might be using the word ""category"" in a non-technical sense.)
This has been the topic of past discussions and tickets (#6132, #7160, #9752),
and there is a conflict between at least two different desirable meanings for `__cmp__`, which could be
- lexicographic comparison of the coordinates in the power basis of the generator;
- or, as proposed, the linear order.
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 `NumberFieldElement_quadratic.__cmp__`.
{{{
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. = QuadraticField(2,name='sqrt2')
sage: 1 < sqrt2 < 2 < 3 * sqrt2 < 5
True
}}}
(I mentioned this to some developers during the Sage Days in Davis in 2013, but didn't follow up on it.)
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:
https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/real_number_field.sage
" defect closed major sage-duplicate/invalid/wontfix number fields fixed vbraun gagern vdelecroix N/A