From: Michael Orlitzky Date: Mon, 22 Feb 2021 17:02:04 +0000 (-0500) Subject: eja: cache one() for Cartesian product algebras. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=9c771ecf5712b700f294f1ff2f18f785008f0f63;p=sage.d.git eja: cache one() for Cartesian product algebras. --- diff --git a/mjo/eja/TODO b/mjo/eja/TODO index fe18d56..03bf404 100644 --- a/mjo/eja/TODO +++ b/mjo/eja/TODO @@ -1,9 +1,9 @@ -1. Finish CartesianProductEJA: add to_matrix(), random_instance(), - one()... methods. This will require rethinking what a "matrix - representation" and "matrix space" means for a cartesian product - algebra. Do we want our matrix basis to consist of ordered pairs - (or triples, or...)? Should the matrix_space() of the algebra be - the cartesian product of the factors' matrix spaces? Can we just +1. Finish CartesianProductEJA: add to_matrix(), + random_instance(),... methods. This will require rethinking what a + "matrix representation" and "matrix space" means for a cartesian + product algebra. Do we want our matrix basis to consist of ordered + pairs (or triples, or...)? Should the matrix_space() of the algebra + be the cartesian product of the factors' matrix spaces? Can we just fix the matrix basis/space after we call the FDEJA initializer? 2. Add references and start citing them. diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 3390df7..850447b 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -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,6 +2832,8 @@ 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)) @cached_method