]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: define matrix basis/space for Cartesian product algebras.
[sage.d.git] / mjo / eja / eja_algebra.py
index 3390df7545bb41257ee58c68f04154ce7a18d462..065339617b4b711dc52cd4a498cf59e59a6c18b1 100644 (file)
@@ -2780,6 +2780,19 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         True
         sage: x.inner_product(y) == J.cartesian_inner_product(x,y)
         True
+
+    The cached unit element is the same one that would be computed::
+
+        sage: set_random_seed()              # long time
+        sage: J1 = random_eja()              # long time
+        sage: J2 = random_eja()              # long time
+        sage: J = cartesian_product([J1,J2]) # long time
+        sage: actual = J.one()               # long time
+        sage: J.one.clear_cache()            # long time
+        sage: expected = J.one()             # long time
+        sage: actual == expected             # long time
+        True
+
     """
     def __init__(self, modules, **kwargs):
         CombinatorialFreeModule_CartesianProduct.__init__(self,
@@ -2819,8 +2832,49 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
                                       check_axioms=False,
                                       category=self.category())
 
+        ones = tuple(J.one() for J in modules)
+        self.one.set_cache(self._cartesian_product_of_elements(ones))
         self.rank.set_cache(sum(J.rank() for J in modules))
 
+        # Now that everything else is ready, we clobber our computed
+        # matrix basis with the "correct" one consisting of ordered
+        # tuples. Since we didn't orthonormalize our basis, we can
+        # create these from the basis that was handed to us; that is,
+        # we don't need to use the one that the earlier __init__()
+        # method came up with.
+        m = len(self.cartesian_factors())
+        MS = self.matrix_space()
+        self._matrix_basis = tuple(
+            MS(tuple( self.cartesian_projection(i)(b).to_matrix()
+                      for i in range(m) ))
+            for b in self.basis()
+        )
+
+    def matrix_space(self):
+        r"""
+        Return the space that our matrix basis lives in as a Cartesian
+        product.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import (HadamardEJA,
+            ....:                                  RealSymmetricEJA)
+
+        EXAMPLES::
+
+            sage: J1 = HadamardEJA(1)
+            sage: J2 = RealSymmetricEJA(2)
+            sage: J = cartesian_product([J1,J2])
+            sage: J.matrix_space()
+            The Cartesian product of (Full MatrixSpace of 1 by 1 dense
+            matrices over Algebraic Real Field, Full MatrixSpace of 2
+            by 2 dense matrices over Algebraic Real Field)
+
+        """
+        from sage.categories.cartesian_product import cartesian_product
+        return cartesian_product( [J.matrix_space()
+                                   for J in self.cartesian_factors()] )
+
     @cached_method
     def cartesian_projection(self, i):
         r"""
@@ -3081,6 +3135,31 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         return sum( P(x).inner_product(P(y)) for P in projections )
 
 
+    def _element_constructor_(self, elt):
+        r"""
+        Construct an element of this algebra from an ordered tuple.
+
+        We just apply the element constructor from each of our factors
+        to the corresponding component of the tuple, and package up
+        the result.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import (HadamardEJA,
+            ....:                                  RealSymmetricEJA)
+
+        EXAMPLES::
+
+            sage: J1 = HadamardEJA(3)
+            sage: J2 = RealSymmetricEJA(2)
+            sage: J = cartesian_product([J1,J2])
+            sage: J( (J1.matrix_basis()[1], J2.matrix_basis()[2]) )
+            e(0, 1) + e(1, 2)
+        """
+        m = len(self.cartesian_factors())
+        z = tuple( self.cartesian_factors()[i](elt[i]) for i in range(m) )
+        return self._cartesian_product_of_elements(z)
+
     Element = FiniteDimensionalEJAElement