]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: don't waste time computing the unit element in subalgebras.
[sage.d.git] / mjo / eja / eja_algebra.py
index db1494681d054887781efc14acebd2f73653beb0..d4ee9b022d8524752d3e15edf37284c2381ce509 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)
@@ -379,6 +382,41 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         return x.trace_inner_product(y)
 
 
+    def multiplication_table(self):
+        """
+        Return a readable matrix representation of this algebra's
+        multiplication table. The (i,j)th entry in the matrix contains
+        the product of the ith basis element with the jth.
+
+        This is not extraordinarily useful, but it overrides a superclass
+        method that would otherwise just crash and complain about the
+        algebra being infinite.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
+            ....:                                  RealCartesianProductEJA)
+
+        EXAMPLES::
+
+            sage: J = RealCartesianProductEJA(3)
+            sage: J.multiplication_table()
+            [e0  0  0]
+            [ 0 e1  0]
+            [ 0  0 e2]
+
+        ::
+
+            sage: J = JordanSpinEJA(3)
+            sage: J.multiplication_table()
+            [e0 e1 e2]
+            [e1 e0  0]
+            [e2  0 e0]
+
+        """
+        return self._multiplication_table
+
+
     def natural_basis(self):
         """
         Return a more-natural representation of this algebra's basis.
@@ -442,7 +480,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
             sage: J.one()
             e0 + e1 + e2 + e3 + e4
 
-        TESTS::
+        TESTS:
 
         The identity element acts like the identity::
 
@@ -603,8 +641,8 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
     """
     def __init__(self, n, field=QQ):
         V = VectorSpace(field, n)
-        mult_table = [ [ V.basis()[i]*(i == j) for i in range(n) ]
-                       for j in range(n) ]
+        mult_table = [ [ V.gen(i)*(i == j) for j in range(n) ]
+                       for i in range(n) ]
 
         fdeja = super(RealCartesianProductEJA, self)
         return fdeja.__init__(field, mult_table, rank=n)
@@ -791,7 +829,7 @@ def _multiplication_table_from_matrix_basis(basis):
     V = VectorSpace(field, dimension**2)
     W = V.span_of_basis( _mat2vec(s) for s in basis )
     n = len(basis)
-    mult_table = [[W.zero() for i in range(n)] for j in range(n)]
+    mult_table = [[W.zero() for j in range(n)] for i in range(n)]
     for i in range(n):
         for j in range(n):
             mat_entry = (basis[i]*basis[j] + basis[j]*basis[i])/2
@@ -1257,11 +1295,11 @@ class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
     """
     def __init__(self, n, field=QQ):
         V = VectorSpace(field, n)
-        mult_table = [[V.zero() for i in range(n)] for j in range(n)]
+        mult_table = [[V.zero() for j in range(n)] for i in range(n)]
         for i in range(n):
             for j in range(n):
-                x = V.basis()[i]
-                y = V.basis()[j]
+                x = V.gen(i)
+                y = V.gen(j)
                 x0 = x[0]
                 xbar = x[1:]
                 y0 = y[0]