X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fmatrix_algebra.py;h=29a37d1e7c9bdee3dee6b36960126d5f545753fe;hb=9c7fc4d836d337fcba8846ee4538bb0571c60f08;hp=73286ff452adf3323a9fdf534dfbeba8c6777bbd;hpb=a87cbac5c3e1f3a6422b2152609f8209676fb4cb;p=sage.d.git diff --git a/mjo/matrix_algebra.py b/mjo/matrix_algebra.py index 73286ff..29a37d1 100644 --- a/mjo/matrix_algebra.py +++ b/mjo/matrix_algebra.py @@ -57,8 +57,18 @@ class MatrixAlgebraElement(IndexedFreeModuleElement): | 0 | 0 | +---+---+ + TESTS:: + + sage: MatrixAlgebra(0,ZZ,ZZ).zero() + 0 + """ - return table(self.rows(), frame=True)._repr_() + if self.nrows() == 0 or self.ncols() == 0: + # Otherwise we get a crash or a blank space, depending + # on how hard we work for it. + return self.parent().entry_algebra().zero().__repr__() + + return table(rs, frame=True)._repr_() def list(self): @@ -185,9 +195,8 @@ 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() ) + self.one = lambda: self.sum( (self.monomial((i,i,entry_one)) + for i in range(self.nrows()) ) ) if "Associative" in entry_algebra.category().axioms(): category = category.Associative() @@ -352,9 +361,10 @@ class MatrixAlgebra(CombinatorialFreeModule): # We have to convert alpha_g because a priori it lives in the # base ring of the entry algebra. R = self.base_ring() - return self.sum( R(alpha_g)*self.monomial( (i,l,g) ) - for (alpha_g, g) - in zip(p, self.entry_algebra_gens())) + return self.sum_of_terms( (((i,l,g), R(alpha_g)) + for (alpha_g, g) + in zip(p, self.entry_algebra_gens()) ), + distinct=True) else: return self.zero() @@ -414,9 +424,10 @@ class MatrixAlgebra(CombinatorialFreeModule): # We have to convert alpha_g because a priori it lives in the # base ring of the entry algebra. R = self.base_ring() - return self.sum( R(alpha_g)*self.monomial( (i,j,g) ) - for (alpha_g, g) - in zip(p, self.entry_algebra_gens())) + return self.sum_of_terms( (((i,j,g), R(alpha_g)) + for (alpha_g, g) + in zip(p, self.entry_algebra_gens()) ), + distinct=True) return self.sum( entry_to_element(i,j,entries[i][j]) for j in range(ncols)