From e8d6e417a08d9f82398dd2aec6a28ced656fab53 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 3 Mar 2021 11:22:30 -0500 Subject: [PATCH] matrix_algebra: rename __repr__ to _repr_ and fix a multiplication bug. --- mjo/matrix_algebra.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/mjo/matrix_algebra.py b/mjo/matrix_algebra.py index 5b8b267..a67a9b4 100644 --- a/mjo/matrix_algebra.py +++ b/mjo/matrix_algebra.py @@ -37,7 +37,7 @@ class MatrixAlgebraElement(IndexedFreeModuleElement): l[i][j] += v*e return l - def __repr__(self): + def _repr_(self): r""" Display this matrix as a table. @@ -232,10 +232,38 @@ class MatrixAlgebra(CombinatorialFreeModule): ncols = nrows def product_on_basis(self, mon1, mon2): + r""" + + SETUP:: + + sage: from mjo.octonions import Octonions + sage: from mjo.matrix_algebra import MatrixAlgebra + + TESTS:: + + sage: O = Octonions(QQ) + sage: e = O.gens() + sage: e[2]*e[1] + -e3 + sage: A = MatrixAlgebra(O,QQ,2) + sage: A.product_on_basis( (0,0,e[2]), (0,0,e[1]) ) + +-----+---+ + | -e3 | 0 | + +-----+---+ + | 0 | 0 | + +-----+---+ + + """ (i,j,e1) = mon1 (k,l,e2) = mon2 if j == k: - return self.monomial((i,l,e1*e2)) + # If e1*e2 has a negative sign in front of it, + # then (i,l,e1*e2) won't be a monomial! + p = e1*e2 + if (i,l,p) in self.indices(): + return self.monomial((i,l,p)) + else: + return -self.monomial((i,l,-p)) else: return self.zero() -- 2.44.2