]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: more tests/examples.
[sage.d.git] / mjo / eja / eja_algebra.py
index cbe5c08a344a95248e0b7c15e94de80b0c662816..5d96a53f402f4f3343cc396049b4311d13fa3ba1 100644 (file)
@@ -3115,6 +3115,33 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         sage: CP2.is_associative()
         False
 
+    Cartesian products of Cartesian products work::
+
+        sage: J1 = JordanSpinEJA(1)
+        sage: J2 = JordanSpinEJA(1)
+        sage: J3 = JordanSpinEJA(1)
+        sage: J = cartesian_product([J1,cartesian_product([J2,J3])])
+        sage: J.multiplication_table()
+        +--------------++---------+--------------+--------------+
+        | *            || e(0, 0) | e(1, (0, 0)) | e(1, (1, 0)) |
+        +==============++=========+==============+==============+
+        | e(0, 0)      || e(0, 0) | 0            | 0            |
+        +--------------++---------+--------------+--------------+
+        | e(1, (0, 0)) || 0       | e(1, (0, 0)) | 0            |
+        +--------------++---------+--------------+--------------+
+        | e(1, (1, 0)) || 0       | 0            | e(1, (1, 0)) |
+        +--------------++---------+--------------+--------------+
+        sage: HadamardEJA(3).multiplication_table()
+        +----++----+----+----+
+        | *  || e0 | e1 | e2 |
+        +====++====+====+====+
+        | e0 || e0 | 0  | 0  |
+        +----++----+----+----+
+        | e1 || 0  | e1 | 0  |
+        +----++----+----+----+
+        | e2 || 0  | 0  | e2 |
+        +----++----+----+----+
+
     TESTS:
 
     All factors must share the same base field::
@@ -3200,9 +3227,12 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         r"""
         Convert a monomial index into a generator index.
 
+        This is needed in product algebras because the multiplication
+        table is in terms of the generator indices.
+
         SETUP::
 
-            sage: from mjo.eja.eja_algebra import random_eja()
+            sage: from mjo.eja.eja_algebra import random_eja
 
         TESTS::
 
@@ -3213,15 +3243,19 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
             ....:      ==
             ....:      J.gens()[J._monomial_to_generator(m)]
             ....:      for m in J.basis().keys() )
+            True
 
         """
-        # The superclass method indexes into a matrix, so we have to
-        # turn the tuples i and j into integers. This is easy enough
-        # given that the first coordinate of i and j corresponds to
-        # the factor, and the second coordinate corresponds to the
-        # index of the generator within that factor.
-        factor = mon[0]
-        idx_in_factor = mon[1]
+        # This works recursively so that we can handle Cartesian
+        # products of Cartesian products.
+        try:
+            # monomial is an ordered pair
+            factor = mon[0]
+        except TypeError: # 'int' object is not subscriptable
+            # base case where the monomials are integers
+            return mon
+
+        idx_in_factor = self._monomial_to_generator(mon[1])
 
         offset = sum( f.dimension()
                       for f in self.cartesian_factors()[:factor] )
@@ -3236,8 +3270,24 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
 
         SETUP::
 
-            sage: from mjo.eja.eja_algebra import (QuaternionHermitianEJA,
-            ....:                                  RealSymmetricEJA)
+            sage: from mjo.eja.eja_algebra import (HadamardEJA,
+            ....:                                  JordanSpinEJA,
+            ....:                                  QuaternionHermitianEJA,
+            ....:                                  RealSymmetricEJA,)
+
+        EXAMPLES::
+
+            sage: J1 = JordanSpinEJA(2, field=QQ)
+            sage: J2 = RealSymmetricEJA(2, field=QQ, orthonormalize=False)
+            sage: J3 = HadamardEJA(1, field=QQ)
+            sage: K1 = cartesian_product([J1,J2])
+            sage: K2 = cartesian_product([K1,J3])
+            sage: list(K2.basis())
+            [e(0, (0, 0)), e(0, (0, 1)), e(0, (1, 0)), e(0, (1, 1)),
+            e(0, (1, 2)), e(1, 0)]
+            sage: g = K2.gens()
+            sage: (g[0] + 2*g[3]) * (g[1] - 4*g[2])
+            e(0, (0, 1)) - 4*e(0, (1, 1))
 
         TESTS::
 
@@ -3506,3 +3556,16 @@ class RationalBasisCartesianProductEJA(CartesianProductEJA,
 RationalBasisEJA.CartesianProduct = RationalBasisCartesianProductEJA
 
 random_eja = ConcreteEJA.random_instance
+
+# def random_eja(*args, **kwargs):
+#     J1 = ConcreteEJA.random_instance(*args, **kwargs)
+
+#     # This might make Cartesian products appear roughly as often as
+#     # any other ConcreteEJA.
+#     if ZZ.random_element(len(ConcreteEJA.__subclasses__()) + 1) == 0:
+#         # Use random_eja() again so we can get more than two factors.
+#         J2 = random_eja(*args, **kwargs)
+#         J = cartesian_product([J1,J2])
+#         return J
+#     else:
+#         return J1