Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fixing doctests, making category an arugment, and other small tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Aug 22, 2018
1 parent a3dccfd commit 0fa41ad
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/sage/algebras/lie_algebras/abelian.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AbelianLieAlgebra(LieAlgebraWithStructureCoefficients):
0
"""
@staticmethod
def __classcall_private__(cls, R, names=None, index_set=None, **kwds):
def __classcall_private__(cls, R, names=None, index_set=None, category=None, **kwds):
"""
Normalize input to ensure a unique representation.
Expand All @@ -54,9 +54,9 @@ def __classcall_private__(cls, R, names=None, index_set=None, **kwds):
names, index_set = standardize_names_index_set(names, index_set)
if index_set.cardinality() == infinity:
return InfiniteDimensionalAbelianLieAlgebra(R, index_set, **kwds)
return super(AbelianLieAlgebra, cls).__classcall__(cls, R, names, index_set, **kwds)
return super(AbelianLieAlgebra, cls).__classcall__(cls, R, names, index_set, category=category, **kwds)

def __init__(self, R, names, index_set, **kwds):
def __init__(self, R, names, index_set, category, **kwds):
"""
Initialize ``self``.
Expand All @@ -65,10 +65,10 @@ def __init__(self, R, names, index_set, **kwds):
sage: L = LieAlgebra(QQ, 3, 'x', abelian=True)
sage: TestSuite(L).run()
"""
category = kwds.get("category", None)
kwds["category"] = LieAlgebras(R).FiniteDimensional().WithBasis() \
.Nilpotent().or_subcategory(category)
LieAlgebraWithStructureCoefficients.__init__(self, R, Family({}), names, index_set, **kwds)
cat = LieAlgebras(R).FiniteDimensional().WithBasis().Nilpotent()
category = cat.or_subcategory(category)
LieAlgebraWithStructureCoefficients.__init__(self, R, Family({}), names,
index_set, category, **kwds)

