1818
1919from sage .algebras .lie_algebras .structure_coefficients import LieAlgebraWithStructureCoefficients
2020from sage .categories .lie_algebras import LieAlgebras
21-
21+ from sage .structure .indexed_generators import standardize_names_index_set
22+ from sage .rings .integer_ring import ZZ
23+ from collections import OrderedDict
2224
2325class NilpotentLieAlgebra_dense (LieAlgebraWithStructureCoefficients ):
2426 r"""
@@ -156,37 +158,40 @@ def _repr_(self):
156158
157159class FreeNilpotentLieAlgebra (NilpotentLieAlgebra_dense ):
158160 r"""
159- Returns the free nilpotent Lie algebra of step ``s`` with ``r`` generators.
161+ Return the free nilpotent Lie algebra of step ``s`` with ``r`` generators.
160162
161- The free nilpotent Lie algebra `L` of step `s` with `r` generators is the
162- quotient of the free Lie algebra on `r` generators by the `s+1`th term of
163- the lower central series. That is, the only relations in the Lie algebra `L`
164- are anticommutativity, the Jacobi identity, and the vanishing of all
165- brackets of length more than `s`.
163+ The free nilpotent Lie algebra `L` of step `s` with `r` generators is
164+ the quotient of the free Lie algebra on `r` generators by the `( s+1)`-th
165+ term of the lower central series. That is, the only relations in the
166+ Lie algebra `L` are anticommutativity, the Jacobi identity, and the
167+ vanishing of all brackets of length more than `s`.
166168
167169 INPUT:
168170
169171 - ``R`` -- the base ring
170172 - ``r`` -- an integer; the number of generators
171173 - ``s`` -- an integer; the nilpotency step of the algebra
172174 - ``names`` -- (optional) a string or a list of strings used to name the
173- basis elements; If ``names`` is a string, then names for the basis will be
174- autogenerated as determined by the ``naming`` parameter.
175- - ``naming`` -- (optional) a string; the naming scheme to use for the basis.
176- Valid values are:
177- 'index' : The basis elements are ``names_w``, where `w` are Lyndon
178- words indexing the basis.
179- This naming scheme is not supported if `r > 10`, since it
180- leads to ambiguous names. When `r \leq 10`, this is the
181- default naming scheme.
182- 'linear' : the basis is indexed ``names_1``,...,``names_n`` in the
183- ordering of the Lyndon basis. When `r > 10`, this is the
184- default naming scheme.
175+ basis elements; if ``names`` is a string, then names for the basis
176+ will be autogenerated as determined by the ``naming`` parameter
177+ - ``naming`` -- (optional) a string; the naming scheme to use for
178+ the basis; valid values are:
179+
180+ * ``'index'`` - (default for `r \leq 10`) the basis elements are
181+ ``names_w``, where ``w`` are Lyndon words indexing the basis
182+ * ``'linear'`` - (default for `r > 10`) the basis is indexed
183+ ``names_1``, ..., ``names_n`` in the ordering of the Lyndon basis
184+
185+ .. NOTE::
186+
187+ The ``'index'`` naming scheme is not supported if `r > 10` since
188+ it leads to ambiguous names.
185189
186190 EXAMPLES:
187191
188- We compute the free step 4 Lie algebra on 2 generators and verify the only
189- non-trivial relation [[1,[1,2]],2] = [1,[[1,2],2]]::
192+ We compute the free step 4 Lie algebra on 2 generators and
193+ verify the only non-trivial relation
194+ `[[X_1,[X_1,X_2]],X_2] = [X_1,[[X_1,X_2],X_2]]`::
190195
191196 sage: L = LieAlgebra(QQ, 2, step=4)
192197 sage: L.basis().list()
@@ -288,33 +293,51 @@ class FreeNilpotentLieAlgebra(NilpotentLieAlgebra_dense):
288293 sage: [X_12222.bracket(Xk) for Xk in L.basis()]
289294 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
290295
291- The dimensions of the smallest free nilpotent Lie algebras on 2 or 3
292- generators::
296+ The dimensions of the smallest free nilpotent Lie algebras on
297+ 2 and 3 generators::
293298
294299 sage: l = [LieAlgebra(QQ, 2, step=k) for k in range(1, 7)]
295300 sage: [L.dimension() for L in l]
296301 [2, 3, 5, 8, 14, 23]
297302 sage: l = [LieAlgebra(QQ, 3, step=k) for k in range(1, 4)]
298303 sage: [L.dimension() for L in l]
299304 [3, 6, 14]
305+ """
306+ @staticmethod
307+ def __classcall_private__ (cls , R , r , s , names = None , naming = None , category = None , ** kwds ):
308+ """
309+ Normalize input to ensure a unique representation.
300310
301- Test suite for a free nilpotent Lie algebra ::
311+ TESTS ::
302312
303- sage: L = LieAlgebra(QQ, 4, step=3)
304- sage: TestSuite(L).run()
305- """
313+ sage: L1.<X> = LieAlgebra(ZZ, 2, step=2)
314+ sage: L2 = LieAlgebra(ZZ, 2, step=2, names=['X'])
315+ sage: L3 = LieAlgebra(ZZ, 2, step=2)
316+ sage: L1 is L2 and L2 is L3
317+ True
318+ """
319+ if names is None :
320+ names = 'X'
306321
307- def __init__ (self , R , r , s , names = None , naming = None , category = None , ** kwds ):
322+ cat = LieAlgebras (R ).FiniteDimensional ().WithBasis ()
323+ category = cat .Graded ().Stratified ().or_subcategory (category )
324+
325+ return super (FreeNilpotentLieAlgebra , cls ).__classcall__ (
326+ cls , R ,r , s , names = tuple (names ), naming = naming ,
327+ category = category , ** kwds )
328+
329+ def __init__ (self , R , r , s , names , naming , category , ** kwds ):
308330 r"""
309331 Initialize ``self``
310332
311333 EXAMPLES::
312334
313- sage: LieAlgebra(ZZ, 2, step=2)
314- Free Nilpotent Lie algebra on 3 generators (X_1, X_2, X_12) over Integer Ring
315- """
316- from sage .rings .integer_ring import ZZ
335+ sage: L = LieAlgebra(ZZ, 2, step=2)
336+ sage: TestSuite(L).run()
317337
338+ sage: L = LieAlgebra(QQ, 4, step=3)
339+ sage: TestSuite(L).run() # long time
340+ """
318341 if r not in ZZ or r <= 0 :
319342 raise ValueError ("number of generators %s is not "
320343 "a positive integer" % r )
@@ -327,7 +350,7 @@ def __init__(self, R, r, s, names=None, naming=None, category=None, **kwds):
327350
328351 free_gen_names = ['F%d' % k for k in range (r )]
329352 L = LieAlgebra (R , free_gen_names ).Lyndon ()
330- from collections import OrderedDict
353+
331354 basis_dict = OrderedDict ()
332355 for d in range (1 , s + 1 ):
333356 for X in L .graded_basis (d ):
@@ -336,12 +359,7 @@ def __init__(self, R, r, s, names=None, naming=None, category=None, **kwds):
336359 for s in X .leading_support ().to_word ())
337360 basis_dict [w ] = X
338361
339- # define names for basis elements
340- if not names :
341- names = 'X'
342- if isinstance (names , str ):
343- names = tuple (names )
344- if len (names ) == 1 and len (basis_dict )> 1 :
362+ if len (names ) == 1 and len (basis_dict ) > 1 :
345363 if not naming :
346364 if r > 10 :
347365 naming = 'linear'
@@ -361,7 +379,7 @@ def __init__(self, R, r, s, names=None, naming=None, category=None, **kwds):
361379
362380 # extract structural coefficients from the free Lie algebra
363381 s_coeff = {}
364- for k ,X_ind in enumerate (basis_dict ):
382+ for k , X_ind in enumerate (basis_dict ):
365383 X = basis_dict [X_ind ]
366384 degX = len (X_ind )
367385 for Y_ind in basis_dict .keys ()[k + 1 :]:
@@ -376,20 +394,17 @@ def __init__(self, R, r, s, names=None, naming=None, category=None, **kwds):
376394 s_coeff [(X_ind , Y_ind )] = {W : Z [basis_dict [W ].leading_support ()]
377395 for W in basis_dict }
378396
379- from sage .structure .indexed_generators import standardize_names_index_set
380397 names , index_set = standardize_names_index_set (names , basis_dict .keys ())
381398 s_coeff = LieAlgebraWithStructureCoefficients ._standardize_s_coeff (
382399 s_coeff , index_set )
383400
384- category = LieAlgebras (R ).FiniteDimensional ().WithBasis () \
385- .Graded ().Stratified ().or_subcategory (category )
386401 NilpotentLieAlgebra_dense .__init__ (self , R , s_coeff , names ,
387402 index_set , s ,
388403 category = category , ** kwds )
389404
390405 def _repr_generator (self , w ):
391406 r"""
392- Returns the string representation of the basis element
407+ Return the string representation of the basis element
393408 indexed by the word ``w`` in ``self``.
394409
395410 EXAMPLES::
@@ -408,7 +423,7 @@ def _repr_generator(self, w):
408423 return self .variable_names ()[i ]
409424
410425 def _repr_ (self ):
411- """
426+ r """
412427 Return a string representation of ``self``.
413428
414429 EXAMPLES::
@@ -418,3 +433,4 @@ def _repr_(self):
418433 Free Nilpotent Lie algebra on 5 generators (X_1, X_2, X_12, X_112, X_122) over Rational Field
419434 """
420435 return "Free %s" % (super (FreeNilpotentLieAlgebra , self )._repr_ ())
436+
0 commit comments