Opened 5 years ago

Closed 4 years ago

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

Reported by: Owned by: mkoeppe major sage-duplicate/invalid/wontfix number fields vbraun, gagern, vdelecroix N/A

### Description

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

### comment:1 follow-up: ↓ 2 Changed 5 years ago by vdelecroix

Duplicate of #17380?

Version 0, edited 5 years ago by vdelecroix (next)

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

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 4 years ago by vbraun

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