]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
mjo/eja/eja_operator.py: speed up is_isometry() and is_homomorphism()
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 28 Nov 2024 18:15:57 +0000 (13:15 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 28 Nov 2024 18:15:57 +0000 (13:15 -0500)
Both of these are symmetric, so we can skip about half of the checks.

mjo/eja/eja_operator.py

index c2a8d9c782ac5b5e10d7ba6f7c8a1089631cddb1..8b6dbe2d7217833e4a29a896c3ca904b8cf4a343 100644 (file)
@@ -656,11 +656,18 @@ class EJAOperator(Map):
         """
         # The basis may not be orthonormalized, so just having an
         # orthogonal matrix is not sufficient to determine isometry.
-        return all(
-            b1.inner_product(b2) == self(b1).inner_product(self(b2))
-            for b1 in self.domain().basis()
-            for b2 in self.domain().basis()
-        )
+        # Note: inner products are symmetric, so we only need to
+        # check the "above diagonal" pairs.
+        J = self.domain()
+        results = []
+        for i in range(J.dimension()):
+            for j in range(i+1):
+                results.append(
+                  J.monomial(i).inner_product(J.monomial(j))
+                  ==
+                  self(J.monomial(i)).inner_product(self(J.monomial(j)))
+                )
+        return all(results)
 
 
     def is_homomorphism(self):
@@ -710,11 +717,18 @@ class EJAOperator(Map):
             True
 
         """
-        return all(
-            self(b1*b2) == self(b1)*self(b2)
-            for b1 in self.domain().basis()
-            for b2 in self.domain().basis()
-        )
+        J = self.domain()
+        results = []
+        for i in range(J.dimension()):
+            for j in range(i+1):
+                # Multiplication is commutative, so we only
+                # need to test the "above-diagonal" pairs.
+                results.append(
+                  self(J.monomial(i)*J.monomial(j))
+                  ==
+                  self(J.monomial(i))*self(J.monomial(j))
+                )
+        return all(results)
 
 
     def is_isomorphism(self):