From 827b203e50561de19857935f456509cf2392ee70 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 28 Feb 2021 23:28:55 -0500 Subject: [PATCH] eja: speed up minimal_polynomial(), in theory. --- mjo/eja/eja_element.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index 81c2b54..52933e2 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -1047,19 +1047,30 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement): """ if self.is_zero(): - # We would generate a zero-dimensional subalgebra - # where the minimal polynomial would be constant. - # That might be correct, but only if *this* algebra - # is trivial too. - if not self.parent().is_trivial(): - # Pretty sure we know what the minimal polynomial of - # the zero operator is going to be. This ensures - # consistency of e.g. the polynomial variable returned - # in the "normal" case without us having to think about it. - return self.operator().minimal_polynomial() - + # Pretty sure we know what the minimal polynomial of + # the zero operator is going to be. This ensures + # consistency of e.g. the polynomial variable returned + # in the "normal" case without us having to think about it. + return self.operator().minimal_polynomial() + + # If we don't orthonormalize the subalgebra's basis, then the + # first two monomials in the subalgebra will be self^0 and + # self^1... assuming that self^1 is not a scalar multiple of + # self^0 (the unit element). We special case these to avoid + # having to solve a system to coerce self into the subalgebra. A = self.subalgebra_generated_by(orthonormalize=False) - return A(self).operator().minimal_polynomial() + + if A.dimension() == 1: + # Does a solve to find the scalar multiple alpha such that + # alpha*unit = self. We have to do this because the basis + # for the subalgebra will be [ self^0 ], and not [ self^1 ]! + unit = self.parent().one() + alpha = self.to_vector() / unit.to_vector() + return (unit.operator()*alpha).minimal_polynomial() + else: + # If the dimension of the subalgebra is >= 2, then we just + # use the second basis element. + return A.monomial(1).operator().minimal_polynomial() -- 2.43.2