Skip to content

Commit dd30f47

Browse files
committed
use Parent in Monsky-Washnitzer
1 parent 439065e commit dd30f47

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

src/sage/schemes/hyperelliptic_curves/monsky_washnitzer.py

Lines changed: 34 additions & 41 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 Element, 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,19 @@ 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: p = R.create_element(t, t^2 - 2, 3)
118+
sage: -p
119+
(124*T) + (124*T^2 + 2)*x + (122)*x^2
111120
"""
112121
if not isinstance(parent, SpecialCubicQuotientRing):
113122
raise TypeError(f"parent (={parent}) must be a SpecialCubicQuotientRing")
114123

115-
CommutativeAlgebraElement.__init__(self, parent)
124+
ModuleElement.__init__(self, parent)
116125

117126
if check:
118127
poly_ring = parent._poly_ring
@@ -145,7 +154,7 @@ def coeffs(self):
145154
column.extend([base_ring(0)] * (degree - len(column)))
146155
return coeffs
147156

148-
def __bool__(self):
157+
def __bool__(self) -> bool:
149158
"""
150159
EXAMPLES::
151160
@@ -161,7 +170,7 @@ def __bool__(self):
161170
"""
162171
return bool(self._triple[0]) or bool(self._triple[1]) or bool(self._triple[2])
163172

164-
def _richcmp_(self, other, op):
173+
def _richcmp_(self, other, op) -> bool:
165174
"""
166175
EXAMPLES::
167176
@@ -176,7 +185,7 @@ def _richcmp_(self, other, op):
176185
"""
177186
return richcmp(self._triple, other._triple, op)
178187

179-
def _repr_(self):
188+
def _repr_(self) -> str:
180189
"""
181190
EXAMPLES::
182191
@@ -188,7 +197,7 @@ def _repr_(self):
188197
"""
189198
return "(%s) + (%s)*x + (%s)*x^2" % self._triple
190199

191-
def _latex_(self):
200+
def _latex_(self) -> str:
192201
"""
193202
EXAMPLES::
194203
@@ -387,7 +396,7 @@ def _mul_(self, other):
387396
check=False)
388397

389398

390-
class SpecialCubicQuotientRing(CommutativeAlgebra):
399+
class SpecialCubicQuotientRing(Parent):
391400
r"""
392401
Specialised class for representing the quotient ring
393402
`R[x,T]/(T - x^3 - ax - b)`, where `R` is an
@@ -513,12 +522,12 @@ def __init__(self, Q, laurent_series=False):
513522
raise ArithmeticError("2 and 3 must be invertible in the "
514523
"coefficient ring (=%s) of Q" % base_ring)
515524

516-
# CommutativeAlgebra.__init__ tries to establish a coercion
525+
# .__init__ tries to establish a coercion
517526
# from the base ring, by github issue #9138. The corresponding
518527
# hom set is cached. In order to use self as cache key, its
519528
# string representation is used. In otder to get the string
520529
# representation, we need to know the attributes _a and
521-
# _b. Hence, in #9138, we have to move CommutativeAlgebra.__init__
530+
# _b. Hence, in #9138, we have to move .__init__
522531
# further down:
523532
self._a = Q[1]
524533
self._b = Q[0]
@@ -527,7 +536,8 @@ def __init__(self, Q, laurent_series=False):
527536
else:
528537
self._poly_ring = PolynomialRing(base_ring, 'T') # R[T]
529538
self._poly_generator = self._poly_ring.gen(0) # the generator T
530-
CommutativeAlgebra.__init__(self, base_ring)
539+
Parent.__init__(self, base=base_ring,
540+
category=Algebras(base_ring).Commutative())
531541

532542
# Precompute a matrix that is used in the Toom-Cook multiplication.
533543
# This is where we need 2 and 3 invertible.
@@ -654,7 +664,7 @@ def _coerce_map_from_(self, R):
654664
Element = SpecialCubicQuotientRingElement
655665

656666

657-
def transpose_list(input):
667+
def transpose_list(input) -> list[list]:
658668
"""
659669
INPUT:
660670
@@ -1854,7 +1864,7 @@ def matrix_of_frobenius_hyperelliptic(Q, p=None, prec=None, M=None):
18541864
return M.transpose(), [f for f, a in reduced]
18551865

18561866

