from sage.categories.magmatic_algebras import MagmaticAlgebras
from sage.combinat.free_module import CombinatorialFreeModule
from sage.matrix.constructor import matrix
+from sage.matrix.matrix_space import MatrixSpace
from sage.misc.cachefunc import cached_method
from sage.misc.prandom import choice
from sage.misc.table import table
"""
if self._natural_basis is None:
- return tuple( b.to_vector().column() for b in self.basis() )
+ M = self.natural_basis_space()
+ return tuple( M(b.to_vector()) for b in self.basis() )
else:
return self._natural_basis
+ def natural_basis_space(self):
+ """
+ Return the matrix space in which this algebra's natural basis
+ elements live.
+ """
+ if self._natural_basis is None or len(self._natural_basis) == 0:
+ return MatrixSpace(self.base_ring(), self.dimension(), 1)
+ else:
+ return self._natural_basis[0].matrix_space()
+
+
@cached_method
def one(self):
"""
"""
B = self.parent().natural_basis()
- W = B[0].matrix_space()
+ W = self.parent().natural_basis_space()
return W.linear_combination(zip(B,self.to_vector()))
return self.monomial(self.one_basis())
+ def natural_basis_space(self):
+ """
+ Return the natural basis space of this algebra, which is identical
+ to that of its superalgebra.
+
+ This is correct "by definition," and avoids a mismatch when the
+ subalgebra is trivial (with no natural basis to infer anything
+ from) and the parent is not.
+ """
+ return self.superalgebra().natural_basis_space()
+
+
def superalgebra(self):
"""
Return the superalgebra that this algebra was generated from.