Skip to content

Commit e788164

Browse files
author
Release Manager
committed
gh-37079: use Parent in Monsky-Washnitzer use `Parent` in the modified file also removing `__neg__` method and some other details ### 📝 Checklist - [ ] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. URL: #37079 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 74bcb8e + 1c4c375 commit e788164

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
from sage.arith.misc import integer_ceil as ceil
5050
from sage.arith.misc import binomial
51+
from sage.categories.algebras import Algebras
5152
from sage.functions.log import log
5253
from sage.matrix.constructor import matrix
5354
from sage.misc.cachefunc import cached_method
@@ -72,17 +73,17 @@
7273
from sage.rings.laurent_series_ring import is_LaurentSeriesRing
7374
from sage.rings.padics.factory import Qp as pAdicField
7475
from sage.rings.polynomial.polynomial_element import Polynomial
75-
from sage.rings.ring import CommutativeAlgebra
7676
from sage.schemes.elliptic_curves.constructor import EllipticCurve
7777
from sage.schemes.elliptic_curves.ell_generic import is_EllipticCurve
7878
from sage.schemes.hyperelliptic_curves.constructor import HyperellipticCurve
7979
from sage.schemes.hyperelliptic_curves.hyperelliptic_generic import is_HyperellipticCurve
80-
from sage.structure.element import CommutativeAlgebraElement, ModuleElement
80+
from sage.structure.element import ModuleElement
81+
from sage.structure.parent import Parent
8182
from sage.structure.richcmp import richcmp
8283
from sage.structure.unique_representation import UniqueRepresentation
8384

8485

85-
class SpecialCubicQuotientRingElement(CommutativeAlgebraElement):
86+
class SpecialCubicQuotientRingElement(ModuleElement):
8687
"""
8788
An element of a :class:`SpecialCubicQuotientRing`.
8889
"""
@@ -108,11 +109,20 @@ def __init__(self, parent, p0, p1, p2, check=True):
108109
sage: from sage.schemes.hyperelliptic_curves.monsky_washnitzer import SpecialCubicQuotientRingElement
109110
sage: SpecialCubicQuotientRingElement(R, 2, 3, 4)
110111
(2) + (3)*x + (4)*x^2
112+
113+
TESTS::
114+
115+
sage: B.<t> = PolynomialRing(Integers(125))
116+
sage: R = monsky_washnitzer.SpecialCubicQuotientRing(t^3 - t + B(1/4))
117+
sage: TestSuite(R).run()
118+
sage: p = R.create_element(t, t^2 - 2, 3)
119+
sage: -p
120+
(124*T) + (124*T^2 + 2)*x + (122)*x^2
111121
"""
112122
if not isinstance(parent, SpecialCubicQuotientRing):
113123
raise TypeError(f"parent (={parent}) must be a SpecialCubicQuotientRing")
114124

115-
CommutativeAlgebraElement.__init__(self, parent)
125+
ModuleElement.__init__(self, parent)
116126

117127
if check:
118128
poly_ring = parent._poly_ring
@@ -145,7 +155,7 @@ def coeffs(self):
145155
column.extend([base_ring(0)] * (degree - len(column)))
146156
return coeffs
147157

148-
def __bool__(self):
158+
def __bool__(self) -> bool:
149159
"""
150160
EXAMPLES::
151161
@@ -161,7 +171,7 @@ def __bool__(self):
161171
"""
162172
return bool(self._triple[0]) or bool(self._triple[1]) or bool(self._triple[2])
163173

164-
def _richcmp_(self, other, op):
174+
def _richcmp_(self, other, op) -> bool:
165175
"""
166176
EXAMPLES::
167177
@@ -176,7 +186,7 @@ def _richcmp_(self, other, op):
176186
"""
177187
return richcmp(self._triple, other._triple, op)
178188

179-
def _repr_(self):
189+
def _repr_(self) -> str:
180190
"""
181191
EXAMPLES::
182192
@@ -188,7 +198,7 @@ def _repr_(self):
188198
"""
189199
return "(%s) + (%s)*x + (%s)*x^2" % self._triple
190200

191-
def _latex_(self):
201+
def _latex_(self) -> str:
192202
"""
193203
EXAMPLES::
194204
@@ -387,7 +397,7 @@ def _mul_(self, other):
387397
check=False)
388398

389399

390-
class SpecialCubicQuotientRing(CommutativeAlgebra):
400+
class SpecialCubicQuotientRing(UniqueRepresentation, Parent):
391401
r"""
392402
Specialised class for representing the quotient ring
393403
`R[x,T]/(T - x^3 - ax - b)`, where `R` is an
@@ -419,6 +429,7 @@ class SpecialCubicQuotientRing(CommutativeAlgebra):
419429
sage: R
420430
SpecialCubicQuotientRing over Ring of integers modulo 125
421431
with polynomial T = x^3 + 124*x + 94
432+
sage: TestSuite(R).run()
422433
423434
Get generators::
424435
@@ -513,21 +524,15 @@ def __init__(self, Q, laurent_series=False):
513524
raise ArithmeticError("2 and 3 must be invertible in the "
514525
"coefficient ring (=%s) of Q" % base_ring)
515526

516-
# CommutativeAlgebra.__init__ tries to establish a coercion
517-
# from the base ring, by github issue #9138. The corresponding
518-
# hom set is cached. In order to use self as cache key, its
519-
# string representation is used. In otder to get the string
520-
# representation, we need to know the attributes _a and
521-
# _b. Hence, in #9138, we have to move CommutativeAlgebra.__init__
522-
# further down:
523527
self._a = Q[1]
524528
self._b = Q[0]
525529
if laurent_series:
526530
self._poly_ring = LaurentSeriesRing(base_ring, 'T') # R[T]
527531
else:
528532
self._poly_ring = PolynomialRing(base_ring, 'T') # R[T]
529533
self._poly_generator = self._poly_ring.gen(0) # the generator T
530-
CommutativeAlgebra.__init__(self, base_ring)
534+
Parent.__init__(self, base=base_ring,
535+
category=Algebras(base_ring).Commutative())
531536

532537
# Precompute a matrix that is used in the Toom-Cook multiplication.
533538
# This is where we need 2 and 3 invertible.
@@ -537,7 +542,7 @@ def __init__(self, Q, laurent_series=False):
537542
m = matrix(QQ, [[1, -12, 2], [-3, 30, -3], [2, -12, 1]]) / 6
538543
self._speedup_matrix = m.change_ring(base_ring).list()
539544

540-
def _repr_(self):
545+
def _repr_(self) -> str:
541546
"""
542547
String representation.
543548
@@ -654,7 +659,7 @@ def _coerce_map_from_(self, R):
654659
Element = SpecialCubicQuotientRingElement
655660

