]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/octonions.py
octonions: use more generic variable names in a few places.
[sage.d.git] / mjo / octonions.py
index 352c4c586e7506a218bcc9e7f9cb6332c1cd72c7..04aa318a3d8bed7158da61c26b0bb8b25f7cab0b 100644 (file)
@@ -345,7 +345,7 @@ class OctonionMatrix(IndexedFreeModuleElement):
     ncols = nrows
 
     @cached_method
-    def to_list(self):
+    def to_nested_list(self):
         r"""
         SETUP::
 
@@ -372,11 +372,11 @@ class OctonionMatrix(IndexedFreeModuleElement):
             +----+---+---+
             | 0  | 0 | 0 |
             +----+---+---+
-            sage: (E00e0 + 2*E00e3).to_list()
+            sage: (E00e0 + 2*E00e3).to_nested_list()
             [[e0 + 2*e3, 0, 0], [0, 0, 0], [0, 0, 0]]
 
         """
-        zero = self.parent().octonions().zero()
+        zero = self.parent().entry_algebra().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
@@ -401,7 +401,29 @@ class OctonionMatrix(IndexedFreeModuleElement):
             +----+----+----+
 
         """
-        return table(self.to_list(), frame=True)._repr_()
+        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):
@@ -426,7 +448,7 @@ class OctonionMatrix(IndexedFreeModuleElement):
 
         """
         i,j = indices
-        return self.to_list()[i][j]
+        return self.to_nested_list()[i][j]
 
     def trace(self):
         r"""
@@ -442,9 +464,44 @@ class OctonionMatrix(IndexedFreeModuleElement):
             3*e0
 
         """
-        zero = self.parent().octonions().zero()
+        zero = self.parent().entry_algebra().zero()
         return sum( (self[i,i] for i in range(self.nrows())), zero )
 
+    def matrix_space(self):
+        r"""
+
+        SETUP::
+
+            sage: from mjo.octonions import OctonionMatrixAlgebra
+
+        TESTS::
+
+            sage: set_random_seed()
+            sage: MS = OctonionMatrixAlgebra(2)
+            sage: MS.random_element().matrix_space()
+            Module of 2 by 2 matrices with octonion entries over the
+            scalar ring Algebraic Real Field
+
+        """
+        return self.parent()
+
+    def is_hermitian(self):
+        r"""
+
+        SETUP::
+
+            sage: from mjo.octonions import OctonionMatrixAlgebra
+
+        EXAMPLES::
+
+            sage: MS = OctonionMatrixAlgebra(3)
+            sage: MS.one().is_hermitian()
+            True
+
+        """
+        return all( self[i,j] == self[j,i].conjugate()
+                    for i in range(self.nrows())
+                    for j in range(self.ncols()) )
 
 class OctonionMatrixAlgebra(CombinatorialFreeModule):
     r"""
@@ -457,37 +514,42 @@ class OctonionMatrixAlgebra(CombinatorialFreeModule):
     """
     Element = OctonionMatrix
 
-    def __init__(self, n, field=AA, prefix="E", **kwargs):
+    def __init__(self, n, scalars=AA, prefix="E", **kwargs):
         # Not associative, not commutative
-        category = MagmaticAlgebras(field).FiniteDimensional()
+        category = MagmaticAlgebras(scalars).FiniteDimensional()
         category = category.WithBasis().Unital()
 
         self._nrows = n
 
-        # Since the scalar field is real but the entries are octonion,
+        # Since the scalar ring is real but the entries are not,
         # sticking a "1" in each position doesn't give us a basis for
-        # the space. We actually need to stick each of e0, e1, ..., e7
-        # (a basis for the Octonions themselves) into each position.
+        # the space. We actually need to stick each of e0, e1, ...  (a
+        # basis for the entry algebra itself) into each position.
         from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
         from sage.categories.sets_cat import cartesian_product
 
         I = FiniteEnumeratedSet(range(n))
         J = FiniteEnumeratedSet(range(n))
-        self._octonions = Octonions(field=field)
-        entry_basis = self._octonions.gens()
+        self._entry_algebra = Octonions(field=scalars)
+        entry_basis = self._entry_algebra.gens()
 
         basis_indices = cartesian_product([I,J,entry_basis])
-        super().__init__(field,
+        super().__init__(scalars,
                          basis_indices,
                          category=category,
                          prefix=prefix,
                          bracket='(')
 
-    def octonions(self):
+    def _repr_(self):
+        return ("Module of %d by %d matrices with octonion entries"
+                " over the scalar ring %s" %
+                (self.nrows(), self.ncols(), self.base_ring()) )
+
+    def entry_algebra(self):
         r"""
-        Return the Octonion algebra that our elements' entries come from.
+        Return the algebra that our elements' entries come from.
         """
-        return self._octonions
+        return self._entry_algebra
 
     def nrows(self):
         return self._nrows
@@ -516,7 +578,7 @@ class OctonionMatrixAlgebra(CombinatorialFreeModule):
             True
 
         """
-        return sum( (self.monomial((i,i,self._octonions.one()))
+        return sum( (self.monomial((i,i,self.entry_algebra().one()))
                      for i in range(self.nrows()) ),
                     self.zero() )
 
@@ -556,7 +618,7 @@ class OctonionMatrixAlgebra(CombinatorialFreeModule):
             # given octonion algebra to ours. Otherwise we can fail
             # to convert an element of (for example) Octonions(QQ)
             # to Octonions(AA).
-            return self.octonions().from_vector(e_ij.to_vector())
+            return self.entry_algebra().from_vector(e_ij.to_vector())
 
         return sum( (self.monomial( (i,j, convert(entries[i][j])) )
                      for i in range(nrows)