From: Michael Orlitzky Date: Wed, 3 Mar 2021 15:16:42 +0000 (-0500) Subject: matrix_algebra: implement one() dynamically. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=93b513358f3ef7e789ba75f6f82faedea9fc34b3 matrix_algebra: implement one() dynamically. --- 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() ) - -