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,
27 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
30 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
31 raise ValueError("input is not a multiplication table")
32 mult_table
= tuple(mult_table
)
34 cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
35 cat
.or_subcategory(category
)
36 if assume_associative
:
37 cat
= cat
.Associative()
39 names
= normalize_names(n
, names
)
41 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
42 return fda
.__classcall
__(cls
,
45 assume_associative
=assume_associative
,
49 natural_basis
=natural_basis
,
50 inner_product
=inner_product
)
57 assume_associative
=False,
65 By definition, Jordan multiplication commutes::
67 sage: set_random_seed()
68 sage: J = random_eja()
69 sage: x = J.random_element()
70 sage: y = J.random_element()
76 self
._natural
_basis
= natural_basis
77 self
._inner
_product
= inner_product
78 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
87 Return a string representation of ``self``.
89 fmt
= "Euclidean Jordan algebra of degree {} over {}"
90 return fmt
.format(self
.degree(), self
.base_ring())
93 def inner_product(self
, x
, y
):
95 The inner product associated with this Euclidean Jordan algebra.
97 Will default to the trace inner product if nothing else.
101 The inner product must satisfy its axiom for this algebra to truly
102 be a Euclidean Jordan Algebra::
104 sage: set_random_seed()
105 sage: J = random_eja()
106 sage: x = J.random_element()
107 sage: y = J.random_element()
108 sage: z = J.random_element()
109 sage: (x*y).inner_product(z) == y.inner_product(x*z)
113 if (not x
in self
) or (not y
in self
):
114 raise TypeError("arguments must live in this algebra")
115 if self
._inner
_product
is None:
116 return x
.trace_inner_product(y
)
118 return self
._inner
_product
(x
,y
)
121 def natural_basis(self
):
123 Return a more-natural representation of this algebra's basis.
125 Every finite-dimensional Euclidean Jordan Algebra is a direct
126 sum of five simple algebras, four of which comprise Hermitian
127 matrices. This method returns the original "natural" basis
128 for our underlying vector space. (Typically, the natural basis
129 is used to construct the multiplication table in the first place.)
131 Note that this will always return a matrix. The standard basis
132 in `R^n` will be returned as `n`-by-`1` column matrices.
136 sage: J = RealSymmetricSimpleEJA(2)
139 sage: J.natural_basis()
147 sage: J = JordanSpinAlgebra(2)
150 sage: J.natural_basis()
157 if self
._natural
_basis
is None:
158 return tuple( b
.vector().column() for b
in self
.basis() )
160 return self
._natural
_basis
165 Return the rank of this EJA.
167 if self
._rank
is None:
168 raise ValueError("no rank specified at genesis")
173 class Element(FiniteDimensionalAlgebraElement
):
175 An element of a Euclidean Jordan algebra.
178 def __init__(self
, A
, elt
=None):
182 The identity in `S^n` is converted to the identity in the EJA::
184 sage: J = RealSymmetricSimpleEJA(3)
185 sage: I = identity_matrix(QQ,3)
186 sage: J(I) == J.one()
189 This skew-symmetric matrix can't be represented in the EJA::
191 sage: J = RealSymmetricSimpleEJA(3)
192 sage: A = matrix(QQ,3, lambda i,j: i-j)
194 Traceback (most recent call last):
196 ArithmeticError: vector is not in free module
199 # Goal: if we're given a matrix, and if it lives in our
200 # parent algebra's "natural ambient space," convert it
201 # into an algebra element.
203 # The catch is, we make a recursive call after converting
204 # the given matrix into a vector that lives in the algebra.
205 # This we need to try the parent class initializer first,
206 # to avoid recursing forever if we're given something that
207 # already fits into the algebra, but also happens to live
208 # in the parent's "natural ambient space" (this happens with
211 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
213 natural_basis
= A
.natural_basis()
214 if elt
in natural_basis
[0].matrix_space():
215 # Thanks for nothing! Matrix spaces aren't vector
216 # spaces in Sage, so we have to figure out its
217 # natural-basis coordinates ourselves.
218 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
219 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
220 coords
= W
.coordinates(_mat2vec(elt
))
221 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
223 def __pow__(self
, n
):
225 Return ``self`` raised to the power ``n``.
227 Jordan algebras are always power-associative; see for
228 example Faraut and Koranyi, Proposition II.1.2 (ii).
232 We have to override this because our superclass uses row vectors
233 instead of column vectors! We, on the other hand, assume column
238 sage: set_random_seed()
239 sage: x = random_eja().random_element()
240 sage: x.operator_matrix()*x.vector() == (x^2).vector()
243 A few examples of power-associativity::
245 sage: set_random_seed()
246 sage: x = random_eja().random_element()
247 sage: x*(x*x)*(x*x) == x^5
249 sage: (x*x)*(x*x*x) == x^5
252 We also know that powers operator-commute (Koecher, Chapter
255 sage: set_random_seed()
256 sage: x = random_eja().random_element()
257 sage: m = ZZ.random_element(0,10)
258 sage: n = ZZ.random_element(0,10)
259 sage: Lxm = (x^m).operator_matrix()
260 sage: Lxn = (x^n).operator_matrix()
261 sage: Lxm*Lxn == Lxn*Lxm
271 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
274 def characteristic_polynomial(self
):
276 Return my characteristic polynomial (if I'm a regular
279 Eventually this should be implemented in terms of the parent
280 algebra's characteristic polynomial that works for ALL
283 if self
.is_regular():
284 return self
.minimal_polynomial()
286 raise NotImplementedError('irregular element')
289 def inner_product(self
, other
):
291 Return the parent algebra's inner product of myself and ``other``.
295 The inner product in the Jordan spin algebra is the usual
296 inner product on `R^n` (this example only works because the
297 basis for the Jordan algebra is the standard basis in `R^n`)::
299 sage: J = JordanSpinAlgebra(3)
300 sage: x = vector(QQ,[1,2,3])
301 sage: y = vector(QQ,[4,5,6])
302 sage: x.inner_product(y)
304 sage: J(x).inner_product(J(y))
307 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
308 multiplication is the usual matrix multiplication in `S^n`,
309 so the inner product of the identity matrix with itself
312 sage: J = RealSymmetricSimpleEJA(3)
313 sage: J.one().inner_product(J.one())
316 Likewise, the inner product on `C^n` is `<X,Y> =
317 Re(trace(X*Y))`, where we must necessarily take the real
318 part because the product of Hermitian matrices may not be
321 sage: J = ComplexHermitianSimpleEJA(3)
322 sage: J.one().inner_product(J.one())
325 Ditto for the quaternions::
327 sage: J = QuaternionHermitianSimpleEJA(3)
328 sage: J.one().inner_product(J.one())
333 Ensure that we can always compute an inner product, and that
334 it gives us back a real number::
336 sage: set_random_seed()
337 sage: J = random_eja()
338 sage: x = J.random_element()
339 sage: y = J.random_element()
340 sage: x.inner_product(y) in RR
346 raise TypeError("'other' must live in the same algebra")
348 return P
.inner_product(self
, other
)
351 def operator_commutes_with(self
, other
):
353 Return whether or not this element operator-commutes
358 The definition of a Jordan algebra says that any element
359 operator-commutes with its square::
361 sage: set_random_seed()
362 sage: x = random_eja().random_element()
363 sage: x.operator_commutes_with(x^2)
368 Test Lemma 1 from Chapter III of Koecher::
370 sage: set_random_seed()
371 sage: J = random_eja()
372 sage: u = J.random_element()
373 sage: v = J.random_element()
374 sage: lhs = u.operator_commutes_with(u*v)
375 sage: rhs = v.operator_commutes_with(u^2)
380 if not other
in self
.parent():
381 raise TypeError("'other' must live in the same algebra")
383 A
= self
.operator_matrix()
384 B
= other
.operator_matrix()
390 Return my determinant, the product of my eigenvalues.
394 sage: J = JordanSpinAlgebra(2)
395 sage: e0,e1 = J.gens()
399 sage: J = JordanSpinAlgebra(3)
400 sage: e0,e1,e2 = J.gens()
401 sage: x = e0 + e1 + e2
406 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
409 return cs
[0] * (-1)**r
411 raise ValueError('charpoly had no coefficients')
416 Return the Jordan-multiplicative inverse of this element.
418 We can't use the superclass method because it relies on the
419 algebra being associative.
423 The inverse in the spin factor algebra is given in Alizadeh's
426 sage: set_random_seed()
427 sage: n = ZZ.random_element(1,10)
428 sage: J = JordanSpinAlgebra(n)
429 sage: x = J.random_element()
430 sage: while x.is_zero():
431 ....: x = J.random_element()
432 sage: x_vec = x.vector()
434 sage: x_bar = x_vec[1:]
435 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
436 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
437 sage: x_inverse = coeff*inv_vec
438 sage: x.inverse() == J(x_inverse)
443 The identity element is its own inverse::
445 sage: set_random_seed()
446 sage: J = random_eja()
447 sage: J.one().inverse() == J.one()
450 If an element has an inverse, it acts like one. TODO: this
451 can be a lot less ugly once ``is_invertible`` doesn't crash
452 on irregular elements::
454 sage: set_random_seed()
455 sage: J = random_eja()
456 sage: x = J.random_element()
458 ....: x.inverse()*x == J.one()
464 if self
.parent().is_associative():
465 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
468 # TODO: we can do better once the call to is_invertible()
469 # doesn't crash on irregular elements.
470 #if not self.is_invertible():
471 # raise ValueError('element is not invertible')
473 # We do this a little different than the usual recursive
474 # call to a finite-dimensional algebra element, because we
475 # wind up with an inverse that lives in the subalgebra and
476 # we need information about the parent to convert it back.
477 V
= self
.span_of_powers()
478 assoc_subalg
= self
.subalgebra_generated_by()
479 # Mis-design warning: the basis used for span_of_powers()
480 # and subalgebra_generated_by() must be the same, and in
482 elt
= assoc_subalg(V
.coordinates(self
.vector()))
484 # This will be in the subalgebra's coordinates...
485 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
486 subalg_inverse
= fda_elt
.inverse()
488 # So we have to convert back...
489 basis
= [ self
.parent(v
) for v
in V
.basis() ]
490 pairs
= zip(subalg_inverse
.vector(), basis
)
491 return self
.parent().linear_combination(pairs
)
494 def is_invertible(self
):
496 Return whether or not this element is invertible.
498 We can't use the superclass method because it relies on
499 the algebra being associative.
501 return not self
.det().is_zero()
504 def is_nilpotent(self
):
506 Return whether or not some power of this element is zero.
508 The superclass method won't work unless we're in an
509 associative algebra, and we aren't. However, we generate
510 an assocoative subalgebra and we're nilpotent there if and
511 only if we're nilpotent here (probably).
515 The identity element is never nilpotent::
517 sage: set_random_seed()
518 sage: random_eja().one().is_nilpotent()
521 The additive identity is always nilpotent::
523 sage: set_random_seed()
524 sage: random_eja().zero().is_nilpotent()
528 # The element we're going to call "is_nilpotent()" on.
529 # Either myself, interpreted as an element of a finite-
530 # dimensional algebra, or an element of an associative
534 if self
.parent().is_associative():
535 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
537 V
= self
.span_of_powers()
538 assoc_subalg
= self
.subalgebra_generated_by()
539 # Mis-design warning: the basis used for span_of_powers()
540 # and subalgebra_generated_by() must be the same, and in
542 elt
= assoc_subalg(V
.coordinates(self
.vector()))
544 # Recursive call, but should work since elt lives in an
545 # associative algebra.
546 return elt
.is_nilpotent()
549 def is_regular(self
):
551 Return whether or not this is a regular element.
555 The identity element always has degree one, but any element
556 linearly-independent from it is regular::
558 sage: J = JordanSpinAlgebra(5)
559 sage: J.one().is_regular()
561 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
562 sage: for x in J.gens():
563 ....: (J.one() + x).is_regular()
571 return self
.degree() == self
.parent().rank()
576 Compute the degree of this element the straightforward way
577 according to the definition; by appending powers to a list
578 and figuring out its dimension (that is, whether or not
579 they're linearly dependent).
583 sage: J = JordanSpinAlgebra(4)
584 sage: J.one().degree()
586 sage: e0,e1,e2,e3 = J.gens()
587 sage: (e0 - e1).degree()
590 In the spin factor algebra (of rank two), all elements that
591 aren't multiples of the identity are regular::
593 sage: set_random_seed()
594 sage: n = ZZ.random_element(1,10)
595 sage: J = JordanSpinAlgebra(n)
596 sage: x = J.random_element()
597 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
601 return self
.span_of_powers().dimension()
604 def minimal_polynomial(self
):
608 sage: set_random_seed()
609 sage: x = random_eja().random_element()
610 sage: x.degree() == x.minimal_polynomial().degree()
615 sage: set_random_seed()
616 sage: x = random_eja().random_element()
617 sage: x.degree() == x.minimal_polynomial().degree()
620 The minimal polynomial and the characteristic polynomial coincide
621 and are known (see Alizadeh, Example 11.11) for all elements of
622 the spin factor algebra that aren't scalar multiples of the
625 sage: set_random_seed()
626 sage: n = ZZ.random_element(2,10)
627 sage: J = JordanSpinAlgebra(n)
628 sage: y = J.random_element()
629 sage: while y == y.coefficient(0)*J.one():
630 ....: y = J.random_element()
631 sage: y0 = y.vector()[0]
632 sage: y_bar = y.vector()[1:]
633 sage: actual = y.minimal_polynomial()
634 sage: x = SR.symbol('x', domain='real')
635 sage: expected = x^2 - 2*y0*x + (y0^2 - norm(y_bar)^2)
636 sage: bool(actual == expected)
640 # The element we're going to call "minimal_polynomial()" on.
641 # Either myself, interpreted as an element of a finite-
642 # dimensional algebra, or an element of an associative
646 if self
.parent().is_associative():
647 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
649 V
= self
.span_of_powers()
650 assoc_subalg
= self
.subalgebra_generated_by()
651 # Mis-design warning: the basis used for span_of_powers()
652 # and subalgebra_generated_by() must be the same, and in
654 elt
= assoc_subalg(V
.coordinates(self
.vector()))
656 # Recursive call, but should work since elt lives in an
657 # associative algebra.
658 return elt
.minimal_polynomial()
661 def natural_representation(self
):
663 Return a more-natural representation of this element.
665 Every finite-dimensional Euclidean Jordan Algebra is a
666 direct sum of five simple algebras, four of which comprise
667 Hermitian matrices. This method returns the original
668 "natural" representation of this element as a Hermitian
669 matrix, if it has one. If not, you get the usual representation.
673 sage: J = ComplexHermitianSimpleEJA(3)
676 sage: J.one().natural_representation()
686 sage: J = QuaternionHermitianSimpleEJA(3)
689 sage: J.one().natural_representation()
690 [1 0 0 0 0 0 0 0 0 0 0 0]
691 [0 1 0 0 0 0 0 0 0 0 0 0]
692 [0 0 1 0 0 0 0 0 0 0 0 0]
693 [0 0 0 1 0 0 0 0 0 0 0 0]
694 [0 0 0 0 1 0 0 0 0 0 0 0]
695 [0 0 0 0 0 1 0 0 0 0 0 0]
696 [0 0 0 0 0 0 1 0 0 0 0 0]
697 [0 0 0 0 0 0 0 1 0 0 0 0]
698 [0 0 0 0 0 0 0 0 1 0 0 0]
699 [0 0 0 0 0 0 0 0 0 1 0 0]
700 [0 0 0 0 0 0 0 0 0 0 1 0]
701 [0 0 0 0 0 0 0 0 0 0 0 1]
704 B
= self
.parent().natural_basis()
705 W
= B
[0].matrix_space()
706 return W
.linear_combination(zip(self
.vector(), B
))
709 def operator_matrix(self
):
711 Return the matrix that represents left- (or right-)
712 multiplication by this element in the parent algebra.
714 We have to override this because the superclass method
715 returns a matrix that acts on row vectors (that is, on
720 Test the first polarization identity from my notes, Koecher Chapter
721 III, or from Baes (2.3)::
723 sage: set_random_seed()
724 sage: J = random_eja()
725 sage: x = J.random_element()
726 sage: y = J.random_element()
727 sage: Lx = x.operator_matrix()
728 sage: Ly = y.operator_matrix()
729 sage: Lxx = (x*x).operator_matrix()
730 sage: Lxy = (x*y).operator_matrix()
731 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
734 Test the second polarization identity from my notes or from
737 sage: set_random_seed()
738 sage: J = random_eja()
739 sage: x = J.random_element()
740 sage: y = J.random_element()
741 sage: z = J.random_element()
742 sage: Lx = x.operator_matrix()
743 sage: Ly = y.operator_matrix()
744 sage: Lz = z.operator_matrix()
745 sage: Lzy = (z*y).operator_matrix()
746 sage: Lxy = (x*y).operator_matrix()
747 sage: Lxz = (x*z).operator_matrix()
748 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
751 Test the third polarization identity from my notes or from
754 sage: set_random_seed()
755 sage: J = random_eja()
756 sage: u = J.random_element()
757 sage: y = J.random_element()
758 sage: z = J.random_element()
759 sage: Lu = u.operator_matrix()
760 sage: Ly = y.operator_matrix()
761 sage: Lz = z.operator_matrix()
762 sage: Lzy = (z*y).operator_matrix()
763 sage: Luy = (u*y).operator_matrix()
764 sage: Luz = (u*z).operator_matrix()
765 sage: Luyz = (u*(y*z)).operator_matrix()
766 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
767 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
768 sage: bool(lhs == rhs)
772 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
773 return fda_elt
.matrix().transpose()
776 def quadratic_representation(self
, other
=None):
778 Return the quadratic representation of this element.
782 The explicit form in the spin factor algebra is given by
783 Alizadeh's Example 11.12::
785 sage: set_random_seed()
786 sage: n = ZZ.random_element(1,10)
787 sage: J = JordanSpinAlgebra(n)
788 sage: x = J.random_element()
789 sage: x_vec = x.vector()
791 sage: x_bar = x_vec[1:]
792 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
793 sage: B = 2*x0*x_bar.row()
794 sage: C = 2*x0*x_bar.column()
795 sage: D = identity_matrix(QQ, n-1)
796 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
797 sage: D = D + 2*x_bar.tensor_product(x_bar)
798 sage: Q = block_matrix(2,2,[A,B,C,D])
799 sage: Q == x.quadratic_representation()
802 Test all of the properties from Theorem 11.2 in Alizadeh::
804 sage: set_random_seed()
805 sage: J = random_eja()
806 sage: x = J.random_element()
807 sage: y = J.random_element()
811 sage: actual = x.quadratic_representation(y)
812 sage: expected = ( (x+y).quadratic_representation()
813 ....: -x.quadratic_representation()
814 ....: -y.quadratic_representation() ) / 2
815 sage: actual == expected
820 sage: alpha = QQ.random_element()
821 sage: actual = (alpha*x).quadratic_representation()
822 sage: expected = (alpha^2)*x.quadratic_representation()
823 sage: actual == expected
828 sage: Qy = y.quadratic_representation()
829 sage: actual = J(Qy*x.vector()).quadratic_representation()
830 sage: expected = Qy*x.quadratic_representation()*Qy
831 sage: actual == expected
836 sage: k = ZZ.random_element(1,10)
837 sage: actual = (x^k).quadratic_representation()
838 sage: expected = (x.quadratic_representation())^k
839 sage: actual == expected
845 elif not other
in self
.parent():
846 raise TypeError("'other' must live in the same algebra")
848 L
= self
.operator_matrix()
849 M
= other
.operator_matrix()
850 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
853 def span_of_powers(self
):
855 Return the vector space spanned by successive powers of
858 # The dimension of the subalgebra can't be greater than
859 # the big algebra, so just put everything into a list
860 # and let span() get rid of the excess.
861 V
= self
.vector().parent()
862 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
865 def subalgebra_generated_by(self
):
867 Return the associative subalgebra of the parent EJA generated
872 sage: set_random_seed()
873 sage: x = random_eja().random_element()
874 sage: x.subalgebra_generated_by().is_associative()
877 Squaring in the subalgebra should be the same thing as
878 squaring in the superalgebra::
880 sage: set_random_seed()
881 sage: x = random_eja().random_element()
882 sage: u = x.subalgebra_generated_by().random_element()
883 sage: u.operator_matrix()*u.vector() == (u**2).vector()
887 # First get the subspace spanned by the powers of myself...
888 V
= self
.span_of_powers()
891 # Now figure out the entries of the right-multiplication
892 # matrix for the successive basis elements b0, b1,... of
895 for b_right
in V
.basis():
896 eja_b_right
= self
.parent()(b_right
)
898 # The first row of the right-multiplication matrix by
899 # b1 is what we get if we apply that matrix to b1. The
900 # second row of the right multiplication matrix by b1
901 # is what we get when we apply that matrix to b2...
903 # IMPORTANT: this assumes that all vectors are COLUMN
904 # vectors, unlike our superclass (which uses row vectors).
905 for b_left
in V
.basis():
906 eja_b_left
= self
.parent()(b_left
)
907 # Multiply in the original EJA, but then get the
908 # coordinates from the subalgebra in terms of its
910 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
911 b_right_rows
.append(this_row
)
912 b_right_matrix
= matrix(F
, b_right_rows
)
913 mats
.append(b_right_matrix
)
915 # It's an algebra of polynomials in one element, and EJAs
916 # are power-associative.
918 # TODO: choose generator names intelligently.
919 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
922 def subalgebra_idempotent(self
):
924 Find an idempotent in the associative subalgebra I generate
925 using Proposition 2.3.5 in Baes.
929 sage: set_random_seed()
931 sage: c = J.random_element().subalgebra_idempotent()
934 sage: J = JordanSpinAlgebra(5)
935 sage: c = J.random_element().subalgebra_idempotent()
940 if self
.is_nilpotent():
941 raise ValueError("this only works with non-nilpotent elements!")
943 V
= self
.span_of_powers()
944 J
= self
.subalgebra_generated_by()
945 # Mis-design warning: the basis used for span_of_powers()
946 # and subalgebra_generated_by() must be the same, and in
948 u
= J(V
.coordinates(self
.vector()))
950 # The image of the matrix of left-u^m-multiplication
951 # will be minimal for some natural number s...
953 minimal_dim
= V
.dimension()
954 for i
in xrange(1, V
.dimension()):
955 this_dim
= (u
**i
).operator_matrix().image().dimension()
956 if this_dim
< minimal_dim
:
957 minimal_dim
= this_dim
960 # Now minimal_matrix should correspond to the smallest
961 # non-zero subspace in Baes's (or really, Koecher's)
964 # However, we need to restrict the matrix to work on the
965 # subspace... or do we? Can't we just solve, knowing that
966 # A(c) = u^(s+1) should have a solution in the big space,
969 # Beware, solve_right() means that we're using COLUMN vectors.
970 # Our FiniteDimensionalAlgebraElement superclass uses rows.
972 A
= u_next
.operator_matrix()
973 c_coordinates
= A
.solve_right(u_next
.vector())
975 # Now c_coordinates is the idempotent we want, but it's in
976 # the coordinate system of the subalgebra.
978 # We need the basis for J, but as elements of the parent algebra.
980 basis
= [self
.parent(v
) for v
in V
.basis()]
981 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
986 Return my trace, the sum of my eigenvalues.
990 sage: J = JordanSpinAlgebra(3)
991 sage: e0,e1,e2 = J.gens()
992 sage: x = e0 + e1 + e2
997 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
1001 raise ValueError('charpoly had fewer than 2 coefficients')
1004 def trace_inner_product(self
, other
):
1006 Return the trace inner product of myself and ``other``.
1008 if not other
in self
.parent():
1009 raise TypeError("'other' must live in the same algebra")
1011 return (self
*other
).trace()
1014 def eja_rn(dimension
, field
=QQ
):
1016 Return the Euclidean Jordan Algebra corresponding to the set
1017 `R^n` under the Hadamard product.
1021 This multiplication table can be verified by hand::
1024 sage: e0,e1,e2 = J.gens()
1039 # The FiniteDimensionalAlgebra constructor takes a list of
1040 # matrices, the ith representing right multiplication by the ith
1041 # basis element in the vector space. So if e_1 = (1,0,0), then
1042 # right (Hadamard) multiplication of x by e_1 picks out the first
1043 # component of x; and likewise for the ith basis element e_i.
1044 Qs
= [ matrix(field
, dimension
, dimension
, lambda k
,j
: 1*(k
== j
== i
))
1045 for i
in xrange(dimension
) ]
1047 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1050 inner_product
=_usual_ip
)
1056 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1060 For now, we choose a random natural number ``n`` (greater than zero)
1061 and then give you back one of the following:
1063 * The cartesian product of the rational numbers ``n`` times; this is
1064 ``QQ^n`` with the Hadamard product.
1066 * The Jordan spin algebra on ``QQ^n``.
1068 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1071 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1072 in the space of ``2n``-by-``2n`` real symmetric matrices.
1074 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1075 in the space of ``4n``-by-``4n`` real symmetric matrices.
1077 Later this might be extended to return Cartesian products of the
1083 Euclidean Jordan algebra of degree...
1086 n
= ZZ
.random_element(1,5)
1087 constructor
= choice([eja_rn
,
1089 RealSymmetricSimpleEJA
,
1090 ComplexHermitianSimpleEJA
,
1091 QuaternionHermitianSimpleEJA
])
1092 return constructor(n
, field
=QQ
)
1096 def _real_symmetric_basis(n
, field
=QQ
):
1098 Return a basis for the space of real symmetric n-by-n matrices.
1100 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1104 for j
in xrange(i
+1):
1105 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1109 # Beware, orthogonal but not normalized!
1110 Sij
= Eij
+ Eij
.transpose()
1115 def _complex_hermitian_basis(n
, field
=QQ
):
1117 Returns a basis for the space of complex Hermitian n-by-n matrices.
1121 sage: set_random_seed()
1122 sage: n = ZZ.random_element(1,5)
1123 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1127 F
= QuadraticField(-1, 'I')
1130 # This is like the symmetric case, but we need to be careful:
1132 # * We want conjugate-symmetry, not just symmetry.
1133 # * The diagonal will (as a result) be real.
1137 for j
in xrange(i
+1):
1138 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1140 Sij
= _embed_complex_matrix(Eij
)
1143 # Beware, orthogonal but not normalized! The second one
1144 # has a minus because it's conjugated.
1145 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1147 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1152 def _quaternion_hermitian_basis(n
, field
=QQ
):
1154 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1158 sage: set_random_seed()
1159 sage: n = ZZ.random_element(1,5)
1160 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1164 Q
= QuaternionAlgebra(QQ
,-1,-1)
1167 # This is like the symmetric case, but we need to be careful:
1169 # * We want conjugate-symmetry, not just symmetry.
1170 # * The diagonal will (as a result) be real.
1174 for j
in xrange(i
+1):
1175 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1177 Sij
= _embed_quaternion_matrix(Eij
)
1180 # Beware, orthogonal but not normalized! The second,
1181 # third, and fourth ones have a minus because they're
1183 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1185 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1187 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1189 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1195 return vector(m
.base_ring(), m
.list())
1198 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1200 def _multiplication_table_from_matrix_basis(basis
):
1202 At least three of the five simple Euclidean Jordan algebras have the
1203 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1204 multiplication on the right is matrix multiplication. Given a basis
1205 for the underlying matrix space, this function returns a
1206 multiplication table (obtained by looping through the basis
1207 elements) for an algebra of those matrices. A reordered copy
1208 of the basis is also returned to work around the fact that
1209 the ``span()`` in this function will change the order of the basis
1210 from what we think it is, to... something else.
1212 # In S^2, for example, we nominally have four coordinates even
1213 # though the space is of dimension three only. The vector space V
1214 # is supposed to hold the entire long vector, and the subspace W
1215 # of V will be spanned by the vectors that arise from symmetric
1216 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1217 field
= basis
[0].base_ring()
1218 dimension
= basis
[0].nrows()
1220 V
= VectorSpace(field
, dimension
**2)
1221 W
= V
.span( _mat2vec(s
) for s
in basis
)
1223 # Taking the span above reorders our basis (thanks, jerk!) so we
1224 # need to put our "matrix basis" in the same order as the
1225 # (reordered) vector basis.
1226 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1230 # Brute force the multiplication-by-s matrix by looping
1231 # through all elements of the basis and doing the computation
1232 # to find out what the corresponding row should be. BEWARE:
1233 # these multiplication tables won't be symmetric! It therefore
1234 # becomes REALLY IMPORTANT that the underlying algebra
1235 # constructor uses ROW vectors and not COLUMN vectors. That's
1236 # why we're computing rows here and not columns.
1239 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1240 Q_rows
.append(W
.coordinates(this_row
))
1241 Q
= matrix(field
, W
.dimension(), Q_rows
)
1247 def _embed_complex_matrix(M
):
1249 Embed the n-by-n complex matrix ``M`` into the space of real
1250 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1251 bi` to the block matrix ``[[a,b],[-b,a]]``.
1255 sage: F = QuadraticField(-1,'i')
1256 sage: x1 = F(4 - 2*i)
1257 sage: x2 = F(1 + 2*i)
1260 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1261 sage: _embed_complex_matrix(M)
1270 Embedding is a homomorphism (isomorphism, in fact)::
1272 sage: set_random_seed()
1273 sage: n = ZZ.random_element(5)
1274 sage: F = QuadraticField(-1, 'i')
1275 sage: X = random_matrix(F, n)
1276 sage: Y = random_matrix(F, n)
1277 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1278 sage: expected = _embed_complex_matrix(X*Y)
1279 sage: actual == expected
1285 raise ValueError("the matrix 'M' must be square")
1286 field
= M
.base_ring()
1291 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1293 # We can drop the imaginaries here.
1294 return block_matrix(field
.base_ring(), n
, blocks
)
1297 def _unembed_complex_matrix(M
):
1299 The inverse of _embed_complex_matrix().
1303 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1304 ....: [-2, 1, -4, 3],
1305 ....: [ 9, 10, 11, 12],
1306 ....: [-10, 9, -12, 11] ])
1307 sage: _unembed_complex_matrix(A)
1309 [ 10*i + 9 12*i + 11]
1313 Unembedding is the inverse of embedding::
1315 sage: set_random_seed()
1316 sage: F = QuadraticField(-1, 'i')
1317 sage: M = random_matrix(F, 3)
1318 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1324 raise ValueError("the matrix 'M' must be square")
1325 if not n
.mod(2).is_zero():
1326 raise ValueError("the matrix 'M' must be a complex embedding")
1328 F
= QuadraticField(-1, 'i')
1331 # Go top-left to bottom-right (reading order), converting every
1332 # 2-by-2 block we see to a single complex element.
1334 for k
in xrange(n
/2):
1335 for j
in xrange(n
/2):
1336 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1337 if submat
[0,0] != submat
[1,1]:
1338 raise ValueError('bad on-diagonal submatrix')
1339 if submat
[0,1] != -submat
[1,0]:
1340 raise ValueError('bad off-diagonal submatrix')
1341 z
= submat
[0,0] + submat
[0,1]*i
1344 return matrix(F
, n
/2, elements
)
1347 def _embed_quaternion_matrix(M
):
1349 Embed the n-by-n quaternion matrix ``M`` into the space of real
1350 matrices of size 4n-by-4n by first sending each quaternion entry
1351 `z = a + bi + cj + dk` to the block-complex matrix
1352 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1357 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1358 sage: i,j,k = Q.gens()
1359 sage: x = 1 + 2*i + 3*j + 4*k
1360 sage: M = matrix(Q, 1, [[x]])
1361 sage: _embed_quaternion_matrix(M)
1367 Embedding is a homomorphism (isomorphism, in fact)::
1369 sage: set_random_seed()
1370 sage: n = ZZ.random_element(5)
1371 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1372 sage: X = random_matrix(Q, n)
1373 sage: Y = random_matrix(Q, n)
1374 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1375 sage: expected = _embed_quaternion_matrix(X*Y)
1376 sage: actual == expected
1380 quaternions
= M
.base_ring()
1383 raise ValueError("the matrix 'M' must be square")
1385 F
= QuadraticField(-1, 'i')
1390 t
= z
.coefficient_tuple()
1395 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1396 [-c
+ d
*i
, a
- b
*i
]])
1397 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1399 # We should have real entries by now, so use the realest field
1400 # we've got for the return value.
1401 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1404 def _unembed_quaternion_matrix(M
):
1406 The inverse of _embed_quaternion_matrix().
1410 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1411 ....: [-2, 1, -4, 3],
1412 ....: [-3, 4, 1, -2],
1413 ....: [-4, -3, 2, 1]])
1414 sage: _unembed_quaternion_matrix(M)
1415 [1 + 2*i + 3*j + 4*k]
1419 Unembedding is the inverse of embedding::
1421 sage: set_random_seed()
1422 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1423 sage: M = random_matrix(Q, 3)
1424 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1430 raise ValueError("the matrix 'M' must be square")
1431 if not n
.mod(4).is_zero():
1432 raise ValueError("the matrix 'M' must be a complex embedding")
1434 Q
= QuaternionAlgebra(QQ
,-1,-1)
1437 # Go top-left to bottom-right (reading order), converting every
1438 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1441 for l
in xrange(n
/4):
1442 for m
in xrange(n
/4):
1443 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1444 if submat
[0,0] != submat
[1,1].conjugate():
1445 raise ValueError('bad on-diagonal submatrix')
1446 if submat
[0,1] != -submat
[1,0].conjugate():
1447 raise ValueError('bad off-diagonal submatrix')
1448 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1449 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1452 return matrix(Q
, n
/4, elements
)
1455 # The usual inner product on R^n.
1457 return x
.vector().inner_product(y
.vector())
1459 # The inner product used for the real symmetric simple EJA.
1460 # We keep it as a separate function because e.g. the complex
1461 # algebra uses the same inner product, except divided by 2.
1462 def _matrix_ip(X
,Y
):
1463 X_mat
= X
.natural_representation()
1464 Y_mat
= Y
.natural_representation()
1465 return (X_mat
*Y_mat
).trace()
1468 def RealSymmetricSimpleEJA(n
, field
=QQ
):
1470 The rank-n simple EJA consisting of real symmetric n-by-n
1471 matrices, the usual symmetric Jordan product, and the trace inner
1472 product. It has dimension `(n^2 + n)/2` over the reals.
1476 sage: J = RealSymmetricSimpleEJA(2)
1477 sage: e0, e1, e2 = J.gens()
1487 The degree of this algebra is `(n^2 + n) / 2`::
1489 sage: set_random_seed()
1490 sage: n = ZZ.random_element(1,5)
1491 sage: J = RealSymmetricSimpleEJA(n)
1492 sage: J.degree() == (n^2 + n)/2
1495 The Jordan multiplication is what we think it is::
1497 sage: set_random_seed()
1498 sage: n = ZZ.random_element(1,5)
1499 sage: J = RealSymmetricSimpleEJA(n)
1500 sage: x = J.random_element()
1501 sage: y = J.random_element()
1502 sage: actual = (x*y).natural_representation()
1503 sage: X = x.natural_representation()
1504 sage: Y = y.natural_representation()
1505 sage: expected = (X*Y + Y*X)/2
1506 sage: actual == expected
1508 sage: J(expected) == x*y
1512 S
= _real_symmetric_basis(n
, field
=field
)
1513 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1515 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1519 inner_product
=_matrix_ip
)
1522 def ComplexHermitianSimpleEJA(n
, field
=QQ
):
1524 The rank-n simple EJA consisting of complex Hermitian n-by-n
1525 matrices over the real numbers, the usual symmetric Jordan product,
1526 and the real-part-of-trace inner product. It has dimension `n^2` over
1531 The degree of this algebra is `n^2`::
1533 sage: set_random_seed()
1534 sage: n = ZZ.random_element(1,5)
1535 sage: J = ComplexHermitianSimpleEJA(n)
1536 sage: J.degree() == n^2
1539 The Jordan multiplication is what we think it is::
1541 sage: set_random_seed()
1542 sage: n = ZZ.random_element(1,5)
1543 sage: J = ComplexHermitianSimpleEJA(n)
1544 sage: x = J.random_element()
1545 sage: y = J.random_element()
1546 sage: actual = (x*y).natural_representation()
1547 sage: X = x.natural_representation()
1548 sage: Y = y.natural_representation()
1549 sage: expected = (X*Y + Y*X)/2
1550 sage: actual == expected
1552 sage: J(expected) == x*y
1556 S
= _complex_hermitian_basis(n
)
1557 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1559 # Since a+bi on the diagonal is represented as
1564 # we'll double-count the "a" entries if we take the trace of
1566 ip
= lambda X
,Y
: _matrix_ip(X
,Y
)/2
1568 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1575 def QuaternionHermitianSimpleEJA(n
, field
=QQ
):
1577 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1578 matrices, the usual symmetric Jordan product, and the
1579 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1584 The degree of this algebra is `n^2`::
1586 sage: set_random_seed()
1587 sage: n = ZZ.random_element(1,5)
1588 sage: J = QuaternionHermitianSimpleEJA(n)
1589 sage: J.degree() == 2*(n^2) - n
1592 The Jordan multiplication is what we think it is::
1594 sage: set_random_seed()
1595 sage: n = ZZ.random_element(1,5)
1596 sage: J = QuaternionHermitianSimpleEJA(n)
1597 sage: x = J.random_element()
1598 sage: y = J.random_element()
1599 sage: actual = (x*y).natural_representation()
1600 sage: X = x.natural_representation()
1601 sage: Y = y.natural_representation()
1602 sage: expected = (X*Y + Y*X)/2
1603 sage: actual == expected
1605 sage: J(expected) == x*y
1609 S
= _quaternion_hermitian_basis(n
)
1610 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1612 # Since a+bi+cj+dk on the diagonal is represented as
1614 # a + bi +cj + dk = [ a b c d]
1619 # we'll quadruple-count the "a" entries if we take the trace of
1621 ip
= lambda X
,Y
: _matrix_ip(X
,Y
)/4
1623 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1630 def OctonionHermitianSimpleEJA(n
):
1632 This shit be crazy. It has dimension 27 over the reals.
1637 class JordanSpinAlgebra(FiniteDimensionalEuclideanJordanAlgebra
):
1639 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1640 with the usual inner product and jordan product ``x*y =
1641 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1646 This multiplication table can be verified by hand::
1648 sage: J = JordanSpinAlgebra(4)
1649 sage: e0,e1,e2,e3 = J.gens()
1667 def __classcall_private__(cls
, n
, field
=QQ
):
1669 id_matrix
= identity_matrix(field
, n
)
1671 ei
= id_matrix
.column(i
)
1672 Qi
= zero_matrix(field
, n
)
1674 Qi
.set_column(0, ei
)
1675 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
1676 # The addition of the diagonal matrix adds an extra ei[0] in the
1677 # upper-left corner of the matrix.
1678 Qi
[0,0] = Qi
[0,0] * ~
field(2)
1681 fdeja
= super(JordanSpinAlgebra
, cls
)
1682 return fdeja
.__classcall
_private
__(cls
, field
, Qs
)
1686 Return the rank of this Jordan Spin Algebra.
1688 The rank of the spin algebra is two, unless we're in a
1689 one-dimensional ambient space (because the rank is bounded by
1690 the ambient dimension).
1692 return min(self
.dimension(),2)
1694 def inner_product(self
, x
, y
):
1695 return _usual_ip(x
,y
)