Skip to content

Commit 8de95f8

Browse files
committed
use CommutativeRing in ring_extension
1 parent 0c390a0 commit 8de95f8

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/sage/rings/ring_extension.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from sage.categories.map cimport Map
2-
from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra
2+
from sage.rings.ring cimport CommutativeRing
33

44

5-
cdef class RingExtension_generic(CommutativeAlgebra):
5+
cdef class RingExtension_generic(CommutativeRing):
66
cdef _type
77
cdef _backend
88
cdef _defining_morphism

src/sage/rings/ring_extension.pyx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ from sage.structure.category_object import normalize_names
122122
from sage.categories.map cimport Map
123123
from sage.categories.commutative_rings import CommutativeRings
124124
from sage.categories.fields import Fields
125-
from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra
125+
from sage.rings.ring cimport CommutativeRing
126126
from sage.rings.integer_ring import ZZ
127127
from sage.rings.infinity import Infinity
128128

@@ -174,8 +174,8 @@ def tower_bases(ring, degree):
174174
5-adic Field with capped relative precision 20],
175175
[1, 3, 6])
176176
"""
177-
bases = [ ]
178-
degrees = [ ]
177+
bases = []
178+
degrees = []
179179
base = ring
180180
deg = 1
181181
while True:
@@ -454,7 +454,7 @@ class RingExtensionFactory(UniqueFactory):
454454

455455
# We figure out what are the best constructors
456456
if constructors is None:
457-
constructors = [ ]
457+
constructors = []
458458
if gens is not None and len(gens) == 1:
459459
constructors.append((RingExtensionWithGen,
460460
{'gen': gens[0], 'names': names,
@@ -498,7 +498,7 @@ RingExtension = RingExtensionFactory("sage.rings.ring_extension.RingExtension")
498498
# General extensions
499499
####################
500500

501-
cdef class RingExtension_generic(CommutativeAlgebra):
501+
cdef class RingExtension_generic(CommutativeRing):
502502
r"""
503503
A generic class for all ring extensions.
504504
@@ -580,7 +580,7 @@ cdef class RingExtension_generic(CommutativeAlgebra):
580580
# but CommutativeRings() seems safer, especially when dealing with
581581
# morphisms which do not need to preserve the base
582582
category = CommutativeRings()
583-
CommutativeAlgebra.__init__(self, ZZ, category=category)
583+
CommutativeRing.__init__(self, ZZ, category=category)
584584
self._base = base
585585
self._backend = ring
586586
self._backend_defining_morphism = defining_morphism
@@ -1135,7 +1135,7 @@ cdef class RingExtension_generic(CommutativeAlgebra):
11351135
11361136
:meth:`base`, :meth:`absolute_base`, :meth:`is_defined_over`
11371137
"""
1138-
L = [ self ]
1138+
L = [self]
11391139
base = self
11401140
while isinstance(base, RingExtension_generic):
11411141
base = base.base_ring()
@@ -1358,7 +1358,8 @@ cdef class RingExtension_generic(CommutativeAlgebra):
13581358
(y, x)
13591359
"""
13601360
self._check_base(base)
1361-
return tuple([ self(x) for x in generators(self._backend, backend_parent(self._base)) ])
1361+
return tuple([self(x) for x in generators(self._backend,
1362+
backend_parent(self._base))])
13621363

