X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Feja%2Feja_element.py;h=6547668965a690b883a5ac59757ef1e625016604;hb=9a6de831e947f663cacf56e409e99ec3aa086c62;hp=c5f0e77599e821ba153726c519b9f8dc9f9c8532;hpb=93e7b502538bd416c11a81cd0b8f47c24e934691;p=sage.d.git diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index c5f0e77..6547668 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -2,11 +2,6 @@ from sage.matrix.constructor import matrix from sage.modules.free_module import VectorSpace from sage.modules.with_basis.indexed_element import IndexedFreeModuleElement -# TODO: make this unnecessary somehow. -from sage.misc.lazy_import import lazy_import -lazy_import('mjo.eja.eja_algebra', 'FiniteDimensionalEuclideanJordanAlgebra') -lazy_import('mjo.eja.eja_element_subalgebra', - 'FiniteDimensionalEuclideanJordanElementSubalgebra') from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator from mjo.eja.eja_utils import _mat2vec @@ -507,6 +502,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) @@ -523,6 +526,11 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): whether or not the paren't algebra's zero element is a root of this element's minimal polynomial. + That is... unless the coefficients of our algebra's + "characteristic polynomial of" function are already cached! + In that case, we just use the determinant (which will be fast + as a result). + Beware that we can't use the superclass method, because it relies on the algebra being associative. @@ -553,6 +561,11 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): else: return False + if self.parent()._charpoly_coefficients.is_in_cache(): + # The determinant will be quicker than computing the minimal + # polynomial from scratch, most likely. + return (not self.det().is_zero()) + # In fact, we only need to know if the constant term is non-zero, # so we can pass in the field's zero element instead. zero = self.base_ring().zero() @@ -958,15 +971,16 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): - def natural_representation(self): + def to_matrix(self): """ - Return a more-natural representation of this element. + Return an (often more natural) representation of this element as a + matrix. - Every finite-dimensional Euclidean Jordan Algebra is a - direct sum of five simple algebras, four of which comprise - Hermitian matrices. This method returns the original - "natural" representation of this element as a Hermitian - matrix, if it has one. If not, you get the usual representation. + Every finite-dimensional Euclidean Jordan Algebra is a direct + sum of five simple algebras, four of which comprise Hermitian + matrices. This method returns a "natural" matrix + representation of this element as either a Hermitian matrix or + column vector. SETUP:: @@ -978,7 +992,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): sage: J = ComplexHermitianEJA(3) sage: J.one() e0 + e3 + e8 - sage: J.one().natural_representation() + sage: J.one().to_matrix() [1 0 0 0 0 0] [0 1 0 0 0 0] [0 0 1 0 0 0] @@ -991,7 +1005,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): sage: J = QuaternionHermitianEJA(3) sage: J.one() e0 + e5 + e14 - sage: J.one().natural_representation() + sage: J.one().to_matrix() [1 0 0 0 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 0 0 0 0] @@ -1004,11 +1018,14 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): [0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 1] - """ - B = self.parent().natural_basis() - W = self.parent().natural_basis_space() - return W.linear_combination(zip(B,self.to_vector())) + B = self.parent().matrix_basis() + W = self.parent().matrix_space() + + # This is just a manual "from_vector()", but of course + # matrix spaces aren't vector spaces in sage, so they + # don't have a from_vector() method. + return W.linear_combination( zip(B, self.to_vector()) ) def norm(self): @@ -1309,6 +1326,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): True """ + from mjo.eja.eja_element_subalgebra import FiniteDimensionalEuclideanJordanElementSubalgebra return FiniteDimensionalEuclideanJordanElementSubalgebra(self, orthonormalize_basis)