Skip to content

Commit dcadc84

Browse files
author
Release Manager
committed
gh-40160: get rid of CommutativeRing in p-adics using `Parent` instead of the auld class `CommutativeRing` there ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #40160 Reported by: Frédéric Chapoton Reviewer(s): Rubén Muñoz--Bertrand, Travis Scrimshaw
2 parents 52f51a7 + 2fc451c commit dcadc84

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

src/sage/rings/padics/local_generic.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from sage.rings.integer import Integer
2828
from sage.rings.integer_ring import ZZ
2929
from sage.rings.infinity import Infinity
30-
from sage.rings.ring import CommutativeRing
30+
from sage.structure.parent import Parent
3131

3232

33-
class LocalGeneric(CommutativeRing):
33+
class LocalGeneric(Parent):
3434
def __init__(self, base, prec, names, element_class, category=None):
3535
r"""
3636
Initialize ``self``.
@@ -74,10 +74,10 @@ def __init__(self, base, prec, names, element_class, category=None):
7474
category = category.Metric().Complete().Infinite()
7575
if default_category is not None:
7676
category = check_default_category(default_category, category)
77-
CommutativeRing.__init__(self, base, names=(names,),
78-
normalize=False, category=category)
77+
Parent.__init__(self, base=base, names=(names,),
78+
normalize=False, category=category)
7979

80-
def is_capped_relative(self):
80+
def is_capped_relative(self) -> bool:
8181
r"""
8282
Return whether this `p`-adic ring bounds precision in a capped
8383
relative fashion.
@@ -102,7 +102,7 @@ def is_capped_relative(self):
102102
"""
103103
return False
104104

105-
def is_capped_absolute(self):
105+
def is_capped_absolute(self) -> bool:
106106
r"""
107107
Return whether this `p`-adic ring bounds precision in a
108108
capped absolute fashion.
@@ -127,7 +127,7 @@ def is_capped_absolute(self):
127127
"""
128128
return False
129129

130-
def is_fixed_mod(self):
130+
def is_fixed_mod(self) -> bool:
131131
r"""
132132
Return whether this `p`-adic ring bounds precision in a fixed
133133
modulus fashion.
@@ -154,7 +154,7 @@ def is_fixed_mod(self):
154154
"""
155155
return False
156156

157-
def is_floating_point(self):
157+
def is_floating_point(self) -> bool:
158158
r"""
159159
Return whether this `p`-adic ring bounds precision in a floating
160160
point fashion.
@@ -179,7 +179,7 @@ def is_floating_point(self):
179179
"""
180180
return False
181181

182-
def is_lattice_prec(self):
182+
def is_lattice_prec(self) -> bool:
183183
r"""
184184
Return whether this `p`-adic ring bounds precision using
185185
a lattice model.
@@ -208,7 +208,7 @@ def is_lattice_prec(self):
208208
"""
209209
return False
210210

211-
def is_relaxed(self):
211+
def is_relaxed(self) -> bool:
212212
r"""
213213
Return whether this `p`-adic ring bounds precision in a relaxed
214214
fashion.
@@ -224,7 +224,7 @@ def is_relaxed(self):
224224
"""
225225
return False
226226

227-
def _latex_(self):
227+
def _latex_(self) -> str:
228228
r"""
229229
Latex.
230230

src/sage/rings/padics/witt_vector_ring.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
# (at your option) any later version.
2222
# https://www.gnu.org/licenses/
2323
# ****************************************************************************
24-
25-
2624
from itertools import product
25+
from typing import Iterator
2726

2827
from sage.categories.commutative_rings import CommutativeRings
28+
from sage.categories.integral_domains import IntegralDomains
2929
from sage.categories.fields import Fields
3030
from sage.misc.latex import latex
3131
from sage.rings.integer import Integer
@@ -42,15 +42,14 @@
4242
from sage.rings.polynomial.polynomial_element import Polynomial
4343
from sage.rings.polynomial.polynomial_ring import PolynomialRing_generic
4444
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
45-
from sage.rings.ring import CommutativeRing
45+
from sage.structure.parent import Parent
4646
from sage.sets.primes import Primes
4747
from sage.structure.unique_representation import UniqueRepresentation
4848

4949

5050
def fast_char_p_power(x, n, p=None):
5151
r"""
52-
Return `x^n` assuming that `x` lives in a ring of
53-
characteristic `p`.
52+
Return `x^n` assuming that `x` lives in a ring of characteristic `p`.
5453
5554
If `x` is not an element of a ring of characteristic `p`,
5655
this throws an error.
@@ -120,7 +119,7 @@ def fast_char_p_power(x, n, p=None):
120119
return xn
121120

122121

123-
class WittVectorRing(CommutativeRing, UniqueRepresentation):
122+
class WittVectorRing(Parent, UniqueRepresentation):
124123
r"""
125124
Return the appropriate `p`-typical truncated Witt vector ring.
126125
@@ -263,27 +262,32 @@ def __classcall_private__(cls, coefficient_ring, prec=1, p=None, algorithm=None)
263262

264263
return child.__classcall__(child, coefficient_ring, prec, p)
265264

266-
def __init__(self, coefficient_ring, prec, prime):
265+
def __init__(self, coefficient_ring, prec, prime) -> None:
267266
r"""
268-
Initialises ``self``.
267+
Initialise ``self``.
269268
270269
EXAMPLES::
271270
272-
sage: W = WittVectorRing(PolynomialRing(GF(5), 't'), prec=4)
273-
sage: W
271+
sage: W = WittVectorRing(PolynomialRing(GF(5), 't'), prec=4); W
274272
Ring of truncated 5-typical Witt vectors of length 4 over Univariate Polynomial Ring in t over Finite Field of size 5
275273
sage: type(W)
276274
<class 'sage.rings.padics.witt_vector_ring.WittVectorRing_phantom_with_category'>
277275
278276
sage: TestSuite(W).run()
279277
"""
280-
self._coefficient_ring = coefficient_ring
278+
cring = coefficient_ring
279+
self._coefficient_ring = cring
281280
self._prec = prec
282281
self._prime = prime
283282

