]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_element.py
eja: fix the natural representation in trivial subalgebras.
[sage.d.git] / mjo / eja / eja_element.py
index 1b5e3149e8e804f410403c066cc7e483eaa42a61..aef1c5d2813660ced5d9fe66314b4f5fd7577a11 100644 (file)
@@ -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):
         """
@@ -224,9 +165,24 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
             sage: x.apply_univariate_polynomial(p)
             0
 
+        The characteristic polynomials of the zero and unit elements
+        should be what we think they are in a subalgebra, too::
+
+            sage: J = RealCartesianProductEJA(3)
+            sage: p1 = J.one().characteristic_polynomial()
+            sage: q1 = J.zero().characteristic_polynomial()
+            sage: e0,e1,e2 = J.gens()
+            sage: A = (e0 + 2*e1 + 3*e2).subalgebra_generated_by() # dim 3
+            sage: p2 = A.one().characteristic_polynomial()
+            sage: q2 = A.zero().characteristic_polynomial()
+            sage: p1 == p2
+            True
+            sage: q1 == q2
+            True
+
         """
         p = self.parent().characteristic_polynomial()
-        return p(*self.vector())
+        return p(*self.to_vector())
 
 
     def inner_product(self, other):
@@ -253,7 +209,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 `<X,Y> = trace(X*Y)`, where
@@ -427,6 +383,16 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
             sage: x.is_invertible() == (x.det() != 0)
             True
 
+        Ensure that the determinant is multiplicative on an associative
+        subalgebra as in Faraut and Koranyi's Proposition II.2.2::
+
+            sage: set_random_seed()
+            sage: J = random_eja().random_element().subalgebra_generated_by()
+            sage: x = J.random_element()
+            sage: y = J.random_element()
+            sage: (x*y).det() == x.det()*y.det()
+            True
+
         """
         P = self.parent()
         r = P.rank()
@@ -435,7 +401,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 +429,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:
@@ -541,15 +507,23 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
             sage: J.one().is_invertible()
             True
 
-        The zero element is never invertible::
+        The zero element is never invertible in a non-trivial algebra::
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: J.zero().is_invertible()
+            sage: (not J.is_trivial()) and J.zero().is_invertible()
             False
 
         """
-        zero = self.parent().zero()
+        if self.is_zero():
+            if self.parent().is_trivial():
+                return True
+            else:
+                return False
+
+        # 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)
 
@@ -627,12 +601,13 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
 
         TESTS:
 
-        The zero element should never be regular::
+        The zero element should never be regular, unless the parent
+        algebra has dimension one::
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: J.zero().is_regular()
-            False
+            sage: J.dimension() == 1 or not J.zero().is_regular()
+            True
 
         The unit element isn't regular unless the algebra happens to
         consist of only its scalar multiples::
@@ -701,7 +676,12 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
             True
 
         """
-        return self.span_of_powers().dimension()
+        if self.is_zero() and not self.parent().is_trivial():
+            # The minimal polynomial of zero in a nontrivial algebra
+            # is "t"; in a trivial algebra it's "1" by convention
+            # (it's an empty product).
+            return 1
+        return self.subalgebra_generated_by().dimension()
 
 
     def left_matrix(self):
@@ -762,8 +742,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)
@@ -779,13 +759,20 @@ 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()
+        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()
+
+        A = self.subalgebra_generated_by()
+        return A(self).operator().minimal_polynomial()
 
 
 
@@ -808,7 +795,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]
@@ -821,7 +808,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]
@@ -838,8 +825,8 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(FiniteDimensionalAlgebraEle
 
         """
         B = self.parent().natural_basis()
-        W = B[0].matrix_space()
-        return W.linear_combination(zip(self.vector(), B))
+        W = self.parent().natural_basis_space()
+        return W.linear_combination(zip(B,self.to_vector()))
 
 
     def operator(self):
@@ -864,11 +851,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):
@@ -889,7 +877,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)])
@@ -991,19 +979,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):
@@ -1015,11 +990,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
@@ -1027,54 +1008,21 @@ 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
 
+        The subalgebra generated by the zero element is trivial::
+
+            sage: set_random_seed()
+            sage: A = random_eja().zero().subalgebra_generated_by()
+            sage: A
+            Euclidean Jordan algebra of dimension 0 over Rational Field
+            sage: A.one()
+            0
+
         """
-        # 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):
@@ -1101,18 +1049,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
@@ -1131,15 +1075,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):
@@ -1182,7 +1121,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):