13631364
def ngens(self, base=None):
13641365
r"""
@@ -2026,7 +2027,6 @@ cdef class RingExtensionFractionField(RingExtension_generic):
20262027
Maximal Order generated by a in Number Field in a
20272028
with defining polynomial x^2 - 2 over its base
20282029
sage: TestSuite(K).run()
2029-
20302030
"""
20312031
RingExtension_generic.__init__(self, defining_morphism, **kwargs)
20322032
if ring is None:
@@ -2138,9 +2138,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
21382138
sage: TestSuite(E).run() # needs sage.rings.number_field
21392139
"""
21402140
RingExtension_generic.__init__(self, defining_morphism, **kwargs)
2141-
self._basis = [ self(b) for b in basis ]
2141+
self._basis = [self(b) for b in basis]
21422142
if names is None:
2143-
names = [ ]
2143+
names = []
21442144
for b in self._basis:
21452145
b = b._backend
21462146
if b == 1:
@@ -2154,7 +2154,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
21542154
if len(names) != len(self._basis):
21552155
raise ValueError("the number of names does not match the cardinality of the basis")
21562156
self._basis_names = names
2157-
self._basis_latex_names = [ latex_variable_name(name) for name in names ]
2157+
self._basis_latex_names = [latex_variable_name(name) for name in names]
21582158
self._names = tuple(names)
21592159
if check:
21602160
try:
@@ -2335,12 +2335,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
23352335
[1, u, u^2]
23362336
"""
23372337
if base is self:
2338-
return [ self.one() ]
2339-
elif base is self._base:
2338+
return [self.one()]
2339+
if base is self._base:
23402340
return self._basis[:]
2341-
else:
2342-
b = self._base._basis_over(base)
2343-
return [ x*y for x in self._basis for y in b ]
2341+
b = self._base._basis_over(base)
2342+
return [x * y for x in self._basis for y in b]
23442343

23452344
def free_module(self, base=None, map=True):
23462345
r"""
@@ -2461,8 +2460,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic):
24612460
sage: L = GF(7^15).over(K) # needs sage.rings.finite_rings
24622461
sage: for base in L.bases(): # needs sage.rings.finite_rings
24632462
....: V, i, j = L.free_module(base)
2464-
....: assert([ i(v) for v in V.basis() ] == L.basis_over(base))
2465-
....: assert([ j(x) for x in L.basis_over(base) ] == V.basis())
2463+
....: assert([i(v) for v in V.basis()] == L.basis_over(base))
2464+
....: assert([j(x) for x in L.basis_over(base)] == V.basis())
24662465
24672466
"""
24682467
d = self._degree_over(base)
@@ -2599,15 +2598,15 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis):
25992598
backend_base = backend_parent(defining_morphism.domain())
26002599
_, deg_domain, deg_codomain = common_base(backend_base, defining_morphism.codomain(), True)
26012600
degree = deg_codomain // deg_domain
2602-
basis_names = [ "" ]
2603-
basis_latex_names = [ "" ]
2601+
basis_names = [""]
2602+
basis_latex_names = [""]
26042603
if degree == 1:
26052604
self._name = None
26062605
else:
2607-
basis_names += [ self._name ] + [ "%s^%s" % (self._name, i) for i in range(2,degree) ]
2606+
basis_names += [self._name] + ["%s^%s" % (self._name, i) for i in range(2, degree)]
26082607
latex_name = latex_variable_name(self._name)
2609-
basis_latex_names += [ latex_name ] + [ "%s^{%s}" % (latex_name, i) for i in range(2,degree) ]
2610-
basis = [ gen ** i for i in range(degree) ]
2608+
basis_latex_names += [latex_name] + ["%s^{%s}" % (latex_name, i) for i in range(2, degree)]
2609+
basis = [gen ** i for i in range(degree)]
26112610
RingExtensionWithBasis.__init__(self, defining_morphism, basis, basis_names, check, **kwargs)
26122611
self._gen = self._backend(gen)
26132612
self._names = (self._name,)
@@ -2681,7 +2680,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis):
26812680
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
26822681
_, _, j = self.free_module(map=True)
26832682
d = self.relative_degree()
2684-
coeffs = [ -c for c in j(self._gen**d) ] + [ 1 ]
2683+
coeffs = [-c for c in j(self._gen**d)] + [1]
26852684
S = PolynomialRing(self._base, name=var)
26862685
return S(coeffs)
26872686

0 commit comments

Comments
 (0)