From 93b513358f3ef7e789ba75f6f82faedea9fc34b3 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 3 Mar 2021 10:16:42 -0500 Subject: [PATCH] matrix_algebra: implement one() dynamically. --- mjo/matrix_algebra.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/mjo/matrix_algebra.py b/mjo/matrix_algebra.py index 4049ef6..5b8b267 100644 --- a/mjo/matrix_algebra.py +++ b/mjo/matrix_algebra.py @@ -158,6 +158,22 @@ class MatrixAlgebra(CombinatorialFreeModule): the entries come from a commutative and associative ring. This is problematic in several interesting matrix algebras, like those where the entries are quaternions or octonions. + + SETUP:: + + sage: from mjo.matrix_algebra import MatrixAlgebra + + EXAMPLES:: + + The existence of a unit element is determined dynamically:: + + sage: MatrixAlgebra(ZZ,ZZ,2).one() + +---+---+ + | 1 | 0 | + +---+---+ + | 0 | 1 | + +---+---+ + """ Element = MatrixAlgebraElement @@ -168,6 +184,11 @@ class MatrixAlgebra(CombinatorialFreeModule): if "Unital" in entry_algebra.category().axioms(): category = category.Unital() + entry_one = entry_algebra.one() + self.one = lambda: sum( (self.monomial((i,i,entry_one)) + for i in range(self.nrows()) ), + self.zero() ) + if "Associative" in entry_algebra.category().axioms(): category = category.Associative() @@ -299,16 +320,3 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement): class HurwitzMatrixAlgebra(MatrixAlgebra): Element = HurwitzMatrixAlgebraElement - - def one(self): - r""" - SETUP:: - - sage: from mjo.matrix_algebra import HurwitzMatrixAlgebra - - """ - return sum( (self.monomial((i,i,self.entry_algebra().one())) - for i in range(self.nrows()) ), - self.zero() ) - - -- 2.44.2