284-
CommutativeRing.__init__(self, self)
283+
if prec == 1 and cring in IntegralDomains():
284+
cat = IntegralDomains()
285+
else:
286+
cat = CommutativeRings()
285287

286-
def __iter__(self):
288+
Parent.__init__(self, base=ZZ, category=cat)
289+
290+
def __iter__(self) -> Iterator:
287291
"""
288292
Iterator for truncated Witt vector rings.
289293
@@ -347,7 +351,7 @@ def _coerce_map_from_(self, S):
347351
if (isinstance(S, WittVectorRing)
348352
and S.precision() >= self._prec and S.prime() == self._prime
349353
and self._coefficient_ring.has_coerce_map_from(
350-
S.coefficient_ring())):
354+
S.coefficient_ring())):
351355
return (any(isinstance(S, rng) for rng in self._always_coerce)
352356
or (S.precision() != self._prec
353357
or S.coefficient_ring() is not self._coefficient_ring)
@@ -358,7 +362,7 @@ def _coerce_map_from_(self, S):
358362

359363
def _generate_sum_and_product_polynomials(self, coefficient_ring, prec, p):
360364
"""
361-
Generates the sum and product polynomials defining the ring laws of
365+
Generate the sum and product polynomials defining the ring laws of
362366
truncated Witt vectors for the ``standard`` algorithm.
363367
364368
EXAMPLES::
@@ -387,7 +391,7 @@ def _generate_sum_and_product_polynomials(self, coefficient_ring, prec, p):
387391
#
388392
# Remark: Since when is SIXTEEN bits sufficient for anyone???
389393
#
390-
if p**(prec-1) >= 2**16:
394+
if p**(prec - 1) >= 2**16:
391395
implementation = 'generic'
392396
else:
393397
implementation = 'singular'
@@ -421,7 +425,7 @@ def _generate_sum_and_product_polynomials(self, coefficient_ring, prec, p):
421425
self._sum_polynomials[n] = S(self._sum_polynomials[n])
422426
self._prod_polynomials[n] = S(self._prod_polynomials[n])
423427

424-
def _latex_(self):
428+
def _latex_(self) -> str:
425429
r"""
426430
Return a `\LaTeX` representation of ``self``.
427431
@@ -439,7 +443,7 @@ def _latex_(self):
439443
return "W_{%s}\\left(%s\\right)" % (latex(self._prec),
440444
latex(self._coefficient_ring))
441445

442-
def _repr_(self):
446+
def _repr_(self) -> str:
443447
"""
444448
Return a string representation of the ring.
445449
@@ -498,7 +502,7 @@ def coefficient_ring(self):
498502
"""
499503
return self._coefficient_ring
500504

501-
def is_finite(self):
505+
def is_finite(self) -> bool:
502506
"""
503507
Return whether ``self`` is a finite ring.
504508
@@ -572,7 +576,9 @@ def prod_polynomials(self, variables=None):
572576

573577
def random_element(self, *args, **kwds):
574578
"""
575-
Return a random truncated Witt vector. Extra arguments are passed to
579+
Return a random truncated Witt vector.
580+
581+
Extra arguments are passed to
576582
the random generator of the coefficient ring.
577583
578584
EXAMPLES::
@@ -621,8 +627,9 @@ def sum_polynomials(self, variables=None):
621627

622628
def teichmuller_lift(self, x):
623629
"""
624-
Return the Teichmüller lift of ``x`` in ``self``. This lift is
625-
sometimes known as the multiplicative lift of ``x``.
630+
Return the Teichmüller lift of ``x`` in ``self``.
631+
632+
This lift is sometimes known as the multiplicative lift of ``x``.
626633
627634
EXAMPLES::
628635
@@ -656,9 +663,9 @@ class WittVectorRing_finotti(WittVectorRing):
656663
"""
657664
Element = WittVector_finotti
658665

659-
def __init__(self, coefficient_ring, prec, prime):
666+
def __init__(self, coefficient_ring, prec, prime) -> None:
660667
r"""
661-
Initialises ``self``.
668+
Initialise ``self``.
662669
663670
EXAMPLES::
664671
@@ -798,9 +805,9 @@ class WittVectorRing_phantom(WittVectorRing):
798805
"""
799806
Element = WittVector_phantom
800807

801-
def __init__(self, coefficient_ring, prec, prime):
808+
def __init__(self, coefficient_ring, prec, prime) -> None:
802809
r"""
803-
Initialises ``self``.
810+
Initialise ``self``.
804811
805812
EXAMPLES::
806813
@@ -859,9 +866,9 @@ class WittVectorRing_pinvertible(WittVectorRing):
859866
"""
860867
Element = WittVector_pinvertible
861868

862-
def __init__(self, coefficient_ring, prec, prime):
869+
def __init__(self, coefficient_ring, prec, prime) -> None:
863870
r"""
864-
Initialises ``self``.
871+
Initialise ``self``.
865872
866873
EXAMPLES::
867874
@@ -901,9 +908,9 @@ class WittVectorRing_standard(WittVectorRing):
901908
"""
902909
Element = WittVector_standard
903910

904-
def __init__(self, coefficient_ring, prec, prime):
911+
def __init__(self, coefficient_ring, prec, prime) -> None:
905912
r"""
906-
Initialises ``self``.
913+
Initialise ``self``.
907914
908915
EXAMPLES::
909916

0 commit comments

Comments
 (0)