48
48
49
49
from sage .arith .misc import integer_ceil as ceil
50
50
from sage .arith .misc import binomial
51
+ from sage .categories .algebras import Algebras
51
52
from sage .functions .log import log
52
53
from sage .matrix .constructor import matrix
53
54
from sage .misc .cachefunc import cached_method
72
73
from sage .rings .laurent_series_ring import is_LaurentSeriesRing
73
74
from sage .rings .padics .factory import Qp as pAdicField
74
75
from sage .rings .polynomial .polynomial_element import Polynomial
75
- from sage .rings .ring import CommutativeAlgebra
76
76
from sage .schemes .elliptic_curves .constructor import EllipticCurve
77
77
from sage .schemes .elliptic_curves .ell_generic import is_EllipticCurve
78
78
from sage .schemes .hyperelliptic_curves .constructor import HyperellipticCurve
79
79
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
81
82
from sage .structure .richcmp import richcmp
82
83
from sage .structure .unique_representation import UniqueRepresentation
83
84
84
85
85
- class SpecialCubicQuotientRingElement (CommutativeAlgebraElement ):
86
+ class SpecialCubicQuotientRingElement (ModuleElement ):
86
87
"""
87
88
An element of a :class:`SpecialCubicQuotientRing`.
88
89
"""
@@ -108,11 +109,20 @@ def __init__(self, parent, p0, p1, p2, check=True):
108
109
sage: from sage.schemes.hyperelliptic_curves.monsky_washnitzer import SpecialCubicQuotientRingElement
109
110
sage: SpecialCubicQuotientRingElement(R, 2, 3, 4)
110
111
(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
111
121
"""
112
122
if not isinstance (parent , SpecialCubicQuotientRing ):
113
123
raise TypeError (f"parent (={ parent } ) must be a SpecialCubicQuotientRing" )
114
124
115
- CommutativeAlgebraElement .__init__ (self , parent )
125
+ ModuleElement .__init__ (self , parent )
116
126
117
127
if check :
118
128
poly_ring = parent ._poly_ring
@@ -145,7 +155,7 @@ def coeffs(self):
145
155
column .extend ([base_ring (0 )] * (degree - len (column )))
146
156
return coeffs
147
157
148
- def __bool__ (self ):
158
+ def __bool__ (self ) -> bool :
149
159
"""
150
160
EXAMPLES::
151
161
@@ -161,7 +171,7 @@ def __bool__(self):
161
171
"""
162
172
return bool (self ._triple [0 ]) or bool (self ._triple [1 ]) or bool (self ._triple [2 ])
163
173
164
- def _richcmp_ (self , other , op ):
174
+ def _richcmp_ (self , other , op ) -> bool :
165
175
"""
166
176
EXAMPLES::
167
177
@@ -176,7 +186,7 @@ def _richcmp_(self, other, op):
176
186
"""
177
187
return richcmp (self ._triple , other ._triple , op )
178
188
179
- def _repr_ (self ):
189
+ def _repr_ (self ) -> str :
180
190
"""
181
191
EXAMPLES::
182
192
@@ -188,7 +198,7 @@ def _repr_(self):
188
198
"""
189
199
return "(%s) + (%s)*x + (%s)*x^2" % self ._triple
190
200
191
- def _latex_ (self ):
201
+ def _latex_ (self ) -> str :
192
202
"""
193
203
EXAMPLES::
194
204
@@ -387,7 +397,7 @@ def _mul_(self, other):
387
397
check = False )
388
398
389
399
390
- class SpecialCubicQuotientRing (CommutativeAlgebra ):
400
+ class SpecialCubicQuotientRing (UniqueRepresentation , Parent ):
391
401
r"""
392
402
Specialised class for representing the quotient ring
393
403
`R[x,T]/(T - x^3 - ax - b)`, where `R` is an
@@ -419,6 +429,7 @@ class SpecialCubicQuotientRing(CommutativeAlgebra):
419
429
sage: R
420
430
SpecialCubicQuotientRing over Ring of integers modulo 125
421
431
with polynomial T = x^3 + 124*x + 94
432
+ sage: TestSuite(R).run()
422
433
423
434
Get generators::
424
435
@@ -513,21 +524,15 @@ def __init__(self, Q, laurent_series=False):
513
524
raise ArithmeticError ("2 and 3 must be invertible in the "
514
525
"coefficient ring (=%s) of Q" % base_ring )
515
526
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:
523
527
self ._a = Q [1 ]
524
528
self ._b = Q [0 ]
525
529
if laurent_series :
526
530
self ._poly_ring = LaurentSeriesRing (base_ring , 'T' ) # R[T]
527
531
else :
528
532
self ._poly_ring = PolynomialRing (base_ring , 'T' ) # R[T]
529
533
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 ())
531
536
532
537
# Precompute a matrix that is used in the Toom-Cook multiplication.
533
538
# This is where we need 2 and 3 invertible.
@@ -537,7 +542,7 @@ def __init__(self, Q, laurent_series=False):
537
542
m = matrix (QQ , [[1 , - 12 , 2 ], [- 3 , 30 , - 3 ], [2 , - 12 , 1 ]]) / 6
538
543
self ._speedup_matrix = m .change_ring (base_ring ).list ()
539
544
540
- def _repr_ (self ):
545
+ def _repr_ (self ) -> str :
541
546
"""
542
547
String representation.
543
548
@@ -654,7 +659,7 @@ def _coerce_map_from_(self, R):
654
659
Element = SpecialCubicQuotientRingElement
655
660
656
661
657
- def transpose_list (input ):
662
+ def transpose_list (input ) -> list [ list ] :
658
663
"""
659
664
INPUT:
660
665
@@ -1854,7 +1859,7 @@ def matrix_of_frobenius_hyperelliptic(Q, p=None, prec=None, M=None):
1854
1859
return M .transpose (), [f for f , a in reduced ]
1855
1860
1856
1861
1857
- class SpecialHyperellipticQuotientElement (CommutativeAlgebraElement ):
1862
+ class SpecialHyperellipticQuotientElement (ModuleElement ):
1858
1863
r"""
1859
1864
Element in the Hyperelliptic quotient ring.
1860
1865
@@ -1880,7 +1885,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
1880
1885
sage: elt = MW(x + x**2 + y - 77)
1881
1886
sage: TestSuite(elt).run()
1882
1887
"""
1883
- CommutativeAlgebraElement .__init__ (self , parent )
1888
+ ModuleElement .__init__ (self , parent )
1884
1889
if not check :
1885
1890
self ._f = parent ._poly_ring (val , check = False )
1886
1891
return
@@ -1896,7 +1901,7 @@ def __init__(self, parent, val=0, offset=0, check=True):
1896
1901
if offset != 0 :
1897
1902
self ._f = self ._f .parent ()([a << offset for a in self ._f ], check = False )
1898
1903
1899
- def _richcmp_ (self , other , op ):
1904
+ def _richcmp_ (self , other , op ) -> bool :
1900
1905
"""
1901
1906
Compare the elements.
1902
1907
@@ -2358,7 +2363,8 @@ def coeffs(self, R=None):
2358
2363
coeffs = transpose_list (coeffs )
2359
2364
return [V (a ) for a in coeffs ], y_offset
2360
2365
2361
- class SpecialHyperellipticQuotientRing (UniqueRepresentation , CommutativeAlgebra ):
2366
+
2367
+ class SpecialHyperellipticQuotientRing (UniqueRepresentation , Parent ):
2362
2368
"""
2363
2369
The special hyperelliptic quotient ring.
2364
2370
"""
@@ -2380,18 +2386,10 @@ def __init__(self, Q, R=None, invert_y=True):
2380
2386
2381
2387
sage: HQR is SpecialHyperellipticQuotientRing(E)
2382
2388
True
2383
-
2384
2389
"""
2385
2390
if R is None :
2386
2391
R = Q .base_ring ()
2387
2392
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
-
2395
2393
x = PolynomialRing (R , 'xx' ).gen ()
2396
2394
if is_EllipticCurve (Q ):
2397
2395
E = Q
@@ -2428,10 +2426,7 @@ def __init__(self, Q, R=None, invert_y=True):
2428
2426
self ._series_ring_y = self ._series_ring .gen (0 )
2429
2427
self ._series_ring_0 = self ._series_ring .zero ()
2430
2428
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 ())
2435
2430
2436
2431
self ._poly_ring = PolynomialRing (self ._series_ring , 'x' )
2437
2432
@@ -2445,7 +2440,7 @@ def __init__(self, Q, R=None, invert_y=True):
2445
2440
self ._monomial_diffs = {}
2446
2441
self ._monomial_diff_coeffs = {}
2447
2442
2448
- def _repr_ (self ):
2443
+ def _repr_ (self ) -> str :
2449
2444
r"""
2450
2445
String representation.
2451
2446
@@ -2495,7 +2490,7 @@ def change_ring(self, R):
2495
2490
over Integer Ring
2496
2491
"""
2497
2492
return SpecialHyperellipticQuotientRing (self ._Q .change_ring (R ), R ,
2498
- is_LaurentSeriesRing (self ._series_ring ))
2493
+ is_LaurentSeriesRing (self ._series_ring ))
2499
2494
2500
2495
def _element_constructor_ (self , val , offset = 0 , check = True ):
2501
2496
r"""
@@ -2787,7 +2782,7 @@ def monsky_washnitzer(self):
2787
2782
"""
2788
2783
return self ._monsky_washnitzer
2789
2784
2790
- def is_field (self , proof = True ):
2785
+ def is_field (self , proof = True ) -> bool :
2791
2786
"""
2792
2787
Return ``False`` as ``self`` is not a field.
2793
2788
0 commit comments