]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/hurwitz.py
mjo/hurwitz.py: speed up is_hermitian() and is_skew_symmetric().
[sage.d.git] / mjo / hurwitz.py
index 10b308d2bfa602373e0924e390e7e10453eff221..614804f21fb831aae04ff97be31413e84c1b61f8 100644 (file)
@@ -23,7 +23,6 @@ class Octonion(IndexedFreeModuleElement):
 
         Conjugating twice gets you the original element::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: x.conjugate().conjugate() == x
@@ -58,7 +57,6 @@ class Octonion(IndexedFreeModuleElement):
 
         This method is idempotent::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: x.real().real() == x.real()
@@ -91,7 +89,6 @@ class Octonion(IndexedFreeModuleElement):
 
         This method is idempotent::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: x.imag().imag() == x.imag()
@@ -121,7 +118,6 @@ class Octonion(IndexedFreeModuleElement):
 
         The norm is nonnegative and belongs to the base field::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: n = O.random_element().norm()
             sage: n >= 0 and n in O.base_ring()
@@ -129,7 +125,6 @@ class Octonion(IndexedFreeModuleElement):
 
         The norm is homogeneous::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: alpha = O.base_ring().random_element()
@@ -167,7 +162,6 @@ class Octonion(IndexedFreeModuleElement):
 
         TESTS::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: x.is_zero() or ( x*x.inverse() == O.one() )
@@ -241,7 +235,6 @@ class Octonions(CombinatorialFreeModule):
 
         This gives the correct unit element::
 
-            sage: set_random_seed()
             sage: O = Octonions()
             sage: x = O.random_element()
             sage: x*O.one() == x and O.one()*x == x
@@ -306,6 +299,32 @@ class Octonions(CombinatorialFreeModule):
 
 
 class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
+    def conjugate(self):
+        r"""
+        Return the entrywise conjugate of this matrix.
+
+        SETUP::
+
+            sage: from mjo.hurwitz import ComplexMatrixAlgebra
+
+        EXAMPLES::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [ I,   1 + 2*I],
+            ....:         [ 3*I,     4*I] ])
+            sage: M.conjugate()
+            +------+----------+
+            | -I   | -2*I + 1 |
+            +------+----------+
+            | -3*I | -4*I     |
+            +------+----------+
+
+        """
+        entries = [ [ self[i,j].conjugate()
+                      for j in range(self.ncols())]
+                    for i in range(self.nrows()) ]
+        return self.parent()._element_constructor_(entries)
+
     def conjugate_transpose(self):
         r"""
         Return the conjugate-transpose of this matrix.
@@ -350,6 +369,14 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
             sage: M.is_hermitian()
             True
 
+        ::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [ 0,0],
+            ....:         [-I,0] ])
+            sage: M.is_hermitian()
+            False
+
         ::
 
             sage: A = HurwitzMatrixAlgebra(2, AA, QQ)
@@ -363,7 +390,56 @@ class HurwitzMatrixAlgebraElement(MatrixAlgebraElement):
         # transpose.
         return all( self[i,j] == self[j,i].conjugate()
                     for i in range(self.nrows())
-                    for j in range(self.ncols()) )
+                    for j in range(i+1) )
+
+
+    def is_skew_symmetric(self):
+        r"""
+        Return whether or not this matrix is skew-symmetric.
+
+        SETUP::
+
+            sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
+            ....:                          HurwitzMatrixAlgebra)
+
+        EXAMPLES::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [ 0,I],
+            ....:         [-I,1] ])
+            sage: M.is_skew_symmetric()
+            False
+
+        ::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [   0, 1+I],
+            ....:         [-1-I,   0] ])
+            sage: M.is_skew_symmetric()
+            True
+
+        ::
+
+            sage: A = HurwitzMatrixAlgebra(2, AA, QQ)
+            sage: M = A([ [1, 1],
+            ....:         [1, 1] ])
+            sage: M.is_skew_symmetric()
+            False
+
+        ::
+
+            sage: A = ComplexMatrixAlgebra(2, QQbar, ZZ)
+            sage: M = A([ [2*I   ,  1 + I],
+            ....:         [-1 + I, -2*I] ])
+            sage: M.is_skew_symmetric()
+            False
+
+        """
+        # A tiny bit faster than checking equality with the negation
+        # of the transpose.
+        return all( self[i,j] == -self[j,i]
+                    for i in range(self.nrows())
+                    for j in range(i+1) )
 
 
 class HurwitzMatrixAlgebra(MatrixAlgebra):
@@ -529,7 +605,6 @@ class OctonionMatrixAlgebra(HurwitzMatrixAlgebra):
 
     TESTS::
 
-        sage: set_random_seed()
         sage: A = OctonionMatrixAlgebra(ZZ.random_element(10))
         sage: x = A.random_element()
         sage: x*A.one() == x and A.one()*x == x
@@ -622,7 +697,6 @@ class QuaternionMatrixAlgebra(HurwitzMatrixAlgebra):
 
     TESTS::
 
-        sage: set_random_seed()
         sage: A = QuaternionMatrixAlgebra(ZZ.random_element(10))
         sage: x = A.random_element()
         sage: x*A.one() == x and A.one()*x == x
@@ -732,7 +806,6 @@ class ComplexMatrixAlgebra(HurwitzMatrixAlgebra):
 
     TESTS::
 
-        sage: set_random_seed()
         sage: A = ComplexMatrixAlgebra(ZZ.random_element(10))
         sage: x = A.random_element()
         sage: x*A.one() == x and A.one()*x == x