From: Michael Orlitzky Date: Wed, 25 Nov 2020 04:43:17 +0000 (-0500) Subject: eja: use cached charpoly for element inverse() if possible. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=0b151420d2a7cfc0b0af812f2204eeda4b9a70ba eja: use cached charpoly for element inverse() if possible. --- diff --git a/mjo/eja/TODO b/mjo/eja/TODO index 3c63d3b..87cdcbc 100644 --- a/mjo/eja/TODO +++ b/mjo/eja/TODO @@ -30,9 +30,7 @@ the usual one. Then for the basis to be orthonormal, we would need to divide e.g. (1,0,0) by <(1,0,0),(1,0,0)> = 2 to normalize it. -8. Use charpoly for inverse itself? +8. Pre-cache charpoly for some small algebras? -9. Pre-cache charpoly for some small algebras? - -10. Compute the scalar in the general natural_inner_product() for - matrices, so no overrides are necessary. \ No newline at end of file +9. Compute the scalar in the general natural_inner_product() for + matrices, so no overrides are necessary. \ No newline at end of file diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index 739bff3..5a0b213 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -507,6 +507,14 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): if not self.is_invertible(): raise ValueError("element is not invertible") + if self.parent()._charpoly_coefficients.is_in_cache(): + # We can invert using our charpoly if it will be fast to + # compute. If the coefficients are cached, our rank had + # better be too! + r = self.parent().rank() + a = self.characteristic_polynomial().coefficients(sparse=False) + return (-1)**(r+1)*sum(a[i+1]*self**i for i in range(r))/self.det() + return (~self.quadratic_representation())(self)