]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/hurwitz.py
matrix_algebra: add _entry_algebra_element_to_vector() method.
[sage.d.git] / mjo / hurwitz.py
index a1a6af06e944e97ea49536b8b9f76e1ecf54cde6..cad89ca177cbdcfbc065682d4a64af43aad6917a 100644 (file)
@@ -306,6 +306,32 @@ class Octonions(CombinatorialFreeModule):
 
 
 class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
+    def conjugate_transpose(self):
+        r"""
+        Return the conjugate-transpose of this matrix.
+
+        SETUP::
+
+            sage: from mjo.hurwitz import HurwitzMatrixAlgebra
+
+        EXAMPLES::
+
+            sage: A = HurwitzMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [ I,   2*I],
+            ....:         [ 3*I, 4*I] ])
+            sage: M.conjugate_transpose()
+            +------+------+
+            | -1*I | -3*I |
+            +------+------+
+            | -2*I | -4*I |
+            +------+------+
+
+        """
+        entries = [ [ self[j,i].conjugate()
+                      for j in range(self.ncols())]
+                    for i in range(self.nrows()) ]
+        return self.parent()._element_constructor_(entries)
+
     def is_hermitian(self):
         r"""
 
@@ -322,6 +348,8 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
             True
 
         """
+        # A tiny bit faster than checking equality with the conjugate
+        # transpose.
         return all( self[i,j] == self[j,i].conjugate()
                     for i in range(self.nrows())
                     for j in range(self.ncols()) )
@@ -440,6 +468,31 @@ class OctonionMatrixAlgebra(HurwitzMatrixAlgebra):
         +---------------------+
         | 1.00000000000000*e0 |
         +---------------------+
+        sage: A.gens()
+        (+---------------------+
+        | 1.00000000000000*e0 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e1 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e2 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e3 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e4 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e5 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e6 |
+        +---------------------+,
+        +---------------------+
+        | 1.00000000000000*e7 |
+        +---------------------+)
 
     ::
 
@@ -519,6 +572,19 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra):
         +-----+
         | 1.0 |
         +-----+
+        sage: A.gens()
+        (+-----+
+        | 1.0 |
+        +-----+,
+        +---+
+        | i |
+        +---+,
+        +---+
+        | j |
+        +---+,
+        +---+
+        | k |
+        +---+)
 
     ::
 
@@ -561,6 +627,32 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra):
             entry_algebra = QuaternionAlgebra(scalars,-1,-1)
         super().__init__(n, entry_algebra, scalars, **kwargs)
 
+    def _entry_algebra_element_to_vector(self, entry):
+        r"""
+
+        SETUP::
+
+            sage: from mjo.hurwitz import QuaternionMatrixAlgebra
+
+        EXAMPLES::
+
+            sage: A = QuaternionMatrixAlgebra(2)
+            sage: u = A.entry_algebra().one()
+            sage: A._entry_algebra_element_to_vector(u)
+            (1, 0, 0, 0)
+            sage: i,j,k = A.entry_algebra().gens()
+            sage: A._entry_algebra_element_to_vector(i)
+            (0, 1, 0, 0)
+            sage: A._entry_algebra_element_to_vector(j)
+            (0, 0, 1, 0)
+            sage: A._entry_algebra_element_to_vector(k)
+            (0, 0, 0, 1)
+
+        """
+        from sage.modules.free_module import VectorSpace
+        d = len(self.entry_algebra_gens())
+        V = VectorSpace(self.entry_algebra().base_ring(), d)
+        return V(entry.coefficient_tuple())
 
 class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
     r"""
@@ -598,6 +690,13 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
         +------------------+
         | 1.00000000000000 |
         +------------------+
+        sage: A.gens()
+        (+------------------+
+        | 1.00000000000000 |
+        +------------------+,
+        +--------------------+
+        | 1.00000000000000*I |
+        +--------------------+)
 
     ::
 
@@ -634,3 +733,24 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
             from sage.rings.all import QQbar
             entry_algebra = QQbar
         super().__init__(n, entry_algebra, scalars, **kwargs)
+
+    def _entry_algebra_element_to_vector(self, entry):
+        r"""
+
+        SETUP::
+
+            sage: from mjo.hurwitz import ComplexMatrixAlgebra
+
+        EXAMPLES::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, QQ)
+            sage: A._entry_algebra_element_to_vector(QQbar(1))
+            (1, 0)
+            sage: A._entry_algebra_element_to_vector(QQbar(I))
+            (0, 1)
+
+        """
+        from sage.modules.free_module import VectorSpace
+        d = len(self.entry_algebra_gens())
+        V = VectorSpace(self.entry_algebra().base_ring(), d)
+        return V((entry.real(), entry.imag()))