From: Michael Orlitzky Date: Sat, 27 Feb 2021 23:29:29 +0000 (-0500) Subject: eja: use the new deep change_ring() to clean things up. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=78bee5c30c1cd2828d9834fc7d652db21331d4fe eja: use the new deep change_ring() to clean things up. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 558ff6b..7994900 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -144,17 +144,7 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): check_axioms=True, prefix='e'): - # Keep track of whether or not the matrix basis consists of - # tuples, since we need special cases for them damned near - # everywhere. This is INDEPENDENT of whether or not the - # algebra is a cartesian product, since a subalgebra of a - # cartesian product will have a basis of tuples, but will not - # in general itself be a cartesian product algebra. - self._matrix_basis_is_cartesian = False n = len(basis) - if n > 0: - if hasattr(basis[0], 'cartesian_factors'): - self._matrix_basis_is_cartesian = True if check_field: if not field.is_subring(RR): @@ -163,20 +153,10 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): # we've specified a real embedding. raise ValueError("scalar field is not real") + from mjo.eja.eja_utils import _change_ring # If the basis given to us wasn't over the field that it's # supposed to be over, fix that. Or, you know, crash. - if not cartesian_product: - # The field for a cartesian product algebra comes from one - # of its factors and is the same for all factors, so - # there's no need to "reapply" it on product algebras. - if self._matrix_basis_is_cartesian: - # OK since if n == 0, the basis does not consist of tuples. - P = basis[0].parent() - basis = tuple( P(tuple(b_i.change_ring(field) for b_i in b)) - for b in basis ) - else: - basis = tuple( b.change_ring(field) for b in basis ) - + basis = tuple( _change_ring(b, field) for b in basis ) if check_axioms: # Check commutativity of the Jordan and inner-products. diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index e8c183b..81c2b54 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -1125,14 +1125,13 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement): B = self.parent().matrix_basis() W = self.parent().matrix_space() - if self.parent()._matrix_basis_is_cartesian: + if hasattr(W, 'cartesian_factors'): # Aaaaand linear combinations don't work in Cartesian - # product spaces, even though they provide a method - # with that name. This is special-cased because the + # product spaces, even though they provide a method with + # that name. This is hidden behind an "if" because the # _scale() function is slow. pairs = zip(B, self.to_vector()) - return sum( ( _scale(b, alpha) for (b,alpha) in pairs ), - W.zero()) + return W.sum( _scale(b, alpha) for (b,alpha) in pairs ) else: # This is just a manual "from_vector()", but of course # matrix spaces aren't vector spaces in sage, so they