Skip to content

Commit

Permalink
sagemathgh-39018: Fix Singular polynomial comparison
Browse files Browse the repository at this point in the history
    
Fixes sagemath#35681

Basically, I think this change makes the comparison makes more sense
(apart from that, it should speed up the comparison a bit because it
only calls `cfGreater` when `cfEqual` returns `False`, and get rid of
the `cfSub`)

After this change, **as long as `cfGreater` defines a total order, you
get a total order on the polynomials**.
For example now `Integers(10)[]` has a total order.

For unordered fields however, `cfGreater` may not define a total order
anyway;
but in newer Singular, `cfGreater` now defines a total order. It's not
always consistent with `cfGreaterZero` though.
Singular/Singular#1253 (comment)

There's a lot of test breakage because now we change which polynomial
compares greater than `0`, and that is used to determine whether the
sign to display is `+` or `-` in several places.

--------

More detail:

```python
    TESTS::

        sage: R.<x, y> = ZZ[]
        sage: x^2+x > x^2
        True
        sage: x^2 > x^2-x                       # NEW
        True
        sage: x^2 > x^2-x                       # OLD
        False
        sage: x^2+x > x^2-x
        True
        sage: x^2 > 0
        True
        sage: -x^2 > 0                          # NEW
        False
        sage: -x^2 > 0                          # OLD
        True
        sage: x^2 > -x^2
        True

    ::

        sage: R.<x, y> = GF(7)[]
        sage: x^2+x > x^2
        True
        sage: x^2 > x^2-x                       # NEW
        True
        sage: x^2 > x^2-x                       # OLD
        False
        sage: x^2+x > x^2-x                     # NEW
        False
        sage: x^2+x > x^2-x                     # OLD
        True
        sage: x^2 > 0
        True
        sage: -x^2 > 0                          # NEW
        False
        sage: -x^2 > 0                          # OLD
        True
        sage: x^2 > -x^2                        # NEW
        False
        sage: x^2 > -x^2                        # OLD
        True

    ::

        sage: R.<x, y> = Integers(8)[]
        sage: x^2+x > x^2
        True
        sage: x^2 > x^2-x                       # NEW
        True
        sage: x^2 > x^2-x                       # OLD
        False
        sage: x^2+x > x^2-x
        True
        sage: x^2 > 0
        True
        sage: -x^2 > 0                          # NEW
        False
        sage: -x^2 > 0                          # OLD
        True
        sage: x^2 > -x^2
        True

    ::

        sage: R.<x, y> = Integers(10)[]
        sage: x^2+x > x^2
        True
        sage: x^2 > x^2-x
        False
        sage: x^2+x > x^2-x                     # NEW
        False
        sage: x^2+x > x^2-x                     # OLD
        True
        sage: x^2 > 0
        True
        sage: -x^2 > 0
        True
        sage: x^2 > -x^2                        # NEW
        False
        sage: x^2 > -x^2                        # OLD
        True

    ::

        sage: R.<x, y> = ZZ[]
        sage: l = [i*x+j*x^2 for i in range(-5, 5) for j in range(-5,
5)]
        sage: l.sort()
        sage: for i in range(len(l)):
        ....:     for b in l[:i]:
        ....:         assert b < l[i], (b, l[i])

    ::

        sage: R.<x, y> = Integers(10)[]
        sage: l = [i*x+j*y for i in range(7) for j in range(7)]
        sage: l.sort()
        sage: for i in range(len(l)):           # NEW
        ....:     for b in l[:i]:
        ....:         assert b < l[i], (b, l[i])
        sage: for i in range(len(l)):           # OLD
        ....:     for b in l[:i]:
        ....:         assert b < l[i], (b, l[i])
        Traceback (most recent call last):
        ...
        AssertionError: (y, 2*y)
```

The comparison function was added all the way back in 2007 without
explanation e22dc86

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39018
Reported by: user202729
Reviewer(s): Kwankyu Lee, user202729
  • Loading branch information
