X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Feja%2Feja_element.py;h=287a217e785ff3e44109d3fc8d8fd85ed1ca4771;hb=17aee61574caf7f62a70d181840c2be69879a3e7;hp=a8594ca02688493355d9de5f867b3c0cfc1faf07;hpb=fb62f0efeab4e93afcbdd5c1828f28d527ef3ddf;p=sage.d.git diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index a8594ca..287a217 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -1,14 +1,16 @@ -from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement 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_subalgebra', + 'FiniteDimensionalEuclideanJordanElementSubalgebra') from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator from mjo.eja.eja_utils import _mat2vec -class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraElement): +class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement): """ An element of a Euclidean Jordan algebra. """ @@ -23,68 +25,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle dir(self.__class__) ) - def __init__(self, A, elt=None): - """ - - SETUP:: - - sage: from mjo.eja.eja_algebra import (RealSymmetricEJA, - ....: random_eja) - - EXAMPLES: - - The identity in `S^n` is converted to the identity in the EJA:: - - sage: J = RealSymmetricEJA(3) - sage: I = matrix.identity(QQ,3) - sage: J(I) == J.one() - True - - This skew-symmetric matrix can't be represented in the EJA:: - - sage: J = RealSymmetricEJA(3) - sage: A = matrix(QQ,3, lambda i,j: i-j) - sage: J(A) - Traceback (most recent call last): - ... - ArithmeticError: vector is not in free module - - TESTS: - Ensure that we can convert any element of the parent's - underlying vector space back into an algebra element whose - vector representation is what we started with:: - - sage: set_random_seed() - sage: J = random_eja() - sage: v = J.vector_space().random_element() - sage: J(v).vector() == v - True - - """ - # Goal: if we're given a matrix, and if it lives in our - # parent algebra's "natural ambient space," convert it - # into an algebra element. - # - # The catch is, we make a recursive call after converting - # the given matrix into a vector that lives in the algebra. - # This we need to try the parent class initializer first, - # to avoid recursing forever if we're given something that - # already fits into the algebra, but also happens to live - # in the parent's "natural ambient space" (this happens with - # vectors in R^n). - try: - FiniteDimensionalAlgebraElement.__init__(self, A, elt) - except ValueError: - natural_basis = A.natural_basis() - if elt in natural_basis[0].matrix_space(): - # Thanks for nothing! Matrix spaces aren't vector - # spaces in Sage, so we have to figure out its - # natural-basis coordinates ourselves. - V = VectorSpace(elt.base_ring(), elt.nrows()**2) - W = V.span( _mat2vec(s) for s in natural_basis ) - coords = W.coordinates(_mat2vec(elt)) - FiniteDimensionalAlgebraElement.__init__(self, A, coords) def __pow__(self, n): """ @@ -226,7 +167,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle """ p = self.parent().characteristic_polynomial() - return p(*self.vector()) + return p(*self.to_vector()) def inner_product(self, other): @@ -253,7 +194,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: y = vector(QQ,[4,5,6]) sage: x.inner_product(y) 32 - sage: J(x).inner_product(J(y)) + sage: J.from_vector(x).inner_product(J.from_vector(y)) 32 The inner product on `S^n` is ` = trace(X*Y)`, where @@ -435,7 +376,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle # -1 to ensure that _charpoly_coeff(0) is really what # appears in front of t^{0} in the charpoly. However, # we want (-1)^r times THAT for the determinant. - return ((-1)**r)*p(*self.vector()) + return ((-1)**r)*p(*self.to_vector()) def inverse(self): @@ -463,13 +404,13 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: x = J.random_element() sage: while not x.is_invertible(): ....: x = J.random_element() - sage: x_vec = x.vector() + sage: x_vec = x.to_vector() sage: x0 = x_vec[0] sage: x_bar = x_vec[1:] sage: coeff = ~(x0^2 - x_bar.inner_product(x_bar)) sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list()) sage: x_inverse = coeff*inv_vec - sage: x.inverse() == J(x_inverse) + sage: x.inverse() == J.from_vector(x_inverse) True TESTS: @@ -549,7 +490,9 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle False """ - zero = self.parent().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() p = self.minimal_polynomial() return not (p(zero) == zero) @@ -702,7 +645,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle True """ - return self.span_of_powers().dimension() + return self.subalgebra_generated_by().dimension() def left_matrix(self): @@ -763,8 +706,8 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: y = J.random_element() sage: while y == y.coefficient(0)*J.one(): ....: y = J.random_element() - sage: y0 = y.vector()[0] - sage: y_bar = y.vector()[1:] + sage: y0 = y.to_vector()[0] + sage: y_bar = y.to_vector()[1:] sage: actual = y.minimal_polynomial() sage: t = PolynomialRing(J.base_ring(),'t').gen(0) sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2) @@ -780,13 +723,8 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle 0 """ - V = self.span_of_powers() - assoc_subalg = self.subalgebra_generated_by() - # Mis-design warning: the basis used for span_of_powers() - # and subalgebra_generated_by() must be the same, and in - # the same order! - elt = assoc_subalg(V.coordinates(self.vector())) - return elt.operator().minimal_polynomial() + A = self.subalgebra_generated_by() + return A(self).operator().minimal_polynomial() @@ -809,7 +747,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: J = ComplexHermitianEJA(3) sage: J.one() - e0 + e5 + e8 + e0 + e3 + e8 sage: J.one().natural_representation() [1 0 0 0 0 0] [0 1 0 0 0 0] @@ -822,7 +760,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: J = QuaternionHermitianEJA(3) sage: J.one() - e0 + e9 + e14 + e0 + e5 + e14 sage: J.one().natural_representation() [1 0 0 0 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0] @@ -840,7 +778,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle """ B = self.parent().natural_basis() W = B[0].matrix_space() - return W.linear_combination(zip(self.vector(), B)) + return W.linear_combination(zip(B,self.to_vector())) def operator(self): @@ -865,11 +803,12 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle """ P = self.parent() - fda_elt = FiniteDimensionalAlgebraElement(P, self) + left_mult_by_self = lambda y: self*y + L = P.module_morphism(function=left_mult_by_self, codomain=P) return FiniteDimensionalEuclideanJordanAlgebraOperator( P, P, - fda_elt.matrix().transpose() ) + L.matrix() ) def quadratic_representation(self, other=None): @@ -890,7 +829,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: n = ZZ.random_element(1,10) sage: J = JordanSpinEJA(n) sage: x = J.random_element() - sage: x_vec = x.vector() + sage: x_vec = x.to_vector() sage: x0 = x_vec[0] sage: x_bar = x_vec[1:] sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)]) @@ -992,19 +931,6 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle return ( L*M + M*L - (self*other).operator() ) - def span_of_powers(self): - """ - Return the vector space spanned by successive powers of - this element. - """ - # The dimension of the subalgebra can't be greater than - # the big algebra, so just put everything into a list - # and let span() get rid of the excess. - # - # We do the extra ambient_vector_space() in case we're messing - # with polynomials and the direct parent is a module. - V = self.parent().vector_space() - return V.span( (self**d).vector() for d in xrange(V.dimension()) ) def subalgebra_generated_by(self): @@ -1016,11 +942,17 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: from mjo.eja.eja_algebra import random_eja - TESTS:: + TESTS: + + This subalgebra, being composed of only powers, is associative:: sage: set_random_seed() - sage: x = random_eja().random_element() - sage: x.subalgebra_generated_by().is_associative() + sage: x0 = random_eja().random_element() + sage: A = x0.subalgebra_generated_by() + sage: x = A.random_element() + sage: y = A.random_element() + sage: z = A.random_element() + sage: (x*y)*z == x*(y*z) True Squaring in the subalgebra should work the same as in @@ -1028,54 +960,12 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle sage: set_random_seed() sage: x = random_eja().random_element() - sage: u = x.subalgebra_generated_by().random_element() - sage: u.operator()(u) == u^2 + sage: A = x.subalgebra_generated_by() + sage: A(x^2) == A(x)*A(x) True """ - # First get the subspace spanned by the powers of myself... - V = self.span_of_powers() - F = self.base_ring() - - # Now figure out the entries of the right-multiplication - # matrix for the successive basis elements b0, b1,... of - # that subspace. - mats = [] - for b_right in V.basis(): - eja_b_right = self.parent()(b_right) - b_right_rows = [] - # The first row of the right-multiplication matrix by - # b1 is what we get if we apply that matrix to b1. The - # second row of the right multiplication matrix by b1 - # is what we get when we apply that matrix to b2... - # - # IMPORTANT: this assumes that all vectors are COLUMN - # vectors, unlike our superclass (which uses row vectors). - for b_left in V.basis(): - eja_b_left = self.parent()(b_left) - # Multiply in the original EJA, but then get the - # coordinates from the subalgebra in terms of its - # basis. - this_row = V.coordinates((eja_b_left*eja_b_right).vector()) - b_right_rows.append(this_row) - b_right_matrix = matrix(F, b_right_rows) - mats.append(b_right_matrix) - - # It's an algebra of polynomials in one element, and EJAs - # are power-associative. - # - # TODO: choose generator names intelligently. - # - # The rank is the highest possible degree of a minimal polynomial, - # and is bounded above by the dimension. We know in this case that - # there's an element whose minimal polynomial has the same degree - # as the space's dimension, so that must be its rank too. - return FiniteDimensionalEuclideanJordanAlgebra( - F, - mats, - V.dimension(), - assume_associative=True, - names='f') + return FiniteDimensionalEuclideanJordanElementSubalgebra(self) def subalgebra_idempotent(self): @@ -1102,18 +992,14 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle if self.is_nilpotent(): raise ValueError("this only works with non-nilpotent elements!") - V = self.span_of_powers() J = self.subalgebra_generated_by() - # Mis-design warning: the basis used for span_of_powers() - # and subalgebra_generated_by() must be the same, and in - # the same order! - u = J(V.coordinates(self.vector())) + u = J(self) # The image of the matrix of left-u^m-multiplication # will be minimal for some natural number s... s = 0 - minimal_dim = V.dimension() - for i in xrange(1, V.dimension()): + minimal_dim = J.dimension() + for i in xrange(1, minimal_dim): this_dim = (u**i).operator().matrix().image().dimension() if this_dim < minimal_dim: minimal_dim = this_dim @@ -1132,15 +1018,10 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle # Our FiniteDimensionalAlgebraElement superclass uses rows. u_next = u**(s+1) A = u_next.operator().matrix() - c_coordinates = A.solve_right(u_next.vector()) + c = J.from_vector(A.solve_right(u_next.to_vector())) - # Now c_coordinates is the idempotent we want, but it's in - # the coordinate system of the subalgebra. - # - # We need the basis for J, but as elements of the parent algebra. - # - basis = [self.parent(v) for v in V.basis()] - return self.parent().linear_combination(zip(c_coordinates, basis)) + # Now c is the idempotent we want, but it still lives in the subalgebra. + return c.superalgebra_element() def trace(self): @@ -1183,7 +1064,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle # -1 to ensure that _charpoly_coeff(r-1) is really what # appears in front of t^{r-1} in the charpoly. However, # we want the negative of THAT for the trace. - return -p(*self.vector()) + return -p(*self.to_vector()) def trace_inner_product(self, other):