diff --git a/src/sage/algebras/clifford_algebra.py b/src/sage/algebras/clifford_algebra.py index 2039f24780c..b00c252a31a 100644 --- a/src/sage/algebras/clifford_algebra.py +++ b/src/sage/algebras/clifford_algebra.py @@ -385,27 +385,11 @@ def supercommutator(self, x): return ret -class CliffordAlgebraIndices(Parent): +class CliffordAlgebraIndices(UniqueRepresentation, Parent): r""" A facade parent for the indices of Clifford algebra. Users should not create instances of this class directly. """ - def __call__(self, el): - r""" - EXAMPLES:: - - sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices - sage: idx = CliffordAlgebraIndices(7) - sage: idx([1,3,6]) - 0101001 - sage: E = ExteriorAlgebra(QQ, 7) - sage: B = E.basis() - """ - if not isinstance(el, Element): - return self._element_constructor_(el) - else: - return Parent.__call__(self, el) - def __init__(self, Qdim): r""" Initialize ``self``. @@ -419,12 +403,12 @@ def __init__(self, Qdim): sage: idx._cardinality 128 sage: i = idx.an_element(); i - 0 + 1111 sage: type(i) """ self._nbits = Qdim - self._cardinality = 2**Qdim + self._cardinality = 2 ** Qdim # the if statement here is in case Qdim is 0. category = FiniteEnumeratedSets().Facade() Parent.__init__(self, category=category, facade=True) @@ -456,6 +440,22 @@ def _element_constructor_(self, x): if isinstance(x, int): return FrozenBitset((x,)) + def __call__(self, el): + r""" + EXAMPLES:: + + sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices + sage: idx = CliffordAlgebraIndices(7) + sage: idx([1,3,6]) + 0101001 + sage: E = ExteriorAlgebra(QQ, 7) + sage: B = E.basis() + """ + if not isinstance(el, Element): + return self._element_constructor_(el) + else: + return Parent.__call__(self, el) + def cardinality(self): r""" Return the cardinality of ``self``. @@ -556,7 +556,7 @@ def __contains__(self, elt): EXAMPLES:: sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices - sage: idx = CliffordAlgebraIndices(3); + sage: idx = CliffordAlgebraIndices(3) sage: int(8) in idx # representing the set {4} False sage: int(5) in idx # representing the set {1,3} @@ -572,6 +572,32 @@ def __contains__(self, elt): return False return elt.capacity() <= self._nbits + def _an_element_(self): + """ + Returns an element of ``self``. + + EXAMPLES:: + + sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices + sage: idx = CliffordAlgebraIndices(0) + sage: idx._an_element_() + 0 + sage: idx = CliffordAlgebraIndices(1) + sage: idx._an_element_() + 1 + sage: idx = CliffordAlgebraIndices(2) + sage: idx._an_element_() + 01 + sage: idx = CliffordAlgebraIndices(3) + sage: idx._an_element_() + 11 + """ + if not self._nbits: + return FrozenBitset() + + from sage.combinat.subset import SubsetsSorted + X = SubsetsSorted(range(self._nbits)) + return FrozenBitset(X.an_element()) class CliffordAlgebra(CombinatorialFreeModule): r""" diff --git a/src/sage/categories/filtered_modules_with_basis.py b/src/sage/categories/filtered_modules_with_basis.py index bd75b8f8e8a..336c1c326c8 100644 --- a/src/sage/categories/filtered_modules_with_basis.py +++ b/src/sage/categories/filtered_modules_with_basis.py @@ -178,9 +178,9 @@ def basis(self, d=None): sage: E. = ExteriorAlgebra(QQ) sage: E.basis() - Lazy family (Term map from Subsets of {0, 1} to + Lazy family (Term map from Subsets of {0,1} to The exterior algebra of rank 2 over Rational Field(i))_{i in - Subsets of {0, 1}} + Subsets of {0,1}} """ if d is None: from sage.sets.family import Family diff --git a/src/sage/categories/graded_algebras_with_basis.py b/src/sage/categories/graded_algebras_with_basis.py index e80c1b00bf4..abece323a5c 100644 --- a/src/sage/categories/graded_algebras_with_basis.py +++ b/src/sage/categories/graded_algebras_with_basis.py @@ -168,10 +168,10 @@ def one_basis(self): sage: A. = ExteriorAlgebra(QQ) sage: A.one_basis() - () + 0 sage: B = tensor((A, A, A)) sage: B.one_basis() - ((), (), ()) + (0, 0, 0) sage: B.one() 1 # 1 # 1 """ diff --git a/src/sage/modules/with_basis/invariant.py b/src/sage/modules/with_basis/invariant.py index e44c1ece287..f180f442c19 100644 --- a/src/sage/modules/with_basis/invariant.py +++ b/src/sage/modules/with_basis/invariant.py @@ -109,7 +109,7 @@ class FiniteDimensionalInvariantModule(SubmoduleWithBasis): sage: M = algebras.Exterior(QQ, 'x', 3) sage: def cyclic_ext_action(g, m): ....: # cyclically permute generators - ....: return M.prod([M.monomial((g(j+1)-1,)) for j in m]) + ....: return M.prod([M.monomial(FrozenBitset([g(j+1)-1])) for j in m]) If you care about being able to exploit the algebra structure of the exterior algebra (i.e. if you want to multiply elements together), you @@ -398,7 +398,7 @@ def _mul_(self, other): sage: G = CyclicPermutationGroup(3); G.rename('G') sage: M = algebras.Exterior(QQ, 'x', 3) - sage: def on_basis(g,m): return M.prod([M.monomial((g(j+1)-1,)) for j in m]) # cyclically permute generators + sage: def on_basis(g,m): return M.prod([M.monomial(FrozenBitset([g(j+1)-1])) for j in m]) # cyclically permute generators sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional(), side='right') sage: I = R.invariant_module(); I.rename('I') sage: B = I.basis() @@ -466,7 +466,6 @@ def _acted_upon_(self, scalar, self_on_left=False): sage: g = G.an_element(); g (1,2,3) sage: M = CombinatorialFreeModule(QQ, [1,2,3]) - sage: E = algebras.Exterior(QQ, 'x', 3) sage: from sage.modules.with_basis.representation import Representation sage: R = Representation(G, M, lambda g,x: M.monomial(g(x))) sage: I = R.invariant_module() @@ -480,7 +479,8 @@ def _acted_upon_(self, scalar, self_on_left=False): [2*B[0], 2*B[0], 2*B[0]] - sage: def on_basis(g,m): return E.prod([E.monomial((g(j+1)-1,)) for j in m]) # cyclically permute generators + sage: E = algebras.Exterior(QQ, 'x', 3) + sage: def on_basis(g,m): return E.prod([E.monomial(FrozenBitset([g(j+1)-1])) for j in m]) # cyclically permute generators sage: R = Representation(G, E, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional()) sage: I = R.invariant_module() sage: B = I.basis() @@ -528,7 +528,7 @@ def _acted_upon_(self, scalar, self_on_left=False): sage: [b._acted_upon_(G((1,3,2)), self_on_left=True) for b in I.basis()] [B[0]] - sage: def on_basis(g,m): return E.prod([E.monomial((g(j+1)-1,)) for j in m]) # cyclically permute generators + sage: def on_basis(g,m): return E.prod([E.monomial(FrozenBitset([g(j+1)-1])) for j in m]) # cyclically permute generators sage: R = Representation(G, E, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional(), side='right') sage: I = R.invariant_module() sage: B = I.basis() @@ -687,7 +687,7 @@ class FiniteDimensionalTwistedInvariantModule(SubmoduleWithBasis): sage: G = SymmetricGroup(3); G.rename('S3') sage: E = algebras.Exterior(QQ, 'x', 3); E.rename('E') - sage: def action(g,m): return E.prod([E.monomial((g(j+1)-1,)) for j in m]) + sage: def action(g,m): return E.prod([E.monomial(FrozenBitset([g(j+1)-1])) for j in m]) sage: from sage.modules.with_basis.representation import Representation sage: EA = Representation(G, E, action, category=Algebras(QQ).WithBasis().FiniteDimensional()) sage: T = EA.twisted_invariant_module([2,0,-1]) diff --git a/src/sage/modules/with_basis/representation.py b/src/sage/modules/with_basis/representation.py index 89721adffae..815871e038d 100644 --- a/src/sage/modules/with_basis/representation.py +++ b/src/sage/modules/with_basis/representation.py @@ -276,7 +276,7 @@ def __init__(self, semigroup, module, on_basis, side="left", **kwargs): sage: G = CyclicPermutationGroup(3) sage: M = algebras.Exterior(QQ, 'x', 3) sage: from sage.modules.with_basis.representation import Representation - sage: on_basis = lambda g,m: M.prod([M.monomial((g(j+1)-1,)) for j in m]) #cyclically permute generators + sage: on_basis = lambda g,m: M.prod([M.monomial(FrozenBitset([g(j+1)-1])) for j in m]) #cyclically permute generators sage: from sage.categories.algebras import Algebras sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional()) sage: r = R.an_element(); r @@ -451,9 +451,9 @@ def product_by_coercion(self, left, right): ... TypeError: unsupported operand parent(s) for *: 'Representation of The Klein 4 group of order 4, as a permutation - group indexed by Subsets of {0, 1, 2, 3} over Rational Field' and + group indexed by Subsets of {0,1,...,3} over Rational Field' and 'Representation of The Klein 4 group of order 4, as a permutation - group indexed by Subsets of {0, 1, 2, 3} over Rational Field' + group indexed by Subsets of {0,1,...,3} over Rational Field' sage: from sage.categories.algebras import Algebras sage: category = Algebras(QQ).FiniteDimensional().WithBasis()