60
60
# https://www.gnu.org/licenses/
61
61
# ****************************************************************************
62
62
63
- from sage .modules .free_module import FreeModule
64
- from sage .rings .ring import Algebra
65
63
from sage .algebras .free_algebra import is_FreeAlgebra
66
64
from sage .algebras .free_algebra_quotient_element import FreeAlgebraQuotientElement
65
+ from sage .categories .algebras import Algebras
66
+ from sage .modules .free_module import FreeModule
67
67
from sage .structure .unique_representation import UniqueRepresentation
68
+ from sage .structure .parent import Parent
68
69
69
70
70
- class FreeAlgebraQuotient (UniqueRepresentation , Algebra ):
71
+ class FreeAlgebraQuotient (UniqueRepresentation , Parent ):
71
72
@staticmethod
72
73
def __classcall__ (cls , A , mons , mats , names ):
73
74
"""
@@ -151,10 +152,9 @@ def __init__(self, A, mons, mats, names):
151
152
TESTS::
152
153
153
154
sage: TestSuite(H2).run()
154
-
155
155
"""
156
156
if not is_FreeAlgebra (A ):
157
- raise TypeError ("argument A must be an algebra" )
157
+ raise TypeError ("argument A must be a free algebra" )
158
158
R = A .base_ring ()
159
159
n = A .ngens ()
160
160
assert n == len (mats )
@@ -164,7 +164,8 @@ def __init__(self, A, mons, mats, names):
164
164
self .__module = FreeModule (R , self .__dim )
165
165
self .__matrix_action = mats
166
166
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 ))
168
169
169
170
def _element_constructor_ (self , x ):
170
171
"""
@@ -196,7 +197,7 @@ def _coerce_map_from_(self, S):
196
197
"""
197
198
return S == self or self .__free_algebra .has_coerce_map_from (S )
198
199
199
- def _repr_ (self ):
200
+ def _repr_ (self ) -> str :
200
201
"""
201
202
EXAMPLES::
202
203
@@ -208,11 +209,11 @@ def _repr_(self):
208
209
n = self .__ngens
209
210
r = self .__module .dimension ()
210
211
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 } "
212
213
213
214
def gen (self , i ):
214
215
"""
215
- The i -th generator of the algebra.
216
+ Return the ``i`` -th generator of the algebra.
216
217
217
218
EXAMPLES::
218
219
@@ -238,14 +239,29 @@ def gen(self, i):
238
239
"""
239
240
n = self .__ngens
240
241
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 ()
243
244
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 ))
245
261
246
262
def ngens (self ):
247
263
"""
248
- The number of generators of the algebra.
264
+ Return the number of generators of the algebra.
249
265
250
266
EXAMPLES::
251
267
@@ -256,7 +272,7 @@ def ngens(self):
256
272
257
273
def dimension (self ):
258
274
"""
259
- The rank of the algebra (as a free module).
275
+ Return the rank of the algebra (as a free module).
260
276
261
277
EXAMPLES::
262
278
@@ -267,6 +283,8 @@ def dimension(self):
267
283
268
284
def matrix_action (self ):
269
285
"""
286
+ Return the matrix action used to define the algebra.
287
+
270
288
EXAMPLES::
271
289
272
290
sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].matrix_action()
@@ -293,7 +311,7 @@ def monomial_basis(self):
293
311
294
312
def rank (self ):
295
313
"""
296
- The rank of the algebra (as a free module).
314
+ Return the rank of the algebra (as a free module).
297
315
298
316
EXAMPLES::
299
317
@@ -304,7 +322,7 @@ def rank(self):
304
322
305
323
def module (self ):
306
324
"""
307
- The free module of the algebra.
325
+ Return the free module of the algebra.
308
326
309
327
EXAMPLES::
310
328
@@ -317,7 +335,7 @@ def module(self):
317
335
318
336
def monoid (self ):
319
337
"""
320
- The free monoid of generators of the algebra.
338
+ Return the free monoid of generators of the algebra.
321
339
322
340
EXAMPLES::
323
341
@@ -328,7 +346,7 @@ def monoid(self):
328
346
329
347
def free_algebra (self ):
330
348
"""
331
- The free algebra generating the algebra.
349
+ Return the free algebra generating the algebra.
332
350
333
351
EXAMPLES::
334
352
@@ -340,17 +358,17 @@ def free_algebra(self):
340
358
341
359
def hamilton_quatalg (R ):
342
360
"""
343
- Hamilton quaternion algebra over the commutative ring R ,
361
+ Hamilton quaternion algebra over the commutative ring ``R`` ,
344
362
constructed as a free algebra quotient.
345
363
346
364
INPUT:
347
365
348
- - R -- a commutative ring
366
+ - ``R`` -- a commutative ring
349
367
350
368
OUTPUT:
351
369
352
- - Q -- quaternion algebra
353
- - gens -- generators for Q
370
+ - ``Q`` -- quaternion algebra
371
+ - `` gens`` -- generators for ``Q``
354
372
355
373
EXAMPLES::
356
374
@@ -363,19 +381,18 @@ def hamilton_quatalg(R):
363
381
sage: i in H
364
382
True
365
383
366
- Note that there is another vastly more efficient models for
384
+ Note that there is another vastly more efficient model for
367
385
quaternion algebras in Sage; the one here is mainly for testing
368
386
purposes::
369
387
370
388
sage: R.<i,j,k> = QuaternionAlgebra(QQ,-1,-1) # much fast than the above
371
389
"""
372
- n = 3
373
390
from sage .algebras .free_algebra import FreeAlgebra
374
391
from sage .matrix .matrix_space import MatrixSpace
375
- A = FreeAlgebra (R , n , 'i' )
392
+ A = FreeAlgebra (R , 3 , 'i' )
376
393
F = A .monoid ()
377
394
i , j , k = F .gens ()
378
- mons = [F ( 1 ), i , j , k ]
395
+ mons = [F . one ( ), i , j , k ]
379
396
M = MatrixSpace (R , 4 )
380
397
mats = [M ([0 , 1 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 1 , 0 ]),
381
398
M ([0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 ]),
0 commit comments