From: Michael Orlitzky Date: Thu, 28 Nov 2024 18:15:57 +0000 (-0500) Subject: mjo/eja/eja_operator.py: speed up is_isometry() and is_homomorphism() X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=32c118994ce9a02632bbc8498e6008e80da5558d;p=sage.d.git mjo/eja/eja_operator.py: speed up is_isometry() and is_homomorphism() Both of these are symmetric, so we can skip about half of the checks. --- diff --git a/mjo/eja/eja_operator.py b/mjo/eja/eja_operator.py index c2a8d9c..8b6dbe2 100644 --- a/mjo/eja/eja_operator.py +++ b/mjo/eja/eja_operator.py @@ -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):