From: Michael Orlitzky Date: Fri, 26 Feb 2021 18:30:28 +0000 (-0500) Subject: eja: more tests/examples. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=8059516ad9df112ac18c740af7d6f856639d4b8d;p=sage.d.git eja: more tests/examples. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index ad619f6..5d96a53 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -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,6 +3227,9 @@ 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 @@ -3216,15 +3246,15 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct, 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. + # 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() diff --git a/mjo/eja/eja_utils.py b/mjo/eja/eja_utils.py index c25b819..832dcef 100644 --- a/mjo/eja/eja_utils.py +++ b/mjo/eja/eja_utils.py @@ -6,6 +6,32 @@ def _scale(x, alpha): r""" Scale the vector, matrix, or cartesian-product-of-those-things ``x`` by ``alpha``. + + This works around the inability to scale certain elements of + Cartesian product spaces, as reported in + + https://trac.sagemath.org/ticket/31435 + + ..WARNING: + + This will do the wrong thing if you feed it a tuple or list. + + SETUP:: + + sage: from mjo.eja.eja_utils import _scale + + EXAMPLES:: + + sage: v = vector(QQ, (1,2,3)) + sage: _scale(v,2) + (2, 4, 6) + sage: m = matrix(QQ, [[1,2],[3,4]]) + sage: M = cartesian_product([m.parent(), m.parent()]) + sage: _scale(M((m,m)), 2) + ([2 4] + [6 8], [2 4] + [6 8]) + """ if hasattr(x, 'cartesian_factors'): P = x.parent() @@ -14,6 +40,7 @@ def _scale(x, alpha): else: return x*alpha + def _all2list(x): r""" Flatten a vector, matrix, or cartesian product of those things