]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: factor out MatrixEJA initialization.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 9 Mar 2021 23:51:29 +0000 (18:51 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 9 Mar 2021 23:51:29 +0000 (18:51 -0500)
mjo/eja/eja_algebra.py
mjo/eja/eja_element.py

index 4ee5aba352bf870b679e8c782559c53e2db579ad..b2891e577e9aa0c5e36b64b6a537807e9330d0e6 100644 (file)
@@ -1746,7 +1746,7 @@ class ConcreteEJA(FiniteDimensionalEJA):
         return eja_class.random_instance(*args, **kwargs)
 
 
-class MatrixEJA:
+class MatrixEJA(FiniteDimensionalEJA):
     @staticmethod
     def _denormalized_basis(A):
         """
@@ -1887,8 +1887,23 @@ class MatrixEJA:
         return tr.real()
 
 
+    def __init__(self, matrix_space, **kwargs):
+        # We know this is a valid EJA, but will double-check
+        # if the user passes check_axioms=True.
+        if "check_axioms" not in kwargs: kwargs["check_axioms"] = False
+
+
+        super().__init__(self._denormalized_basis(matrix_space),
+                         self.jordan_product,
+                         self.trace_inner_product,
+                         field=matrix_space.base_ring(),
+                         matrix_space=matrix_space,
+                         **kwargs)
+
+        self.rank.set_cache(matrix_space.nrows())
+        self.one.set_cache( self(matrix_space.one()) )
 
-class RealSymmetricEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
+class RealSymmetricEJA(MatrixEJA, RationalBasisEJA, ConcreteEJA):
     """
     The rank-n simple EJA consisting of real symmetric n-by-n
     matrices, the usual symmetric Jordan product, and the trace inner
@@ -1971,22 +1986,11 @@ class RealSymmetricEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
         if "check_axioms" not in kwargs: kwargs["check_axioms"] = False
 
         A = MatrixSpace(field, n)
-        super().__init__(self._denormalized_basis(A),
-                         self.jordan_product,
-                         self.trace_inner_product,
-                         field=field,
-                         matrix_space=A,
-                         **kwargs)
-
-        # TODO: this could be factored out somehow, but is left here
-        # because the MatrixEJA is not presently a subclass of the
-        # FDEJA class that defines rank() and one().
-        self.rank.set_cache(n)
-        self.one.set_cache( self(A.one()) )
+        super().__init__(A, **kwargs)
 
 
 
-class ComplexHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
+class ComplexHermitianEJA(MatrixEJA, RationalBasisEJA, ConcreteEJA):
     """
     The rank-n simple EJA consisting of complex Hermitian n-by-n
     matrices over the real numbers, the usual symmetric Jordan product,
@@ -2064,18 +2068,7 @@ class ComplexHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
 
         from mjo.hurwitz import ComplexMatrixAlgebra
         A = ComplexMatrixAlgebra(n, scalars=field)
-        super().__init__(self._denormalized_basis(A),
-                         self.jordan_product,
-                         self.trace_inner_product,
-                         field=field,
-                         matrix_space=A,
-                         **kwargs)
-
-        # TODO: this could be factored out somehow, but is left here
-        # because the MatrixEJA is not presently a subclass of the
-        # FDEJA class that defines rank() and one().
-        self.rank.set_cache(n)
-        self.one.set_cache( self(A.one()) )
+        super().__init__(A, **kwargs)
 
 
     @staticmethod
@@ -2091,7 +2084,7 @@ class ComplexHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
         return cls(n, **kwargs)
 
 
-class QuaternionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
+class QuaternionHermitianEJA(MatrixEJA, RationalBasisEJA, ConcreteEJA):
     r"""
     The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
     matrices, the usual symmetric Jordan product, and the
@@ -2155,18 +2148,7 @@ class QuaternionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
 
         from mjo.hurwitz import QuaternionMatrixAlgebra
         A = QuaternionMatrixAlgebra(n, scalars=field)
-        super().__init__(self._denormalized_basis(A),
-                         self.jordan_product,
-                         self.trace_inner_product,
-                         field=field,
-                         matrix_space=A,
-                         **kwargs)
-
-        # TODO: this could be factored out somehow, but is left here
-        # because the MatrixEJA is not presently a subclass of the
-        # FDEJA class that defines rank() and one().
-        self.rank.set_cache(n)
-        self.one.set_cache( self(A.one()) )
+        super().__init__(A, **kwargs)
 
 
     @staticmethod
@@ -2184,7 +2166,7 @@ class QuaternionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
         n = ZZ.random_element(cls._max_random_instance_size() + 1)
         return cls(n, **kwargs)
 
-class OctonionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
+class OctonionHermitianEJA(MatrixEJA, RationalBasisEJA, ConcreteEJA):
     r"""
     SETUP::
 
@@ -2297,18 +2279,7 @@ class OctonionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA):
 
         from mjo.hurwitz import OctonionMatrixAlgebra
         A = OctonionMatrixAlgebra(n, scalars=field)
-        super().__init__(self._denormalized_basis(A),
-                         self.jordan_product,
-                         self.trace_inner_product,
-                         field=field,
-                         matrix_space=A,
-                         **kwargs)
-
-        # TODO: this could be factored out somehow, but is left here
-        # because the MatrixEJA is not presently a subclass of the
-        # FDEJA class that defines rank() and one().
-        self.rank.set_cache(n)
-        self.one.set_cache( self(A.one()) )
+        super().__init__(A, **kwargs)
 
 
 class AlbertEJA(OctonionHermitianEJA):
index 6a48309499bce637cd039d4c8631ce451f890ff1..c98d9a2b64651562928a6489ef88e03fdd2b0dc9 100644 (file)
@@ -389,7 +389,7 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
             sage: (x*y).det() == x.det()*y.det()
             True
 
-        The determinant in matrix algebras is just the usual determinant::
+        The determinant in real matrix algebras is the usual determinant::
 
             sage: set_random_seed()
             sage: X = matrix.random(QQ,3)
@@ -404,21 +404,6 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
             sage: actual2 == expected
             True
 
-        ::
-
-            sage: set_random_seed()
-            sage: J1 = ComplexHermitianEJA(2)
-            sage: J2 = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
-            sage: X = matrix.random(GaussianIntegers(), 2)
-            sage: X = X + X.H
-            sage: expected = AA(X.det())
-            sage: actual1 = J1(J1.real_embed(X)).det()
-            sage: actual2 = J2(J2.real_embed(X)).det()
-            sage: expected == actual1
-            True
-            sage: expected == actual2
-            True
-
         """
         P = self.parent()
         r = P.rank()
@@ -1098,12 +1083,13 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
             sage: J.one()
             b0 + b3 + b8
             sage: J.one().to_matrix()
-            [1 0 0 0 0 0]
-            [0 1 0 0 0 0]
-            [0 0 1 0 0 0]
-            [0 0 0 1 0 0]
-            [0 0 0 0 1 0]
-            [0 0 0 0 0 1]
+            +---+---+---+
+            | 1 | 0 | 0 |
+            +---+---+---+
+            | 0 | 1 | 0 |
+            +---+---+---+
+            | 0 | 0 | 1 |
+            +---+---+---+
 
         ::