]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: speed up _charpoly_coefficients when rank is cached.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2020 22:28:56 +0000 (17:28 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 4 Nov 2020 22:28:56 +0000 (17:28 -0500)
mjo/eja/eja_algebra.py

index fc64510dde701f7f820456d9972691fe07f71178..bcafe57cbebd2b974eda6e3f13b3ceda26ffd4ab 100644 (file)
@@ -688,6 +688,14 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
                         for k in range(n) )
 
         L_x = matrix(F, n, n, L_x_i_j)
+
+        r = None
+        if self.rank.is_in_cache():
+            r = self.rank()
+            # There's no need to pad the system with redundant
+            # columns if we *know* they'll be redundant.
+            n = r
+
         # Compute an extra power in case the rank is equal to
         # the dimension (otherwise, we would stop at x^(r-1)).
         x_powers = [ (L_x**k)*self.one().to_vector()
@@ -696,7 +704,8 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         AE = A.extended_echelon_form()
         E = AE[:,n:]
         A_rref = AE[:,:n]
-        r = A_rref.rank()
+        if r is None:
+            r = A_rref.rank()
         b = x_powers[r]
 
         # The theory says that only the first "r" coefficients are