Opened 4 years ago

Closed 3 years ago

#18819 closed defect (fixed)

Real number fields with __cmp__ that gives a linear order induced by its real embedding

Reported by: mkoeppe Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: number fields Keywords:
Cc: vbraun, gagern, vdelecroix Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


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
# but the number field elements themselves do not compare according to that linear order.
sage: field_values[0] < field_values[1]

# 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

(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:

Change History (6)

comment:1 follow-up: Changed 4 years ago by vdelecroix

Duplicate of #17830?

Last edited 4 years ago by vdelecroix (previous) (diff)

comment:2 in reply to: ↑ 1 Changed 4 years ago by mkoeppe

Replying to vdelecroix:

Duplicate of #17830?

Indeed. Not sure how I managed to overlook this ticket.

comment:3 Changed 4 years ago by mkoeppe

  • Milestone changed from sage-6.8 to sage-duplicate/invalid/wontfix

Most of this is a duplicate of #17830; but see #20181 for the remaining "wishlist item" of having number_field_elements_from_algebraics create embedded elements by default, or by option.

comment:4 Changed 4 years ago by mkoeppe

  • Status changed from new to needs_review

Setting this to "needs_review" so that this ticket can be closed.

comment:5 Changed 4 years ago by mmezzarobba

  • Status changed from needs_review to positive_review

comment:6 Changed 3 years ago by vbraun

  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.