]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: store the multiplication table as a matrix.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Aug 2019 01:07:23 +0000 (21:07 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Aug 2019 01:07:23 +0000 (21:07 -0400)
This way, we don't need to either regenerate it when someone calls
multiplication_table(), or cache a second copy of it. Besides,
matrices are efficient and indexing one is probably faster than
indexing a list of lists.

mjo/eja/eja_algebra.py

index 8fe3a3ceee26f579b7ce9fa126d2169c2a12ec62..a7bccc3f400899e90837911a6b5683f70e71a35c 100644 (file)
@@ -64,8 +64,10 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         # long run to have the multiplication table be in terms of
         # algebra elements. We do this after calling the superclass
         # constructor so that from_vector() knows what to do.
-        self._multiplication_table = [ map(lambda x: self.from_vector(x), ls)
-                                       for ls in mult_table ]
+        self._multiplication_table = matrix(
+            [ map(lambda x: self.from_vector(x), ls)
+              for ls in mult_table ] )
+        self._multiplication_table.set_immutable()
 
 
     def _element_constructor_(self, elt):
@@ -153,7 +155,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         return fmt.format(self.dimension(), self.base_ring())
 
     def product_on_basis(self, i, j):
-        return self._multiplication_table[i][j]
+        return self._multiplication_table[i,j]
 
     def _a_regular_element(self):
         """
@@ -249,8 +251,9 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         R = PolynomialRing(self.base_ring(), names)
         # Hack around the fact that our multiplication table is in terms of
         # algebra elements but the constructor wants it in terms of vectors.
-        vmt = [ tuple(map(lambda x: x.to_vector(), ls))
-                for ls in self._multiplication_table ]
+        vmt = [ tuple([ self._multiplication_table[i,j].to_vector()
+                        for j in range(self._multiplication_table.nrows()) ])
+                for i in range(self._multiplication_table.ncols()) ]
         J = FiniteDimensionalEuclideanJordanAlgebra(R, tuple(vmt), r)
 
         idmat = matrix.identity(J.base_ring(), n)
@@ -411,7 +414,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
             [e2  0 e0]
 
         """
-        return matrix(self._multiplication_table)
+        return self._multiplication_table
 
 
     def natural_basis(self):