]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add subclass for Cartesian product elements.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 23 Feb 2021 14:58:07 +0000 (09:58 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 23 Feb 2021 14:58:07 +0000 (09:58 -0500)
mjo/eja/eja_algebra.py
mjo/eja/eja_element.py

index 7fb8027658bd7a407e52ab0525acd8a7470a3f6e..a8df29f6e94161016217a9e13f6c1cc73c30354e 100644 (file)
@@ -31,7 +31,8 @@ from sage.modules.free_module import FreeModule, VectorSpace
 from sage.rings.all import (ZZ, QQ, AA, QQbar, RR, RLF, CLF,
                             PolynomialRing,
                             QuadraticField)
-from mjo.eja.eja_element import FiniteDimensionalEJAElement
+from mjo.eja.eja_element import (CartesianProductEJAElement,
+                                 FiniteDimensionalEJAElement)
 from mjo.eja.eja_operator import FiniteDimensionalEJAOperator
 from mjo.eja.eja_utils import _mat2vec
 
@@ -3163,7 +3164,7 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct,
         except:
             raise ValueError("not an element of this algebra")
 
-    Element = FiniteDimensionalEJAElement
+    Element = CartesianProductEJAElement
 
 
 FiniteDimensionalEJA.CartesianProduct = CartesianProductEJA
index c2f2b7c12ff92dbc0a57036057afad55acd63ddd..7388e963ceaf42c0bdf41851e2b8019de5e69b3a 100644 (file)
@@ -1117,6 +1117,7 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
         return W.linear_combination( zip(B, self.to_vector()) )
 
 
+
     def norm(self):
         """
         The norm of this element with respect to :meth:`inner_product`.
@@ -1618,3 +1619,40 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
 
         """
         return self.trace_inner_product(self).sqrt()
+
+
+
+class CartesianProductEJAElement(FiniteDimensionalEJAElement):
+
+    def to_matrix(self):
+        r"""
+        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: x = sum(J.gens())
+            sage: x.to_matrix()[0]
+            [1]
+            sage: x.to_matrix()[1]
+            [                  1 0.7071067811865475?]
+            [0.7071067811865475?                   1]
+
+        """
+        B = self.parent().matrix_basis()
+        W = self.parent().matrix_space()
+
+        # Aaaaand linear combinations don't work in Cartesian
+        # product spaces, even though they provide a method
+        # with that name.
+        pairs = zip(B, self.to_vector())
+        sigma = W.zero()
+        for (b,alpha) in pairs:
+            # sum(...) ALSO doesn't work on Cartesian products.
+            sigma += W(tuple(alpha*b_i for b_i in b))
+        return sigma