]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/hurwitz.py
matrix_algebra: use "[]" for trivial matrices and fix a test.
[sage.d.git] / mjo / hurwitz.py
index 1f7c9dc3781a844d6d77a1e63168c52340bf6770..10b308d2bfa602373e0924e390e7e10453eff221 100644 (file)
@@ -312,18 +312,21 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
 
         SETUP::
 
-            sage: from mjo.hurwitz import HurwitzMatrixAlgebra
+            sage: from mjo.hurwitz import ComplexMatrixAlgebra
 
         EXAMPLES::
 
-            sage: A = HurwitzMatrixAlgebra(2, QQbar, ZZ)
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
             sage: M = A([ [ I,   2*I],
             ....:         [ 3*I, 4*I] ])
+            sage: M.conjugate_transpose()
             +------+------+
-            | -1*I | -3*I |
+            | -I   | -3*I |
             +------+------+
             | -2*I | -4*I |
             +------+------+
+            sage: M.conjugate_transpose().to_vector()
+            (0, -1, 0, -3, 0, -2, 0, -4)
 
         """
         entries = [ [ self[j,i].conjugate()
@@ -336,16 +339,25 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
 
         SETUP::
 
-            sage: from mjo.hurwitz import HurwitzMatrixAlgebra
+            sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
+            ....:                          HurwitzMatrixAlgebra)
 
         EXAMPLES::
 
-            sage: A = HurwitzMatrixAlgebra(2, QQbar, ZZ)
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
             sage: M = A([ [ 0,I],
             ....:         [-I,0] ])
             sage: M.is_hermitian()
             True
 
+        ::
+
+            sage: A = HurwitzMatrixAlgebra(2, AA, QQ)
+            sage: M = A([ [1, 1],
+            ....:         [1, 1] ])
+            sage: M.is_hermitian()
+            True
+
         """
         # A tiny bit faster than checking equality with the conjugate
         # transpose.
@@ -626,6 +638,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 FreeModule
+        d = len(self.entry_algebra_gens())
+        V = FreeModule(self.entry_algebra().base_ring(), d)
+        return V(entry.coefficient_tuple())
 
 class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
     r"""
@@ -677,11 +715,11 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
         sage: (I,) = A.entry_algebra().gens()
         sage: A([ [1+I, 1],
         ....:     [-1, -I] ])
-        +-------+----+
-        | I + 1 | 1  |
-        +-------+----+
-        | -1    | -I |
-        +-------+----+
+        +---------+------+
+        | 1 + 1*I | 1    |
+        +---------+------+
+        | -1      | -1*I |
+        +---------+------+
 
     ::
 
@@ -706,3 +744,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 FreeModule
+        d = len(self.entry_algebra_gens())
+        V = FreeModule(self.entry_algebra().base_ring(), d)
+        return V((entry.real(), entry.imag()))