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

Commit

Permalink
Fixing up doctests and some other compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Aug 8, 2022
1 parent c01586d commit 8b777a0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
66 changes: 46 additions & 20 deletions src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -419,12 +403,12 @@ def __init__(self, Qdim):
sage: idx._cardinality
128
sage: i = idx.an_element(); i
0
1111
sage: type(i)
<class 'sage.data_structures.bitset.FrozenBitset'>
"""
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)
Expand Down Expand Up @@ -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``.
Expand Down Expand Up @@ -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}
Expand All @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/filtered_modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def basis(self, d=None):
sage: E.<x,y> = 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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/graded_algebras_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ def one_basis(self):
sage: A.<x,y> = 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
"""
Expand Down
12 changes: 6 additions & 6 deletions src/sage/modules/with_basis/invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions src/sage/modules/with_basis/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8b777a0

Please sign in to comment.