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
.magmatic_algebras
import MagmaticAlgebras
9 from sage
.structure
.element
import is_Matrix
10 from sage
.structure
.category_object
import normalize_names
12 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra
import FiniteDimensionalAlgebra
13 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_element
import FiniteDimensionalAlgebraElement
15 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
17 def __classcall_private__(cls
,
21 assume_associative
=False,
26 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
29 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
30 raise ValueError("input is not a multiplication table")
31 mult_table
= tuple(mult_table
)
33 cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
34 cat
.or_subcategory(category
)
35 if assume_associative
:
36 cat
= cat
.Associative()
38 names
= normalize_names(n
, names
)
40 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
41 return fda
.__classcall
__(cls
,
44 assume_associative
=assume_associative
,
48 natural_basis
=natural_basis
)
55 assume_associative
=False,
62 By definition, Jordan multiplication commutes::
64 sage: set_random_seed()
65 sage: J = random_eja()
66 sage: x = J.random_element()
67 sage: y = J.random_element()
73 self
._natural
_basis
= natural_basis
74 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
83 Return a string representation of ``self``.
85 fmt
= "Euclidean Jordan algebra of degree {} over {}"
86 return fmt
.format(self
.degree(), self
.base_ring())
89 def inner_product(self
, x
, y
):
91 The inner product associated with this Euclidean Jordan algebra.
93 Defaults to the trace inner product, but can be overridden by
94 subclasses if they are sure that the necessary properties are
99 The inner product must satisfy its axiom for this algebra to truly
100 be a Euclidean Jordan Algebra::
102 sage: set_random_seed()
103 sage: J = random_eja()
104 sage: x = J.random_element()
105 sage: y = J.random_element()
106 sage: z = J.random_element()
107 sage: (x*y).inner_product(z) == y.inner_product(x*z)
111 if (not x
in self
) or (not y
in self
):
112 raise TypeError("arguments must live in this algebra")
113 return x
.trace_inner_product(y
)
116 def natural_basis(self
):
118 Return a more-natural representation of this algebra's basis.
120 Every finite-dimensional Euclidean Jordan Algebra is a direct
121 sum of five simple algebras, four of which comprise Hermitian
122 matrices. This method returns the original "natural" basis
123 for our underlying vector space. (Typically, the natural basis
124 is used to construct the multiplication table in the first place.)
126 Note that this will always return a matrix. The standard basis
127 in `R^n` will be returned as `n`-by-`1` column matrices.
131 sage: J = RealSymmetricEJA(2)
134 sage: J.natural_basis()
142 sage: J = JordanSpinEJA(2)
145 sage: J.natural_basis()
152 if self
._natural
_basis
is None:
153 return tuple( b
.vector().column() for b
in self
.basis() )
155 return self
._natural
_basis
160 Return the rank of this EJA.
162 if self
._rank
is None:
163 raise ValueError("no rank specified at genesis")
168 class Element(FiniteDimensionalAlgebraElement
):
170 An element of a Euclidean Jordan algebra.
173 def __init__(self
, A
, elt
=None):
177 The identity in `S^n` is converted to the identity in the EJA::
179 sage: J = RealSymmetricEJA(3)
180 sage: I = identity_matrix(QQ,3)
181 sage: J(I) == J.one()
184 This skew-symmetric matrix can't be represented in the EJA::
186 sage: J = RealSymmetricEJA(3)
187 sage: A = matrix(QQ,3, lambda i,j: i-j)
189 Traceback (most recent call last):
191 ArithmeticError: vector is not in free module
194 # Goal: if we're given a matrix, and if it lives in our
195 # parent algebra's "natural ambient space," convert it
196 # into an algebra element.
198 # The catch is, we make a recursive call after converting
199 # the given matrix into a vector that lives in the algebra.
200 # This we need to try the parent class initializer first,
201 # to avoid recursing forever if we're given something that
202 # already fits into the algebra, but also happens to live
203 # in the parent's "natural ambient space" (this happens with
206 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
208 natural_basis
= A
.natural_basis()
209 if elt
in natural_basis
[0].matrix_space():
210 # Thanks for nothing! Matrix spaces aren't vector
211 # spaces in Sage, so we have to figure out its
212 # natural-basis coordinates ourselves.
213 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
214 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
215 coords
= W
.coordinates(_mat2vec(elt
))
216 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
218 def __pow__(self
, n
):
220 Return ``self`` raised to the power ``n``.
222 Jordan algebras are always power-associative; see for
223 example Faraut and Koranyi, Proposition II.1.2 (ii).
227 We have to override this because our superclass uses row vectors
228 instead of column vectors! We, on the other hand, assume column
233 sage: set_random_seed()
234 sage: x = random_eja().random_element()
235 sage: x.operator_matrix()*x.vector() == (x^2).vector()
238 A few examples of power-associativity::
240 sage: set_random_seed()
241 sage: x = random_eja().random_element()
242 sage: x*(x*x)*(x*x) == x^5
244 sage: (x*x)*(x*x*x) == x^5
247 We also know that powers operator-commute (Koecher, Chapter
250 sage: set_random_seed()
251 sage: x = random_eja().random_element()
252 sage: m = ZZ.random_element(0,10)
253 sage: n = ZZ.random_element(0,10)
254 sage: Lxm = (x^m).operator_matrix()
255 sage: Lxn = (x^n).operator_matrix()
256 sage: Lxm*Lxn == Lxn*Lxm
266 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
269 def characteristic_polynomial(self
):
271 Return my characteristic polynomial (if I'm a regular
274 Eventually this should be implemented in terms of the parent
275 algebra's characteristic polynomial that works for ALL
278 if self
.is_regular():
279 return self
.minimal_polynomial()
281 raise NotImplementedError('irregular element')
284 def inner_product(self
, other
):
286 Return the parent algebra's inner product of myself and ``other``.
290 The inner product in the Jordan spin algebra is the usual
291 inner product on `R^n` (this example only works because the
292 basis for the Jordan algebra is the standard basis in `R^n`)::
294 sage: J = JordanSpinEJA(3)
295 sage: x = vector(QQ,[1,2,3])
296 sage: y = vector(QQ,[4,5,6])
297 sage: x.inner_product(y)
299 sage: J(x).inner_product(J(y))
302 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
303 multiplication is the usual matrix multiplication in `S^n`,
304 so the inner product of the identity matrix with itself
307 sage: J = RealSymmetricEJA(3)
308 sage: J.one().inner_product(J.one())
311 Likewise, the inner product on `C^n` is `<X,Y> =
312 Re(trace(X*Y))`, where we must necessarily take the real
313 part because the product of Hermitian matrices may not be
316 sage: J = ComplexHermitianEJA(3)
317 sage: J.one().inner_product(J.one())
320 Ditto for the quaternions::
322 sage: J = QuaternionHermitianEJA(3)
323 sage: J.one().inner_product(J.one())
328 Ensure that we can always compute an inner product, and that
329 it gives us back a real number::
331 sage: set_random_seed()
332 sage: J = random_eja()
333 sage: x = J.random_element()
334 sage: y = J.random_element()
335 sage: x.inner_product(y) in RR
341 raise TypeError("'other' must live in the same algebra")
343 return P
.inner_product(self
, other
)
346 def operator_commutes_with(self
, other
):
348 Return whether or not this element operator-commutes
353 The definition of a Jordan algebra says that any element
354 operator-commutes with its square::
356 sage: set_random_seed()
357 sage: x = random_eja().random_element()
358 sage: x.operator_commutes_with(x^2)
363 Test Lemma 1 from Chapter III of Koecher::
365 sage: set_random_seed()
366 sage: J = random_eja()
367 sage: u = J.random_element()
368 sage: v = J.random_element()
369 sage: lhs = u.operator_commutes_with(u*v)
370 sage: rhs = v.operator_commutes_with(u^2)
375 if not other
in self
.parent():
376 raise TypeError("'other' must live in the same algebra")
378 A
= self
.operator_matrix()
379 B
= other
.operator_matrix()
385 Return my determinant, the product of my eigenvalues.
389 sage: J = JordanSpinEJA(2)
390 sage: e0,e1 = J.gens()
394 sage: J = JordanSpinEJA(3)
395 sage: e0,e1,e2 = J.gens()
396 sage: x = e0 + e1 + e2
401 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
404 return cs
[0] * (-1)**r
406 raise ValueError('charpoly had no coefficients')
411 Return the Jordan-multiplicative inverse of this element.
413 We can't use the superclass method because it relies on the
414 algebra being associative.
418 The inverse in the spin factor algebra is given in Alizadeh's
421 sage: set_random_seed()
422 sage: n = ZZ.random_element(1,10)
423 sage: J = JordanSpinEJA(n)
424 sage: x = J.random_element()
425 sage: while x.is_zero():
426 ....: x = J.random_element()
427 sage: x_vec = x.vector()
429 sage: x_bar = x_vec[1:]
430 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
431 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
432 sage: x_inverse = coeff*inv_vec
433 sage: x.inverse() == J(x_inverse)
438 The identity element is its own inverse::
440 sage: set_random_seed()
441 sage: J = random_eja()
442 sage: J.one().inverse() == J.one()
445 If an element has an inverse, it acts like one. TODO: this
446 can be a lot less ugly once ``is_invertible`` doesn't crash
447 on irregular elements::
449 sage: set_random_seed()
450 sage: J = random_eja()
451 sage: x = J.random_element()
453 ....: x.inverse()*x == J.one()
459 if self
.parent().is_associative():
460 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
463 # TODO: we can do better once the call to is_invertible()
464 # doesn't crash on irregular elements.
465 #if not self.is_invertible():
466 # raise ValueError('element is not invertible')
468 # We do this a little different than the usual recursive
469 # call to a finite-dimensional algebra element, because we
470 # wind up with an inverse that lives in the subalgebra and
471 # we need information about the parent to convert it back.
472 V
= self
.span_of_powers()
473 assoc_subalg
= self
.subalgebra_generated_by()
474 # Mis-design warning: the basis used for span_of_powers()
475 # and subalgebra_generated_by() must be the same, and in
477 elt
= assoc_subalg(V
.coordinates(self
.vector()))
479 # This will be in the subalgebra's coordinates...
480 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
481 subalg_inverse
= fda_elt
.inverse()
483 # So we have to convert back...
484 basis
= [ self
.parent(v
) for v
in V
.basis() ]
485 pairs
= zip(subalg_inverse
.vector(), basis
)
486 return self
.parent().linear_combination(pairs
)
489 def is_invertible(self
):
491 Return whether or not this element is invertible.
493 We can't use the superclass method because it relies on
494 the algebra being associative.
498 The usual way to do this is to check if the determinant is
499 zero, but we need the characteristic polynomial for the
500 determinant. The minimal polynomial is a lot easier to get,
501 so we use Corollary 2 in Chapter V of Koecher to check
502 whether or not the paren't algebra's zero element is a root
503 of this element's minimal polynomial.
507 The identity element is always invertible::
509 sage: set_random_seed()
510 sage: J = random_eja()
511 sage: J.one().is_invertible()
514 The zero element is never invertible::
516 sage: set_random_seed()
517 sage: J = random_eja()
518 sage: J.zero().is_invertible()
522 zero
= self
.parent().zero()
523 p
= self
.minimal_polynomial()
524 return not (p(zero
) == zero
)
527 def is_nilpotent(self
):
529 Return whether or not some power of this element is zero.
531 The superclass method won't work unless we're in an
532 associative algebra, and we aren't. However, we generate
533 an assocoative subalgebra and we're nilpotent there if and
534 only if we're nilpotent here (probably).
538 The identity element is never nilpotent::
540 sage: set_random_seed()
541 sage: random_eja().one().is_nilpotent()
544 The additive identity is always nilpotent::
546 sage: set_random_seed()
547 sage: random_eja().zero().is_nilpotent()
551 # The element we're going to call "is_nilpotent()" on.
552 # Either myself, interpreted as an element of a finite-
553 # dimensional algebra, or an element of an associative
557 if self
.parent().is_associative():
558 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
560 V
= self
.span_of_powers()
561 assoc_subalg
= self
.subalgebra_generated_by()
562 # Mis-design warning: the basis used for span_of_powers()
563 # and subalgebra_generated_by() must be the same, and in
565 elt
= assoc_subalg(V
.coordinates(self
.vector()))
567 # Recursive call, but should work since elt lives in an
568 # associative algebra.
569 return elt
.is_nilpotent()
572 def is_regular(self
):
574 Return whether or not this is a regular element.
578 The identity element always has degree one, but any element
579 linearly-independent from it is regular::
581 sage: J = JordanSpinEJA(5)
582 sage: J.one().is_regular()
584 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
585 sage: for x in J.gens():
586 ....: (J.one() + x).is_regular()
594 return self
.degree() == self
.parent().rank()
599 Compute the degree of this element the straightforward way
600 according to the definition; by appending powers to a list
601 and figuring out its dimension (that is, whether or not
602 they're linearly dependent).
606 sage: J = JordanSpinEJA(4)
607 sage: J.one().degree()
609 sage: e0,e1,e2,e3 = J.gens()
610 sage: (e0 - e1).degree()
613 In the spin factor algebra (of rank two), all elements that
614 aren't multiples of the identity are regular::
616 sage: set_random_seed()
617 sage: n = ZZ.random_element(1,10)
618 sage: J = JordanSpinEJA(n)
619 sage: x = J.random_element()
620 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
624 return self
.span_of_powers().dimension()
627 def minimal_polynomial(self
):
631 We restrict ourselves to the associative subalgebra
632 generated by this element, and then return the minimal
633 polynomial of this element's operator matrix (in that
634 subalgebra). This works by Baes Proposition 2.3.16.
638 sage: set_random_seed()
639 sage: x = random_eja().random_element()
640 sage: x.degree() == x.minimal_polynomial().degree()
645 sage: set_random_seed()
646 sage: x = random_eja().random_element()
647 sage: x.degree() == x.minimal_polynomial().degree()
650 The minimal polynomial and the characteristic polynomial coincide
651 and are known (see Alizadeh, Example 11.11) for all elements of
652 the spin factor algebra that aren't scalar multiples of the
655 sage: set_random_seed()
656 sage: n = ZZ.random_element(2,10)
657 sage: J = JordanSpinEJA(n)
658 sage: y = J.random_element()
659 sage: while y == y.coefficient(0)*J.one():
660 ....: y = J.random_element()
661 sage: y0 = y.vector()[0]
662 sage: y_bar = y.vector()[1:]
663 sage: actual = y.minimal_polynomial()
664 sage: x = SR.symbol('x', domain='real')
665 sage: expected = x^2 - 2*y0*x + (y0^2 - norm(y_bar)^2)
666 sage: bool(actual == expected)
670 V
= self
.span_of_powers()
671 assoc_subalg
= self
.subalgebra_generated_by()
672 # Mis-design warning: the basis used for span_of_powers()
673 # and subalgebra_generated_by() must be the same, and in
675 elt
= assoc_subalg(V
.coordinates(self
.vector()))
676 return elt
.operator_matrix().minimal_polynomial()
679 def natural_representation(self
):
681 Return a more-natural representation of this element.
683 Every finite-dimensional Euclidean Jordan Algebra is a
684 direct sum of five simple algebras, four of which comprise
685 Hermitian matrices. This method returns the original
686 "natural" representation of this element as a Hermitian
687 matrix, if it has one. If not, you get the usual representation.
691 sage: J = ComplexHermitianEJA(3)
694 sage: J.one().natural_representation()
704 sage: J = QuaternionHermitianEJA(3)
707 sage: J.one().natural_representation()
708 [1 0 0 0 0 0 0 0 0 0 0 0]
709 [0 1 0 0 0 0 0 0 0 0 0 0]
710 [0 0 1 0 0 0 0 0 0 0 0 0]
711 [0 0 0 1 0 0 0 0 0 0 0 0]
712 [0 0 0 0 1 0 0 0 0 0 0 0]
713 [0 0 0 0 0 1 0 0 0 0 0 0]
714 [0 0 0 0 0 0 1 0 0 0 0 0]
715 [0 0 0 0 0 0 0 1 0 0 0 0]
716 [0 0 0 0 0 0 0 0 1 0 0 0]
717 [0 0 0 0 0 0 0 0 0 1 0 0]
718 [0 0 0 0 0 0 0 0 0 0 1 0]
719 [0 0 0 0 0 0 0 0 0 0 0 1]
722 B
= self
.parent().natural_basis()
723 W
= B
[0].matrix_space()
724 return W
.linear_combination(zip(self
.vector(), B
))
727 def operator_matrix(self
):
729 Return the matrix that represents left- (or right-)
730 multiplication by this element in the parent algebra.
732 We have to override this because the superclass method
733 returns a matrix that acts on row vectors (that is, on
738 Test the first polarization identity from my notes, Koecher Chapter
739 III, or from Baes (2.3)::
741 sage: set_random_seed()
742 sage: J = random_eja()
743 sage: x = J.random_element()
744 sage: y = J.random_element()
745 sage: Lx = x.operator_matrix()
746 sage: Ly = y.operator_matrix()
747 sage: Lxx = (x*x).operator_matrix()
748 sage: Lxy = (x*y).operator_matrix()
749 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
752 Test the second polarization identity from my notes or from
755 sage: set_random_seed()
756 sage: J = random_eja()
757 sage: x = J.random_element()
758 sage: y = J.random_element()
759 sage: z = J.random_element()
760 sage: Lx = x.operator_matrix()
761 sage: Ly = y.operator_matrix()
762 sage: Lz = z.operator_matrix()
763 sage: Lzy = (z*y).operator_matrix()
764 sage: Lxy = (x*y).operator_matrix()
765 sage: Lxz = (x*z).operator_matrix()
766 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
769 Test the third polarization identity from my notes or from
772 sage: set_random_seed()
773 sage: J = random_eja()
774 sage: u = J.random_element()
775 sage: y = J.random_element()
776 sage: z = J.random_element()
777 sage: Lu = u.operator_matrix()
778 sage: Ly = y.operator_matrix()
779 sage: Lz = z.operator_matrix()
780 sage: Lzy = (z*y).operator_matrix()
781 sage: Luy = (u*y).operator_matrix()
782 sage: Luz = (u*z).operator_matrix()
783 sage: Luyz = (u*(y*z)).operator_matrix()
784 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
785 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
786 sage: bool(lhs == rhs)
790 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
791 return fda_elt
.matrix().transpose()
794 def quadratic_representation(self
, other
=None):
796 Return the quadratic representation of this element.
800 The explicit form in the spin factor algebra is given by
801 Alizadeh's Example 11.12::
803 sage: set_random_seed()
804 sage: n = ZZ.random_element(1,10)
805 sage: J = JordanSpinEJA(n)
806 sage: x = J.random_element()
807 sage: x_vec = x.vector()
809 sage: x_bar = x_vec[1:]
810 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
811 sage: B = 2*x0*x_bar.row()
812 sage: C = 2*x0*x_bar.column()
813 sage: D = identity_matrix(QQ, n-1)
814 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
815 sage: D = D + 2*x_bar.tensor_product(x_bar)
816 sage: Q = block_matrix(2,2,[A,B,C,D])
817 sage: Q == x.quadratic_representation()
820 Test all of the properties from Theorem 11.2 in Alizadeh::
822 sage: set_random_seed()
823 sage: J = random_eja()
824 sage: x = J.random_element()
825 sage: y = J.random_element()
829 sage: actual = x.quadratic_representation(y)
830 sage: expected = ( (x+y).quadratic_representation()
831 ....: -x.quadratic_representation()
832 ....: -y.quadratic_representation() ) / 2
833 sage: actual == expected
838 sage: alpha = QQ.random_element()
839 sage: actual = (alpha*x).quadratic_representation()
840 sage: expected = (alpha^2)*x.quadratic_representation()
841 sage: actual == expected
846 sage: Qy = y.quadratic_representation()
847 sage: actual = J(Qy*x.vector()).quadratic_representation()
848 sage: expected = Qy*x.quadratic_representation()*Qy
849 sage: actual == expected
854 sage: k = ZZ.random_element(1,10)
855 sage: actual = (x^k).quadratic_representation()
856 sage: expected = (x.quadratic_representation())^k
857 sage: actual == expected
863 elif not other
in self
.parent():
864 raise TypeError("'other' must live in the same algebra")
866 L
= self
.operator_matrix()
867 M
= other
.operator_matrix()
868 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
871 def span_of_powers(self
):
873 Return the vector space spanned by successive powers of
876 # The dimension of the subalgebra can't be greater than
877 # the big algebra, so just put everything into a list
878 # and let span() get rid of the excess.
880 # We do the extra ambient_vector_space() in case we're messing
881 # with polynomials and the direct parent is a module.
882 V
= self
.vector().parent().ambient_vector_space()
883 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
886 def subalgebra_generated_by(self
):
888 Return the associative subalgebra of the parent EJA generated
893 sage: set_random_seed()
894 sage: x = random_eja().random_element()
895 sage: x.subalgebra_generated_by().is_associative()
898 Squaring in the subalgebra should be the same thing as
899 squaring in the superalgebra::
901 sage: set_random_seed()
902 sage: x = random_eja().random_element()
903 sage: u = x.subalgebra_generated_by().random_element()
904 sage: u.operator_matrix()*u.vector() == (u**2).vector()
908 # First get the subspace spanned by the powers of myself...
909 V
= self
.span_of_powers()
912 # Now figure out the entries of the right-multiplication
913 # matrix for the successive basis elements b0, b1,... of
916 for b_right
in V
.basis():
917 eja_b_right
= self
.parent()(b_right
)
919 # The first row of the right-multiplication matrix by
920 # b1 is what we get if we apply that matrix to b1. The
921 # second row of the right multiplication matrix by b1
922 # is what we get when we apply that matrix to b2...
924 # IMPORTANT: this assumes that all vectors are COLUMN
925 # vectors, unlike our superclass (which uses row vectors).
926 for b_left
in V
.basis():
927 eja_b_left
= self
.parent()(b_left
)
928 # Multiply in the original EJA, but then get the
929 # coordinates from the subalgebra in terms of its
931 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
932 b_right_rows
.append(this_row
)
933 b_right_matrix
= matrix(F
, b_right_rows
)
934 mats
.append(b_right_matrix
)
936 # It's an algebra of polynomials in one element, and EJAs
937 # are power-associative.
939 # TODO: choose generator names intelligently.
940 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
943 def subalgebra_idempotent(self
):
945 Find an idempotent in the associative subalgebra I generate
946 using Proposition 2.3.5 in Baes.
950 sage: set_random_seed()
951 sage: J = RealCartesianProductEJA(5)
952 sage: c = J.random_element().subalgebra_idempotent()
955 sage: J = JordanSpinEJA(5)
956 sage: c = J.random_element().subalgebra_idempotent()
961 if self
.is_nilpotent():
962 raise ValueError("this only works with non-nilpotent elements!")
964 V
= self
.span_of_powers()
965 J
= self
.subalgebra_generated_by()
966 # Mis-design warning: the basis used for span_of_powers()
967 # and subalgebra_generated_by() must be the same, and in
969 u
= J(V
.coordinates(self
.vector()))
971 # The image of the matrix of left-u^m-multiplication
972 # will be minimal for some natural number s...
974 minimal_dim
= V
.dimension()
975 for i
in xrange(1, V
.dimension()):
976 this_dim
= (u
**i
).operator_matrix().image().dimension()
977 if this_dim
< minimal_dim
:
978 minimal_dim
= this_dim
981 # Now minimal_matrix should correspond to the smallest
982 # non-zero subspace in Baes's (or really, Koecher's)
985 # However, we need to restrict the matrix to work on the
986 # subspace... or do we? Can't we just solve, knowing that
987 # A(c) = u^(s+1) should have a solution in the big space,
990 # Beware, solve_right() means that we're using COLUMN vectors.
991 # Our FiniteDimensionalAlgebraElement superclass uses rows.
993 A
= u_next
.operator_matrix()
994 c_coordinates
= A
.solve_right(u_next
.vector())
996 # Now c_coordinates is the idempotent we want, but it's in
997 # the coordinate system of the subalgebra.
999 # We need the basis for J, but as elements of the parent algebra.
1001 basis
= [self
.parent(v
) for v
in V
.basis()]
1002 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1007 Return my trace, the sum of my eigenvalues.
1011 sage: J = JordanSpinEJA(3)
1012 sage: e0,e1,e2 = J.gens()
1013 sage: x = e0 + e1 + e2
1018 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
1022 raise ValueError('charpoly had fewer than 2 coefficients')
1025 def trace_inner_product(self
, other
):
1027 Return the trace inner product of myself and ``other``.
1029 if not other
in self
.parent():
1030 raise TypeError("'other' must live in the same algebra")
1032 return (self
*other
).trace()
1035 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1037 Return the Euclidean Jordan Algebra corresponding to the set
1038 `R^n` under the Hadamard product.
1040 Note: this is nothing more than the Cartesian product of ``n``
1041 copies of the spin algebra. Once Cartesian product algebras
1042 are implemented, this can go.
1046 This multiplication table can be verified by hand::
1048 sage: J = RealCartesianProductEJA(3)
1049 sage: e0,e1,e2 = J.gens()
1065 def __classcall_private__(cls
, n
, field
=QQ
):
1066 # The FiniteDimensionalAlgebra constructor takes a list of
1067 # matrices, the ith representing right multiplication by the ith
1068 # basis element in the vector space. So if e_1 = (1,0,0), then
1069 # right (Hadamard) multiplication of x by e_1 picks out the first
1070 # component of x; and likewise for the ith basis element e_i.
1071 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1072 for i
in xrange(n
) ]
1074 fdeja
= super(RealCartesianProductEJA
, cls
)
1075 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1077 def inner_product(self
, x
, y
):
1078 return _usual_ip(x
,y
)
1083 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1087 For now, we choose a random natural number ``n`` (greater than zero)
1088 and then give you back one of the following:
1090 * The cartesian product of the rational numbers ``n`` times; this is
1091 ``QQ^n`` with the Hadamard product.
1093 * The Jordan spin algebra on ``QQ^n``.
1095 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1098 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1099 in the space of ``2n``-by-``2n`` real symmetric matrices.
1101 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1102 in the space of ``4n``-by-``4n`` real symmetric matrices.
1104 Later this might be extended to return Cartesian products of the
1110 Euclidean Jordan algebra of degree...
1113 n
= ZZ
.random_element(1,5)
1114 constructor
= choice([RealCartesianProductEJA
,
1117 ComplexHermitianEJA
,
1118 QuaternionHermitianEJA
])
1119 return constructor(n
, field
=QQ
)
1123 def _real_symmetric_basis(n
, field
=QQ
):
1125 Return a basis for the space of real symmetric n-by-n matrices.
1127 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1131 for j
in xrange(i
+1):
1132 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1136 # Beware, orthogonal but not normalized!
1137 Sij
= Eij
+ Eij
.transpose()
1142 def _complex_hermitian_basis(n
, field
=QQ
):
1144 Returns a basis for the space of complex Hermitian n-by-n matrices.
1148 sage: set_random_seed()
1149 sage: n = ZZ.random_element(1,5)
1150 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1154 F
= QuadraticField(-1, 'I')
1157 # This is like the symmetric case, but we need to be careful:
1159 # * We want conjugate-symmetry, not just symmetry.
1160 # * The diagonal will (as a result) be real.
1164 for j
in xrange(i
+1):
1165 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1167 Sij
= _embed_complex_matrix(Eij
)
1170 # Beware, orthogonal but not normalized! The second one
1171 # has a minus because it's conjugated.
1172 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1174 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1179 def _quaternion_hermitian_basis(n
, field
=QQ
):
1181 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1185 sage: set_random_seed()
1186 sage: n = ZZ.random_element(1,5)
1187 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1191 Q
= QuaternionAlgebra(QQ
,-1,-1)
1194 # This is like the symmetric case, but we need to be careful:
1196 # * We want conjugate-symmetry, not just symmetry.
1197 # * The diagonal will (as a result) be real.
1201 for j
in xrange(i
+1):
1202 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1204 Sij
= _embed_quaternion_matrix(Eij
)
1207 # Beware, orthogonal but not normalized! The second,
1208 # third, and fourth ones have a minus because they're
1210 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1212 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1214 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1216 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1222 return vector(m
.base_ring(), m
.list())
1225 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1227 def _multiplication_table_from_matrix_basis(basis
):
1229 At least three of the five simple Euclidean Jordan algebras have the
1230 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1231 multiplication on the right is matrix multiplication. Given a basis
1232 for the underlying matrix space, this function returns a
1233 multiplication table (obtained by looping through the basis
1234 elements) for an algebra of those matrices. A reordered copy
1235 of the basis is also returned to work around the fact that
1236 the ``span()`` in this function will change the order of the basis
1237 from what we think it is, to... something else.
1239 # In S^2, for example, we nominally have four coordinates even
1240 # though the space is of dimension three only. The vector space V
1241 # is supposed to hold the entire long vector, and the subspace W
1242 # of V will be spanned by the vectors that arise from symmetric
1243 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1244 field
= basis
[0].base_ring()
1245 dimension
= basis
[0].nrows()
1247 V
= VectorSpace(field
, dimension
**2)
1248 W
= V
.span( _mat2vec(s
) for s
in basis
)
1250 # Taking the span above reorders our basis (thanks, jerk!) so we
1251 # need to put our "matrix basis" in the same order as the
1252 # (reordered) vector basis.
1253 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1257 # Brute force the multiplication-by-s matrix by looping
1258 # through all elements of the basis and doing the computation
1259 # to find out what the corresponding row should be. BEWARE:
1260 # these multiplication tables won't be symmetric! It therefore
1261 # becomes REALLY IMPORTANT that the underlying algebra
1262 # constructor uses ROW vectors and not COLUMN vectors. That's
1263 # why we're computing rows here and not columns.
1266 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1267 Q_rows
.append(W
.coordinates(this_row
))
1268 Q
= matrix(field
, W
.dimension(), Q_rows
)
1274 def _embed_complex_matrix(M
):
1276 Embed the n-by-n complex matrix ``M`` into the space of real
1277 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1278 bi` to the block matrix ``[[a,b],[-b,a]]``.
1282 sage: F = QuadraticField(-1,'i')
1283 sage: x1 = F(4 - 2*i)
1284 sage: x2 = F(1 + 2*i)
1287 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1288 sage: _embed_complex_matrix(M)
1297 Embedding is a homomorphism (isomorphism, in fact)::
1299 sage: set_random_seed()
1300 sage: n = ZZ.random_element(5)
1301 sage: F = QuadraticField(-1, 'i')
1302 sage: X = random_matrix(F, n)
1303 sage: Y = random_matrix(F, n)
1304 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1305 sage: expected = _embed_complex_matrix(X*Y)
1306 sage: actual == expected
1312 raise ValueError("the matrix 'M' must be square")
1313 field
= M
.base_ring()
1318 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1320 # We can drop the imaginaries here.
1321 return block_matrix(field
.base_ring(), n
, blocks
)
1324 def _unembed_complex_matrix(M
):
1326 The inverse of _embed_complex_matrix().
1330 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1331 ....: [-2, 1, -4, 3],
1332 ....: [ 9, 10, 11, 12],
1333 ....: [-10, 9, -12, 11] ])
1334 sage: _unembed_complex_matrix(A)
1336 [ 10*i + 9 12*i + 11]
1340 Unembedding is the inverse of embedding::
1342 sage: set_random_seed()
1343 sage: F = QuadraticField(-1, 'i')
1344 sage: M = random_matrix(F, 3)
1345 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1351 raise ValueError("the matrix 'M' must be square")
1352 if not n
.mod(2).is_zero():
1353 raise ValueError("the matrix 'M' must be a complex embedding")
1355 F
= QuadraticField(-1, 'i')
1358 # Go top-left to bottom-right (reading order), converting every
1359 # 2-by-2 block we see to a single complex element.
1361 for k
in xrange(n
/2):
1362 for j
in xrange(n
/2):
1363 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1364 if submat
[0,0] != submat
[1,1]:
1365 raise ValueError('bad on-diagonal submatrix')
1366 if submat
[0,1] != -submat
[1,0]:
1367 raise ValueError('bad off-diagonal submatrix')
1368 z
= submat
[0,0] + submat
[0,1]*i
1371 return matrix(F
, n
/2, elements
)
1374 def _embed_quaternion_matrix(M
):
1376 Embed the n-by-n quaternion matrix ``M`` into the space of real
1377 matrices of size 4n-by-4n by first sending each quaternion entry
1378 `z = a + bi + cj + dk` to the block-complex matrix
1379 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1384 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1385 sage: i,j,k = Q.gens()
1386 sage: x = 1 + 2*i + 3*j + 4*k
1387 sage: M = matrix(Q, 1, [[x]])
1388 sage: _embed_quaternion_matrix(M)
1394 Embedding is a homomorphism (isomorphism, in fact)::
1396 sage: set_random_seed()
1397 sage: n = ZZ.random_element(5)
1398 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1399 sage: X = random_matrix(Q, n)
1400 sage: Y = random_matrix(Q, n)
1401 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1402 sage: expected = _embed_quaternion_matrix(X*Y)
1403 sage: actual == expected
1407 quaternions
= M
.base_ring()
1410 raise ValueError("the matrix 'M' must be square")
1412 F
= QuadraticField(-1, 'i')
1417 t
= z
.coefficient_tuple()
1422 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1423 [-c
+ d
*i
, a
- b
*i
]])
1424 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1426 # We should have real entries by now, so use the realest field
1427 # we've got for the return value.
1428 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1431 def _unembed_quaternion_matrix(M
):
1433 The inverse of _embed_quaternion_matrix().
1437 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1438 ....: [-2, 1, -4, 3],
1439 ....: [-3, 4, 1, -2],
1440 ....: [-4, -3, 2, 1]])
1441 sage: _unembed_quaternion_matrix(M)
1442 [1 + 2*i + 3*j + 4*k]
1446 Unembedding is the inverse of embedding::
1448 sage: set_random_seed()
1449 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1450 sage: M = random_matrix(Q, 3)
1451 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1457 raise ValueError("the matrix 'M' must be square")
1458 if not n
.mod(4).is_zero():
1459 raise ValueError("the matrix 'M' must be a complex embedding")
1461 Q
= QuaternionAlgebra(QQ
,-1,-1)
1464 # Go top-left to bottom-right (reading order), converting every
1465 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1468 for l
in xrange(n
/4):
1469 for m
in xrange(n
/4):
1470 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1471 if submat
[0,0] != submat
[1,1].conjugate():
1472 raise ValueError('bad on-diagonal submatrix')
1473 if submat
[0,1] != -submat
[1,0].conjugate():
1474 raise ValueError('bad off-diagonal submatrix')
1475 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1476 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1479 return matrix(Q
, n
/4, elements
)
1482 # The usual inner product on R^n.
1484 return x
.vector().inner_product(y
.vector())
1486 # The inner product used for the real symmetric simple EJA.
1487 # We keep it as a separate function because e.g. the complex
1488 # algebra uses the same inner product, except divided by 2.
1489 def _matrix_ip(X
,Y
):
1490 X_mat
= X
.natural_representation()
1491 Y_mat
= Y
.natural_representation()
1492 return (X_mat
*Y_mat
).trace()
1495 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1497 The rank-n simple EJA consisting of real symmetric n-by-n
1498 matrices, the usual symmetric Jordan product, and the trace inner
1499 product. It has dimension `(n^2 + n)/2` over the reals.
1503 sage: J = RealSymmetricEJA(2)
1504 sage: e0, e1, e2 = J.gens()
1514 The degree of this algebra is `(n^2 + n) / 2`::
1516 sage: set_random_seed()
1517 sage: n = ZZ.random_element(1,5)
1518 sage: J = RealSymmetricEJA(n)
1519 sage: J.degree() == (n^2 + n)/2
1522 The Jordan multiplication is what we think it is::
1524 sage: set_random_seed()
1525 sage: n = ZZ.random_element(1,5)
1526 sage: J = RealSymmetricEJA(n)
1527 sage: x = J.random_element()
1528 sage: y = J.random_element()
1529 sage: actual = (x*y).natural_representation()
1530 sage: X = x.natural_representation()
1531 sage: Y = y.natural_representation()
1532 sage: expected = (X*Y + Y*X)/2
1533 sage: actual == expected
1535 sage: J(expected) == x*y
1540 def __classcall_private__(cls
, n
, field
=QQ
):
1541 S
= _real_symmetric_basis(n
, field
=field
)
1542 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1544 fdeja
= super(RealSymmetricEJA
, cls
)
1545 return fdeja
.__classcall
_private
__(cls
,
1551 def inner_product(self
, x
, y
):
1552 return _matrix_ip(x
,y
)
1555 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1557 The rank-n simple EJA consisting of complex Hermitian n-by-n
1558 matrices over the real numbers, the usual symmetric Jordan product,
1559 and the real-part-of-trace inner product. It has dimension `n^2` over
1564 The degree of this algebra is `n^2`::
1566 sage: set_random_seed()
1567 sage: n = ZZ.random_element(1,5)
1568 sage: J = ComplexHermitianEJA(n)
1569 sage: J.degree() == n^2
1572 The Jordan multiplication is what we think it is::
1574 sage: set_random_seed()
1575 sage: n = ZZ.random_element(1,5)
1576 sage: J = ComplexHermitianEJA(n)
1577 sage: x = J.random_element()
1578 sage: y = J.random_element()
1579 sage: actual = (x*y).natural_representation()
1580 sage: X = x.natural_representation()
1581 sage: Y = y.natural_representation()
1582 sage: expected = (X*Y + Y*X)/2
1583 sage: actual == expected
1585 sage: J(expected) == x*y
1590 def __classcall_private__(cls
, n
, field
=QQ
):
1591 S
= _complex_hermitian_basis(n
)
1592 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1594 fdeja
= super(ComplexHermitianEJA
, cls
)
1595 return fdeja
.__classcall
_private
__(cls
,
1601 def inner_product(self
, x
, y
):
1602 # Since a+bi on the diagonal is represented as
1607 # we'll double-count the "a" entries if we take the trace of
1609 return _matrix_ip(x
,y
)/2
1612 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1614 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1615 matrices, the usual symmetric Jordan product, and the
1616 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1621 The degree of this algebra is `n^2`::
1623 sage: set_random_seed()
1624 sage: n = ZZ.random_element(1,5)
1625 sage: J = QuaternionHermitianEJA(n)
1626 sage: J.degree() == 2*(n^2) - n
1629 The Jordan multiplication is what we think it is::
1631 sage: set_random_seed()
1632 sage: n = ZZ.random_element(1,5)
1633 sage: J = QuaternionHermitianEJA(n)
1634 sage: x = J.random_element()
1635 sage: y = J.random_element()
1636 sage: actual = (x*y).natural_representation()
1637 sage: X = x.natural_representation()
1638 sage: Y = y.natural_representation()
1639 sage: expected = (X*Y + Y*X)/2
1640 sage: actual == expected
1642 sage: J(expected) == x*y
1647 def __classcall_private__(cls
, n
, field
=QQ
):
1648 S
= _quaternion_hermitian_basis(n
)
1649 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1651 fdeja
= super(QuaternionHermitianEJA
, cls
)
1652 return fdeja
.__classcall
_private
__(cls
,
1658 def inner_product(self
, x
, y
):
1659 # Since a+bi+cj+dk on the diagonal is represented as
1661 # a + bi +cj + dk = [ a b c d]
1666 # we'll quadruple-count the "a" entries if we take the trace of
1668 return _matrix_ip(x
,y
)/4
1671 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1673 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1674 with the usual inner product and jordan product ``x*y =
1675 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1680 This multiplication table can be verified by hand::
1682 sage: J = JordanSpinEJA(4)
1683 sage: e0,e1,e2,e3 = J.gens()
1701 def __classcall_private__(cls
, n
, field
=QQ
):
1703 id_matrix
= identity_matrix(field
, n
)
1705 ei
= id_matrix
.column(i
)
1706 Qi
= zero_matrix(field
, n
)
1708 Qi
.set_column(0, ei
)
1709 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
1710 # The addition of the diagonal matrix adds an extra ei[0] in the
1711 # upper-left corner of the matrix.
1712 Qi
[0,0] = Qi
[0,0] * ~
field(2)
1715 # The rank of the spin algebra is two, unless we're in a
1716 # one-dimensional ambient space (because the rank is bounded by
1717 # the ambient dimension).
1718 fdeja
= super(JordanSpinEJA
, cls
)
1719 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
1721 def inner_product(self
, x
, y
):
1722 return _usual_ip(x
,y
)