| 0 | 0 |
+---+---+
+ TESTS::
+
+ sage: MatrixAlgebra(0,ZZ,ZZ).zero()
+ []
+
"""
+ 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. This is what MatrixSpace(...,
+ # 0) returns.
+ return "[]"
+
return table(self.rows(), frame=True)._repr_()
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()
# 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()
# 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)