From 2eead94218aad1f63faec9cdeacc30171a880438 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 11 Mar 2021 15:03:14 -0500 Subject: [PATCH] eja: fix a deorthonormalization bug. --- mjo/eja/TODO | 19 +------------------ mjo/eja/eja_algebra.py | 22 ++++++++++++---------- mjo/eja/eja_element.py | 3 ++- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/mjo/eja/TODO b/mjo/eja/TODO index 529f70f..38cff88 100644 --- a/mjo/eja/TODO +++ b/mjo/eja/TODO @@ -2,24 +2,7 @@ 2. Profile (and fix?) any remaining slow operations. -3. Every once in a long while, the test - - sage: set_random_seed() - sage: x = random_eja().random_element() - sage: x.is_invertible() == (x.det() != 0) - - in eja_element.py returns False. Example: - - sage: J1 = ComplexHermitianEJA(2) - sage: J2 = TrivialEJA() - sage: J = cartesian_product([J1,J2]) - sage: x = J.from_vector(vector(QQ, [-1, -1/2, -1/2, -1/2])) - sage: x.is_invertible() - True - sage: x.det() - 0 - -4. When we take a Cartesian product involving a trivial algebra, we +3. When we take a Cartesian product involving a trivial algebra, we could easily cache the identity and charpoly coefficients using the nontrivial factor. On the other hand, it's nice that we can test out some alternate code paths... diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 8b37a83..615b0d4 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -319,9 +319,11 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): # written out as "long vectors." V = VectorSpace(field, degree) - # The matrix that will hole the orthonormal -> unorthonormal - # coordinate transformation. - self._deortho_matrix = None + # The matrix that will hold the orthonormal -> unorthonormal + # coordinate transformation. Default to an identity matrix of + # the appropriate size to avoid special cases for None + # everywhere. + self._deortho_matrix = matrix.identity(field,n) if orthonormalize: # Save a copy of the un-orthonormalized basis for later. @@ -1753,13 +1755,6 @@ class RationalBasisEJA(FiniteDimensionalEJA): a = ( a_i.change_ring(self.base_ring()) for a_i in self._rational_algebra._charpoly_coefficients() ) - if self._deortho_matrix is None: - # This can happen if our base ring was, say, AA and we - # chose not to (or didn't need to) orthonormalize. It's - # still faster to do the computations over QQ even if - # the numbers in the boxes stay the same. - return tuple(a) - # Otherwise, convert the coordinate variables back to the # deorthonormalized ones. R = self.coordinate_polynomial_ring() @@ -3086,6 +3081,13 @@ class CartesianProductEJA(FiniteDimensionalEJA): check_field=False, check_axioms=False) + # Since we don't (re)orthonormalize the basis, the FDEJA + # constructor is going to set self._deortho_matrix to the + # identity matrix. Here we set it to the correct value using + # the deortho matrices from our factors. + self._deortho_matrix = matrix.block_diagonal( [J._deortho_matrix + for J in factors] ) + self.rank.set_cache(sum(J.rank() for J in factors)) ones = tuple(J.one().to_matrix() for J in factors) self.one.set_cache(self(ones)) diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index fbfd127..14bc8cb 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -131,7 +131,8 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement): SETUP:: - sage: from mjo.eja.eja_algebra import HadamardEJA + sage: from mjo.eja.eja_algebra import (random_eja, + ....: HadamardEJA) EXAMPLES: -- 2.43.2