-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.
"""
dir(self.__class__) )
- def __init__(self, A, elt=None):
+ def __init__(self, A, elt):
"""
SETUP::
sage: set_random_seed()
sage: J = random_eja()
sage: v = J.vector_space().random_element()
- sage: J(v).vector() == v
+ sage: J(v).to_vector() == v
True
"""
# already fits into the algebra, but also happens to live
# in the parent's "natural ambient space" (this happens with
# vectors in R^n).
+ ifme = super(FiniteDimensionalEuclideanJordanAlgebraElement, self)
try:
- FiniteDimensionalAlgebraElement.__init__(self, A, elt)
+ ifme.__init__(A, elt)
except ValueError:
natural_basis = A.natural_basis()
if elt in natural_basis[0].matrix_space():
# 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)
+ coords = W.coordinate_vector(_mat2vec(elt))
+ ifme.__init__(A, coords)
+
def __pow__(self, n):
"""
"""
p = self.parent().characteristic_polynomial()
- return p(*self.vector())
+ return p(*self.to_vector())
def inner_product(self, other):
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 `<X,Y> = trace(X*Y)`, where
# -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):
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))
True
"""
- return self.span_of_powers().dimension()
+ return self.subalgebra_generated_by().dimension()
def left_matrix(self):
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)
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.element_class(A,self).operator().minimal_polynomial()
"""
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):
"""
P = self.parent()
- fda_elt = FiniteDimensionalAlgebraElement(P, self)
return FiniteDimensionalEuclideanJordanAlgebraOperator(
P,
P,
- fda_elt.matrix().transpose() )
+ self.to_matrix() )
def quadratic_representation(self, other=None):
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)])
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):
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):
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.from_vector(self.to_vector())
# 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
# 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(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):
# -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):