def _repr_(self):
"""
Expand Down
45 changes: 28 additions & 17 deletions src/sage/algebras/lie_algebras/lie_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ class LieAlgebra(Parent, UniqueRepresentation): # IndexedGenerators):
sage: E[X, [X, [X, Y + Z]]]
0
A nilpotent Lie algebra will also be constructed if given a ``category``
of a nilpotent Lie algebra::
sage: C = LieAlgebras(QQ).Nilpotent().FiniteDimensional().WithBasis()
sage: L.<X,Y,Z> = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, category=C); L
Nilpotent Lie algebra on 3 generators (X, Y, Z) over Rational Field
REFERENCES:
- [deG2000]_ Willem A. de Graaf. *Lie Algebras: Theory and Algorithms*.
Expand All @@ -322,8 +329,8 @@ class LieAlgebra(Parent, UniqueRepresentation): # IndexedGenerators):
# __classcall_private__ will only be called when calling LieAlgebra
@staticmethod
def __classcall_private__(cls, R=None, arg0=None, arg1=None, names=None,
index_set=None, abelian=False,
nilpotent=False, **kwds):
index_set=None, abelian=False, nilpotent=False,
category=None, **kwds):
"""
Select the correct parent based upon input.
Expand All @@ -340,7 +347,8 @@ def __classcall_private__(cls, R=None, arg0=None, arg1=None, names=None,

assoc = kwds.get("associative", None)
if assoc is not None:
return LieAlgebraFromAssociative(assoc, names=names, index_set=index_set)
return LieAlgebraFromAssociative(assoc, names=names, index_set=index_set,
category=category)

# Parse input as a Cartan type
# -----
Expand Down Expand Up @@ -402,12 +410,14 @@ def __classcall_private__(cls, R=None, arg0=None, arg1=None, names=None,

if isinstance(arg1, dict):
# Assume it is some structure coefficients
if nilpotent:
if nilpotent or (category is not None and category.is_subcategory(LieAlgebras(R).Nilpotent())):
from sage.algebras.lie_algebras.nilpotent_lie_algebra import NilpotentLieAlgebra_dense
return NilpotentLieAlgebra_dense(R, arg1, names, index_set, **kwds)
return NilpotentLieAlgebra_dense(R, arg1, names, index_set,
category=category, **kwds)

from sage.algebras.lie_algebras.structure_coefficients import LieAlgebraWithStructureCoefficients
return LieAlgebraWithStructureCoefficients(R, arg1, names, index_set, **kwds)
return LieAlgebraWithStructureCoefficients(R, arg1, names, index_set,
category=category, **kwds)

# Otherwise it must be either a free or abelian Lie algebra

Expand Down Expand Up @@ -951,7 +961,7 @@ class LieAlgebraFromAssociative(LieAlgebraWithGenerators):
"""
@staticmethod
def __classcall_private__(cls, A, gens=None, names=None, index_set=None,
free_lie_algebra=False):
free_lie_algebra=False, category=None):
"""
Normalize input to ensure a unique representation.
Expand Down Expand Up @@ -1023,15 +1033,24 @@ def __classcall_private__(cls, A, gens=None, names=None, index_set=None,

names, index_set = standardize_names_index_set(names, index_set, ngens)

# We strip the following axioms from the category of the assoc. algebra:
# FiniteDimensional and WithBasis
category = LieAlgebras(A.base_ring()).or_subcategory(category)
if 'FiniteDimensional' in A.category().axioms():
category = category.FiniteDimensional()
if 'WithBasis' in A.category().axioms() and gens is None:
category = category.WithBasis()

if isinstance(A, MatrixSpace):
if gens is not None:
for g in gens:
g.set_immutable()
return MatrixLieAlgebraFromAssociative(A, gens, names=names,
index_set=index_set)
index_set=index_set,
category=category)

return super(LieAlgebraFromAssociative, cls).__classcall__(cls,
A, gens, names=names, index_set=index_set)
A, gens, names=names, index_set=index_set, category=category)

def __init__(self, A, gens=None, names=None, index_set=None, category=None):
"""
Expand All @@ -1053,14 +1072,6 @@ def __init__(self, A, gens=None, names=None, index_set=None, category=None):
self._assoc = A
R = self._assoc.base_ring()

# We strip the following axioms from the category of the assoc. algebra:
# FiniteDimensional and WithBasis
category = LieAlgebras(R).or_subcategory(category)
if 'FiniteDimensional' in self._assoc.category().axioms():
category = category.FiniteDimensional()
if 'WithBasis' in self._assoc.category().axioms() and gens is None:
category = category.WithBasis()

LieAlgebraWithGenerators.__init__(self, R, names, index_set, category)

if isinstance(gens, tuple):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ def _test_grading(self, **options):
tester = self._tester(**options)

from sage.misc.misc import some_tuples
for X,Y in some_tuples(self.basis(), 2, tester._max_runs):
for X, Y in some_tuples(self.basis(), 2, tester._max_runs):
i = X.degree()
j = Y.degree()
Z = self.bracket(X, Y)
if Z == 0:
continue
tester.assertEquals(Z.degree(), i + j,
msg="Lie bracket [%s, %s] has degree %d, not degree %d " %
(X, Y, Z.degree(), i + j))
Zdeg = Z.degree()
tester.assertEquals(Zdeg, i + j,
msg="Lie bracket [%s, %s] has degree %s, not degree %s " %
(X, Y, Zdeg, i + j))
tester.assertTrue(
Z.to_vector() in self.homogeneous_component_as_submodule(i + j),
msg="Lie bracket [%s, %s] is not in the "
"homogeneous component of degree %d" % (X, Y, i + j))
"homogeneous component of degree %s" % (X, Y, i + j))

@cached_method
def homogeneous_component_as_submodule(self, d):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ class FiniteDimensionalNilpotentLieAlgebrasWithBasis(CategoryWithAxiom_over_base
class ParentMethods:
def _test_nilpotency(self, **options):
r"""
Tests that the Lie algebra is nilpotent and has
the correct step.
Tests that ``self`` is nilpotent and has the correct step.
INPUT:
- ``options`` -- any keyword arguments accepted by
:meth:`_tester`.
:meth:`_tester`
EXAMPLES::
sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True)
sage: L._test_nilpotency()
sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}},
Expand Down Expand Up @@ -89,10 +88,10 @@ def _test_nilpotency(self, **options):

def step(self):
r"""
Return the nilpotency step of the Lie algebra.
Return the nilpotency step of ``self``.
EXAMPLES::
sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True)
sage: L.step()
2
Expand Down
4 changes: 3 additions & 1 deletion src/sage/categories/graded_lie_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class FiniteDimensional(CategoryWithAxiom_over_base_ring):
sage: C = LieAlgebras(QQ).Graded().Stratified().FiniteDimensional()
sage: TestSuite(C).run()
"""

def extra_super_categories(self):
"""
Implements the fact that a finite dimensional stratified Lie
Expand All @@ -78,6 +77,9 @@ def extra_super_categories(self):
[Category of nilpotent Lie algebras over Rational Field]
sage: C is C.Nilpotent()
True
sage: C.is_subcategory(LieAlgebras(QQ).Nilpotent())
True
"""
from sage.categories.lie_algebras import LieAlgebras
return [LieAlgebras(self.base_ring()).Nilpotent()]

4 changes: 2 additions & 2 deletions src/sage/categories/triangular_kac_moody_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def super_categories(self):
sage: from sage.categories.triangular_kac_moody_algebras import TriangularKacMoodyAlgebras
sage: TriangularKacMoodyAlgebras(QQ).super_categories()
[Join of Category of graded modules with basis over Rational Field
and Category of lie algebras with basis over Rational Field
[Join of Category of graded lie algebras with basis over Rational Field
and Category of kac moody algebras over Rational Field]
"""
# We do not also derive from (Magmatic) algebras since we don't want *
# to be our Lie bracket
Expand Down

0 comments on commit 0fa41ad

Please sign in to comment.