Skip to content

Commit

Permalink
Fix CIF sorting by forcing key=repr.
Browse files Browse the repository at this point in the history
It turns out sorting in `ComplexIntervalField` is broken. In this case,
there are two elements that do not compare.
```
sage: x = PolynomialRing(CBF, 'x').gen()
sage: _, a, b, _ = sorted((x^4 - 3).roots(ComplexIntervalField(100),
multiplicities=False))
sage: a == b
False
sage: a < b
False
sage: a > b
False
sage: sorted([a,b])
[0.?e-37 + 1.31607401295249246081921890180?*I,
 0.?e-37 - 1.31607401295249246081921890180?*I]
sage: sorted([b,a])
[0.?e-37 - 1.31607401295249246081921890180?*I,
 0.?e-37 + 1.31607401295249246081921890180?*I]
```
  • Loading branch information
tornaria committed Feb 5, 2025
1 parent d8d87fd commit 5f2cfff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/sage/rings/complex_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
{[-1.316074012952492460819218901797 +/- 9.7e-34],
[1.316074012952492460819218901797 +/- 9.7e-34]}
sage: set((x^4 - 3).roots(ComplexIntervalField(100), multiplicities=False))
{-1.31607401295249246081921890180? + 0.?e-37*I,
sage: sorted((x^4 - 3).roots(ComplexIntervalField(100),
....: multiplicities=False), key=repr)
[-1.31607401295249246081921890180? + 0.?e-37*I,
0.?e-37 + 1.31607401295249246081921890180?*I,
0.?e-37 - 1.31607401295249246081921890180?*I,
1.31607401295249246081921890180? + 0.?e-37*I}
1.31607401295249246081921890180? + 0.?e-37*I]
sage: set((x^2 - i/3).roots(ComplexBallField(2), multiplicities=False))
{[+/- 0.409] + [+/- 0.409]*I, [+/- 0.409] + [+/- 0.409]*I}
Expand Down

0 comments on commit 5f2cfff

Please sign in to comment.