Skip to content

Commit

Permalink
sagemathgh-37316: use CommutativeRing in ring_extension
Browse files Browse the repository at this point in the history
    
Removing one of the last uses of `CommutativeAlgebra` class, towards its
deprecation.

Also a few pep8 fixes in the modified file.

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#37316
Reported by: Frédéric Chapoton
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Feb 17, 2024
2 parents b889f53 + 8de95f8 commit d8523a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/sage/rings/ring_extension.pxd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sage.categories.map cimport Map
from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra
from sage.rings.ring cimport CommutativeRing


cdef class RingExtension_generic(CommutativeAlgebra):
cdef class RingExtension_generic(CommutativeRing):
cdef _type
cdef _backend
cdef _defining_morphism
Expand Down
49 changes: 24 additions & 25 deletions src/sage/rings/ring_extension.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ from sage.structure.category_object import normalize_names
from sage.categories.map cimport Map
from sage.categories.commutative_rings import CommutativeRings
from sage.categories.fields import Fields
from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra
from sage.rings.ring cimport CommutativeRing
from sage.rings.integer_ring import ZZ
from sage.rings.infinity import Infinity

Expand Down Expand Up @@ -174,8 +174,8 @@ def tower_bases(ring, degree):
5-adic Field with capped relative precision 20],
[1, 3, 6])
"""
bases = [ ]
degrees = [ ]
bases = []
degrees = []
base = ring
deg = 1
while True:
Expand Down Expand Up @@ -454,7 +454,7 @@ class RingExtensionFactory(UniqueFactory):

# We figure out what are the best constructors
if constructors is None:
constructors = [ ]
constructors = []
if gens is not None and len(gens) == 1:
constructors.append((RingExtensionWithGen,
{'gen': gens[0], 'names': names,
Expand Down Expand Up @@ -498,7 +498,7 @@ RingExtension = RingExtensionFactory("sage.rings.ring_extension.RingExtension")
# General extensions
####################

cdef class RingExtension_generic(CommutativeAlgebra):
cdef class RingExtension_generic(CommutativeRing):
r"""
A generic class for all ring extensions.
Expand Down Expand Up @@ -580,7 +580,7 @@ cdef class RingExtension_generic(CommutativeAlgebra):
# but CommutativeRings() seems safer, especially when dealing with
# morphisms which do not need to preserve the base
category = CommutativeRings()
CommutativeAlgebra.__init__(self, ZZ, category=category)
CommutativeRing.__init__(self, ZZ, category=category)
self._base = base
self._backend = ring
self._backend_defining_morphism = defining_morphism
Expand Down Expand Up @@ -1135,7 +1135,7 @@ cdef class RingExtension_generic(CommutativeAlgebra):
:meth:`base`, :meth:`absolute_base`, :meth:`is_defined_over`
"""
L = [ self ]
L = [self]
base = self
while isinstance(base, RingExtension_generic):
base = base.base_ring()
Expand Down Expand Up @@ -1358,7 +1358,8 @@ cdef class RingExtension_generic(CommutativeAlgebra):
(y, x)
"""
self._check_base(base)
return tuple([ self(x) for x in generators(self._backend, backend_parent(self._base)) ])
return tuple([self(x) for x in generators(self._backend,
backend_parent(self._base))])

def ngens(self, base=None):
r"""
Expand Down Expand Up @@ -2026,7 +2027,6 @@ cdef class RingExtensionFractionField(RingExtension_generic):
Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
sage: TestSuite(K).run()
"""
RingExtension_generic.__init__(self, defining_morphism, **kwargs)
if ring is None:
Expand Down Expand Up @@ -2138,9 +2138,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
sage: TestSuite(E).run() # needs sage.rings.number_field
"""
RingExtension_generic.__init__(self, defining_morphism, **kwargs)
self._basis = [ self(b) for b in basis ]
self._basis = [self(b) for b in basis]
if names is None:
names = [ ]
names = []
for b in self._basis:
b = b._backend
if b == 1:
Expand All @@ -2154,7 +2154,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
if len(names) != len(self._basis):
raise ValueError("the number of names does not match the cardinality of the basis")
self._basis_names = names
self._basis_latex_names = [ latex_variable_name(name) for name in names ]
self._basis_latex_names = [latex_variable_name(name) for name in names]
self._names = tuple(names)
if check:
try:
Expand Down Expand Up @@ -2335,12 +2335,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
[1, u, u^2]
"""
if base is self:
return [ self.one() ]
elif base is self._base:
return [self.one()]
if base is self._base:
return self._basis[:]
else:
b = self._base._basis_over(base)
return [ x*y for x in self._basis for y in b ]
b = self._base._basis_over(base)
return [x * y for x in self._basis for y in b]

def free_module(self, base=None, map=True):
r"""
Expand Down Expand Up @@ -2461,8 +2460,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
sage: L = GF(7^15).over(K) # needs sage.rings.finite_rings
sage: for base in L.bases(): # needs sage.rings.finite_rings
....: V, i, j = L.free_module(base)
....: assert([ i(v) for v in V.basis() ] == L.basis_over(base))
....: assert([ j(x) for x in L.basis_over(base) ] == V.basis())
....: assert([i(v) for v in V.basis()] == L.basis_over(base))
....: assert([j(x) for x in L.basis_over(base)] == V.basis())
"""
d = self._degree_over(base)
Expand Down Expand Up @@ -2599,15 +2598,15 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis):
backend_base = backend_parent(defining_morphism.domain())
_, deg_domain, deg_codomain = common_base(backend_base, defining_morphism.codomain(), True)
degree = deg_codomain // deg_domain
basis_names = [ "" ]
basis_latex_names = [ "" ]
basis_names = [""]
basis_latex_names = [""]
if degree == 1:
self._name = None
else:
basis_names += [ self._name ] + [ "%s^%s" % (self._name, i) for i in range(2,degree) ]
basis_names += [self._name] + ["%s^%s" % (self._name, i) for i in range(2, degree)]
latex_name = latex_variable_name(self._name)
basis_latex_names += [ latex_name ] + [ "%s^{%s}" % (latex_name, i) for i in range(2,degree) ]
basis = [ gen ** i for i in range(degree) ]
basis_latex_names += [latex_name] + ["%s^{%s}" % (latex_name, i) for i in range(2, degree)]
basis = [gen ** i for i in range(degree)]
RingExtensionWithBasis.__init__(self, defining_morphism, basis, basis_names, check, **kwargs)
self._gen = self._backend(gen)
self._names = (self._name,)
Expand Down Expand Up @@ -2681,7 +2680,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis):
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
_, _, j = self.free_module(map=True)
d = self.relative_degree()
coeffs = [ -c for c in j(self._gen**d) ] + [ 1 ]
coeffs = [-c for c in j(self._gen**d)] + [1]
S = PolynomialRing(self._base, name=var)
return S(coeffs)

Expand Down

0 comments on commit d8523a6

Please sign in to comment.