X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fmatrix_algebra.py;h=bd173eaba835b8b82632587e62fcf6a8e7ec4e44;hb=77d2d169ac8a3e46030ee98e6bdb45df418a59c2;hp=73286ff452adf3323a9fdf534dfbeba8c6777bbd;hpb=197e8fdf8737fabde9003bd093cf45527afd4568;p=sage.d.git diff --git a/mjo/matrix_algebra.py b/mjo/matrix_algebra.py index 73286ff..bd173ea 100644 --- a/mjo/matrix_algebra.py +++ b/mjo/matrix_algebra.py @@ -185,9 +185,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 +351,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 +414,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)