656661

657-
def transpose_list(input):
662+
def transpose_list(input) -> list[list]:
658663
"""
659664
INPUT:
660665
@@ -1854,7 +1859,7 @@ def matrix_of_frobenius_hyperelliptic(Q, p=None, prec=None, M=None):
18541859
return M.transpose(), [f for f, a in reduced]
18551860

18561861

1857-
class SpecialHyperellipticQuotientElement(CommutativeAlgebraElement):
1862+
class SpecialHyperellipticQuotientElement(ModuleElement):
18581863
r"""
18591864
Element in the Hyperelliptic quotient ring.
18601865
@@ -1880,7 +1885,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
18801885
sage: elt = MW(x + x**2 + y - 77)
18811886
sage: TestSuite(elt).run()
18821887
"""
1883-
CommutativeAlgebraElement.__init__(self, parent)
1888+
ModuleElement.__init__(self, parent)
18841889
if not check:
18851890
self._f = parent._poly_ring(val, check=False)
18861891
return
@@ -1896,7 +1901,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
18961901
if offset != 0:
18971902
self._f = self._f.parent()([a << offset for a in self._f], check=False)
18981903

1899-
def _richcmp_(self, other, op):
1904+
def _richcmp_(self, other, op) -> bool:
19001905
"""
19011906
Compare the elements.
19021907
@@ -2358,7 +2363,8 @@ def coeffs(self, R=None):
23582363
coeffs = transpose_list(coeffs)
23592364
return [V(a) for a in coeffs], y_offset
23602365

2361-
class SpecialHyperellipticQuotientRing(UniqueRepresentation, CommutativeAlgebra):
2366+
2367+
class SpecialHyperellipticQuotientRing(UniqueRepresentation, Parent):
23622368
"""
23632369
The special hyperelliptic quotient ring.
23642370
"""
@@ -2380,18 +2386,10 @@ def __init__(self, Q, R=None, invert_y=True):
23802386
23812387
sage: HQR is SpecialHyperellipticQuotientRing(E)
23822388
True
2383-
23842389
"""
23852390
if R is None:
23862391
R = Q.base_ring()
23872392

2388-
# Github issue #9138: CommutativeAlgebra.__init__ must not be
2389-
# done so early. It tries to register a coercion, but that
2390-
# requires the hash being available. But the hash, in its
2391-
# default implementation, relies on the string representation,
2392-
# which is not available at this point.
2393-
# CommutativeAlgebra.__init__(self, R) # moved to below.
2394-
23952393
x = PolynomialRing(R, 'xx').gen()
23962394
if is_EllipticCurve(Q):
23972395
E = Q
@@ -2428,10 +2426,7 @@ def __init__(self, Q, R=None, invert_y=True):
24282426
self._series_ring_y = self._series_ring.gen(0)
24292427
self._series_ring_0 = self._series_ring.zero()
24302428

2431-
# Github issue #9138: Initialise the commutative algebra here!
2432-
# Below, we do self(self._poly_ring.gen(0)), which requires
2433-
# the initialisation being finished.
2434-
CommutativeAlgebra.__init__(self, R)
2429+
Parent.__init__(self, base=R, category=Algebras(R).Commutative())
24352430

24362431
self._poly_ring = PolynomialRing(self._series_ring, 'x')
24372432

@@ -2445,7 +2440,7 @@ def __init__(self, Q, R=None, invert_y=True):
24452440
self._monomial_diffs = {}
24462441
self._monomial_diff_coeffs = {}
24472442

2448-
def _repr_(self):
2443+
def _repr_(self) -> str:
24492444
r"""
24502445
String representation.
24512446
@@ -2495,7 +2490,7 @@ def change_ring(self, R):
24952490
over Integer Ring
24962491
"""
24972492
return SpecialHyperellipticQuotientRing(self._Q.change_ring(R), R,
2498-
is_LaurentSeriesRing(self._series_ring))
2493+
is_LaurentSeriesRing(self._series_ring))
24992494

25002495
def _element_constructor_(self, val, offset=0, check=True):
25012496
r"""
@@ -2787,7 +2782,7 @@ def monsky_washnitzer(self):
27872782
"""
27882783
return self._monsky_washnitzer
27892784

2790-
def is_field(self, proof=True):
2785+
def is_field(self, proof=True) -> bool:
27912786
"""
27922787
Return ``False`` as ``self`` is not a field.
27932788

0 commit comments

Comments
 (0)