2 Euclidean Jordan Algebras. These are formally-real Jordan Algebras;
3 specifically those where u^2 + v^2 = 0 implies that u = v = 0. They
4 are used in optimization, and have some additional nice methods beyond
5 what can be supported in a general Jordan Algebra.
8 from sage
.categories
.finite_dimensional_algebras_with_basis
import FiniteDimensionalAlgebrasWithBasis
9 from sage
.categories
.morphism
import SetMorphism
10 from sage
.structure
.element
import is_Matrix
11 from sage
.structure
.category_object
import normalize_names
13 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra
import FiniteDimensionalAlgebra
14 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_element
import FiniteDimensionalAlgebraElement
15 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_morphism
import FiniteDimensionalAlgebraMorphism
, FiniteDimensionalAlgebraHomset
18 class FiniteDimensionalEuclideanJordanAlgebraHomset(FiniteDimensionalAlgebraHomset
):
20 def has_coerce_map_from(self
, S
):
24 sage: J = RealSymmetricEJA(2)
26 sage: H.has_coerce_map_from(QQ)
31 # The Homset classes override has_coerce_map_from() with
32 # something that crashes when it's given e.g. QQ.
33 if S
.is_subring(self
.codomain().base_ring()):
36 pclass
= super(FiniteDimensionalEuclideanJordanAlgebraHomset
, self
)
37 return pclass
.has_coerce_map_from(S
)
40 def _coerce_map_from_(self
, S
):
44 sage: J = RealSymmetricEJA(2)
47 Morphism from Euclidean Jordan algebra of degree 3 over Rational
48 Field to Euclidean Jordan algebra of degree 3 over Rational Field
58 h
= S
.hom(self
.codomain())
59 return SetMorphism(Hom(S
,C
), lambda x
: h(x
).operator())
62 def __call__(self
, x
):
66 sage: J = RealSymmetricEJA(2)
69 Morphism from Euclidean Jordan algebra of degree 3 over Rational
70 Field to Euclidean Jordan algebra of degree 3 over Rational Field
77 if x
in self
.base_ring():
78 cols
= self
.domain().dimension()
79 rows
= self
.codomain().dimension()
80 x
= x
*identity_matrix(self
.codomain().base_ring(), rows
, cols
)
81 return FiniteDimensionalEuclideanJordanAlgebraMorphism(self
, x
)
86 Return the identity morphism, but as a member of the right
87 space (so that we can add it, multiply it, etc.)
89 cols
= self
.domain().dimension()
90 rows
= self
.codomain().dimension()
91 mat
= identity_matrix(self
.base_ring(), rows
, cols
)
92 return FiniteDimensionalEuclideanJordanAlgebraMorphism(self
, mat
)
96 class FiniteDimensionalEuclideanJordanAlgebraMorphism(FiniteDimensionalAlgebraMorphism
):
98 A linear map between two finite-dimensional EJAs.
100 This is a very thin wrapper around FiniteDimensionalAlgebraMorphism
101 that does only a few things:
103 1. Avoids the ``unitary`` and ``check`` arguments to the constructor
104 that will always be ``False``. This is necessary because these
105 are homomorphisms with respect to ADDITION, but the SageMath
106 machinery wants to check that they're homomorphisms with respect
107 to (Jordan) MULTIPLICATION. That obviously doesn't work.
109 2. Inputs and outputs the underlying matrix with respect to COLUMN
110 vectors, unlike the parent class.
112 3. Allows us to add, subtract, negate, multiply (compose), and
113 invert morphisms in the obvious way.
115 If this seems a bit heavyweight, it is. I would have been happy to
116 use a the ring morphism that underlies the finite-dimensional
117 algebra morphism, but they don't seem to be callable on elements of
118 our EJA, and you can't add/multiply/etc. them.
120 def _add_(self
, other
):
122 Add two EJA morphisms in the obvious way.
126 sage: J = RealSymmetricEJA(3)
129 sage: x.operator() + y.operator()
130 Morphism from Euclidean Jordan algebra of degree 6 over Rational
131 Field to Euclidean Jordan algebra of degree 6 over Rational Field
142 sage: set_random_seed()
143 sage: J = random_eja()
144 sage: x = J.random_element()
145 sage: y = J.random_element()
146 sage: (x.operator() + y.operator()) in J.Hom(J)
152 raise ValueError("summands must live in the same space")
154 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
156 self
.matrix() + other
.matrix() )
159 def __init__(self
, parent
, f
):
160 FiniteDimensionalAlgebraMorphism
.__init
__(self
,
167 def __invert__(self
):
171 sage: J = RealSymmetricEJA(2)
172 sage: x = J.linear_combination(zip(range(len(J.gens())), J.gens()))
173 sage: x.is_invertible()
176 Morphism from Euclidean Jordan algebra of degree 3 over Rational
177 Field to Euclidean Jordan algebra of degree 3 over Rational Field
182 sage: x.operator_matrix().inverse()
189 Beware, ``x`` being invertible isn't sufficient for its operator
190 to be invertible below::
192 sage: set_random_seed()
193 sage: J = random_eja()
194 sage: x = J.random_element()
195 sage: id = J.Hom(J).one()
196 sage: not x.operator_matrix().is_invertible() or (
197 ....: ~x.operator()*x.operator() == id )
202 if not A
.is_invertible():
203 raise ValueError("morphism is not invertible")
206 return FiniteDimensionalEuclideanJordanAlgebraMorphism(self
.parent(),
209 def _lmul_(self
, right
):
211 Compose two EJA morphisms using multiplicative notation.
215 sage: J = RealSymmetricEJA(2)
218 sage: x.operator() * y.operator()
219 Morphism from Euclidean Jordan algebra of degree 3 over Rational
220 Field to Euclidean Jordan algebra of degree 3 over Rational Field
228 sage: J = RealSymmetricEJA(2)
229 sage: x = J.linear_combination(zip(range(len(J.gens())), J.gens()))
231 Morphism from Euclidean Jordan algebra of degree 3 over Rational
232 Field to Euclidean Jordan algebra of degree 3 over Rational Field
238 Morphism from Euclidean Jordan algebra of degree 3 over Rational
239 Field to Euclidean Jordan algebra of degree 3 over Rational Field
245 Morphism from Euclidean Jordan algebra of degree 3 over Rational
246 Field to Euclidean Jordan algebra of degree 3 over Rational Field
254 sage: set_random_seed()
255 sage: J = random_eja()
256 sage: x = J.random_element()
257 sage: y = J.random_element()
258 sage: (x.operator() * y.operator()) in J.Hom(J)
263 # I think the morphism classes break the coercion framework
264 # somewhere along the way, so we have to do this ourselves.
265 right
= self
.parent().coerce(right
)
269 if not right
.codomain() is self
.domain():
270 raise ValueError("(co)domains must agree for composition")
272 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
274 self
.matrix()*right
.matrix() )
279 def __pow__(self
, n
):
284 sage: J = JordanSpinEJA(4)
285 sage: e0,e1,e2,e3 = J.gens()
286 sage: x = -5/2*e0 + 1/2*e2 + 20*e3
287 sage: Qx = x.quadratic_representation()
289 Morphism from Euclidean Jordan algebra of degree 4 over Rational
290 Field to Euclidean Jordan algebra of degree 4 over Rational Field
296 sage: (x^0).quadratic_representation() == Qx^0
301 # We get back the stupid identity morphism which doesn't
302 # live in the right space.
303 return self
.parent().one()
307 return FiniteDimensionalAlgebraMorphism
.__pow
__(self
,n
)
312 Negate this morphism.
316 sage: J = RealSymmetricEJA(2)
319 Morphism from Euclidean Jordan algebra of degree 3 over Rational
320 Field to Euclidean Jordan algebra of degree 3 over Rational Field
328 sage: set_random_seed()
329 sage: J = random_eja()
330 sage: x = J.random_element()
331 sage: -x.operator() in J.Hom(J)
335 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
342 We override only the representation that is shown to the user,
343 because we want the matrix to be with respect to COLUMN vectors.
347 Ensure that we see the transpose of the underlying matrix object:
349 sage: J = RealSymmetricEJA(3)
350 sage: x = J.linear_combination(zip(range(len(J.gens())), J.gens()))
351 sage: L = x.operator()
353 Morphism from Euclidean Jordan algebra of degree 6 over Rational
354 Field to Euclidean Jordan algebra of degree 6 over Rational Field
371 return "Morphism from {} to {} given by matrix\n{}".format(
372 self
.domain(), self
.codomain(), self
.matrix())
375 def __sub__(self
, other
):
377 Subtract one morphism from another using addition and negation.
381 sage: J = RealSymmetricEJA(2)
382 sage: L1 = J.one().operator()
384 Morphism from Euclidean Jordan algebra of degree 3 over Rational
385 Field to Euclidean Jordan algebra of degree 3 over Rational
386 Field given by matrix
393 sage: set_random_seed()
394 sage: J = random_eja()
395 sage: x = J.random_element()
396 sage: y = J.random_element()
397 sage: x.operator() - y.operator() in J.Hom(J)
401 return self
+ (-other
)
406 Return the matrix of this morphism with respect to a left-action
409 return FiniteDimensionalAlgebraMorphism
.matrix(self
).transpose()
412 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
414 def __classcall_private__(cls
,
418 assume_associative
=False,
423 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
426 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
427 raise ValueError("input is not a multiplication table")
428 mult_table
= tuple(mult_table
)
430 cat
= FiniteDimensionalAlgebrasWithBasis(field
)
431 cat
.or_subcategory(category
)
432 if assume_associative
:
433 cat
= cat
.Associative()
435 names
= normalize_names(n
, names
)
437 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
438 return fda
.__classcall
__(cls
,
441 assume_associative
=assume_associative
,
445 natural_basis
=natural_basis
)
448 def _Hom_(self
, B
, cat
):
450 Construct a homset of ``self`` and ``B``.
452 return FiniteDimensionalEuclideanJordanAlgebraHomset(self
,
461 assume_associative
=False,
468 By definition, Jordan multiplication commutes::
470 sage: set_random_seed()
471 sage: J = random_eja()
472 sage: x = J.random_element()
473 sage: y = J.random_element()
479 self
._natural
_basis
= natural_basis
480 self
._multiplication
_table
= mult_table
481 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
490 Return a string representation of ``self``.
492 fmt
= "Euclidean Jordan algebra of degree {} over {}"
493 return fmt
.format(self
.degree(), self
.base_ring())
496 def _a_regular_element(self
):
498 Guess a regular element. Needed to compute the basis for our
499 characteristic polynomial coefficients.
502 z
= self
.sum( (i
+1)*gs
[i
] for i
in range(len(gs
)) )
503 if not z
.is_regular():
504 raise ValueError("don't know a regular element")
509 def _charpoly_basis_space(self
):
511 Return the vector space spanned by the basis used in our
512 characteristic polynomial coefficients. This is used not only to
513 compute those coefficients, but also any time we need to
514 evaluate the coefficients (like when we compute the trace or
517 z
= self
._a
_regular
_element
()
518 V
= z
.vector().parent().ambient_vector_space()
519 V1
= V
.span_of_basis( (z
**k
).vector() for k
in range(self
.rank()) )
520 b
= (V1
.basis() + V1
.complement().basis())
521 return V
.span_of_basis(b
)
525 def _charpoly_coeff(self
, i
):
527 Return the coefficient polynomial "a_{i}" of this algebra's
528 general characteristic polynomial.
530 Having this be a separate cached method lets us compute and
531 store the trace/determinant (a_{r-1} and a_{0} respectively)
532 separate from the entire characteristic polynomial.
534 (A_of_x
, x
, xr
, detA
) = self
._charpoly
_matrix
_system
()
535 R
= A_of_x
.base_ring()
537 # Guaranteed by theory
540 # Danger: the in-place modification is done for performance
541 # reasons (reconstructing a matrix with huge polynomial
542 # entries is slow), but I don't know how cached_method works,
543 # so it's highly possible that we're modifying some global
544 # list variable by reference, here. In other words, you
545 # probably shouldn't call this method twice on the same
546 # algebra, at the same time, in two threads
547 Ai_orig
= A_of_x
.column(i
)
548 A_of_x
.set_column(i
,xr
)
549 numerator
= A_of_x
.det()
550 A_of_x
.set_column(i
,Ai_orig
)
552 # We're relying on the theory here to ensure that each a_i is
553 # indeed back in R, and the added negative signs are to make
554 # the whole charpoly expression sum to zero.
555 return R(-numerator
/detA
)
559 def _charpoly_matrix_system(self
):
561 Compute the matrix whose entries A_ij are polynomials in
562 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
563 corresponding to `x^r` and the determinent of the matrix A =
564 [A_ij]. In other words, all of the fixed (cachable) data needed
565 to compute the coefficients of the characteristic polynomial.
570 # Construct a new algebra over a multivariate polynomial ring...
571 names
= ['X' + str(i
) for i
in range(1,n
+1)]
572 R
= PolynomialRing(self
.base_ring(), names
)
573 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
574 self
._multiplication
_table
,
577 idmat
= identity_matrix(J
.base_ring(), n
)
579 W
= self
._charpoly
_basis
_space
()
580 W
= W
.change_ring(R
.fraction_field())
582 # Starting with the standard coordinates x = (X1,X2,...,Xn)
583 # and then converting the entries to W-coordinates allows us
584 # to pass in the standard coordinates to the charpoly and get
585 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
588 # W.coordinates(x^2) eval'd at (standard z-coords)
592 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
594 # We want the middle equivalent thing in our matrix, but use
595 # the first equivalent thing instead so that we can pass in
596 # standard coordinates.
597 x
= J(vector(R
, R
.gens()))
598 l1
= [column_matrix(W
.coordinates((x
**k
).vector())) for k
in range(r
)]
599 l2
= [idmat
.column(k
-1).column() for k
in range(r
+1, n
+1)]
600 A_of_x
= block_matrix(R
, 1, n
, (l1
+ l2
))
601 xr
= W
.coordinates((x
**r
).vector())
602 return (A_of_x
, x
, xr
, A_of_x
.det())
606 def characteristic_polynomial(self
):
611 This implementation doesn't guarantee that the polynomial
612 denominator in the coefficients is not identically zero, so
613 theoretically it could crash. The way that this is handled
614 in e.g. Faraut and Koranyi is to use a basis that guarantees
615 the denominator is non-zero. But, doing so requires knowledge
616 of at least one regular element, and we don't even know how
617 to do that. The trade-off is that, if we use the standard basis,
618 the resulting polynomial will accept the "usual" coordinates. In
619 other words, we don't have to do a change of basis before e.g.
620 computing the trace or determinant.
624 The characteristic polynomial in the spin algebra is given in
625 Alizadeh, Example 11.11::
627 sage: J = JordanSpinEJA(3)
628 sage: p = J.characteristic_polynomial(); p
629 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
630 sage: xvec = J.one().vector()
638 # The list of coefficient polynomials a_1, a_2, ..., a_n.
639 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
641 # We go to a bit of trouble here to reorder the
642 # indeterminates, so that it's easier to evaluate the
643 # characteristic polynomial at x's coordinates and get back
644 # something in terms of t, which is what we want.
646 S
= PolynomialRing(self
.base_ring(),'t')
648 S
= PolynomialRing(S
, R
.variable_names())
651 # Note: all entries past the rth should be zero. The
652 # coefficient of the highest power (x^r) is 1, but it doesn't
653 # appear in the solution vector which contains coefficients
654 # for the other powers (to make them sum to x^r).
656 a
[r
] = 1 # corresponds to x^r
658 # When the rank is equal to the dimension, trying to
659 # assign a[r] goes out-of-bounds.
660 a
.append(1) # corresponds to x^r
662 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
665 def inner_product(self
, x
, y
):
667 The inner product associated with this Euclidean Jordan algebra.
669 Defaults to the trace inner product, but can be overridden by
670 subclasses if they are sure that the necessary properties are
675 The inner product must satisfy its axiom for this algebra to truly
676 be a Euclidean Jordan Algebra::
678 sage: set_random_seed()
679 sage: J = random_eja()
680 sage: x = J.random_element()
681 sage: y = J.random_element()
682 sage: z = J.random_element()
683 sage: (x*y).inner_product(z) == y.inner_product(x*z)
687 if (not x
in self
) or (not y
in self
):
688 raise TypeError("arguments must live in this algebra")
689 return x
.trace_inner_product(y
)
692 def natural_basis(self
):
694 Return a more-natural representation of this algebra's basis.
696 Every finite-dimensional Euclidean Jordan Algebra is a direct
697 sum of five simple algebras, four of which comprise Hermitian
698 matrices. This method returns the original "natural" basis
699 for our underlying vector space. (Typically, the natural basis
700 is used to construct the multiplication table in the first place.)
702 Note that this will always return a matrix. The standard basis
703 in `R^n` will be returned as `n`-by-`1` column matrices.
707 sage: J = RealSymmetricEJA(2)
710 sage: J.natural_basis()
718 sage: J = JordanSpinEJA(2)
721 sage: J.natural_basis()
728 if self
._natural
_basis
is None:
729 return tuple( b
.vector().column() for b
in self
.basis() )
731 return self
._natural
_basis
736 Return the rank of this EJA.
738 if self
._rank
is None:
739 raise ValueError("no rank specified at genesis")
744 class Element(FiniteDimensionalAlgebraElement
):
746 An element of a Euclidean Jordan algebra.
751 Oh man, I should not be doing this. This hides the "disabled"
752 methods ``left_matrix`` and ``matrix`` from introspection;
753 in particular it removes them from tab-completion.
755 return filter(lambda s
: s
not in ['left_matrix', 'matrix'],
756 dir(self
.__class
__) )
759 def __init__(self
, A
, elt
=None):
763 The identity in `S^n` is converted to the identity in the EJA::
765 sage: J = RealSymmetricEJA(3)
766 sage: I = identity_matrix(QQ,3)
767 sage: J(I) == J.one()
770 This skew-symmetric matrix can't be represented in the EJA::
772 sage: J = RealSymmetricEJA(3)
773 sage: A = matrix(QQ,3, lambda i,j: i-j)
775 Traceback (most recent call last):
777 ArithmeticError: vector is not in free module
780 # Goal: if we're given a matrix, and if it lives in our
781 # parent algebra's "natural ambient space," convert it
782 # into an algebra element.
784 # The catch is, we make a recursive call after converting
785 # the given matrix into a vector that lives in the algebra.
786 # This we need to try the parent class initializer first,
787 # to avoid recursing forever if we're given something that
788 # already fits into the algebra, but also happens to live
789 # in the parent's "natural ambient space" (this happens with
792 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
794 natural_basis
= A
.natural_basis()
795 if elt
in natural_basis
[0].matrix_space():
796 # Thanks for nothing! Matrix spaces aren't vector
797 # spaces in Sage, so we have to figure out its
798 # natural-basis coordinates ourselves.
799 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
800 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
801 coords
= W
.coordinates(_mat2vec(elt
))
802 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
804 def __pow__(self
, n
):
806 Return ``self`` raised to the power ``n``.
808 Jordan algebras are always power-associative; see for
809 example Faraut and Koranyi, Proposition II.1.2 (ii).
813 We have to override this because our superclass uses row vectors
814 instead of column vectors! We, on the other hand, assume column
819 sage: set_random_seed()
820 sage: x = random_eja().random_element()
821 sage: x.operator_matrix()*x.vector() == (x^2).vector()
824 A few examples of power-associativity::
826 sage: set_random_seed()
827 sage: x = random_eja().random_element()
828 sage: x*(x*x)*(x*x) == x^5
830 sage: (x*x)*(x*x*x) == x^5
833 We also know that powers operator-commute (Koecher, Chapter
836 sage: set_random_seed()
837 sage: x = random_eja().random_element()
838 sage: m = ZZ.random_element(0,10)
839 sage: n = ZZ.random_element(0,10)
840 sage: Lxm = (x^m).operator_matrix()
841 sage: Lxn = (x^n).operator_matrix()
842 sage: Lxm*Lxn == Lxn*Lxm
852 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
855 def apply_univariate_polynomial(self
, p
):
857 Apply the univariate polynomial ``p`` to this element.
859 A priori, SageMath won't allow us to apply a univariate
860 polynomial to an element of an EJA, because we don't know
861 that EJAs are rings (they are usually not associative). Of
862 course, we know that EJAs are power-associative, so the
863 operation is ultimately kosher. This function sidesteps
864 the CAS to get the answer we want and expect.
868 sage: R = PolynomialRing(QQ, 't')
870 sage: p = t^4 - t^3 + 5*t - 2
871 sage: J = RealCartesianProductEJA(5)
872 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
877 We should always get back an element of the algebra::
879 sage: set_random_seed()
880 sage: p = PolynomialRing(QQ, 't').random_element()
881 sage: J = random_eja()
882 sage: x = J.random_element()
883 sage: x.apply_univariate_polynomial(p) in J
887 if len(p
.variables()) > 1:
888 raise ValueError("not a univariate polynomial")
891 # Convert the coeficcients to the parent's base ring,
892 # because a priori they might live in an (unnecessarily)
893 # larger ring for which P.sum() would fail below.
894 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
895 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
898 def characteristic_polynomial(self
):
900 Return the characteristic polynomial of this element.
904 The rank of `R^3` is three, and the minimal polynomial of
905 the identity element is `(t-1)` from which it follows that
906 the characteristic polynomial should be `(t-1)^3`::
908 sage: J = RealCartesianProductEJA(3)
909 sage: J.one().characteristic_polynomial()
910 t^3 - 3*t^2 + 3*t - 1
912 Likewise, the characteristic of the zero element in the
913 rank-three algebra `R^{n}` should be `t^{3}`::
915 sage: J = RealCartesianProductEJA(3)
916 sage: J.zero().characteristic_polynomial()
919 The characteristic polynomial of an element should evaluate
920 to zero on that element::
922 sage: set_random_seed()
923 sage: x = RealCartesianProductEJA(3).random_element()
924 sage: p = x.characteristic_polynomial()
925 sage: x.apply_univariate_polynomial(p)
929 p
= self
.parent().characteristic_polynomial()
930 return p(*self
.vector())
933 def inner_product(self
, other
):
935 Return the parent algebra's inner product of myself and ``other``.
939 The inner product in the Jordan spin algebra is the usual
940 inner product on `R^n` (this example only works because the
941 basis for the Jordan algebra is the standard basis in `R^n`)::
943 sage: J = JordanSpinEJA(3)
944 sage: x = vector(QQ,[1,2,3])
945 sage: y = vector(QQ,[4,5,6])
946 sage: x.inner_product(y)
948 sage: J(x).inner_product(J(y))
951 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
952 multiplication is the usual matrix multiplication in `S^n`,
953 so the inner product of the identity matrix with itself
956 sage: J = RealSymmetricEJA(3)
957 sage: J.one().inner_product(J.one())
960 Likewise, the inner product on `C^n` is `<X,Y> =
961 Re(trace(X*Y))`, where we must necessarily take the real
962 part because the product of Hermitian matrices may not be
965 sage: J = ComplexHermitianEJA(3)
966 sage: J.one().inner_product(J.one())
969 Ditto for the quaternions::
971 sage: J = QuaternionHermitianEJA(3)
972 sage: J.one().inner_product(J.one())
977 Ensure that we can always compute an inner product, and that
978 it gives us back a real number::
980 sage: set_random_seed()
981 sage: J = random_eja()
982 sage: x = J.random_element()
983 sage: y = J.random_element()
984 sage: x.inner_product(y) in RR
990 raise TypeError("'other' must live in the same algebra")
992 return P
.inner_product(self
, other
)
995 def operator_commutes_with(self
, other
):
997 Return whether or not this element operator-commutes
1002 The definition of a Jordan algebra says that any element
1003 operator-commutes with its square::
1005 sage: set_random_seed()
1006 sage: x = random_eja().random_element()
1007 sage: x.operator_commutes_with(x^2)
1012 Test Lemma 1 from Chapter III of Koecher::
1014 sage: set_random_seed()
1015 sage: J = random_eja()
1016 sage: u = J.random_element()
1017 sage: v = J.random_element()
1018 sage: lhs = u.operator_commutes_with(u*v)
1019 sage: rhs = v.operator_commutes_with(u^2)
1024 if not other
in self
.parent():
1025 raise TypeError("'other' must live in the same algebra")
1027 A
= self
.operator_matrix()
1028 B
= other
.operator_matrix()
1034 Return my determinant, the product of my eigenvalues.
1038 sage: J = JordanSpinEJA(2)
1039 sage: e0,e1 = J.gens()
1040 sage: x = sum( J.gens() )
1046 sage: J = JordanSpinEJA(3)
1047 sage: e0,e1,e2 = J.gens()
1048 sage: x = sum( J.gens() )
1054 An element is invertible if and only if its determinant is
1057 sage: set_random_seed()
1058 sage: x = random_eja().random_element()
1059 sage: x.is_invertible() == (x.det() != 0)
1065 p
= P
._charpoly
_coeff
(0)
1066 # The _charpoly_coeff function already adds the factor of
1067 # -1 to ensure that _charpoly_coeff(0) is really what
1068 # appears in front of t^{0} in the charpoly. However,
1069 # we want (-1)^r times THAT for the determinant.
1070 return ((-1)**r
)*p(*self
.vector())
1075 Return the Jordan-multiplicative inverse of this element.
1079 We appeal to the quadratic representation as in Koecher's
1080 Theorem 12 in Chapter III, Section 5.
1084 The inverse in the spin factor algebra is given in Alizadeh's
1087 sage: set_random_seed()
1088 sage: n = ZZ.random_element(1,10)
1089 sage: J = JordanSpinEJA(n)
1090 sage: x = J.random_element()
1091 sage: while not x.is_invertible():
1092 ....: x = J.random_element()
1093 sage: x_vec = x.vector()
1095 sage: x_bar = x_vec[1:]
1096 sage: coeff = ~(x0^2 - x_bar.inner_product(x_bar))
1097 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
1098 sage: x_inverse = coeff*inv_vec
1099 sage: x.inverse() == J(x_inverse)
1104 The identity element is its own inverse::
1106 sage: set_random_seed()
1107 sage: J = random_eja()
1108 sage: J.one().inverse() == J.one()
1111 If an element has an inverse, it acts like one::
1113 sage: set_random_seed()
1114 sage: J = random_eja()
1115 sage: x = J.random_element()
1116 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
1119 The inverse of the inverse is what we started with::
1121 sage: set_random_seed()
1122 sage: J = random_eja()
1123 sage: x = J.random_element()
1124 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
1127 The zero element is never invertible::
1129 sage: set_random_seed()
1130 sage: J = random_eja().zero().inverse()
1131 Traceback (most recent call last):
1133 ValueError: element is not invertible
1136 if not self
.is_invertible():
1137 raise ValueError("element is not invertible")
1139 return (~self
.quadratic_representation())(self
)
1142 def is_invertible(self
):
1144 Return whether or not this element is invertible.
1146 We can't use the superclass method because it relies on
1147 the algebra being associative.
1151 The usual way to do this is to check if the determinant is
1152 zero, but we need the characteristic polynomial for the
1153 determinant. The minimal polynomial is a lot easier to get,
1154 so we use Corollary 2 in Chapter V of Koecher to check
1155 whether or not the paren't algebra's zero element is a root
1156 of this element's minimal polynomial.
1160 The identity element is always invertible::
1162 sage: set_random_seed()
1163 sage: J = random_eja()
1164 sage: J.one().is_invertible()
1167 The zero element is never invertible::
1169 sage: set_random_seed()
1170 sage: J = random_eja()
1171 sage: J.zero().is_invertible()
1175 zero
= self
.parent().zero()
1176 p
= self
.minimal_polynomial()
1177 return not (p(zero
) == zero
)
1180 def is_nilpotent(self
):
1182 Return whether or not some power of this element is zero.
1184 The superclass method won't work unless we're in an
1185 associative algebra, and we aren't. However, we generate
1186 an assocoative subalgebra and we're nilpotent there if and
1187 only if we're nilpotent here (probably).
1191 The identity element is never nilpotent::
1193 sage: set_random_seed()
1194 sage: random_eja().one().is_nilpotent()
1197 The additive identity is always nilpotent::
1199 sage: set_random_seed()
1200 sage: random_eja().zero().is_nilpotent()
1204 # The element we're going to call "is_nilpotent()" on.
1205 # Either myself, interpreted as an element of a finite-
1206 # dimensional algebra, or an element of an associative
1210 if self
.parent().is_associative():
1211 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
1213 V
= self
.span_of_powers()
1214 assoc_subalg
= self
.subalgebra_generated_by()
1215 # Mis-design warning: the basis used for span_of_powers()
1216 # and subalgebra_generated_by() must be the same, and in
1218 elt
= assoc_subalg(V
.coordinates(self
.vector()))
1220 # Recursive call, but should work since elt lives in an
1221 # associative algebra.
1222 return elt
.is_nilpotent()
1225 def is_regular(self
):
1227 Return whether or not this is a regular element.
1231 The identity element always has degree one, but any element
1232 linearly-independent from it is regular::
1234 sage: J = JordanSpinEJA(5)
1235 sage: J.one().is_regular()
1237 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
1238 sage: for x in J.gens():
1239 ....: (J.one() + x).is_regular()
1247 return self
.degree() == self
.parent().rank()
1252 Compute the degree of this element the straightforward way
1253 according to the definition; by appending powers to a list
1254 and figuring out its dimension (that is, whether or not
1255 they're linearly dependent).
1259 sage: J = JordanSpinEJA(4)
1260 sage: J.one().degree()
1262 sage: e0,e1,e2,e3 = J.gens()
1263 sage: (e0 - e1).degree()
1266 In the spin factor algebra (of rank two), all elements that
1267 aren't multiples of the identity are regular::
1269 sage: set_random_seed()
1270 sage: n = ZZ.random_element(1,10)
1271 sage: J = JordanSpinEJA(n)
1272 sage: x = J.random_element()
1273 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
1277 return self
.span_of_powers().dimension()
1280 def left_matrix(self
):
1282 Our parent class defines ``left_matrix`` and ``matrix``
1283 methods whose names are misleading. We don't want them.
1285 raise NotImplementedError("use operator_matrix() instead")
1287 matrix
= left_matrix
1290 def minimal_polynomial(self
):
1292 Return the minimal polynomial of this element,
1293 as a function of the variable `t`.
1297 We restrict ourselves to the associative subalgebra
1298 generated by this element, and then return the minimal
1299 polynomial of this element's operator matrix (in that
1300 subalgebra). This works by Baes Proposition 2.3.16.
1304 The minimal polynomial of the identity and zero elements are
1307 sage: set_random_seed()
1308 sage: J = random_eja()
1309 sage: J.one().minimal_polynomial()
1311 sage: J.zero().minimal_polynomial()
1314 The degree of an element is (by one definition) the degree
1315 of its minimal polynomial::
1317 sage: set_random_seed()
1318 sage: x = random_eja().random_element()
1319 sage: x.degree() == x.minimal_polynomial().degree()
1322 The minimal polynomial and the characteristic polynomial coincide
1323 and are known (see Alizadeh, Example 11.11) for all elements of
1324 the spin factor algebra that aren't scalar multiples of the
1327 sage: set_random_seed()
1328 sage: n = ZZ.random_element(2,10)
1329 sage: J = JordanSpinEJA(n)
1330 sage: y = J.random_element()
1331 sage: while y == y.coefficient(0)*J.one():
1332 ....: y = J.random_element()
1333 sage: y0 = y.vector()[0]
1334 sage: y_bar = y.vector()[1:]
1335 sage: actual = y.minimal_polynomial()
1336 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
1337 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
1338 sage: bool(actual == expected)
1341 The minimal polynomial should always kill its element::
1343 sage: set_random_seed()
1344 sage: x = random_eja().random_element()
1345 sage: p = x.minimal_polynomial()
1346 sage: x.apply_univariate_polynomial(p)
1350 V
= self
.span_of_powers()
1351 assoc_subalg
= self
.subalgebra_generated_by()
1352 # Mis-design warning: the basis used for span_of_powers()
1353 # and subalgebra_generated_by() must be the same, and in
1355 elt
= assoc_subalg(V
.coordinates(self
.vector()))
1357 # We get back a symbolic polynomial in 'x' but want a real
1358 # polynomial in 't'.
1359 p_of_x
= elt
.operator_matrix().minimal_polynomial()
1360 return p_of_x
.change_variable_name('t')
1363 def natural_representation(self
):
1365 Return a more-natural representation of this element.
1367 Every finite-dimensional Euclidean Jordan Algebra is a
1368 direct sum of five simple algebras, four of which comprise
1369 Hermitian matrices. This method returns the original
1370 "natural" representation of this element as a Hermitian
1371 matrix, if it has one. If not, you get the usual representation.
1375 sage: J = ComplexHermitianEJA(3)
1378 sage: J.one().natural_representation()
1388 sage: J = QuaternionHermitianEJA(3)
1391 sage: J.one().natural_representation()
1392 [1 0 0 0 0 0 0 0 0 0 0 0]
1393 [0 1 0 0 0 0 0 0 0 0 0 0]
1394 [0 0 1 0 0 0 0 0 0 0 0 0]
1395 [0 0 0 1 0 0 0 0 0 0 0 0]
1396 [0 0 0 0 1 0 0 0 0 0 0 0]
1397 [0 0 0 0 0 1 0 0 0 0 0 0]
1398 [0 0 0 0 0 0 1 0 0 0 0 0]
1399 [0 0 0 0 0 0 0 1 0 0 0 0]
1400 [0 0 0 0 0 0 0 0 1 0 0 0]
1401 [0 0 0 0 0 0 0 0 0 1 0 0]
1402 [0 0 0 0 0 0 0 0 0 0 1 0]
1403 [0 0 0 0 0 0 0 0 0 0 0 1]
1406 B
= self
.parent().natural_basis()
1407 W
= B
[0].matrix_space()
1408 return W
.linear_combination(zip(self
.vector(), B
))
1413 Return the left-multiplication-by-this-element
1414 operator on the ambient algebra.
1418 sage: set_random_seed()
1419 sage: J = random_eja()
1420 sage: x = J.random_element()
1421 sage: y = J.random_element()
1422 sage: x.operator()(y) == x*y
1424 sage: y.operator()(x) == x*y
1429 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
1431 self
.operator_matrix() )
1435 def operator_matrix(self
):
1437 Return the matrix that represents left- (or right-)
1438 multiplication by this element in the parent algebra.
1440 We implement this ourselves to work around the fact that
1441 our parent class represents everything with row vectors.
1445 Test the first polarization identity from my notes, Koecher Chapter
1446 III, or from Baes (2.3)::
1448 sage: set_random_seed()
1449 sage: J = random_eja()
1450 sage: x = J.random_element()
1451 sage: y = J.random_element()
1452 sage: Lx = x.operator_matrix()
1453 sage: Ly = y.operator_matrix()
1454 sage: Lxx = (x*x).operator_matrix()
1455 sage: Lxy = (x*y).operator_matrix()
1456 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
1459 Test the second polarization identity from my notes or from
1462 sage: set_random_seed()
1463 sage: J = random_eja()
1464 sage: x = J.random_element()
1465 sage: y = J.random_element()
1466 sage: z = J.random_element()
1467 sage: Lx = x.operator_matrix()
1468 sage: Ly = y.operator_matrix()
1469 sage: Lz = z.operator_matrix()
1470 sage: Lzy = (z*y).operator_matrix()
1471 sage: Lxy = (x*y).operator_matrix()
1472 sage: Lxz = (x*z).operator_matrix()
1473 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
1476 Test the third polarization identity from my notes or from
1479 sage: set_random_seed()
1480 sage: J = random_eja()
1481 sage: u = J.random_element()
1482 sage: y = J.random_element()
1483 sage: z = J.random_element()
1484 sage: Lu = u.operator_matrix()
1485 sage: Ly = y.operator_matrix()
1486 sage: Lz = z.operator_matrix()
1487 sage: Lzy = (z*y).operator_matrix()
1488 sage: Luy = (u*y).operator_matrix()
1489 sage: Luz = (u*z).operator_matrix()
1490 sage: Luyz = (u*(y*z)).operator_matrix()
1491 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
1492 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
1493 sage: bool(lhs == rhs)
1497 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
1498 return fda_elt
.matrix().transpose()
1501 def quadratic_representation(self
, other
=None):
1503 Return the quadratic representation of this element.
1507 The explicit form in the spin factor algebra is given by
1508 Alizadeh's Example 11.12::
1510 sage: set_random_seed()
1511 sage: n = ZZ.random_element(1,10)
1512 sage: J = JordanSpinEJA(n)
1513 sage: x = J.random_element()
1514 sage: x_vec = x.vector()
1516 sage: x_bar = x_vec[1:]
1517 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1518 sage: B = 2*x0*x_bar.row()
1519 sage: C = 2*x0*x_bar.column()
1520 sage: D = identity_matrix(QQ, n-1)
1521 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1522 sage: D = D + 2*x_bar.tensor_product(x_bar)
1523 sage: Q = block_matrix(2,2,[A,B,C,D])
1524 sage: Q == x.quadratic_representation().matrix()
1527 Test all of the properties from Theorem 11.2 in Alizadeh::
1529 sage: set_random_seed()
1530 sage: J = random_eja()
1531 sage: x = J.random_element()
1532 sage: y = J.random_element()
1533 sage: Lx = x.operator()
1534 sage: Lxx = (x*x).operator()
1535 sage: Qx = x.quadratic_representation()
1536 sage: Qy = y.quadratic_representation()
1537 sage: Qxy = x.quadratic_representation(y)
1538 sage: Qex = J.one().quadratic_representation(x)
1539 sage: n = ZZ.random_element(10)
1540 sage: Qxn = (x^n).quadratic_representation()
1544 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1549 sage: alpha = QQ.random_element()
1550 sage: (alpha*x).quadratic_representation() == (alpha^2)*Qx
1555 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
1558 sage: not x.is_invertible() or (
1561 ....: x.inverse().quadratic_representation() )
1564 sage: Qxy(J.one()) == x*y
1569 sage: not x.is_invertible() or (
1570 ....: x.quadratic_representation(x.inverse())*Qx
1571 ....: == Qx*x.quadratic_representation(x.inverse()) )
1574 sage: not x.is_invertible() or (
1575 ....: x.quadratic_representation(x.inverse())*Qx
1577 ....: 2*x.operator()*Qex - Qx )
1580 sage: 2*x.operator()*Qex - Qx == Lxx
1585 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
1595 sage: not x.is_invertible() or (
1596 ....: Qx*x.inverse().operator() == Lx )
1601 sage: not x.operator_commutes_with(y) or (
1602 ....: Qx(y)^n == Qxn(y^n) )
1608 elif not other
in self
.parent():
1609 raise TypeError("'other' must live in the same algebra")
1612 M
= other
.operator()
1613 return ( L
*M
+ M
*L
- (self
*other
).operator() )
1616 def span_of_powers(self
):
1618 Return the vector space spanned by successive powers of
1621 # The dimension of the subalgebra can't be greater than
1622 # the big algebra, so just put everything into a list
1623 # and let span() get rid of the excess.
1625 # We do the extra ambient_vector_space() in case we're messing
1626 # with polynomials and the direct parent is a module.
1627 V
= self
.vector().parent().ambient_vector_space()
1628 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1631 def subalgebra_generated_by(self
):
1633 Return the associative subalgebra of the parent EJA generated
1638 sage: set_random_seed()
1639 sage: x = random_eja().random_element()
1640 sage: x.subalgebra_generated_by().is_associative()
1643 Squaring in the subalgebra should be the same thing as
1644 squaring in the superalgebra::
1646 sage: set_random_seed()
1647 sage: x = random_eja().random_element()
1648 sage: u = x.subalgebra_generated_by().random_element()
1649 sage: u.operator_matrix()*u.vector() == (u**2).vector()
1653 # First get the subspace spanned by the powers of myself...
1654 V
= self
.span_of_powers()
1655 F
= self
.base_ring()
1657 # Now figure out the entries of the right-multiplication
1658 # matrix for the successive basis elements b0, b1,... of
1661 for b_right
in V
.basis():
1662 eja_b_right
= self
.parent()(b_right
)
1664 # The first row of the right-multiplication matrix by
1665 # b1 is what we get if we apply that matrix to b1. The
1666 # second row of the right multiplication matrix by b1
1667 # is what we get when we apply that matrix to b2...
1669 # IMPORTANT: this assumes that all vectors are COLUMN
1670 # vectors, unlike our superclass (which uses row vectors).
1671 for b_left
in V
.basis():
1672 eja_b_left
= self
.parent()(b_left
)
1673 # Multiply in the original EJA, but then get the
1674 # coordinates from the subalgebra in terms of its
1676 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1677 b_right_rows
.append(this_row
)
1678 b_right_matrix
= matrix(F
, b_right_rows
)
1679 mats
.append(b_right_matrix
)
1681 # It's an algebra of polynomials in one element, and EJAs
1682 # are power-associative.
1684 # TODO: choose generator names intelligently.
1685 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
1688 def subalgebra_idempotent(self
):
1690 Find an idempotent in the associative subalgebra I generate
1691 using Proposition 2.3.5 in Baes.
1695 sage: set_random_seed()
1696 sage: J = random_eja()
1697 sage: x = J.random_element()
1698 sage: while x.is_nilpotent():
1699 ....: x = J.random_element()
1700 sage: c = x.subalgebra_idempotent()
1705 if self
.is_nilpotent():
1706 raise ValueError("this only works with non-nilpotent elements!")
1708 V
= self
.span_of_powers()
1709 J
= self
.subalgebra_generated_by()
1710 # Mis-design warning: the basis used for span_of_powers()
1711 # and subalgebra_generated_by() must be the same, and in
1713 u
= J(V
.coordinates(self
.vector()))
1715 # The image of the matrix of left-u^m-multiplication
1716 # will be minimal for some natural number s...
1718 minimal_dim
= V
.dimension()
1719 for i
in xrange(1, V
.dimension()):
1720 this_dim
= (u
**i
).operator_matrix().image().dimension()
1721 if this_dim
< minimal_dim
:
1722 minimal_dim
= this_dim
1725 # Now minimal_matrix should correspond to the smallest
1726 # non-zero subspace in Baes's (or really, Koecher's)
1729 # However, we need to restrict the matrix to work on the
1730 # subspace... or do we? Can't we just solve, knowing that
1731 # A(c) = u^(s+1) should have a solution in the big space,
1734 # Beware, solve_right() means that we're using COLUMN vectors.
1735 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1737 A
= u_next
.operator_matrix()
1738 c_coordinates
= A
.solve_right(u_next
.vector())
1740 # Now c_coordinates is the idempotent we want, but it's in
1741 # the coordinate system of the subalgebra.
1743 # We need the basis for J, but as elements of the parent algebra.
1745 basis
= [self
.parent(v
) for v
in V
.basis()]
1746 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1751 Return my trace, the sum of my eigenvalues.
1755 sage: J = JordanSpinEJA(3)
1756 sage: x = sum(J.gens())
1762 sage: J = RealCartesianProductEJA(5)
1763 sage: J.one().trace()
1768 The trace of an element is a real number::
1770 sage: set_random_seed()
1771 sage: J = random_eja()
1772 sage: J.random_element().trace() in J.base_ring()
1778 p
= P
._charpoly
_coeff
(r
-1)
1779 # The _charpoly_coeff function already adds the factor of
1780 # -1 to ensure that _charpoly_coeff(r-1) is really what
1781 # appears in front of t^{r-1} in the charpoly. However,
1782 # we want the negative of THAT for the trace.
1783 return -p(*self
.vector())
1786 def trace_inner_product(self
, other
):
1788 Return the trace inner product of myself and ``other``.
1792 The trace inner product is commutative::
1794 sage: set_random_seed()
1795 sage: J = random_eja()
1796 sage: x = J.random_element(); y = J.random_element()
1797 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1800 The trace inner product is bilinear::
1802 sage: set_random_seed()
1803 sage: J = random_eja()
1804 sage: x = J.random_element()
1805 sage: y = J.random_element()
1806 sage: z = J.random_element()
1807 sage: a = QQ.random_element();
1808 sage: actual = (a*(x+z)).trace_inner_product(y)
1809 sage: expected = ( a*x.trace_inner_product(y) +
1810 ....: a*z.trace_inner_product(y) )
1811 sage: actual == expected
1813 sage: actual = x.trace_inner_product(a*(y+z))
1814 sage: expected = ( a*x.trace_inner_product(y) +
1815 ....: a*x.trace_inner_product(z) )
1816 sage: actual == expected
1819 The trace inner product satisfies the compatibility
1820 condition in the definition of a Euclidean Jordan algebra::
1822 sage: set_random_seed()
1823 sage: J = random_eja()
1824 sage: x = J.random_element()
1825 sage: y = J.random_element()
1826 sage: z = J.random_element()
1827 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1831 if not other
in self
.parent():
1832 raise TypeError("'other' must live in the same algebra")
1834 return (self
*other
).trace()
1837 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1839 Return the Euclidean Jordan Algebra corresponding to the set
1840 `R^n` under the Hadamard product.
1842 Note: this is nothing more than the Cartesian product of ``n``
1843 copies of the spin algebra. Once Cartesian product algebras
1844 are implemented, this can go.
1848 This multiplication table can be verified by hand::
1850 sage: J = RealCartesianProductEJA(3)
1851 sage: e0,e1,e2 = J.gens()
1867 def __classcall_private__(cls
, n
, field
=QQ
):
1868 # The FiniteDimensionalAlgebra constructor takes a list of
1869 # matrices, the ith representing right multiplication by the ith
1870 # basis element in the vector space. So if e_1 = (1,0,0), then
1871 # right (Hadamard) multiplication of x by e_1 picks out the first
1872 # component of x; and likewise for the ith basis element e_i.
1873 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1874 for i
in xrange(n
) ]
1876 fdeja
= super(RealCartesianProductEJA
, cls
)
1877 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1879 def inner_product(self
, x
, y
):
1880 return _usual_ip(x
,y
)
1885 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1889 For now, we choose a random natural number ``n`` (greater than zero)
1890 and then give you back one of the following:
1892 * The cartesian product of the rational numbers ``n`` times; this is
1893 ``QQ^n`` with the Hadamard product.
1895 * The Jordan spin algebra on ``QQ^n``.
1897 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1900 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1901 in the space of ``2n``-by-``2n`` real symmetric matrices.
1903 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1904 in the space of ``4n``-by-``4n`` real symmetric matrices.
1906 Later this might be extended to return Cartesian products of the
1912 Euclidean Jordan algebra of degree...
1916 # The max_n component lets us choose different upper bounds on the
1917 # value "n" that gets passed to the constructor. This is needed
1918 # because e.g. R^{10} is reasonable to test, while the Hermitian
1919 # 10-by-10 quaternion matrices are not.
1920 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1922 (RealSymmetricEJA
, 5),
1923 (ComplexHermitianEJA
, 4),
1924 (QuaternionHermitianEJA
, 3)])
1925 n
= ZZ
.random_element(1, max_n
)
1926 return constructor(n
, field
=QQ
)
1930 def _real_symmetric_basis(n
, field
=QQ
):
1932 Return a basis for the space of real symmetric n-by-n matrices.
1934 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1938 for j
in xrange(i
+1):
1939 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1943 # Beware, orthogonal but not normalized!
1944 Sij
= Eij
+ Eij
.transpose()
1949 def _complex_hermitian_basis(n
, field
=QQ
):
1951 Returns a basis for the space of complex Hermitian n-by-n matrices.
1955 sage: set_random_seed()
1956 sage: n = ZZ.random_element(1,5)
1957 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1961 F
= QuadraticField(-1, 'I')
1964 # This is like the symmetric case, but we need to be careful:
1966 # * We want conjugate-symmetry, not just symmetry.
1967 # * The diagonal will (as a result) be real.
1971 for j
in xrange(i
+1):
1972 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1974 Sij
= _embed_complex_matrix(Eij
)
1977 # Beware, orthogonal but not normalized! The second one
1978 # has a minus because it's conjugated.
1979 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1981 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1986 def _quaternion_hermitian_basis(n
, field
=QQ
):
1988 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1992 sage: set_random_seed()
1993 sage: n = ZZ.random_element(1,5)
1994 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1998 Q
= QuaternionAlgebra(QQ
,-1,-1)
2001 # This is like the symmetric case, but we need to be careful:
2003 # * We want conjugate-symmetry, not just symmetry.
2004 # * The diagonal will (as a result) be real.
2008 for j
in xrange(i
+1):
2009 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
2011 Sij
= _embed_quaternion_matrix(Eij
)
2014 # Beware, orthogonal but not normalized! The second,
2015 # third, and fourth ones have a minus because they're
2017 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
2019 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
2021 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
2023 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
2029 return vector(m
.base_ring(), m
.list())
2032 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
2034 def _multiplication_table_from_matrix_basis(basis
):
2036 At least three of the five simple Euclidean Jordan algebras have the
2037 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
2038 multiplication on the right is matrix multiplication. Given a basis
2039 for the underlying matrix space, this function returns a
2040 multiplication table (obtained by looping through the basis
2041 elements) for an algebra of those matrices. A reordered copy
2042 of the basis is also returned to work around the fact that
2043 the ``span()`` in this function will change the order of the basis
2044 from what we think it is, to... something else.
2046 # In S^2, for example, we nominally have four coordinates even
2047 # though the space is of dimension three only. The vector space V
2048 # is supposed to hold the entire long vector, and the subspace W
2049 # of V will be spanned by the vectors that arise from symmetric
2050 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
2051 field
= basis
[0].base_ring()
2052 dimension
= basis
[0].nrows()
2054 V
= VectorSpace(field
, dimension
**2)
2055 W
= V
.span( _mat2vec(s
) for s
in basis
)
2057 # Taking the span above reorders our basis (thanks, jerk!) so we
2058 # need to put our "matrix basis" in the same order as the
2059 # (reordered) vector basis.
2060 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
2064 # Brute force the multiplication-by-s matrix by looping
2065 # through all elements of the basis and doing the computation
2066 # to find out what the corresponding row should be. BEWARE:
2067 # these multiplication tables won't be symmetric! It therefore
2068 # becomes REALLY IMPORTANT that the underlying algebra
2069 # constructor uses ROW vectors and not COLUMN vectors. That's
2070 # why we're computing rows here and not columns.
2073 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
2074 Q_rows
.append(W
.coordinates(this_row
))
2075 Q
= matrix(field
, W
.dimension(), Q_rows
)
2081 def _embed_complex_matrix(M
):
2083 Embed the n-by-n complex matrix ``M`` into the space of real
2084 matrices of size 2n-by-2n via the map the sends each entry `z = a +
2085 bi` to the block matrix ``[[a,b],[-b,a]]``.
2089 sage: F = QuadraticField(-1,'i')
2090 sage: x1 = F(4 - 2*i)
2091 sage: x2 = F(1 + 2*i)
2094 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
2095 sage: _embed_complex_matrix(M)
2104 Embedding is a homomorphism (isomorphism, in fact)::
2106 sage: set_random_seed()
2107 sage: n = ZZ.random_element(5)
2108 sage: F = QuadraticField(-1, 'i')
2109 sage: X = random_matrix(F, n)
2110 sage: Y = random_matrix(F, n)
2111 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
2112 sage: expected = _embed_complex_matrix(X*Y)
2113 sage: actual == expected
2119 raise ValueError("the matrix 'M' must be square")
2120 field
= M
.base_ring()
2125 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
2127 # We can drop the imaginaries here.
2128 return block_matrix(field
.base_ring(), n
, blocks
)
2131 def _unembed_complex_matrix(M
):
2133 The inverse of _embed_complex_matrix().
2137 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
2138 ....: [-2, 1, -4, 3],
2139 ....: [ 9, 10, 11, 12],
2140 ....: [-10, 9, -12, 11] ])
2141 sage: _unembed_complex_matrix(A)
2143 [ 10*i + 9 12*i + 11]
2147 Unembedding is the inverse of embedding::
2149 sage: set_random_seed()
2150 sage: F = QuadraticField(-1, 'i')
2151 sage: M = random_matrix(F, 3)
2152 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
2158 raise ValueError("the matrix 'M' must be square")
2159 if not n
.mod(2).is_zero():
2160 raise ValueError("the matrix 'M' must be a complex embedding")
2162 F
= QuadraticField(-1, 'i')
2165 # Go top-left to bottom-right (reading order), converting every
2166 # 2-by-2 block we see to a single complex element.
2168 for k
in xrange(n
/2):
2169 for j
in xrange(n
/2):
2170 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
2171 if submat
[0,0] != submat
[1,1]:
2172 raise ValueError('bad on-diagonal submatrix')
2173 if submat
[0,1] != -submat
[1,0]:
2174 raise ValueError('bad off-diagonal submatrix')
2175 z
= submat
[0,0] + submat
[0,1]*i
2178 return matrix(F
, n
/2, elements
)
2181 def _embed_quaternion_matrix(M
):
2183 Embed the n-by-n quaternion matrix ``M`` into the space of real
2184 matrices of size 4n-by-4n by first sending each quaternion entry
2185 `z = a + bi + cj + dk` to the block-complex matrix
2186 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
2191 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2192 sage: i,j,k = Q.gens()
2193 sage: x = 1 + 2*i + 3*j + 4*k
2194 sage: M = matrix(Q, 1, [[x]])
2195 sage: _embed_quaternion_matrix(M)
2201 Embedding is a homomorphism (isomorphism, in fact)::
2203 sage: set_random_seed()
2204 sage: n = ZZ.random_element(5)
2205 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2206 sage: X = random_matrix(Q, n)
2207 sage: Y = random_matrix(Q, n)
2208 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
2209 sage: expected = _embed_quaternion_matrix(X*Y)
2210 sage: actual == expected
2214 quaternions
= M
.base_ring()
2217 raise ValueError("the matrix 'M' must be square")
2219 F
= QuadraticField(-1, 'i')
2224 t
= z
.coefficient_tuple()
2229 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
2230 [-c
+ d
*i
, a
- b
*i
]])
2231 blocks
.append(_embed_complex_matrix(cplx_matrix
))
2233 # We should have real entries by now, so use the realest field
2234 # we've got for the return value.
2235 return block_matrix(quaternions
.base_ring(), n
, blocks
)
2238 def _unembed_quaternion_matrix(M
):
2240 The inverse of _embed_quaternion_matrix().
2244 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
2245 ....: [-2, 1, -4, 3],
2246 ....: [-3, 4, 1, -2],
2247 ....: [-4, -3, 2, 1]])
2248 sage: _unembed_quaternion_matrix(M)
2249 [1 + 2*i + 3*j + 4*k]
2253 Unembedding is the inverse of embedding::
2255 sage: set_random_seed()
2256 sage: Q = QuaternionAlgebra(QQ, -1, -1)
2257 sage: M = random_matrix(Q, 3)
2258 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
2264 raise ValueError("the matrix 'M' must be square")
2265 if not n
.mod(4).is_zero():
2266 raise ValueError("the matrix 'M' must be a complex embedding")
2268 Q
= QuaternionAlgebra(QQ
,-1,-1)
2271 # Go top-left to bottom-right (reading order), converting every
2272 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
2275 for l
in xrange(n
/4):
2276 for m
in xrange(n
/4):
2277 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
2278 if submat
[0,0] != submat
[1,1].conjugate():
2279 raise ValueError('bad on-diagonal submatrix')
2280 if submat
[0,1] != -submat
[1,0].conjugate():
2281 raise ValueError('bad off-diagonal submatrix')
2282 z
= submat
[0,0].real() + submat
[0,0].imag()*i
2283 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
2286 return matrix(Q
, n
/4, elements
)
2289 # The usual inner product on R^n.
2291 return x
.vector().inner_product(y
.vector())
2293 # The inner product used for the real symmetric simple EJA.
2294 # We keep it as a separate function because e.g. the complex
2295 # algebra uses the same inner product, except divided by 2.
2296 def _matrix_ip(X
,Y
):
2297 X_mat
= X
.natural_representation()
2298 Y_mat
= Y
.natural_representation()
2299 return (X_mat
*Y_mat
).trace()
2302 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2304 The rank-n simple EJA consisting of real symmetric n-by-n
2305 matrices, the usual symmetric Jordan product, and the trace inner
2306 product. It has dimension `(n^2 + n)/2` over the reals.
2310 sage: J = RealSymmetricEJA(2)
2311 sage: e0, e1, e2 = J.gens()
2321 The degree of this algebra is `(n^2 + n) / 2`::
2323 sage: set_random_seed()
2324 sage: n = ZZ.random_element(1,5)
2325 sage: J = RealSymmetricEJA(n)
2326 sage: J.degree() == (n^2 + n)/2
2329 The Jordan multiplication is what we think it is::
2331 sage: set_random_seed()
2332 sage: n = ZZ.random_element(1,5)
2333 sage: J = RealSymmetricEJA(n)
2334 sage: x = J.random_element()
2335 sage: y = J.random_element()
2336 sage: actual = (x*y).natural_representation()
2337 sage: X = x.natural_representation()
2338 sage: Y = y.natural_representation()
2339 sage: expected = (X*Y + Y*X)/2
2340 sage: actual == expected
2342 sage: J(expected) == x*y
2347 def __classcall_private__(cls
, n
, field
=QQ
):
2348 S
= _real_symmetric_basis(n
, field
=field
)
2349 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2351 fdeja
= super(RealSymmetricEJA
, cls
)
2352 return fdeja
.__classcall
_private
__(cls
,
2358 def inner_product(self
, x
, y
):
2359 return _matrix_ip(x
,y
)
2362 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2364 The rank-n simple EJA consisting of complex Hermitian n-by-n
2365 matrices over the real numbers, the usual symmetric Jordan product,
2366 and the real-part-of-trace inner product. It has dimension `n^2` over
2371 The degree of this algebra is `n^2`::
2373 sage: set_random_seed()
2374 sage: n = ZZ.random_element(1,5)
2375 sage: J = ComplexHermitianEJA(n)
2376 sage: J.degree() == n^2
2379 The Jordan multiplication is what we think it is::
2381 sage: set_random_seed()
2382 sage: n = ZZ.random_element(1,5)
2383 sage: J = ComplexHermitianEJA(n)
2384 sage: x = J.random_element()
2385 sage: y = J.random_element()
2386 sage: actual = (x*y).natural_representation()
2387 sage: X = x.natural_representation()
2388 sage: Y = y.natural_representation()
2389 sage: expected = (X*Y + Y*X)/2
2390 sage: actual == expected
2392 sage: J(expected) == x*y
2397 def __classcall_private__(cls
, n
, field
=QQ
):
2398 S
= _complex_hermitian_basis(n
)
2399 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2401 fdeja
= super(ComplexHermitianEJA
, cls
)
2402 return fdeja
.__classcall
_private
__(cls
,
2408 def inner_product(self
, x
, y
):
2409 # Since a+bi on the diagonal is represented as
2414 # we'll double-count the "a" entries if we take the trace of
2416 return _matrix_ip(x
,y
)/2
2419 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2421 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2422 matrices, the usual symmetric Jordan product, and the
2423 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2428 The degree of this algebra is `n^2`::
2430 sage: set_random_seed()
2431 sage: n = ZZ.random_element(1,5)
2432 sage: J = QuaternionHermitianEJA(n)
2433 sage: J.degree() == 2*(n^2) - n
2436 The Jordan multiplication is what we think it is::
2438 sage: set_random_seed()
2439 sage: n = ZZ.random_element(1,5)
2440 sage: J = QuaternionHermitianEJA(n)
2441 sage: x = J.random_element()
2442 sage: y = J.random_element()
2443 sage: actual = (x*y).natural_representation()
2444 sage: X = x.natural_representation()
2445 sage: Y = y.natural_representation()
2446 sage: expected = (X*Y + Y*X)/2
2447 sage: actual == expected
2449 sage: J(expected) == x*y
2454 def __classcall_private__(cls
, n
, field
=QQ
):
2455 S
= _quaternion_hermitian_basis(n
)
2456 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2458 fdeja
= super(QuaternionHermitianEJA
, cls
)
2459 return fdeja
.__classcall
_private
__(cls
,
2465 def inner_product(self
, x
, y
):
2466 # Since a+bi+cj+dk on the diagonal is represented as
2468 # a + bi +cj + dk = [ a b c d]
2473 # we'll quadruple-count the "a" entries if we take the trace of
2475 return _matrix_ip(x
,y
)/4
2478 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2480 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2481 with the usual inner product and jordan product ``x*y =
2482 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2487 This multiplication table can be verified by hand::
2489 sage: J = JordanSpinEJA(4)
2490 sage: e0,e1,e2,e3 = J.gens()
2508 def __classcall_private__(cls
, n
, field
=QQ
):
2510 id_matrix
= identity_matrix(field
, n
)
2512 ei
= id_matrix
.column(i
)
2513 Qi
= zero_matrix(field
, n
)
2515 Qi
.set_column(0, ei
)
2516 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
2517 # The addition of the diagonal matrix adds an extra ei[0] in the
2518 # upper-left corner of the matrix.
2519 Qi
[0,0] = Qi
[0,0] * ~
field(2)
2522 # The rank of the spin algebra is two, unless we're in a
2523 # one-dimensional ambient space (because the rank is bounded by
2524 # the ambient dimension).
2525 fdeja
= super(JordanSpinEJA
, cls
)
2526 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
2528 def inner_product(self
, x
, y
):
2529 return _usual_ip(x
,y
)