1857-
class SpecialHyperellipticQuotientElement(CommutativeAlgebraElement):
1867+
class SpecialHyperellipticQuotientElement(ModuleElement):
18581868
r"""
18591869
Element in the Hyperelliptic quotient ring.
18601870
@@ -1880,7 +1890,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
18801890
sage: elt = MW(x + x**2 + y - 77)
18811891
sage: TestSuite(elt).run()
18821892
"""
1883-
CommutativeAlgebraElement.__init__(self, parent)
1893+
ModuleElement.__init__(self, parent)
18841894
if not check:
18851895
self._f = parent._poly_ring(val, check=False)
18861896
return
@@ -1896,7 +1906,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
18961906
if offset != 0:
18971907
self._f = self._f.parent()([a << offset for a in self._f], check=False)
18981908

1899-
def _richcmp_(self, other, op):
1909+
def _richcmp_(self, other, op) -> bool:
19001910
"""
19011911
Compare the elements.
19021912
@@ -2358,7 +2368,8 @@ def coeffs(self, R=None):
23582368
coeffs = transpose_list(coeffs)
23592369
return [V(a) for a in coeffs], y_offset
23602370

2361-
class SpecialHyperellipticQuotientRing(UniqueRepresentation, CommutativeAlgebra):
2371+
2372+
class SpecialHyperellipticQuotientRing(UniqueRepresentation, Parent):
23622373
"""
23632374
The special hyperelliptic quotient ring.
23642375
"""
@@ -2385,12 +2396,12 @@ def __init__(self, Q, R=None, invert_y=True):
23852396
if R is None:
23862397
R = Q.base_ring()
23872398

2388-
# Github issue #9138: CommutativeAlgebra.__init__ must not be
2399+
# Github issue #9138: .__init__ must not be
23892400
# done so early. It tries to register a coercion, but that
23902401
# requires the hash being available. But the hash, in its
23912402
# default implementation, relies on the string representation,
23922403
# which is not available at this point.
2393-
# CommutativeAlgebra.__init__(self, R) # moved to below.
2404+
# .__init__(self, R) # moved to below.
23942405

23952406
x = PolynomialRing(R, 'xx').gen()
23962407
if is_EllipticCurve(Q):
@@ -2428,10 +2439,10 @@ def __init__(self, Q, R=None, invert_y=True):
24282439
self._series_ring_y = self._series_ring.gen(0)
24292440
self._series_ring_0 = self._series_ring.zero()
24302441

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

24362447
self._poly_ring = PolynomialRing(self._series_ring, 'x')
24372448

@@ -2495,7 +2506,7 @@ def change_ring(self, R):
24952506
over Integer Ring
24962507
"""
24972508
return SpecialHyperellipticQuotientRing(self._Q.change_ring(R), R,
2498-
is_LaurentSeriesRing(self._series_ring))
2509+
is_LaurentSeriesRing(self._series_ring))
24992510

25002511
def _element_constructor_(self, val, offset=0, check=True):
25012512
r"""
@@ -2787,7 +2798,7 @@ def monsky_washnitzer(self):
27872798
"""
27882799
return self._monsky_washnitzer
27892800

2790-
def is_field(self, proof=True):
2801+
def is_field(self, proof=True) -> bool:
27912802
"""
27922803
Return ``False`` as ``self`` is not a field.
27932804
@@ -2893,24 +2904,6 @@ def _sub_(self, other):
28932904
P = self.parent()
28942905
return P.element_class(P, self._coeff - other._coeff)
28952906

2896-
def __neg__(self):
2897-
r"""
2898-
Return the additive inverse of ``self``.
2899-
2900-
EXAMPLES::
2901-
2902-
sage: R.<x> = QQ['x']
2903-
sage: C = HyperellipticCurve(x^5 - 4*x + 4)
2904-
sage: x,y = C.monsky_washnitzer_gens()
2905-
sage: w = C.invariant_differential()
2906-
sage: -w
2907-
-1 dx/2y
2908-
sage: -((y-x)*w)
2909-
(-y*1 + x) dx/2y
2910-
"""
2911-
P = self.parent()
2912-
return P.element_class(P, -self._coeff)
2913-
29142907
def _lmul_(self, a):
29152908
r"""
29162909
Return `self * a`.

0 commit comments

Comments
 (0)