]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: start fixing Cartesian products of Cartesian products.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 26 Feb 2021 16:29:15 +0000 (11:29 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 26 Feb 2021 16:29:15 +0000 (11:29 -0500)
mjo/eja/eja_algebra.py
mjo/eja/eja_element.py
mjo/eja/eja_utils.py

index cbe5c08a344a95248e0b7c15e94de80b0c662816..c1fc8078823eb8915f3caad13d55c8e2f61025bf 100644 (file)
@@ -3220,8 +3220,11 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         # 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]
+        try:
+            factor = mon[0]
+        except TypeError: # 'int' object is not subscriptable
+            return mon
+        idx_in_factor = self._monomial_to_generator(mon[1])
 
         offset = sum( f.dimension()
                       for f in self.cartesian_factors()[:factor] )
@@ -3236,8 +3239,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: 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::
 
index b5f661bf037667d4d9210b6af65a3c1f95120732..9a770ae5f68b3e19f3946ca7716f299a3ff82685 100644 (file)
@@ -4,7 +4,7 @@ from sage.modules.free_module import VectorSpace
 from sage.modules.with_basis.indexed_element import IndexedFreeModuleElement
 
 from mjo.eja.eja_operator import FiniteDimensionalEJAOperator
-from mjo.eja.eja_utils import _mat2vec
+from mjo.eja.eja_utils import _mat2vec, _scale
 
 class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
     """
@@ -1128,10 +1128,10 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
         if self.parent()._matrix_basis_is_cartesian:
             # Aaaaand linear combinations don't work in Cartesian
             # product spaces, even though they provide a method
-            # with that name.
+            # with that name. This is special-cased because the
+            # _scale() function is slow.
             pairs = zip(B, self.to_vector())
-            return sum( ( W(tuple(alpha*b_i for b_i in b))
-                          for (b,alpha) in pairs ),
+            return sum( ( _scale(b, alpha) for (b,alpha) in pairs ),
                         W.zero())
         else:
             # This is just a manual "from_vector()", but of course
index 38e75761dab0394f3aa5e6e3016aed7c0edebbc8..c25b81921e1be4f0d6a77580227cb8692e21605f 100644 (file)
@@ -2,6 +2,18 @@ from sage.functions.other import sqrt
 from sage.matrix.constructor import matrix
 from sage.modules.free_module_element import vector
 
+def _scale(x, alpha):
+    r"""
+    Scale the vector, matrix, or cartesian-product-of-those-things
+    ``x`` by ``alpha``.
+    """
+    if hasattr(x, 'cartesian_factors'):
+        P = x.parent()
+        return P(tuple( _scale(x_i, alpha)
+                        for x_i in x.cartesian_factors() ))
+    else:
+        return x*alpha
+
 def _all2list(x):
     r"""
     Flatten a vector, matrix, or cartesian product of those things
@@ -160,18 +172,16 @@ def gram_schmidt(v, inner_product=None):
 
     R = v[0].base_ring()
 
-    # Define a scaling operation that can be used on tuples.
-    # Oh and our "zero" needs to belong to the right space.
-    scale = lambda x,alpha: x*alpha
+    # Our "zero" needs to belong to the right space for sum() to work.
     zero = v[0].parent().zero()
-    if hasattr(v[0], 'cartesian_factors'):
-        P = v[0].parent()
-        scale = lambda x,alpha: P(tuple( x_i*alpha
-                                         for x_i in x.cartesian_factors() ))
 
+    sc = lambda x,a: a*x
+    if hasattr(v[0], 'cartesian_factors'):
+        # Only use the slow implementation if necessary.
+        sc = _scale
 
     def proj(x,y):
-        return scale(x, (inner_product(x,y)/inner_product(x,x)))
+        return sc(x, (inner_product(x,y)/inner_product(x,x)))
 
     # First orthogonalize...
     for i in range(1,len(v)):
@@ -188,6 +198,6 @@ def gram_schmidt(v, inner_product=None):
     # them here because then our subalgebra would have a bigger field
     # than the superalgebra.
     for i in range(len(v)):
-        v[i] = scale(v[i], ~norm(v[i]))
+        v[i] = sc(v[i], ~norm(v[i]))
 
     return v