-class OctonionMatrix(IndexedFreeModuleElement):
- def nrows(self):
- return self.parent().nrows()
- ncols = nrows
-
- @cached_method
- def to_nested_list(self):
- r"""
- SETUP::
-
- sage: from mjo.octonions import OctonionMatrixAlgebra
-
- EXAMPLES::
-
- sage: MS = OctonionMatrixAlgebra(3)
- sage: E00e0 = MS.gens()[0]
- sage: E00e0
- +----+---+---+
- | e0 | 0 | 0 |
- +----+---+---+
- | 0 | 0 | 0 |
- +----+---+---+
- | 0 | 0 | 0 |
- +----+---+---+
- sage: E00e3 = MS.gens()[3]
- sage: E00e3
- +----+---+---+
- | e3 | 0 | 0 |
- +----+---+---+
- | 0 | 0 | 0 |
- +----+---+---+
- | 0 | 0 | 0 |
- +----+---+---+
- sage: (E00e0 + 2*E00e3).to_nested_list()
- [[e0 + 2*e3, 0, 0], [0, 0, 0], [0, 0, 0]]
-
- """
- zero = self.parent().octonions().zero()
- l = [[zero for j in range(self.ncols())] for i in range(self.nrows())]
- for (k,v) in self.monomial_coefficients().items():
- (i,j,e) = k
- l[i][j] += v*e
- return l
-
- def __repr__(self):
- r"""
- SETUP::
-
- sage: from mjo.octonions import OctonionMatrixAlgebra
-
- EXAMPLES::
-
- sage: OctonionMatrixAlgebra(3).one()
- +----+----+----+
- | e0 | 0 | 0 |
- +----+----+----+
- | 0 | e0 | 0 |
- +----+----+----+
- | 0 | 0 | e0 |
- +----+----+----+
-
- """
- return table(self.to_nested_list(), frame=True)._repr_()
-
-
- def list(self):
- r"""
- Return one long list of this matrix's entries.
-
- SETUP::
-
- sage: from mjo.octonions import OctonionMatrixAlgebra
-
- EXAMPLES::
-
- sage: MS = OctonionMatrixAlgebra(3)
- sage: E00e0 = MS.gens()[0]
- sage: E00e3 = MS.gens()[3]
- sage: (E00e0 + 2*E00e3).to_nested_list()
- [[e0 + 2*e3, 0, 0], [0, 0, 0], [0, 0, 0]]
- sage: (E00e0 + 2*E00e3).list()
- [e0 + 2*e3, 0, 0, 0, 0, 0, 0, 0, 0]
-
- """
- return sum( self.to_nested_list(), [] )
-
-
- def __getitem__(self, indices):
- r"""
-
- SETUP::
-
- sage: from mjo.octonions import OctonionMatrixAlgebra
-
- EXAMPLES::
-
- sage: MS = OctonionMatrixAlgebra(2)
- sage: I = MS.one()
- sage: I[0,0]
- e0
- sage: I[0,1]
- 0
- sage: I[1,0]
- 0
- sage: I[1,1]
- e0
-
- """
- i,j = indices
- return self.to_nested_list()[i][j]
-
- def trace(self):
- r"""
-
- SETUP::
-
- sage: from mjo.octonions import OctonionMatrixAlgebra
-
- EXAMPLES::
-
- sage: MS = OctonionMatrixAlgebra(3)
- sage: MS.one().trace()
- 3*e0
-
- """
- zero = self.parent().octonions().zero()
- return sum( (self[i,i] for i in range(self.nrows())), zero )
-
- def matrix_space(self):
- r"""
-
- SETUP::