From: Michael Orlitzky Date: Sat, 21 Nov 2020 18:39:32 +0000 (-0500) Subject: eja: try to speed up super/subalgebra conversion. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=0d9367ac61e9350dbfa3547b93c484243c749d7d;p=sage.d.git eja: try to speed up super/subalgebra conversion. --- diff --git a/mjo/eja/eja_subalgebra.py b/mjo/eja/eja_subalgebra.py index cb9631d..110b049 100644 --- a/mjo/eja/eja_subalgebra.py +++ b/mjo/eja/eja_subalgebra.py @@ -83,11 +83,17 @@ class FiniteDimensionalEuclideanJordanSubalgebraElement(FiniteDimensionalEuclide True """ + # As with the _element_constructor_() method on the + # algebra... even in a subspace of a subspace, the basis + # elements belong to the ambient space. As a result, only one + # level of coordinate_vector() is needed, regardless of how + # deeply we're nested. W = self.parent().vector_space() V = self.parent().superalgebra().vector_space() - A = W.basis_matrix().transpose() - W_coords = A*self.to_vector() - V_coords = V.coordinate_vector(W_coords) + + # Multiply on the left because basis_matrix() is row-wise. + ambient_coords = self.to_vector()*W.basis_matrix() + V_coords = V.coordinate_vector(ambient_coords) return self.parent().superalgebra().from_vector(V_coords) @@ -164,12 +170,10 @@ class FiniteDimensionalEuclideanJordanSubalgebra(FiniteDimensionalEuclideanJorda except ValueError: prefix = prefixen[0] - basis_vectors = [ b.to_vector() for b in basis ] - # If our superalgebra is a subalgebra of something else, then # these vectors won't have the right coordinates for # V.span_of_basis() unless we use V.from_vector() on them. - W = V.span_of_basis( V.from_vector(v) for v in basis_vectors ) + W = V.span_of_basis( V.from_vector(b.to_vector()) for b in basis ) n = len(basis) mult_table = [[W.zero() for i in range(n)] for j in range(n)] @@ -230,12 +234,20 @@ class FiniteDimensionalEuclideanJordanSubalgebra(FiniteDimensionalEuclideanJorda if elt not in self.superalgebra(): raise ValueError("not an element of this subalgebra") - # The extra hackery is because foo.to_vector() might not - # live in foo.parent().vector_space()! - coords = sum( a*b for (a,b) - in zip(elt.to_vector(), - self.superalgebra().vector_space().basis()) ) - return self.from_vector(self.vector_space().coordinate_vector(coords)) + # The extra hackery is because foo.to_vector() might not live + # in foo.parent().vector_space()! Subspaces of subspaces still + # have user bases in the ambient space, though, so only one + # level of coordinate_vector() is needed. In other words, if V + # is itself a subspace, the basis elements for W will be of + # the same length as the basis elements for V -- namely + # whatever the dimension of the ambient (parent of V?) space is. + V = self.superalgebra().vector_space() + W = self.vector_space() + + # Multiply on the left because basis_matrix() is row-wise. + ambient_coords = elt.to_vector()*V.basis_matrix() + W_coords = W.coordinate_vector(ambient_coords) + return self.from_vector(W_coords)