]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: improve rational basis algebra trickery.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 2 Dec 2020 13:42:41 +0000 (08:42 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 2 Dec 2020 13:42:41 +0000 (08:42 -0500)
mjo/eja/eja_algebra.py

index bab1002ae7d0e2bc1e0fe1332f28871f55efadf2..ec3dd1141a9f497acca26f6d09c830420dfb5d5d 100644 (file)
@@ -1189,28 +1189,34 @@ class RationalBasisEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebr
         # deorthonormalized basis. These can be used later to
         # construct a deorthonormalized copy of this algebra over QQ
         # in which several operations are much faster.
-        self._deortho_multiplication_table = None
-        self._deortho_inner_product_table = None
+        self._rational_algebra = None
 
         if orthonormalize:
+            if self.base_ring() is not QQ:
+                # There's no point in constructing the extra algebra if this
+                # one is already rational. If the original basis is rational
+                # but normalization would make it irrational, then this whole
+                # constructor will just fail anyway as it tries to stick an
+                # irrational number into a rational algebra.
+                #
+                # Note: the same Jordan and inner-products work here,
+                # because they are necessarily defined with respect to
+                # ambient coordinates and not any particular basis.
+                self._rational_algebra = RationalBasisEuclideanJordanAlgebra(
+                                          QQ,
+                                          basis,
+                                          jordan_product,
+                                          inner_product,
+                                          orthonormalize=False,
+                                          prefix=prefix,
+                                          category=category,
+                                          check_field=False,
+                                          check_axioms=False)
+
             # Compute the deorthonormalized tables before we orthonormalize
             # the given basis.
             W = V.span_of_basis( vector_basis )
 
-            if check_axioms:
-                # If the superclass constructor is going to verify the
-                # symmetry of this table, it has better at least be
-                # square...
-                self._deortho_multiplication_table = [ [0 for j in range(n)]
-                                                       for i in range(n) ]
-                self._deortho_inner_product_table = [ [0 for j in range(n)]
-                                                      for i in range(n) ]
-            else:
-                self._deortho_multiplication_table = [ [0 for j in range(i+1)]
-                                                       for i in range(n) ]
-                self._deortho_inner_product_table = [ [0 for j in range(i+1)]
-                                                      for i in range(n) ]
-
             # Note: the Jordan and inner-products are defined in terms
             # of the ambient basis. It's important that their arguments
             # are in ambient coordinates as well.
@@ -1232,20 +1238,6 @@ class RationalBasisEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebr
                         # table is in terms of vectors
                         elt = _mat2vec(elt)
 
-                    elt = W.coordinate_vector(elt)
-                    self._deortho_multiplication_table[i][j] = elt
-                    self._deortho_inner_product_table[i][j] = ip
-                    if check_axioms:
-                        # The tables are square if we're verifying that they
-                        # are commutative.
-                        self._deortho_multiplication_table[j][i] = elt
-                        self._deortho_inner_product_table[j][i] = ip
-
-        if self._deortho_multiplication_table is not None:
-            self._deortho_multiplication_table = tuple(map(tuple, self._deortho_multiplication_table))
-        if self._deortho_inner_product_table is not None:
-            self._deortho_inner_product_table = tuple(map(tuple, self._deortho_inner_product_table))
-
         # We overwrite the name "vector_basis" in a second, but never modify it
         # in place, to this effectively makes a copy of it.
         deortho_vector_basis = vector_basis
@@ -1365,13 +1357,9 @@ class RationalBasisEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebr
 
         # Do the computation over the rationals. The answer will be
         # the same, because all we've done is a change of basis.
-        J = FiniteDimensionalEuclideanJordanAlgebra(QQ,
-                                                    self._deortho_multiplication_table,
-                                                    self._deortho_inner_product_table)
-
-        # Change back from QQ to our real base ring
+        # Then, change back from QQ to our real base ring
         a = ( a_i.change_ring(self.base_ring())
-              for a_i in J._charpoly_coefficients() )
+              for a_i in self._rational_algebra._charpoly_coefficients() )
 
         # Now convert the coordinate variables back to the
         # deorthonormalized ones.
@@ -1609,7 +1597,7 @@ class RealSymmetricEJA(ConcreteEuclideanJordanAlgebra,
                 else:
                     Sij = Eij + Eij.transpose()
                 S.append(Sij)
-        return S
+        return tuple(S)
 
 
     @staticmethod