Release Manager committed Jan 25, 2025
2 parents 86ab4a9 + f18e9fc commit debb3ea
Show file tree
Hide file tree
Showing 34 changed files with 518 additions and 472 deletions.
6 changes: 3 additions & 3 deletions src/doc/de/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ wir diese schneiden und dann die irreduziblen Komponenten berechnen.
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
6 changes: 3 additions & 3 deletions src/doc/en/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ intersecting them and computing the irreducible components.
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
6 changes: 3 additions & 3 deletions src/doc/fr/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ irréductibles.
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
6 changes: 3 additions & 3 deletions src/doc/ja/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Sageでは,任意の代数多様体を定義することができるが,そ
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
6 changes: 3 additions & 3 deletions src/doc/pt/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ irredutíveis.
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
6 changes: 3 additions & 3 deletions src/doc/ru/tutorial/tour_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Sage позволяет создавать любые алгебраически
sage: V = C2.intersection(C3)
sage: V.irreducible_components()
[Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y - 1,
x,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
y,
x - 1,
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x + y + 2,
2*y^2 + 4*y + 3]
Expand Down
87 changes: 42 additions & 45 deletions src/sage/algebras/hecke_algebras/ariki_koike_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ class ArikiKoikeAlgebra(Parent, UniqueRepresentation):
sage: T1 * L1 * T2 * L3 * T1 * T2
-(q-q^2)*L2*L3*T[2] + q*L1*L2*T[2,1] - (1-q)*L1*L2*T[2,1,2]
sage: L1^3
u0*u1*u2 + ((-u0*u1-u0*u2-u1*u2))*L1 + ((u0+u1+u2))*L1^2
u0*u1*u2 - ((u0*u1+u0*u2+u1*u2))*L1 + ((u0+u1+u2))*L1^2
sage: L3 * L2 * L1
L1*L2*L3
sage: u = LT.u()
sage: q = LT.q()
sage: (q + 2*u[0]) * (T1 * T2) * L3
(-2*u0+(2*u0-1)*q+q^2)*L3*T[1] + (-2*u0+(2*u0-1)*q+q^2)*L2*T[2]
+ (2*u0+q)*L1*T[1,2]
-(2*u0+(-2*u0+1)*q-q^2)*L3*T[1] - (2*u0+(-2*u0+1)*q-q^2)*L2*T[2]
+ (2*u0+q)*L1*T[1,2]
We check the defining relations::
Expand Down Expand Up @@ -789,11 +789,11 @@ def L(self, i=None):
sage: LT = algebras.ArikiKoike(1, 3).LT()
sage: LT.L(2)
u + (-u*q^-1+u)*T[1]
u - (u*q^-1-u)*T[1]
sage: LT.L()
[u,
u + (-u*q^-1+u)*T[1],
u + (-u*q^-1+u)*T[2] + (-u*q^-2+u*q^-1)*T[2,1,2]]
u - (u*q^-1-u)*T[1],
u - (u*q^-1-u)*T[2] - (u*q^-2-u*q^-1)*T[2,1,2]]
"""
G = self.algebra_generators()
if i is None:
Expand Down Expand Up @@ -824,18 +824,18 @@ def product_on_basis(self, m1, m2):
sage: L1^2 * T1 * L1^2 * T1
q*L1^2*L2^2 + (1-q)*L1^3*L2*T[1]
sage: L1^3 * T1 * L1^2 * T1
(-u0*u1*u2*u3+u0*u1*u2*u3*q)*L2*T[1]
+ ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3)+(-u0*u1*u2-u0*u1*u3-u0*u2*u3-u1*u2*u3)*q)*L1*L2*T[1]
+ ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3)+(u0*u1+u0*u2+u1*u2+u0*u3+u1*u3+u2*u3)*q)*L1^2*L2*T[1]
+ ((u0+u1+u2+u3)+(-u0-u1-u2-u3)*q)*L1^3*L2*T[1] + q*L1^3*L2^2
-(u0*u1*u2*u3-u0*u1*u2*u3*q)*L2*T[1]
+ ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3)+(-u0*u1*u2-u0*u1*u3-u0*u2*u3-u1*u2*u3)*q)*L1*L2*T[1]
- ((u0*u1+u0*u2+u1*u2+u0*u3+u1*u3+u2*u3)+(-u0*u1-u0*u2-u1*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3*T[1] ...
- (q^-1-1)*L1^3*L2*T[1]
sage: H._Li_power(2, 4) == L2^4
Expand All @@ -1078,20 +1078,20 @@ def _Li_power(self, i, m):
L_1^0 = 1
L_1^1 = L1
L_1^2 = L1^2
L_1^3 = u0*u1*u2 + ((-u0*u1-u0*u2-u1*u2))*L1 + ((u0+u1+u2))*L1^2
L_1^3 = u0*u1*u2 - ((u0*u1+u0*u2+u1*u2))*L1 + ((u0+u1+u2))*L1^2
L_2^0 = 1
L_2^1 = L2
L_2^2 = L2^2
L_2^3 = u0*u1*u2 + (-u0*u1*u2*q^-1+u0*u1*u2)*T[1]
+ ((-u0*u1-u0*u2-u1*u2))*L2 + ((u0+u1+u2))*L2^2
L_2^3 = u0*u1*u2 - (u0*u1*u2*q^-1-u0*u1*u2)*T[1]
- ((u0*u1+u0*u2+u1*u2))*L2 + ((u0+u1+u2))*L2^2
+ ((u0+u1+u2)*q^-1+(-u0-u1-u2))*L1*L2*T[1]
- (q^-1-1)*L1*L2^2*T[1] - (q^-1-1)*L1^2*L2*T[1]
L_3^0 = 1
L_3^1 = L3
L_3^2 = L3^2
L_3^3 = u0*u1*u2 + (-u0*u1*u2*q^-1+u0*u1*u2)*T[2]
+ (-u0*u1*u2*q^-2+u0*u1*u2*q^-1)*T[2,1,2]
+ ((-u0*u1-u0*u2-u1*u2))*L3 + ((u0+u1+u2))*L3^2
L_3^3 = u0*u1*u2 - (u0*u1*u2*q^-1-u0*u1*u2)*T[2]
- (u0*u1*u2*q^-2-u0*u1*u2*q^-1)*T[2,1,2]
- ((u0*u1+u0*u2+u1*u2))*L3 + ((u0+u1+u2))*L3^2
+ ((u0+u1+u2)*q^-1+(-u0-u1-u2))*L2*L3*T[2]
- (q^-1-1)*L2*L3^2*T[2] - (q^-1-1)*L2^2*L3*T[2]
+ ((u0+u1+u2)*q^-2+(-2*u0-2*u1-2*u2)*q^-1+(u0+u1+u2))*L1*L3*T[1,2]
Expand Down Expand Up @@ -1376,11 +1376,11 @@ def L(self, i=None):
sage: T = algebras.ArikiKoike(1, 3).T()
sage: T.L(2)
u + (-u*q^-1+u)*T[1]
u - (u*q^-1-u)*T[1]
sage: T.L()
[u,
u + (-u*q^-1+u)*T[1],
u + (-u*q^-1+u)*T[2] + (-u*q^-2+u*q^-1)*T[2,1,2]]
u - (u*q^-1-u)*T[1],
u - (u*q^-1-u)*T[2] - (u*q^-2-u*q^-1)*T[2,1,2]]
TESTS:
Expand Down Expand Up @@ -1432,10 +1432,10 @@ def product_on_basis(self, m1, m2):
sage: T2 * (T2 * T1 * T0)
-(1-q)*T[2,1,0] + q*T[1,0]
sage: (T1 * T0 * T1 * T0) * T0
(-u0*u1)*T[1,0,1] + ((u0+u1))*T[0,1,0,1]
-u0*u1*T[1,0,1] + ((u0+u1))*T[0,1,0,1]
sage: (T0 * T1 * T0 * T1) * (T0 * T1)
(-u0*u1*q)*T[1,0] + (u0*u1-u0*u1*q)*T[1,0,1]
+ ((u0+u1)*q)*T[0,1,0] + ((-u0-u1)+(u0+u1)*q)*T[0,1,0,1]
-u0*u1*q*T[1,0] + (u0*u1-u0*u1*q)*T[1,0,1]
+ ((u0+u1)*q)*T[0,1,0] - ((u0+u1)+(-u0-u1)*q)*T[0,1,0,1]
sage: T1 * (T0 * T2 * T1 * T0)
T[1,0,2,1,0]
sage: (T1 * T2) * (T2 * T1 * T0)
Expand All @@ -1462,7 +1462,7 @@ def product_on_basis(self, m1, m2):
sage: T = algebras.ArikiKoike(2, 3).T()
sage: T0, T1, T2 = T.T()
sage: (T1 * T0 * T1) * (T0 * T0)
(-u0*u1)*T[1,0,1] + ((u0+u1))*T[0,1,0,1]
-u0*u1*T[1,0,1] + ((u0+u1))*T[0,1,0,1]
sage: T1 * T.L(3) * T2 * T1 * T0 - T1 * (T.L(3) * T2 * T1 * T0)
0
Expand Down Expand Up @@ -1674,42 +1674,39 @@ def _product_TT(self, kp, a, k, b):
sage: T._product_TT(1, 2, 0, 1)
T[1,0,0,0]
sage: T._product_TT(1, 3, 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,0,1,0,0,1]
sage: T._product_TT(2,2,2,2)
(-u0*u1*u2+u0*u1*u2*q)*T[2,1,0,2]
-(u0*u1*u2-u0*u1*u2*q)*T[2,1,0,2]
+ (u0*u1*u2-u0*u1*u2*q)*T[1,0,2,1]
+ ((u0+u1+u2)+(-u0-u1-u2)*q)*T[1,0,2,1,0,0]
+ ((-u0-u1-u2)+(u0+u1+u2)*q)*T[1,0,0,2,1,0]
+ T[1,0,0,2,1,0,0,1]
- ((u0+u1+u2)+(-u0-u1-u2)*q)*T[1,0,0,2,1,0] + T[1,0,0,2,1,0,0,1]
sage: T._product_TT(3,2,3,2)
(-u0*u1*u2+u0*u1*u2*q)*T[3,2,1,0,3,2]
-(u0*u1*u2-u0*u1*u2*q)*T[3,2,1,0,3,2]
+ (u0*u1*u2-u0*u1*u2*q)*T[2,1,0,3,2,1]
+ ((u0+u1+u2)+(-u0-u1-u2)*q)*T[2,1,0,3,2,1,0,0]
+ ((-u0-u1-u2)+(u0+u1+u2)*q)*T[2,1,0,0,3,2,1,0]
- ((u0+u1+u2)+(-u0-u1-u2)*q)*T[2,1,0,0,3,2,1,0]
+ T[2,1,0,0,3,2,1,0,0,1]
"""
# Quadratic relation: S_i^2 - (q - 1) S_i - q == 0
Expand Down
Loading

0 comments on commit debb3ea

Please sign in to comment.