Skip to content

Commit e50df44

Browse files
author
Release Manager
committed
sagemathgh-37133: use Parent in free_algebra_quotient change to use `Parent` in the modified file a little step towards removal the old coercion framework also making a little refreshing for doc and pep8 ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: sagemath#37133 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents fb45e34 + 589f4fc commit e50df44

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

src/sage/algebras/free_algebra_quotient.py

+43-26
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@
6060
# https://www.gnu.org/licenses/
6161
# ****************************************************************************
6262

63-
from sage.modules.free_module import FreeModule
64-
from sage.rings.ring import Algebra
6563
from sage.algebras.free_algebra import is_FreeAlgebra
6664
from sage.algebras.free_algebra_quotient_element import FreeAlgebraQuotientElement
65+
from sage.categories.algebras import Algebras
66+
from sage.modules.free_module import FreeModule
6767
from sage.structure.unique_representation import UniqueRepresentation
68+
from sage.structure.parent import Parent
6869

6970

70-
class FreeAlgebraQuotient(UniqueRepresentation, Algebra):
71+
class FreeAlgebraQuotient(UniqueRepresentation, Parent):
7172
@staticmethod
7273
def __classcall__(cls, A, mons, mats, names):
7374
"""
@@ -151,10 +152,9 @@ def __init__(self, A, mons, mats, names):
151152
TESTS::
152153
153154
sage: TestSuite(H2).run()
154-
155155
"""
156156
if not is_FreeAlgebra(A):
157-
raise TypeError("argument A must be an algebra")
157+
raise TypeError("argument A must be a free algebra")
158158
R = A.base_ring()
159159
n = A.ngens()
160160
assert n == len(mats)
@@ -164,7 +164,8 @@ def __init__(self, A, mons, mats, names):
164164
self.__module = FreeModule(R, self.__dim)
165165
self.__matrix_action = mats
166166
self.__monomial_basis = mons # elements of free monoid
167-
Algebra.__init__(self, R, names, normalize=True)
167+
Parent.__init__(self, base=R, names=names,
168+
normalize=True, category=Algebras(R))
168169

169170
def _element_constructor_(self, x):
170171
"""
@@ -196,7 +197,7 @@ def _coerce_map_from_(self, S):
196197
"""
197198
return S == self or self.__free_algebra.has_coerce_map_from(S)
198199

199-
def _repr_(self):
200+
def _repr_(self) -> str:
200201
"""
201202
EXAMPLES::
202203
@@ -208,11 +209,11 @@ def _repr_(self):
208209
n = self.__ngens
209210
r = self.__module.dimension()
210211
x = self.variable_names()
211-
return "Free algebra quotient on %s generators %s and dimension %s over %s" % (n, x, r, R)
212+
return f"Free algebra quotient on {n} generators {x} and dimension {r} over {R}"
212213

213214
def gen(self, i):
214215
"""
215-
The i-th generator of the algebra.
216+
Return the ``i``-th generator of the algebra.
216217
217218
EXAMPLES::
218219
@@ -238,14 +239,29 @@ def gen(self, i):
238239
"""
239240
n = self.__ngens
240241
if i < 0 or not i < n:
241-
raise IndexError("argument i (= %s) must be between 0 and %s" % (i, n - 1))
242-
R = self.base_ring()
242+
raise IndexError(f"argument i (= {i}) must be between 0 and {n - 1}")
243+
one = self.base_ring().one()
243244
F = self.__free_algebra.monoid()
244-
return self.element_class(self, {F.gen(i): R.one()})
245+
return self.element_class(self, {F.gen(i): one})
246+
247+
def gens(self) -> tuple:
248+
"""
249+
Return the tuple of generators of ``self``.
250+
251+
EXAMPLES::
252+
253+
sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)
254+
sage: H.gens()
255+
(i, j, k)
256+
"""
257+
one = self.base_ring().one()
258+
F = self.__free_algebra.monoid()
259+
return tuple(self.element_class(self, {F.gen(i): one})
260+
for i in range(self.__ngens))
245261

246262
def ngens(self):
247263
"""
248-
The number of generators of the algebra.
264+
Return the number of generators of the algebra.
249265
250266
EXAMPLES::
251267
@@ -256,7 +272,7 @@ def ngens(self):
256272

257273
def dimension(self):
258274
"""
259-
The rank of the algebra (as a free module).
275+
Return the rank of the algebra (as a free module).
260276
261277
EXAMPLES::
262278
@@ -267,6 +283,8 @@ def dimension(self):
267283

268284
def matrix_action(self):
269285
"""
286+
Return the matrix action used to define the algebra.
287+
270288
EXAMPLES::
271289
272290
sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].matrix_action()
@@ -293,7 +311,7 @@ def monomial_basis(self):
293311

294312
def rank(self):
295313
"""
296-
The rank of the algebra (as a free module).
314+
Return the rank of the algebra (as a free module).
297315
298316
EXAMPLES::
299317
@@ -304,7 +322,7 @@ def rank(self):
304322

305323
def module(self):
306324
"""
307-
The free module of the algebra.
325+
Return the free module of the algebra.
308326
309327
EXAMPLES::
310328
@@ -317,7 +335,7 @@ def module(self):
317335

318336
def monoid(self):
319337
"""
320-
The free monoid of generators of the algebra.
338+
Return the free monoid of generators of the algebra.
321339
322340
EXAMPLES::
323341
@@ -328,7 +346,7 @@ def monoid(self):
328346

329347
def free_algebra(self):
330348
"""
331-
The free algebra generating the algebra.
349+
Return the free algebra generating the algebra.
332350
333351
EXAMPLES::
334352
@@ -340,17 +358,17 @@ def free_algebra(self):
340358

341359
def hamilton_quatalg(R):
342360
"""
343-
Hamilton quaternion algebra over the commutative ring R,
361+
Hamilton quaternion algebra over the commutative ring ``R``,
344362
constructed as a free algebra quotient.
345363
346364
INPUT:
347365
348-
- R -- a commutative ring
366+
- ``R`` -- a commutative ring
349367
350368
OUTPUT:
351369
352-
- Q -- quaternion algebra
353-
- gens -- generators for Q
370+
- ``Q`` -- quaternion algebra
371+
- ``gens`` -- generators for ``Q``
354372
355373
EXAMPLES::
356374
@@ -363,19 +381,18 @@ def hamilton_quatalg(R):
363381
sage: i in H
364382
True
365383
366-
Note that there is another vastly more efficient models for
384+
Note that there is another vastly more efficient model for
367385
quaternion algebras in Sage; the one here is mainly for testing
368386
purposes::
369387
370388
sage: R.<i,j,k> = QuaternionAlgebra(QQ,-1,-1) # much fast than the above
371389
"""
372-
n = 3
373390
from sage.algebras.free_algebra import FreeAlgebra
374391
from sage.matrix.matrix_space import MatrixSpace
375-
A = FreeAlgebra(R, n, 'i')
392+
A = FreeAlgebra(R, 3, 'i')
376393
F = A.monoid()
377394
i, j, k = F.gens()
378-
mons = [F(1), i, j, k]
395+
mons = [F.one(), i, j, k]
379396
M = MatrixSpace(R, 4)
380397
mats = [M([0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0]),
381398
M([0, 0, 1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, -1, 0, 0]),

0 commit comments

Comments
 (0)