]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add fast natural_inner_product() overrides for complex/quaternions.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 24 Aug 2019 01:44:29 +0000 (21:44 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 24 Aug 2019 01:44:29 +0000 (21:44 -0400)
mjo/eja/eja_algebra.py

index 51973d14822bdc5dd49065de77c1927883161ae9..ae5baa0eff4a64dac97944bbdaf5a8ec132495bd 100644 (file)
@@ -1261,6 +1261,37 @@ class ComplexMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
         return matrix(F, n/2, elements)
 
 
+    @classmethod
+    def natural_inner_product(cls,X,Y):
+        """
+        Compute a natural inner product in this algebra directly from
+        its real embedding.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
+
+        TESTS:
+
+        This gives the same answer as the slow, default method implemented
+        in :class:`MatrixEuclideanJordanAlgebra`::
+
+            sage: set_random_seed()
+            sage: J = ComplexHermitianEJA.random_instance()
+            sage: x,y = J.random_elements(2)
+            sage: Xe = x.natural_representation()
+            sage: Ye = y.natural_representation()
+            sage: X = ComplexHermitianEJA.real_unembed(Xe)
+            sage: Y = ComplexHermitianEJA.real_unembed(Ye)
+            sage: expected = (X*Y).trace().vector()[0]
+            sage: actual = ComplexHermitianEJA.natural_inner_product(Xe,Ye)
+            sage: actual == expected
+            True
+
+        """
+        return RealMatrixEuclideanJordanAlgebra.natural_inner_product(X,Y)/2
+
+
 class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra):
     """
     The rank-n simple EJA consisting of complex Hermitian n-by-n
@@ -1509,6 +1540,36 @@ class QuaternionMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
         return matrix(Q, n/4, elements)
 
 
+    @classmethod
+    def natural_inner_product(cls,X,Y):
+        """
+        Compute a natural inner product in this algebra directly from
+        its real embedding.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
+
+        TESTS:
+
+        This gives the same answer as the slow, default method implemented
+        in :class:`MatrixEuclideanJordanAlgebra`::
+
+            sage: set_random_seed()
+            sage: J = QuaternionHermitianEJA.random_instance()
+            sage: x,y = J.random_elements(2)
+            sage: Xe = x.natural_representation()
+            sage: Ye = y.natural_representation()
+            sage: X = QuaternionHermitianEJA.real_unembed(Xe)
+            sage: Y = QuaternionHermitianEJA.real_unembed(Ye)
+            sage: expected = (X*Y).trace().coefficient_tuple()[0]
+            sage: actual = QuaternionHermitianEJA.natural_inner_product(Xe,Ye)
+            sage: actual == expected
+            True
+
+        """
+        return RealMatrixEuclideanJordanAlgebra.natural_inner_product(X,Y)/4
+
 
 class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra):
     """