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

Commit

Permalink
First draft of basis iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorkarn committed Jun 21, 2022
1 parent b1eca07 commit 62a4f39
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from sage.matrix.args import MatrixArgs
from sage.sets.family import Family
from sage.combinat.free_module import CombinatorialFreeModule
from sage.combinat.subset import SubsetsSorted
from sage.combinat.subset import Subsets
from sage.quadratic_forms.quadratic_form import QuadraticForm
from sage.algebras.weyl_algebra import repr_from_monomials
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
Expand Down Expand Up @@ -715,7 +715,7 @@ def _element_constructor_(self, x):
sage: Cl(2/3)
Traceback (most recent call last):
...
TypeError: do not know how to make x (= 2/3) an element of self ...
TypeError: do not know how to make x=2/3 an element of self
sage: Clp(2/3)
2/3
sage: Clp(x)
Expand Down Expand Up @@ -748,7 +748,57 @@ def _element_constructor_(self, x):
R = self.base_ring()
return self.element_class(self, {FrozenBitset((i,)): R.one() for i in x})

return super(CliffordAlgebra, self)._element_constructor_(x)
try:
return super(CliffordAlgebra, self)._element_constructor_(x)
except TypeError:
raise TypeError(f'do not know how to make {x=} an element of self')

def _basis_index_keys(self):
r"""
This gives the same values as range(2**Q.dim()),
but starting with elements that have 1 set bit,
then 2, then three, etc.
EXAMPLES::
sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])
sage: Cl = CliffordAlgebra(Q)
Notice that the monomial order is strictly lexicographic,
not degree-lexicographic when we use `range`.
sage: for i in range(2**Q.dim()): print(Cl.basis()[i])
1
x
y
x*y
z
x*z
y*z
x*y*z
Notice that ``x*y`` comes before ``z`` if we use ``range``.
This isn't mathematically *wrong* but is not usually what
we want. On the other hand, using this method gives a
degree-respecting monomial order::
sage: for i in Cl.basis(): print(b) # indirect doctest
1
x
y
z
x*y
x*z
y*z
x*y*z
"""
n = self._quadratic_form.dim()

for s in Subsets(range(n)): # it is ok here because this is only called when iterating over the bases, not in hash etc.
if not s:
yield 0
continue
yield FrozenBitset(s).__hash__()

def _basis_index_function(self, x):
"""
Expand Down

0 comments on commit 62a4f39

Please sign in to comment.