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
)
53 def __init__(self
, field
,
56 assume_associative
=False,
64 By definition, Jordan multiplication commutes::
66 sage: set_random_seed()
67 sage: J = random_eja()
68 sage: x = J.random_element()
69 sage: y = J.random_element()
75 self
._natural
_basis
= natural_basis
76 self
._inner
_product
= inner_product
77 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
86 Return a string representation of ``self``.
88 fmt
= "Euclidean Jordan algebra of degree {} over {}"
89 return fmt
.format(self
.degree(), self
.base_ring())
92 def inner_product(self
, x
, y
):
94 The inner product associated with this Euclidean Jordan algebra.
96 Will default to the trace inner product if nothing else.
100 The inner product must satisfy its axiom for this algebra to truly
101 be a Euclidean Jordan Algebra::
103 sage: set_random_seed()
104 sage: J = random_eja()
105 sage: x = J.random_element()
106 sage: y = J.random_element()
107 sage: z = J.random_element()
108 sage: (x*y).inner_product(z) == y.inner_product(x*z)
112 if (not x
in self
) or (not y
in self
):
113 raise TypeError("arguments must live in this algebra")
114 if self
._inner
_product
is None:
115 return x
.trace_inner_product(y
)
117 return self
._inner
_product
(x
,y
)
120 def natural_basis(self
):
122 Return a more-natural representation of this algebra's basis.
124 Every finite-dimensional Euclidean Jordan Algebra is a direct
125 sum of five simple algebras, four of which comprise Hermitian
126 matrices. This method returns the original "natural" basis
127 for our underlying vector space. (Typically, the natural basis
128 is used to construct the multiplication table in the first place.)
130 Note that this will always return a matrix. The standard basis
131 in `R^n` will be returned as `n`-by-`1` column matrices.
135 sage: J = RealSymmetricSimpleEJA(2)
138 sage: J.natural_basis()
146 sage: J = JordanSpinSimpleEJA(2)
149 sage: J.natural_basis()
156 if self
._natural
_basis
is None:
157 return tuple( b
.vector().column() for b
in self
.basis() )
159 return self
._natural
_basis
164 Return the rank of this EJA.
166 if self
._rank
is None:
167 raise ValueError("no rank specified at genesis")
172 class Element(FiniteDimensionalAlgebraElement
):
174 An element of a Euclidean Jordan algebra.
177 def __init__(self
, A
, elt
=None):
181 The identity in `S^n` is converted to the identity in the EJA::
183 sage: J = RealSymmetricSimpleEJA(3)
184 sage: I = identity_matrix(QQ,3)
185 sage: J(I) == J.one()
188 This skew-symmetric matrix can't be represented in the EJA::
190 sage: J = RealSymmetricSimpleEJA(3)
191 sage: A = matrix(QQ,3, lambda i,j: i-j)
193 Traceback (most recent call last):
195 ArithmeticError: vector is not in free module
198 # Goal: if we're given a matrix, and if it lives in our
199 # parent algebra's "natural ambient space," convert it
200 # into an algebra element.
202 # The catch is, we make a recursive call after converting
203 # the given matrix into a vector that lives in the algebra.
204 # This we need to try the parent class initializer first,
205 # to avoid recursing forever if we're given something that
206 # already fits into the algebra, but also happens to live
207 # in the parent's "natural ambient space" (this happens with
210 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
212 natural_basis
= A
.natural_basis()
213 if elt
in natural_basis
[0].matrix_space():
214 # Thanks for nothing! Matrix spaces aren't vector
215 # spaces in Sage, so we have to figure out its
216 # natural-basis coordinates ourselves.
217 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
218 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
219 coords
= W
.coordinates(_mat2vec(elt
))
220 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
222 def __pow__(self
, n
):
224 Return ``self`` raised to the power ``n``.
226 Jordan algebras are always power-associative; see for
227 example Faraut and Koranyi, Proposition II.1.2 (ii).
231 We have to override this because our superclass uses row vectors
232 instead of column vectors! We, on the other hand, assume column
237 sage: set_random_seed()
238 sage: x = random_eja().random_element()
239 sage: x.operator_matrix()*x.vector() == (x^2).vector()
242 A few examples of power-associativity::
244 sage: set_random_seed()
245 sage: x = random_eja().random_element()
246 sage: x*(x*x)*(x*x) == x^5
248 sage: (x*x)*(x*x*x) == x^5
251 We also know that powers operator-commute (Koecher, Chapter
254 sage: set_random_seed()
255 sage: x = random_eja().random_element()
256 sage: m = ZZ.random_element(0,10)
257 sage: n = ZZ.random_element(0,10)
258 sage: Lxm = (x^m).operator_matrix()
259 sage: Lxn = (x^n).operator_matrix()
260 sage: Lxm*Lxn == Lxn*Lxm
270 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
273 def characteristic_polynomial(self
):
275 Return my characteristic polynomial (if I'm a regular
278 Eventually this should be implemented in terms of the parent
279 algebra's characteristic polynomial that works for ALL
282 if self
.is_regular():
283 return self
.minimal_polynomial()
285 raise NotImplementedError('irregular element')
288 def inner_product(self
, other
):
290 Return the parent algebra's inner product of myself and ``other``.
294 The inner product in the Jordan spin algebra is the usual
295 inner product on `R^n` (this example only works because the
296 basis for the Jordan algebra is the standard basis in `R^n`)::
298 sage: J = JordanSpinSimpleEJA(3)
299 sage: x = vector(QQ,[1,2,3])
300 sage: y = vector(QQ,[4,5,6])
301 sage: x.inner_product(y)
303 sage: J(x).inner_product(J(y))
306 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
307 multiplication is the usual matrix multiplication in `S^n`,
308 so the inner product of the identity matrix with itself
311 sage: J = RealSymmetricSimpleEJA(3)
312 sage: J.one().inner_product(J.one())
315 Likewise, the inner product on `C^n` is `<X,Y> =
316 Re(trace(X*Y))`, where we must necessarily take the real
317 part because the product of Hermitian matrices may not be
320 sage: J = ComplexHermitianSimpleEJA(3)
321 sage: J.one().inner_product(J.one())
326 Ensure that we can always compute an inner product, and that
327 it gives us back a real number::
329 sage: set_random_seed()
330 sage: J = random_eja()
331 sage: x = J.random_element()
332 sage: y = J.random_element()
333 sage: x.inner_product(y) in RR
339 raise TypeError("'other' must live in the same algebra")
341 return P
.inner_product(self
, other
)
344 def operator_commutes_with(self
, other
):
346 Return whether or not this element operator-commutes
351 The definition of a Jordan algebra says that any element
352 operator-commutes with its square::
354 sage: set_random_seed()
355 sage: x = random_eja().random_element()
356 sage: x.operator_commutes_with(x^2)
361 Test Lemma 1 from Chapter III of Koecher::
363 sage: set_random_seed()
364 sage: J = random_eja()
365 sage: u = J.random_element()
366 sage: v = J.random_element()
367 sage: lhs = u.operator_commutes_with(u*v)
368 sage: rhs = v.operator_commutes_with(u^2)
373 if not other
in self
.parent():
374 raise TypeError("'other' must live in the same algebra")
376 A
= self
.operator_matrix()
377 B
= other
.operator_matrix()
383 Return my determinant, the product of my eigenvalues.
387 sage: J = JordanSpinSimpleEJA(2)
388 sage: e0,e1 = J.gens()
392 sage: J = JordanSpinSimpleEJA(3)
393 sage: e0,e1,e2 = J.gens()
394 sage: x = e0 + e1 + e2
399 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
402 return cs
[0] * (-1)**r
404 raise ValueError('charpoly had no coefficients')
409 Return the Jordan-multiplicative inverse of this element.
411 We can't use the superclass method because it relies on the
412 algebra being associative.
416 The inverse in the spin factor algebra is given in Alizadeh's
419 sage: set_random_seed()
420 sage: n = ZZ.random_element(1,10)
421 sage: J = JordanSpinSimpleEJA(n)
422 sage: x = J.random_element()
423 sage: while x.is_zero():
424 ....: x = J.random_element()
425 sage: x_vec = x.vector()
427 sage: x_bar = x_vec[1:]
428 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
429 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
430 sage: x_inverse = coeff*inv_vec
431 sage: x.inverse() == J(x_inverse)
436 The identity element is its own inverse::
438 sage: set_random_seed()
439 sage: J = random_eja()
440 sage: J.one().inverse() == J.one()
443 If an element has an inverse, it acts like one. TODO: this
444 can be a lot less ugly once ``is_invertible`` doesn't crash
445 on irregular elements::
447 sage: set_random_seed()
448 sage: J = random_eja()
449 sage: x = J.random_element()
451 ....: x.inverse()*x == J.one()
457 if self
.parent().is_associative():
458 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
461 # TODO: we can do better once the call to is_invertible()
462 # doesn't crash on irregular elements.
463 #if not self.is_invertible():
464 # raise ValueError('element is not invertible')
466 # We do this a little different than the usual recursive
467 # call to a finite-dimensional algebra element, because we
468 # wind up with an inverse that lives in the subalgebra and
469 # we need information about the parent to convert it back.
470 V
= self
.span_of_powers()
471 assoc_subalg
= self
.subalgebra_generated_by()
472 # Mis-design warning: the basis used for span_of_powers()
473 # and subalgebra_generated_by() must be the same, and in
475 elt
= assoc_subalg(V
.coordinates(self
.vector()))
477 # This will be in the subalgebra's coordinates...
478 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
479 subalg_inverse
= fda_elt
.inverse()
481 # So we have to convert back...
482 basis
= [ self
.parent(v
) for v
in V
.basis() ]
483 pairs
= zip(subalg_inverse
.vector(), basis
)
484 return self
.parent().linear_combination(pairs
)
487 def is_invertible(self
):
489 Return whether or not this element is invertible.
491 We can't use the superclass method because it relies on
492 the algebra being associative.
494 return not self
.det().is_zero()
497 def is_nilpotent(self
):
499 Return whether or not some power of this element is zero.
501 The superclass method won't work unless we're in an
502 associative algebra, and we aren't. However, we generate
503 an assocoative subalgebra and we're nilpotent there if and
504 only if we're nilpotent here (probably).
508 The identity element is never nilpotent::
510 sage: set_random_seed()
511 sage: random_eja().one().is_nilpotent()
514 The additive identity is always nilpotent::
516 sage: set_random_seed()
517 sage: random_eja().zero().is_nilpotent()
521 # The element we're going to call "is_nilpotent()" on.
522 # Either myself, interpreted as an element of a finite-
523 # dimensional algebra, or an element of an associative
527 if self
.parent().is_associative():
528 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
530 V
= self
.span_of_powers()
531 assoc_subalg
= self
.subalgebra_generated_by()
532 # Mis-design warning: the basis used for span_of_powers()
533 # and subalgebra_generated_by() must be the same, and in
535 elt
= assoc_subalg(V
.coordinates(self
.vector()))
537 # Recursive call, but should work since elt lives in an
538 # associative algebra.
539 return elt
.is_nilpotent()
542 def is_regular(self
):
544 Return whether or not this is a regular element.
548 The identity element always has degree one, but any element
549 linearly-independent from it is regular::
551 sage: J = JordanSpinSimpleEJA(5)
552 sage: J.one().is_regular()
554 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
555 sage: for x in J.gens():
556 ....: (J.one() + x).is_regular()
564 return self
.degree() == self
.parent().rank()
569 Compute the degree of this element the straightforward way
570 according to the definition; by appending powers to a list
571 and figuring out its dimension (that is, whether or not
572 they're linearly dependent).
576 sage: J = JordanSpinSimpleEJA(4)
577 sage: J.one().degree()
579 sage: e0,e1,e2,e3 = J.gens()
580 sage: (e0 - e1).degree()
583 In the spin factor algebra (of rank two), all elements that
584 aren't multiples of the identity are regular::
586 sage: set_random_seed()
587 sage: n = ZZ.random_element(1,10)
588 sage: J = JordanSpinSimpleEJA(n)
589 sage: x = J.random_element()
590 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
594 return self
.span_of_powers().dimension()
597 def minimal_polynomial(self
):
601 sage: set_random_seed()
602 sage: x = random_eja().random_element()
603 sage: x.degree() == x.minimal_polynomial().degree()
608 sage: set_random_seed()
609 sage: x = random_eja().random_element()
610 sage: x.degree() == x.minimal_polynomial().degree()
613 The minimal polynomial and the characteristic polynomial coincide
614 and are known (see Alizadeh, Example 11.11) for all elements of
615 the spin factor algebra that aren't scalar multiples of the
618 sage: set_random_seed()
619 sage: n = ZZ.random_element(2,10)
620 sage: J = JordanSpinSimpleEJA(n)
621 sage: y = J.random_element()
622 sage: while y == y.coefficient(0)*J.one():
623 ....: y = J.random_element()
624 sage: y0 = y.vector()[0]
625 sage: y_bar = y.vector()[1:]
626 sage: actual = y.minimal_polynomial()
627 sage: x = SR.symbol('x', domain='real')
628 sage: expected = x^2 - 2*y0*x + (y0^2 - norm(y_bar)^2)
629 sage: bool(actual == expected)
633 # The element we're going to call "minimal_polynomial()" on.
634 # Either myself, interpreted as an element of a finite-
635 # dimensional algebra, or an element of an associative
639 if self
.parent().is_associative():
640 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
642 V
= self
.span_of_powers()
643 assoc_subalg
= self
.subalgebra_generated_by()
644 # Mis-design warning: the basis used for span_of_powers()
645 # and subalgebra_generated_by() must be the same, and in
647 elt
= assoc_subalg(V
.coordinates(self
.vector()))
649 # Recursive call, but should work since elt lives in an
650 # associative algebra.
651 return elt
.minimal_polynomial()
654 def natural_representation(self
):
656 Return a more-natural representation of this element.
658 Every finite-dimensional Euclidean Jordan Algebra is a
659 direct sum of five simple algebras, four of which comprise
660 Hermitian matrices. This method returns the original
661 "natural" representation of this element as a Hermitian
662 matrix, if it has one. If not, you get the usual representation.
666 sage: J = ComplexHermitianSimpleEJA(3)
669 sage: J.one().natural_representation()
678 B
= self
.parent().natural_basis()
679 W
= B
[0].matrix_space()
680 return W
.linear_combination(zip(self
.vector(), B
))
683 def operator_matrix(self
):
685 Return the matrix that represents left- (or right-)
686 multiplication by this element in the parent algebra.
688 We have to override this because the superclass method
689 returns a matrix that acts on row vectors (that is, on
694 Test the first polarization identity from my notes, Koecher Chapter
695 III, or from Baes (2.3)::
697 sage: set_random_seed()
698 sage: J = random_eja()
699 sage: x = J.random_element()
700 sage: y = J.random_element()
701 sage: Lx = x.operator_matrix()
702 sage: Ly = y.operator_matrix()
703 sage: Lxx = (x*x).operator_matrix()
704 sage: Lxy = (x*y).operator_matrix()
705 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
708 Test the second polarization identity from my notes or from
711 sage: set_random_seed()
712 sage: J = random_eja()
713 sage: x = J.random_element()
714 sage: y = J.random_element()
715 sage: z = J.random_element()
716 sage: Lx = x.operator_matrix()
717 sage: Ly = y.operator_matrix()
718 sage: Lz = z.operator_matrix()
719 sage: Lzy = (z*y).operator_matrix()
720 sage: Lxy = (x*y).operator_matrix()
721 sage: Lxz = (x*z).operator_matrix()
722 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
725 Test the third polarization identity from my notes or from
728 sage: set_random_seed()
729 sage: J = random_eja()
730 sage: u = J.random_element()
731 sage: y = J.random_element()
732 sage: z = J.random_element()
733 sage: Lu = u.operator_matrix()
734 sage: Ly = y.operator_matrix()
735 sage: Lz = z.operator_matrix()
736 sage: Lzy = (z*y).operator_matrix()
737 sage: Luy = (u*y).operator_matrix()
738 sage: Luz = (u*z).operator_matrix()
739 sage: Luyz = (u*(y*z)).operator_matrix()
740 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
741 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
742 sage: bool(lhs == rhs)
746 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
747 return fda_elt
.matrix().transpose()
750 def quadratic_representation(self
, other
=None):
752 Return the quadratic representation of this element.
756 The explicit form in the spin factor algebra is given by
757 Alizadeh's Example 11.12::
759 sage: set_random_seed()
760 sage: n = ZZ.random_element(1,10)
761 sage: J = JordanSpinSimpleEJA(n)
762 sage: x = J.random_element()
763 sage: x_vec = x.vector()
765 sage: x_bar = x_vec[1:]
766 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
767 sage: B = 2*x0*x_bar.row()
768 sage: C = 2*x0*x_bar.column()
769 sage: D = identity_matrix(QQ, n-1)
770 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
771 sage: D = D + 2*x_bar.tensor_product(x_bar)
772 sage: Q = block_matrix(2,2,[A,B,C,D])
773 sage: Q == x.quadratic_representation()
776 Test all of the properties from Theorem 11.2 in Alizadeh::
778 sage: set_random_seed()
779 sage: J = random_eja()
780 sage: x = J.random_element()
781 sage: y = J.random_element()
785 sage: actual = x.quadratic_representation(y)
786 sage: expected = ( (x+y).quadratic_representation()
787 ....: -x.quadratic_representation()
788 ....: -y.quadratic_representation() ) / 2
789 sage: actual == expected
794 sage: alpha = QQ.random_element()
795 sage: actual = (alpha*x).quadratic_representation()
796 sage: expected = (alpha^2)*x.quadratic_representation()
797 sage: actual == expected
802 sage: Qy = y.quadratic_representation()
803 sage: actual = J(Qy*x.vector()).quadratic_representation()
804 sage: expected = Qy*x.quadratic_representation()*Qy
805 sage: actual == expected
810 sage: k = ZZ.random_element(1,10)
811 sage: actual = (x^k).quadratic_representation()
812 sage: expected = (x.quadratic_representation())^k
813 sage: actual == expected
819 elif not other
in self
.parent():
820 raise TypeError("'other' must live in the same algebra")
822 L
= self
.operator_matrix()
823 M
= other
.operator_matrix()
824 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
827 def span_of_powers(self
):
829 Return the vector space spanned by successive powers of
832 # The dimension of the subalgebra can't be greater than
833 # the big algebra, so just put everything into a list
834 # and let span() get rid of the excess.
835 V
= self
.vector().parent()
836 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
839 def subalgebra_generated_by(self
):
841 Return the associative subalgebra of the parent EJA generated
846 sage: set_random_seed()
847 sage: x = random_eja().random_element()
848 sage: x.subalgebra_generated_by().is_associative()
851 Squaring in the subalgebra should be the same thing as
852 squaring in the superalgebra::
854 sage: set_random_seed()
855 sage: x = random_eja().random_element()
856 sage: u = x.subalgebra_generated_by().random_element()
857 sage: u.operator_matrix()*u.vector() == (u**2).vector()
861 # First get the subspace spanned by the powers of myself...
862 V
= self
.span_of_powers()
865 # Now figure out the entries of the right-multiplication
866 # matrix for the successive basis elements b0, b1,... of
869 for b_right
in V
.basis():
870 eja_b_right
= self
.parent()(b_right
)
872 # The first row of the right-multiplication matrix by
873 # b1 is what we get if we apply that matrix to b1. The
874 # second row of the right multiplication matrix by b1
875 # is what we get when we apply that matrix to b2...
877 # IMPORTANT: this assumes that all vectors are COLUMN
878 # vectors, unlike our superclass (which uses row vectors).
879 for b_left
in V
.basis():
880 eja_b_left
= self
.parent()(b_left
)
881 # Multiply in the original EJA, but then get the
882 # coordinates from the subalgebra in terms of its
884 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
885 b_right_rows
.append(this_row
)
886 b_right_matrix
= matrix(F
, b_right_rows
)
887 mats
.append(b_right_matrix
)
889 # It's an algebra of polynomials in one element, and EJAs
890 # are power-associative.
892 # TODO: choose generator names intelligently.
893 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
896 def subalgebra_idempotent(self
):
898 Find an idempotent in the associative subalgebra I generate
899 using Proposition 2.3.5 in Baes.
903 sage: set_random_seed()
905 sage: c = J.random_element().subalgebra_idempotent()
908 sage: J = JordanSpinSimpleEJA(5)
909 sage: c = J.random_element().subalgebra_idempotent()
914 if self
.is_nilpotent():
915 raise ValueError("this only works with non-nilpotent elements!")
917 V
= self
.span_of_powers()
918 J
= self
.subalgebra_generated_by()
919 # Mis-design warning: the basis used for span_of_powers()
920 # and subalgebra_generated_by() must be the same, and in
922 u
= J(V
.coordinates(self
.vector()))
924 # The image of the matrix of left-u^m-multiplication
925 # will be minimal for some natural number s...
927 minimal_dim
= V
.dimension()
928 for i
in xrange(1, V
.dimension()):
929 this_dim
= (u
**i
).operator_matrix().image().dimension()
930 if this_dim
< minimal_dim
:
931 minimal_dim
= this_dim
934 # Now minimal_matrix should correspond to the smallest
935 # non-zero subspace in Baes's (or really, Koecher's)
938 # However, we need to restrict the matrix to work on the
939 # subspace... or do we? Can't we just solve, knowing that
940 # A(c) = u^(s+1) should have a solution in the big space,
943 # Beware, solve_right() means that we're using COLUMN vectors.
944 # Our FiniteDimensionalAlgebraElement superclass uses rows.
946 A
= u_next
.operator_matrix()
947 c_coordinates
= A
.solve_right(u_next
.vector())
949 # Now c_coordinates is the idempotent we want, but it's in
950 # the coordinate system of the subalgebra.
952 # We need the basis for J, but as elements of the parent algebra.
954 basis
= [self
.parent(v
) for v
in V
.basis()]
955 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
960 Return my trace, the sum of my eigenvalues.
964 sage: J = JordanSpinSimpleEJA(3)
965 sage: e0,e1,e2 = J.gens()
966 sage: x = e0 + e1 + e2
971 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
975 raise ValueError('charpoly had fewer than 2 coefficients')
978 def trace_inner_product(self
, other
):
980 Return the trace inner product of myself and ``other``.
982 if not other
in self
.parent():
983 raise TypeError("'other' must live in the same algebra")
985 return (self
*other
).trace()
988 def eja_rn(dimension
, field
=QQ
):
990 Return the Euclidean Jordan Algebra corresponding to the set
991 `R^n` under the Hadamard product.
995 This multiplication table can be verified by hand::
998 sage: e0,e1,e2 = J.gens()
1013 # The FiniteDimensionalAlgebra constructor takes a list of
1014 # matrices, the ith representing right multiplication by the ith
1015 # basis element in the vector space. So if e_1 = (1,0,0), then
1016 # right (Hadamard) multiplication of x by e_1 picks out the first
1017 # component of x; and likewise for the ith basis element e_i.
1018 Qs
= [ matrix(field
, dimension
, dimension
, lambda k
,j
: 1*(k
== j
== i
))
1019 for i
in xrange(dimension
) ]
1021 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1024 inner_product
=_usual_ip
)
1030 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1034 For now, we choose a random natural number ``n`` (greater than zero)
1035 and then give you back one of the following:
1037 * The cartesian product of the rational numbers ``n`` times; this is
1038 ``QQ^n`` with the Hadamard product.
1040 * The Jordan spin algebra on ``QQ^n``.
1042 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1045 Later this might be extended to return Cartesian products of the
1051 Euclidean Jordan algebra of degree...
1054 n
= ZZ
.random_element(1,5)
1055 constructor
= choice([eja_rn
,
1056 JordanSpinSimpleEJA
,
1057 RealSymmetricSimpleEJA
,
1058 ComplexHermitianSimpleEJA
])
1059 return constructor(n
, field
=QQ
)
1063 def _real_symmetric_basis(n
, field
=QQ
):
1065 Return a basis for the space of real symmetric n-by-n matrices.
1067 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1071 for j
in xrange(i
+1):
1072 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1076 # Beware, orthogonal but not normalized!
1077 Sij
= Eij
+ Eij
.transpose()
1082 def _complex_hermitian_basis(n
, field
=QQ
):
1084 Returns a basis for the space of complex Hermitian n-by-n matrices.
1088 sage: set_random_seed()
1089 sage: n = ZZ.random_element(1,5)
1090 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1094 F
= QuadraticField(-1, 'I')
1097 # This is like the symmetric case, but we need to be careful:
1099 # * We want conjugate-symmetry, not just symmetry.
1100 # * The diagonal will (as a result) be real.
1104 for j
in xrange(i
+1):
1105 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1107 Sij
= _embed_complex_matrix(Eij
)
1110 # Beware, orthogonal but not normalized! The second one
1111 # has a minus because it's conjugated.
1112 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1114 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1120 return vector(m
.base_ring(), m
.list())
1123 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1125 def _multiplication_table_from_matrix_basis(basis
):
1127 At least three of the five simple Euclidean Jordan algebras have the
1128 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1129 multiplication on the right is matrix multiplication. Given a basis
1130 for the underlying matrix space, this function returns a
1131 multiplication table (obtained by looping through the basis
1132 elements) for an algebra of those matrices. A reordered copy
1133 of the basis is also returned to work around the fact that
1134 the ``span()`` in this function will change the order of the basis
1135 from what we think it is, to... something else.
1137 # In S^2, for example, we nominally have four coordinates even
1138 # though the space is of dimension three only. The vector space V
1139 # is supposed to hold the entire long vector, and the subspace W
1140 # of V will be spanned by the vectors that arise from symmetric
1141 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1142 field
= basis
[0].base_ring()
1143 dimension
= basis
[0].nrows()
1145 V
= VectorSpace(field
, dimension
**2)
1146 W
= V
.span( _mat2vec(s
) for s
in basis
)
1148 # Taking the span above reorders our basis (thanks, jerk!) so we
1149 # need to put our "matrix basis" in the same order as the
1150 # (reordered) vector basis.
1151 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1155 # Brute force the multiplication-by-s matrix by looping
1156 # through all elements of the basis and doing the computation
1157 # to find out what the corresponding row should be. BEWARE:
1158 # these multiplication tables won't be symmetric! It therefore
1159 # becomes REALLY IMPORTANT that the underlying algebra
1160 # constructor uses ROW vectors and not COLUMN vectors. That's
1161 # why we're computing rows here and not columns.
1164 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1165 Q_rows
.append(W
.coordinates(this_row
))
1166 Q
= matrix(field
, W
.dimension(), Q_rows
)
1172 def _embed_complex_matrix(M
):
1174 Embed the n-by-n complex matrix ``M`` into the space of real
1175 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1176 bi` to the block matrix ``[[a,b],[-b,a]]``.
1180 sage: F = QuadraticField(-1,'i')
1181 sage: x1 = F(4 - 2*i)
1182 sage: x2 = F(1 + 2*i)
1185 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1186 sage: _embed_complex_matrix(M)
1196 raise ValueError("the matrix 'M' must be square")
1197 field
= M
.base_ring()
1202 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1204 # We can drop the imaginaries here.
1205 return block_matrix(field
.base_ring(), n
, blocks
)
1208 def _unembed_complex_matrix(M
):
1210 The inverse of _embed_complex_matrix().
1214 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1215 ....: [-2, 1, -4, 3],
1216 ....: [ 9, 10, 11, 12],
1217 ....: [-10, 9, -12, 11] ])
1218 sage: _unembed_complex_matrix(A)
1220 [ 10*i + 9 12*i + 11]
1224 sage: set_random_seed()
1225 sage: F = QuadraticField(-1, 'i')
1226 sage: M = random_matrix(F, 3)
1227 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1233 raise ValueError("the matrix 'M' must be square")
1234 if not n
.mod(2).is_zero():
1235 raise ValueError("the matrix 'M' must be a complex embedding")
1237 F
= QuadraticField(-1, 'i')
1240 # Go top-left to bottom-right (reading order), converting every
1241 # 2-by-2 block we see to a single complex element.
1243 for k
in xrange(n
/2):
1244 for j
in xrange(n
/2):
1245 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1246 if submat
[0,0] != submat
[1,1]:
1247 raise ValueError('bad on-diagonal submatrix')
1248 if submat
[0,1] != -submat
[1,0]:
1249 raise ValueError('bad off-diagonal submatrix')
1250 z
= submat
[0,0] + submat
[0,1]*i
1253 return matrix(F
, n
/2, elements
)
1256 def _embed_quaternion_matrix(M
):
1258 Embed the n-by-n quaternion matrix ``M`` into the space of real
1259 matrices of size 4n-by-4n by first sending each quaternion entry
1260 `z = a + bi + cj + dk` to the block-complex matrix
1261 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1266 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1267 sage: i,j,k = Q.gens()
1268 sage: x = 1 + 2*i + 3*j + 4*k
1269 sage: M = matrix(Q, 1, [[x]])
1270 sage: _embed_quaternion_matrix(M)
1277 quaternions
= M
.base_ring()
1280 raise ValueError("the matrix 'M' must be square")
1282 F
= QuadraticField(-1, 'i')
1287 t
= z
.coefficient_tuple()
1292 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1293 [-c
+ d
*i
, a
- b
*i
]])
1294 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1296 # We should have real entries by now, so use the realest field
1297 # we've got for the return value.
1298 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1301 def _unembed_quaternion_matrix(M
):
1303 The inverse of _embed_quaternion_matrix().
1307 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1308 ....: [-2, 1, -4, 3],
1309 ....: [-3, 4, 1, -2],
1310 ....: [-4, -3, 2, 1]])
1311 sage: _unembed_quaternion_matrix(M)
1312 [1 + 2*i + 3*j + 4*k]
1316 sage: set_random_seed()
1317 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1318 sage: M = random_matrix(Q, 3)
1319 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1325 raise ValueError("the matrix 'M' must be square")
1326 if not n
.mod(4).is_zero():
1327 raise ValueError("the matrix 'M' must be a complex embedding")
1329 Q
= QuaternionAlgebra(QQ
,-1,-1)
1332 # Go top-left to bottom-right (reading order), converting every
1333 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1336 for l
in xrange(n
/4):
1337 for m
in xrange(n
/4):
1338 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1339 if submat
[0,0] != submat
[1,1].conjugate():
1340 raise ValueError('bad on-diagonal submatrix')
1341 if submat
[0,1] != -submat
[1,0].conjugate():
1342 raise ValueError('bad off-diagonal submatrix')
1343 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1344 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1347 return matrix(Q
, n
/4, elements
)
1350 # The usual inner product on R^n.
1352 return x
.vector().inner_product(y
.vector())
1354 # The inner product used for the real symmetric simple EJA.
1355 # We keep it as a separate function because e.g. the complex
1356 # algebra uses the same inner product, except divided by 2.
1357 def _matrix_ip(X
,Y
):
1358 X_mat
= X
.natural_representation()
1359 Y_mat
= Y
.natural_representation()
1360 return (X_mat
*Y_mat
).trace()
1363 def RealSymmetricSimpleEJA(n
, field
=QQ
):
1365 The rank-n simple EJA consisting of real symmetric n-by-n
1366 matrices, the usual symmetric Jordan product, and the trace inner
1367 product. It has dimension `(n^2 + n)/2` over the reals.
1371 sage: J = RealSymmetricSimpleEJA(2)
1372 sage: e0, e1, e2 = J.gens()
1382 The degree of this algebra is `(n^2 + n) / 2`::
1384 sage: set_random_seed()
1385 sage: n = ZZ.random_element(1,5)
1386 sage: J = RealSymmetricSimpleEJA(n)
1387 sage: J.degree() == (n^2 + n)/2
1390 The Jordan multiplication is what we think it is::
1392 sage: set_random_seed()
1393 sage: n = ZZ.random_element(1,5)
1394 sage: J = RealSymmetricSimpleEJA(n)
1395 sage: x = J.random_element()
1396 sage: y = J.random_element()
1397 sage: actual = (x*y).natural_representation()
1398 sage: X = x.natural_representation()
1399 sage: Y = y.natural_representation()
1400 sage: expected = (X*Y + Y*X)/2
1401 sage: actual == expected
1403 sage: J(expected) == x*y
1407 S
= _real_symmetric_basis(n
, field
=field
)
1408 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1410 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1414 inner_product
=_matrix_ip
)
1417 def ComplexHermitianSimpleEJA(n
, field
=QQ
):
1419 The rank-n simple EJA consisting of complex Hermitian n-by-n
1420 matrices over the real numbers, the usual symmetric Jordan product,
1421 and the real-part-of-trace inner product. It has dimension `n^2` over
1426 The degree of this algebra is `n^2`::
1428 sage: set_random_seed()
1429 sage: n = ZZ.random_element(1,5)
1430 sage: J = ComplexHermitianSimpleEJA(n)
1431 sage: J.degree() == n^2
1434 The Jordan multiplication is what we think it is::
1436 sage: set_random_seed()
1437 sage: n = ZZ.random_element(1,5)
1438 sage: J = ComplexHermitianSimpleEJA(n)
1439 sage: x = J.random_element()
1440 sage: y = J.random_element()
1441 sage: actual = (x*y).natural_representation()
1442 sage: X = x.natural_representation()
1443 sage: Y = y.natural_representation()
1444 sage: expected = (X*Y + Y*X)/2
1445 sage: actual == expected
1447 sage: J(expected) == x*y
1451 S
= _complex_hermitian_basis(n
)
1452 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1454 # Since a+bi on the diagonal is represented as
1459 # we'll double-count the "a" entries if we take the trace of
1461 ip
= lambda X
,Y
: _matrix_ip(X
,Y
)/2
1463 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1470 def QuaternionHermitianSimpleEJA(n
):
1472 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1473 matrices, the usual symmetric Jordan product, and the
1474 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1479 def OctonionHermitianSimpleEJA(n
):
1481 This shit be crazy. It has dimension 27 over the reals.
1486 def JordanSpinSimpleEJA(n
, field
=QQ
):
1488 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1489 with the usual inner product and jordan product ``x*y =
1490 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1495 This multiplication table can be verified by hand::
1497 sage: J = JordanSpinSimpleEJA(4)
1498 sage: e0,e1,e2,e3 = J.gens()
1514 In one dimension, this is the reals under multiplication::
1516 sage: J1 = JordanSpinSimpleEJA(1)
1517 sage: J2 = eja_rn(1)
1523 id_matrix
= identity_matrix(field
, n
)
1525 ei
= id_matrix
.column(i
)
1526 Qi
= zero_matrix(field
, n
)
1528 Qi
.set_column(0, ei
)
1529 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
1530 # The addition of the diagonal matrix adds an extra ei[0] in the
1531 # upper-left corner of the matrix.
1532 Qi
[0,0] = Qi
[0,0] * ~
field(2)
1535 # The rank of the spin factor algebra is two, UNLESS we're in a
1536 # one-dimensional ambient space (the rank is bounded by the
1537 # ambient dimension).
1538 return FiniteDimensionalEuclideanJordanAlgebra(field
,
1541 inner_product
=_usual_ip
)