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()
72 self
._charpoly
= None # for caching
74 self
._natural
_basis
= natural_basis
75 self
._multiplication
_table
= mult_table
76 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
85 Return a string representation of ``self``.
87 fmt
= "Euclidean Jordan algebra of degree {} over {}"
88 return fmt
.format(self
.degree(), self
.base_ring())
92 def characteristic_polynomial(self
):
96 The characteristic polynomial in the spin algebra is given in
97 Alizadeh, Example 11.11::
99 sage: J = JordanSpinEJA(3)
100 sage: p = J.characteristic_polynomial(); p
101 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
102 sage: xvec = J.one().vector()
107 if self
._charpoly
is not None:
108 return self
._charpoly
113 # First, compute the basis B...
116 for g
in self
.gens():
119 if not x0
.is_regular():
120 raise ValueError("don't know a regular element")
122 V
= x0
.vector().parent().ambient_vector_space()
123 V1
= V
.span_of_basis( (x0
**k
).vector() for k
in range(self
.rank()) )
124 B
= (V1
.basis() + V1
.complement().basis())
126 # Now switch to the polynomial rings.
128 names
= ['X' + str(i
) for i
in range(1,n
+1)]
129 R
= PolynomialRing(self
.base_ring(), names
)
130 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
131 self
._multiplication
_table
,
133 B
= [ b
.change_ring(R
.fraction_field()) for b
in B
]
134 # Get the vector space (as opposed to module) so that
135 # span_of_basis() works.
136 V
= J
.zero().vector().parent().ambient_vector_space()
137 W
= V
.span_of_basis(B
)
140 # The coordinates of e_k with respect to the basis B.
141 # But, the e_k are elements of B...
142 return identity_matrix(J
.base_ring(), n
).column(k
-1).column()
144 # A matrix implementation 1
145 x
= J(vector(R
, R
.gens()))
146 l1
= [column_matrix(W
.coordinates((x
**k
).vector())) for k
in range(r
)]
147 l2
= [e(k
) for k
in range(r
+1, n
+1)]
148 A_of_x
= block_matrix(1, n
, (l1
+ l2
))
149 xr
= W
.coordinates((x
**r
).vector())
151 denominator
= A_of_x
.det() # This is constant
153 A_cols
= A_of_x
.columns()
155 numerator
= column_matrix(A_of_x
.base_ring(), A_cols
).det()
156 ai
= numerator
/denominator
159 # We go to a bit of trouble here to reorder the
160 # indeterminates, so that it's easier to evaluate the
161 # characteristic polynomial at x's coordinates and get back
162 # something in terms of t, which is what we want.
163 S
= PolynomialRing(self
.base_ring(),'t')
165 S
= PolynomialRing(S
, R
.variable_names())
168 # We're relying on the theory here to ensure that each entry
169 # a[i] is indeed back in R, and the added negative signs are
170 # to make the whole expression sum to zero.
171 a
= [R(-ai
) for ai
in a
] # corresponds to powerx x^0 through x^(r-1)
173 # Note: all entries past the rth should be zero. The
174 # coefficient of the highest power (x^r) is 1, but it doesn't
175 # appear in the solution vector which contains coefficients
176 # for the other powers (to make them sum to x^r).
178 a
[r
] = 1 # corresponds to x^r
180 # When the rank is equal to the dimension, trying to
181 # assign a[r] goes out-of-bounds.
182 a
.append(1) # corresponds to x^r
184 self
._charpoly
= sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
185 return self
._charpoly
188 def inner_product(self
, x
, y
):
190 The inner product associated with this Euclidean Jordan algebra.
192 Defaults to the trace inner product, but can be overridden by
193 subclasses if they are sure that the necessary properties are
198 The inner product must satisfy its axiom for this algebra to truly
199 be a Euclidean Jordan Algebra::
201 sage: set_random_seed()
202 sage: J = random_eja()
203 sage: x = J.random_element()
204 sage: y = J.random_element()
205 sage: z = J.random_element()
206 sage: (x*y).inner_product(z) == y.inner_product(x*z)
210 if (not x
in self
) or (not y
in self
):
211 raise TypeError("arguments must live in this algebra")
212 return x
.trace_inner_product(y
)
215 def natural_basis(self
):
217 Return a more-natural representation of this algebra's basis.
219 Every finite-dimensional Euclidean Jordan Algebra is a direct
220 sum of five simple algebras, four of which comprise Hermitian
221 matrices. This method returns the original "natural" basis
222 for our underlying vector space. (Typically, the natural basis
223 is used to construct the multiplication table in the first place.)
225 Note that this will always return a matrix. The standard basis
226 in `R^n` will be returned as `n`-by-`1` column matrices.
230 sage: J = RealSymmetricEJA(2)
233 sage: J.natural_basis()
241 sage: J = JordanSpinEJA(2)
244 sage: J.natural_basis()
251 if self
._natural
_basis
is None:
252 return tuple( b
.vector().column() for b
in self
.basis() )
254 return self
._natural
_basis
259 Return the rank of this EJA.
261 if self
._rank
is None:
262 raise ValueError("no rank specified at genesis")
267 class Element(FiniteDimensionalAlgebraElement
):
269 An element of a Euclidean Jordan algebra.
272 def __init__(self
, A
, elt
=None):
276 The identity in `S^n` is converted to the identity in the EJA::
278 sage: J = RealSymmetricEJA(3)
279 sage: I = identity_matrix(QQ,3)
280 sage: J(I) == J.one()
283 This skew-symmetric matrix can't be represented in the EJA::
285 sage: J = RealSymmetricEJA(3)
286 sage: A = matrix(QQ,3, lambda i,j: i-j)
288 Traceback (most recent call last):
290 ArithmeticError: vector is not in free module
293 # Goal: if we're given a matrix, and if it lives in our
294 # parent algebra's "natural ambient space," convert it
295 # into an algebra element.
297 # The catch is, we make a recursive call after converting
298 # the given matrix into a vector that lives in the algebra.
299 # This we need to try the parent class initializer first,
300 # to avoid recursing forever if we're given something that
301 # already fits into the algebra, but also happens to live
302 # in the parent's "natural ambient space" (this happens with
305 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
307 natural_basis
= A
.natural_basis()
308 if elt
in natural_basis
[0].matrix_space():
309 # Thanks for nothing! Matrix spaces aren't vector
310 # spaces in Sage, so we have to figure out its
311 # natural-basis coordinates ourselves.
312 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
313 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
314 coords
= W
.coordinates(_mat2vec(elt
))
315 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
317 def __pow__(self
, n
):
319 Return ``self`` raised to the power ``n``.
321 Jordan algebras are always power-associative; see for
322 example Faraut and Koranyi, Proposition II.1.2 (ii).
326 We have to override this because our superclass uses row vectors
327 instead of column vectors! We, on the other hand, assume column
332 sage: set_random_seed()
333 sage: x = random_eja().random_element()
334 sage: x.operator_matrix()*x.vector() == (x^2).vector()
337 A few examples of power-associativity::
339 sage: set_random_seed()
340 sage: x = random_eja().random_element()
341 sage: x*(x*x)*(x*x) == x^5
343 sage: (x*x)*(x*x*x) == x^5
346 We also know that powers operator-commute (Koecher, Chapter
349 sage: set_random_seed()
350 sage: x = random_eja().random_element()
351 sage: m = ZZ.random_element(0,10)
352 sage: n = ZZ.random_element(0,10)
353 sage: Lxm = (x^m).operator_matrix()
354 sage: Lxn = (x^n).operator_matrix()
355 sage: Lxm*Lxn == Lxn*Lxm
365 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
368 def apply_univariate_polynomial(self
, p
):
370 Apply the univariate polynomial ``p`` to this element.
372 A priori, SageMath won't allow us to apply a univariate
373 polynomial to an element of an EJA, because we don't know
374 that EJAs are rings (they are usually not associative). Of
375 course, we know that EJAs are power-associative, so the
376 operation is ultimately kosher. This function sidesteps
377 the CAS to get the answer we want and expect.
381 sage: R = PolynomialRing(QQ, 't')
383 sage: p = t^4 - t^3 + 5*t - 2
384 sage: J = RealCartesianProductEJA(5)
385 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
390 We should always get back an element of the algebra::
392 sage: set_random_seed()
393 sage: p = PolynomialRing(QQ, 't').random_element()
394 sage: J = random_eja()
395 sage: x = J.random_element()
396 sage: x.apply_univariate_polynomial(p) in J
400 if len(p
.variables()) > 1:
401 raise ValueError("not a univariate polynomial")
404 # Convert the coeficcients to the parent's base ring,
405 # because a priori they might live in an (unnecessarily)
406 # larger ring for which P.sum() would fail below.
407 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
408 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
411 def characteristic_polynomial(self
):
413 Return my characteristic polynomial (if I'm a regular
416 Eventually this should be implemented in terms of the parent
417 algebra's characteristic polynomial that works for ALL
420 if self
.is_regular():
421 return self
.minimal_polynomial()
423 raise NotImplementedError('irregular element')
426 def inner_product(self
, other
):
428 Return the parent algebra's inner product of myself and ``other``.
432 The inner product in the Jordan spin algebra is the usual
433 inner product on `R^n` (this example only works because the
434 basis for the Jordan algebra is the standard basis in `R^n`)::
436 sage: J = JordanSpinEJA(3)
437 sage: x = vector(QQ,[1,2,3])
438 sage: y = vector(QQ,[4,5,6])
439 sage: x.inner_product(y)
441 sage: J(x).inner_product(J(y))
444 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
445 multiplication is the usual matrix multiplication in `S^n`,
446 so the inner product of the identity matrix with itself
449 sage: J = RealSymmetricEJA(3)
450 sage: J.one().inner_product(J.one())
453 Likewise, the inner product on `C^n` is `<X,Y> =
454 Re(trace(X*Y))`, where we must necessarily take the real
455 part because the product of Hermitian matrices may not be
458 sage: J = ComplexHermitianEJA(3)
459 sage: J.one().inner_product(J.one())
462 Ditto for the quaternions::
464 sage: J = QuaternionHermitianEJA(3)
465 sage: J.one().inner_product(J.one())
470 Ensure that we can always compute an inner product, and that
471 it gives us back a real number::
473 sage: set_random_seed()
474 sage: J = random_eja()
475 sage: x = J.random_element()
476 sage: y = J.random_element()
477 sage: x.inner_product(y) in RR
483 raise TypeError("'other' must live in the same algebra")
485 return P
.inner_product(self
, other
)
488 def operator_commutes_with(self
, other
):
490 Return whether or not this element operator-commutes
495 The definition of a Jordan algebra says that any element
496 operator-commutes with its square::
498 sage: set_random_seed()
499 sage: x = random_eja().random_element()
500 sage: x.operator_commutes_with(x^2)
505 Test Lemma 1 from Chapter III of Koecher::
507 sage: set_random_seed()
508 sage: J = random_eja()
509 sage: u = J.random_element()
510 sage: v = J.random_element()
511 sage: lhs = u.operator_commutes_with(u*v)
512 sage: rhs = v.operator_commutes_with(u^2)
517 if not other
in self
.parent():
518 raise TypeError("'other' must live in the same algebra")
520 A
= self
.operator_matrix()
521 B
= other
.operator_matrix()
527 Return my determinant, the product of my eigenvalues.
531 sage: J = JordanSpinEJA(2)
532 sage: e0,e1 = J.gens()
536 sage: J = JordanSpinEJA(3)
537 sage: e0,e1,e2 = J.gens()
538 sage: x = e0 + e1 + e2
543 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
546 return cs
[0] * (-1)**r
548 raise ValueError('charpoly had no coefficients')
553 Return the Jordan-multiplicative inverse of this element.
555 We can't use the superclass method because it relies on the
556 algebra being associative.
560 The inverse in the spin factor algebra is given in Alizadeh's
563 sage: set_random_seed()
564 sage: n = ZZ.random_element(1,10)
565 sage: J = JordanSpinEJA(n)
566 sage: x = J.random_element()
567 sage: while x.is_zero():
568 ....: x = J.random_element()
569 sage: x_vec = x.vector()
571 sage: x_bar = x_vec[1:]
572 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
573 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
574 sage: x_inverse = coeff*inv_vec
575 sage: x.inverse() == J(x_inverse)
580 The identity element is its own inverse::
582 sage: set_random_seed()
583 sage: J = random_eja()
584 sage: J.one().inverse() == J.one()
587 If an element has an inverse, it acts like one. TODO: this
588 can be a lot less ugly once ``is_invertible`` doesn't crash
589 on irregular elements::
591 sage: set_random_seed()
592 sage: J = random_eja()
593 sage: x = J.random_element()
595 ....: x.inverse()*x == J.one()
601 if self
.parent().is_associative():
602 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
605 # TODO: we can do better once the call to is_invertible()
606 # doesn't crash on irregular elements.
607 #if not self.is_invertible():
608 # raise ValueError('element is not invertible')
610 # We do this a little different than the usual recursive
611 # call to a finite-dimensional algebra element, because we
612 # wind up with an inverse that lives in the subalgebra and
613 # we need information about the parent to convert it back.
614 V
= self
.span_of_powers()
615 assoc_subalg
= self
.subalgebra_generated_by()
616 # Mis-design warning: the basis used for span_of_powers()
617 # and subalgebra_generated_by() must be the same, and in
619 elt
= assoc_subalg(V
.coordinates(self
.vector()))
621 # This will be in the subalgebra's coordinates...
622 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
623 subalg_inverse
= fda_elt
.inverse()
625 # So we have to convert back...
626 basis
= [ self
.parent(v
) for v
in V
.basis() ]
627 pairs
= zip(subalg_inverse
.vector(), basis
)
628 return self
.parent().linear_combination(pairs
)
631 def is_invertible(self
):
633 Return whether or not this element is invertible.
635 We can't use the superclass method because it relies on
636 the algebra being associative.
640 The usual way to do this is to check if the determinant is
641 zero, but we need the characteristic polynomial for the
642 determinant. The minimal polynomial is a lot easier to get,
643 so we use Corollary 2 in Chapter V of Koecher to check
644 whether or not the paren't algebra's zero element is a root
645 of this element's minimal polynomial.
649 The identity element is always invertible::
651 sage: set_random_seed()
652 sage: J = random_eja()
653 sage: J.one().is_invertible()
656 The zero element is never invertible::
658 sage: set_random_seed()
659 sage: J = random_eja()
660 sage: J.zero().is_invertible()
664 zero
= self
.parent().zero()
665 p
= self
.minimal_polynomial()
666 return not (p(zero
) == zero
)
669 def is_nilpotent(self
):
671 Return whether or not some power of this element is zero.
673 The superclass method won't work unless we're in an
674 associative algebra, and we aren't. However, we generate
675 an assocoative subalgebra and we're nilpotent there if and
676 only if we're nilpotent here (probably).
680 The identity element is never nilpotent::
682 sage: set_random_seed()
683 sage: random_eja().one().is_nilpotent()
686 The additive identity is always nilpotent::
688 sage: set_random_seed()
689 sage: random_eja().zero().is_nilpotent()
693 # The element we're going to call "is_nilpotent()" on.
694 # Either myself, interpreted as an element of a finite-
695 # dimensional algebra, or an element of an associative
699 if self
.parent().is_associative():
700 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
702 V
= self
.span_of_powers()
703 assoc_subalg
= self
.subalgebra_generated_by()
704 # Mis-design warning: the basis used for span_of_powers()
705 # and subalgebra_generated_by() must be the same, and in
707 elt
= assoc_subalg(V
.coordinates(self
.vector()))
709 # Recursive call, but should work since elt lives in an
710 # associative algebra.
711 return elt
.is_nilpotent()
714 def is_regular(self
):
716 Return whether or not this is a regular element.
720 The identity element always has degree one, but any element
721 linearly-independent from it is regular::
723 sage: J = JordanSpinEJA(5)
724 sage: J.one().is_regular()
726 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
727 sage: for x in J.gens():
728 ....: (J.one() + x).is_regular()
736 return self
.degree() == self
.parent().rank()
741 Compute the degree of this element the straightforward way
742 according to the definition; by appending powers to a list
743 and figuring out its dimension (that is, whether or not
744 they're linearly dependent).
748 sage: J = JordanSpinEJA(4)
749 sage: J.one().degree()
751 sage: e0,e1,e2,e3 = J.gens()
752 sage: (e0 - e1).degree()
755 In the spin factor algebra (of rank two), all elements that
756 aren't multiples of the identity are regular::
758 sage: set_random_seed()
759 sage: n = ZZ.random_element(1,10)
760 sage: J = JordanSpinEJA(n)
761 sage: x = J.random_element()
762 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
766 return self
.span_of_powers().dimension()
769 def minimal_polynomial(self
):
771 Return the minimal polynomial of this element,
772 as a function of the variable `t`.
776 We restrict ourselves to the associative subalgebra
777 generated by this element, and then return the minimal
778 polynomial of this element's operator matrix (in that
779 subalgebra). This works by Baes Proposition 2.3.16.
783 The minimal polynomial of the identity and zero elements are
786 sage: set_random_seed()
787 sage: J = random_eja()
788 sage: J.one().minimal_polynomial()
790 sage: J.zero().minimal_polynomial()
793 The degree of an element is (by one definition) the degree
794 of its minimal polynomial::
796 sage: set_random_seed()
797 sage: x = random_eja().random_element()
798 sage: x.degree() == x.minimal_polynomial().degree()
801 The minimal polynomial and the characteristic polynomial coincide
802 and are known (see Alizadeh, Example 11.11) for all elements of
803 the spin factor algebra that aren't scalar multiples of the
806 sage: set_random_seed()
807 sage: n = ZZ.random_element(2,10)
808 sage: J = JordanSpinEJA(n)
809 sage: y = J.random_element()
810 sage: while y == y.coefficient(0)*J.one():
811 ....: y = J.random_element()
812 sage: y0 = y.vector()[0]
813 sage: y_bar = y.vector()[1:]
814 sage: actual = y.minimal_polynomial()
815 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
816 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
817 sage: bool(actual == expected)
820 The minimal polynomial should always kill its element::
822 sage: set_random_seed()
823 sage: x = random_eja().random_element()
824 sage: p = x.minimal_polynomial()
825 sage: x.apply_univariate_polynomial(p)
829 V
= self
.span_of_powers()
830 assoc_subalg
= self
.subalgebra_generated_by()
831 # Mis-design warning: the basis used for span_of_powers()
832 # and subalgebra_generated_by() must be the same, and in
834 elt
= assoc_subalg(V
.coordinates(self
.vector()))
836 # We get back a symbolic polynomial in 'x' but want a real
838 p_of_x
= elt
.operator_matrix().minimal_polynomial()
839 return p_of_x
.change_variable_name('t')
842 def natural_representation(self
):
844 Return a more-natural representation of this element.
846 Every finite-dimensional Euclidean Jordan Algebra is a
847 direct sum of five simple algebras, four of which comprise
848 Hermitian matrices. This method returns the original
849 "natural" representation of this element as a Hermitian
850 matrix, if it has one. If not, you get the usual representation.
854 sage: J = ComplexHermitianEJA(3)
857 sage: J.one().natural_representation()
867 sage: J = QuaternionHermitianEJA(3)
870 sage: J.one().natural_representation()
871 [1 0 0 0 0 0 0 0 0 0 0 0]
872 [0 1 0 0 0 0 0 0 0 0 0 0]
873 [0 0 1 0 0 0 0 0 0 0 0 0]
874 [0 0 0 1 0 0 0 0 0 0 0 0]
875 [0 0 0 0 1 0 0 0 0 0 0 0]
876 [0 0 0 0 0 1 0 0 0 0 0 0]
877 [0 0 0 0 0 0 1 0 0 0 0 0]
878 [0 0 0 0 0 0 0 1 0 0 0 0]
879 [0 0 0 0 0 0 0 0 1 0 0 0]
880 [0 0 0 0 0 0 0 0 0 1 0 0]
881 [0 0 0 0 0 0 0 0 0 0 1 0]
882 [0 0 0 0 0 0 0 0 0 0 0 1]
885 B
= self
.parent().natural_basis()
886 W
= B
[0].matrix_space()
887 return W
.linear_combination(zip(self
.vector(), B
))
890 def operator_matrix(self
):
892 Return the matrix that represents left- (or right-)
893 multiplication by this element in the parent algebra.
895 We have to override this because the superclass method
896 returns a matrix that acts on row vectors (that is, on
901 Test the first polarization identity from my notes, Koecher Chapter
902 III, or from Baes (2.3)::
904 sage: set_random_seed()
905 sage: J = random_eja()
906 sage: x = J.random_element()
907 sage: y = J.random_element()
908 sage: Lx = x.operator_matrix()
909 sage: Ly = y.operator_matrix()
910 sage: Lxx = (x*x).operator_matrix()
911 sage: Lxy = (x*y).operator_matrix()
912 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
915 Test the second polarization identity from my notes or from
918 sage: set_random_seed()
919 sage: J = random_eja()
920 sage: x = J.random_element()
921 sage: y = J.random_element()
922 sage: z = J.random_element()
923 sage: Lx = x.operator_matrix()
924 sage: Ly = y.operator_matrix()
925 sage: Lz = z.operator_matrix()
926 sage: Lzy = (z*y).operator_matrix()
927 sage: Lxy = (x*y).operator_matrix()
928 sage: Lxz = (x*z).operator_matrix()
929 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
932 Test the third polarization identity from my notes or from
935 sage: set_random_seed()
936 sage: J = random_eja()
937 sage: u = J.random_element()
938 sage: y = J.random_element()
939 sage: z = J.random_element()
940 sage: Lu = u.operator_matrix()
941 sage: Ly = y.operator_matrix()
942 sage: Lz = z.operator_matrix()
943 sage: Lzy = (z*y).operator_matrix()
944 sage: Luy = (u*y).operator_matrix()
945 sage: Luz = (u*z).operator_matrix()
946 sage: Luyz = (u*(y*z)).operator_matrix()
947 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
948 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
949 sage: bool(lhs == rhs)
953 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
954 return fda_elt
.matrix().transpose()
957 def quadratic_representation(self
, other
=None):
959 Return the quadratic representation of this element.
963 The explicit form in the spin factor algebra is given by
964 Alizadeh's Example 11.12::
966 sage: set_random_seed()
967 sage: n = ZZ.random_element(1,10)
968 sage: J = JordanSpinEJA(n)
969 sage: x = J.random_element()
970 sage: x_vec = x.vector()
972 sage: x_bar = x_vec[1:]
973 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
974 sage: B = 2*x0*x_bar.row()
975 sage: C = 2*x0*x_bar.column()
976 sage: D = identity_matrix(QQ, n-1)
977 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
978 sage: D = D + 2*x_bar.tensor_product(x_bar)
979 sage: Q = block_matrix(2,2,[A,B,C,D])
980 sage: Q == x.quadratic_representation()
983 Test all of the properties from Theorem 11.2 in Alizadeh::
985 sage: set_random_seed()
986 sage: J = random_eja()
987 sage: x = J.random_element()
988 sage: y = J.random_element()
992 sage: actual = x.quadratic_representation(y)
993 sage: expected = ( (x+y).quadratic_representation()
994 ....: -x.quadratic_representation()
995 ....: -y.quadratic_representation() ) / 2
996 sage: actual == expected
1001 sage: alpha = QQ.random_element()
1002 sage: actual = (alpha*x).quadratic_representation()
1003 sage: expected = (alpha^2)*x.quadratic_representation()
1004 sage: actual == expected
1009 sage: Qy = y.quadratic_representation()
1010 sage: actual = J(Qy*x.vector()).quadratic_representation()
1011 sage: expected = Qy*x.quadratic_representation()*Qy
1012 sage: actual == expected
1017 sage: k = ZZ.random_element(1,10)
1018 sage: actual = (x^k).quadratic_representation()
1019 sage: expected = (x.quadratic_representation())^k
1020 sage: actual == expected
1026 elif not other
in self
.parent():
1027 raise TypeError("'other' must live in the same algebra")
1029 L
= self
.operator_matrix()
1030 M
= other
.operator_matrix()
1031 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
1034 def span_of_powers(self
):
1036 Return the vector space spanned by successive powers of
1039 # The dimension of the subalgebra can't be greater than
1040 # the big algebra, so just put everything into a list
1041 # and let span() get rid of the excess.
1043 # We do the extra ambient_vector_space() in case we're messing
1044 # with polynomials and the direct parent is a module.
1045 V
= self
.vector().parent().ambient_vector_space()
1046 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1049 def subalgebra_generated_by(self
):
1051 Return the associative subalgebra of the parent EJA generated
1056 sage: set_random_seed()
1057 sage: x = random_eja().random_element()
1058 sage: x.subalgebra_generated_by().is_associative()
1061 Squaring in the subalgebra should be the same thing as
1062 squaring in the superalgebra::
1064 sage: set_random_seed()
1065 sage: x = random_eja().random_element()
1066 sage: u = x.subalgebra_generated_by().random_element()
1067 sage: u.operator_matrix()*u.vector() == (u**2).vector()
1071 # First get the subspace spanned by the powers of myself...
1072 V
= self
.span_of_powers()
1073 F
= self
.base_ring()
1075 # Now figure out the entries of the right-multiplication
1076 # matrix for the successive basis elements b0, b1,... of
1079 for b_right
in V
.basis():
1080 eja_b_right
= self
.parent()(b_right
)
1082 # The first row of the right-multiplication matrix by
1083 # b1 is what we get if we apply that matrix to b1. The
1084 # second row of the right multiplication matrix by b1
1085 # is what we get when we apply that matrix to b2...
1087 # IMPORTANT: this assumes that all vectors are COLUMN
1088 # vectors, unlike our superclass (which uses row vectors).
1089 for b_left
in V
.basis():
1090 eja_b_left
= self
.parent()(b_left
)
1091 # Multiply in the original EJA, but then get the
1092 # coordinates from the subalgebra in terms of its
1094 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1095 b_right_rows
.append(this_row
)
1096 b_right_matrix
= matrix(F
, b_right_rows
)
1097 mats
.append(b_right_matrix
)
1099 # It's an algebra of polynomials in one element, and EJAs
1100 # are power-associative.
1102 # TODO: choose generator names intelligently.
1103 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
1106 def subalgebra_idempotent(self
):
1108 Find an idempotent in the associative subalgebra I generate
1109 using Proposition 2.3.5 in Baes.
1113 sage: set_random_seed()
1114 sage: J = RealCartesianProductEJA(5)
1115 sage: c = J.random_element().subalgebra_idempotent()
1118 sage: J = JordanSpinEJA(5)
1119 sage: c = J.random_element().subalgebra_idempotent()
1124 if self
.is_nilpotent():
1125 raise ValueError("this only works with non-nilpotent elements!")
1127 V
= self
.span_of_powers()
1128 J
= self
.subalgebra_generated_by()
1129 # Mis-design warning: the basis used for span_of_powers()
1130 # and subalgebra_generated_by() must be the same, and in
1132 u
= J(V
.coordinates(self
.vector()))
1134 # The image of the matrix of left-u^m-multiplication
1135 # will be minimal for some natural number s...
1137 minimal_dim
= V
.dimension()
1138 for i
in xrange(1, V
.dimension()):
1139 this_dim
= (u
**i
).operator_matrix().image().dimension()
1140 if this_dim
< minimal_dim
:
1141 minimal_dim
= this_dim
1144 # Now minimal_matrix should correspond to the smallest
1145 # non-zero subspace in Baes's (or really, Koecher's)
1148 # However, we need to restrict the matrix to work on the
1149 # subspace... or do we? Can't we just solve, knowing that
1150 # A(c) = u^(s+1) should have a solution in the big space,
1153 # Beware, solve_right() means that we're using COLUMN vectors.
1154 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1156 A
= u_next
.operator_matrix()
1157 c_coordinates
= A
.solve_right(u_next
.vector())
1159 # Now c_coordinates is the idempotent we want, but it's in
1160 # the coordinate system of the subalgebra.
1162 # We need the basis for J, but as elements of the parent algebra.
1164 basis
= [self
.parent(v
) for v
in V
.basis()]
1165 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1170 Return my trace, the sum of my eigenvalues.
1174 sage: J = JordanSpinEJA(3)
1175 sage: e0,e1,e2 = J.gens()
1176 sage: x = e0 + e1 + e2
1181 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
1185 raise ValueError('charpoly had fewer than 2 coefficients')
1188 def trace_inner_product(self
, other
):
1190 Return the trace inner product of myself and ``other``.
1192 if not other
in self
.parent():
1193 raise TypeError("'other' must live in the same algebra")
1195 return (self
*other
).trace()
1198 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1200 Return the Euclidean Jordan Algebra corresponding to the set
1201 `R^n` under the Hadamard product.
1203 Note: this is nothing more than the Cartesian product of ``n``
1204 copies of the spin algebra. Once Cartesian product algebras
1205 are implemented, this can go.
1209 This multiplication table can be verified by hand::
1211 sage: J = RealCartesianProductEJA(3)
1212 sage: e0,e1,e2 = J.gens()
1228 def __classcall_private__(cls
, n
, field
=QQ
):
1229 # The FiniteDimensionalAlgebra constructor takes a list of
1230 # matrices, the ith representing right multiplication by the ith
1231 # basis element in the vector space. So if e_1 = (1,0,0), then
1232 # right (Hadamard) multiplication of x by e_1 picks out the first
1233 # component of x; and likewise for the ith basis element e_i.
1234 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1235 for i
in xrange(n
) ]
1237 fdeja
= super(RealCartesianProductEJA
, cls
)
1238 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1240 def inner_product(self
, x
, y
):
1241 return _usual_ip(x
,y
)
1246 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1250 For now, we choose a random natural number ``n`` (greater than zero)
1251 and then give you back one of the following:
1253 * The cartesian product of the rational numbers ``n`` times; this is
1254 ``QQ^n`` with the Hadamard product.
1256 * The Jordan spin algebra on ``QQ^n``.
1258 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1261 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1262 in the space of ``2n``-by-``2n`` real symmetric matrices.
1264 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1265 in the space of ``4n``-by-``4n`` real symmetric matrices.
1267 Later this might be extended to return Cartesian products of the
1273 Euclidean Jordan algebra of degree...
1277 # The max_n component lets us choose different upper bounds on the
1278 # value "n" that gets passed to the constructor. This is needed
1279 # because e.g. R^{10} is reasonable to test, while the Hermitian
1280 # 10-by-10 quaternion matrices are not.
1281 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1283 (RealSymmetricEJA
, 5),
1284 (ComplexHermitianEJA
, 4),
1285 (QuaternionHermitianEJA
, 3)])
1286 n
= ZZ
.random_element(1, max_n
)
1287 return constructor(n
, field
=QQ
)
1291 def _real_symmetric_basis(n
, field
=QQ
):
1293 Return a basis for the space of real symmetric n-by-n matrices.
1295 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1299 for j
in xrange(i
+1):
1300 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1304 # Beware, orthogonal but not normalized!
1305 Sij
= Eij
+ Eij
.transpose()
1310 def _complex_hermitian_basis(n
, field
=QQ
):
1312 Returns a basis for the space of complex Hermitian n-by-n matrices.
1316 sage: set_random_seed()
1317 sage: n = ZZ.random_element(1,5)
1318 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1322 F
= QuadraticField(-1, 'I')
1325 # This is like the symmetric case, but we need to be careful:
1327 # * We want conjugate-symmetry, not just symmetry.
1328 # * The diagonal will (as a result) be real.
1332 for j
in xrange(i
+1):
1333 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1335 Sij
= _embed_complex_matrix(Eij
)
1338 # Beware, orthogonal but not normalized! The second one
1339 # has a minus because it's conjugated.
1340 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1342 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1347 def _quaternion_hermitian_basis(n
, field
=QQ
):
1349 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1353 sage: set_random_seed()
1354 sage: n = ZZ.random_element(1,5)
1355 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1359 Q
= QuaternionAlgebra(QQ
,-1,-1)
1362 # This is like the symmetric case, but we need to be careful:
1364 # * We want conjugate-symmetry, not just symmetry.
1365 # * The diagonal will (as a result) be real.
1369 for j
in xrange(i
+1):
1370 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1372 Sij
= _embed_quaternion_matrix(Eij
)
1375 # Beware, orthogonal but not normalized! The second,
1376 # third, and fourth ones have a minus because they're
1378 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1380 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1382 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1384 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1390 return vector(m
.base_ring(), m
.list())
1393 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1395 def _multiplication_table_from_matrix_basis(basis
):
1397 At least three of the five simple Euclidean Jordan algebras have the
1398 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1399 multiplication on the right is matrix multiplication. Given a basis
1400 for the underlying matrix space, this function returns a
1401 multiplication table (obtained by looping through the basis
1402 elements) for an algebra of those matrices. A reordered copy
1403 of the basis is also returned to work around the fact that
1404 the ``span()`` in this function will change the order of the basis
1405 from what we think it is, to... something else.
1407 # In S^2, for example, we nominally have four coordinates even
1408 # though the space is of dimension three only. The vector space V
1409 # is supposed to hold the entire long vector, and the subspace W
1410 # of V will be spanned by the vectors that arise from symmetric
1411 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1412 field
= basis
[0].base_ring()
1413 dimension
= basis
[0].nrows()
1415 V
= VectorSpace(field
, dimension
**2)
1416 W
= V
.span( _mat2vec(s
) for s
in basis
)
1418 # Taking the span above reorders our basis (thanks, jerk!) so we
1419 # need to put our "matrix basis" in the same order as the
1420 # (reordered) vector basis.
1421 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1425 # Brute force the multiplication-by-s matrix by looping
1426 # through all elements of the basis and doing the computation
1427 # to find out what the corresponding row should be. BEWARE:
1428 # these multiplication tables won't be symmetric! It therefore
1429 # becomes REALLY IMPORTANT that the underlying algebra
1430 # constructor uses ROW vectors and not COLUMN vectors. That's
1431 # why we're computing rows here and not columns.
1434 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1435 Q_rows
.append(W
.coordinates(this_row
))
1436 Q
= matrix(field
, W
.dimension(), Q_rows
)
1442 def _embed_complex_matrix(M
):
1444 Embed the n-by-n complex matrix ``M`` into the space of real
1445 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1446 bi` to the block matrix ``[[a,b],[-b,a]]``.
1450 sage: F = QuadraticField(-1,'i')
1451 sage: x1 = F(4 - 2*i)
1452 sage: x2 = F(1 + 2*i)
1455 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1456 sage: _embed_complex_matrix(M)
1465 Embedding is a homomorphism (isomorphism, in fact)::
1467 sage: set_random_seed()
1468 sage: n = ZZ.random_element(5)
1469 sage: F = QuadraticField(-1, 'i')
1470 sage: X = random_matrix(F, n)
1471 sage: Y = random_matrix(F, n)
1472 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1473 sage: expected = _embed_complex_matrix(X*Y)
1474 sage: actual == expected
1480 raise ValueError("the matrix 'M' must be square")
1481 field
= M
.base_ring()
1486 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1488 # We can drop the imaginaries here.
1489 return block_matrix(field
.base_ring(), n
, blocks
)
1492 def _unembed_complex_matrix(M
):
1494 The inverse of _embed_complex_matrix().
1498 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1499 ....: [-2, 1, -4, 3],
1500 ....: [ 9, 10, 11, 12],
1501 ....: [-10, 9, -12, 11] ])
1502 sage: _unembed_complex_matrix(A)
1504 [ 10*i + 9 12*i + 11]
1508 Unembedding is the inverse of embedding::
1510 sage: set_random_seed()
1511 sage: F = QuadraticField(-1, 'i')
1512 sage: M = random_matrix(F, 3)
1513 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1519 raise ValueError("the matrix 'M' must be square")
1520 if not n
.mod(2).is_zero():
1521 raise ValueError("the matrix 'M' must be a complex embedding")
1523 F
= QuadraticField(-1, 'i')
1526 # Go top-left to bottom-right (reading order), converting every
1527 # 2-by-2 block we see to a single complex element.
1529 for k
in xrange(n
/2):
1530 for j
in xrange(n
/2):
1531 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1532 if submat
[0,0] != submat
[1,1]:
1533 raise ValueError('bad on-diagonal submatrix')
1534 if submat
[0,1] != -submat
[1,0]:
1535 raise ValueError('bad off-diagonal submatrix')
1536 z
= submat
[0,0] + submat
[0,1]*i
1539 return matrix(F
, n
/2, elements
)
1542 def _embed_quaternion_matrix(M
):
1544 Embed the n-by-n quaternion matrix ``M`` into the space of real
1545 matrices of size 4n-by-4n by first sending each quaternion entry
1546 `z = a + bi + cj + dk` to the block-complex matrix
1547 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1552 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1553 sage: i,j,k = Q.gens()
1554 sage: x = 1 + 2*i + 3*j + 4*k
1555 sage: M = matrix(Q, 1, [[x]])
1556 sage: _embed_quaternion_matrix(M)
1562 Embedding is a homomorphism (isomorphism, in fact)::
1564 sage: set_random_seed()
1565 sage: n = ZZ.random_element(5)
1566 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1567 sage: X = random_matrix(Q, n)
1568 sage: Y = random_matrix(Q, n)
1569 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1570 sage: expected = _embed_quaternion_matrix(X*Y)
1571 sage: actual == expected
1575 quaternions
= M
.base_ring()
1578 raise ValueError("the matrix 'M' must be square")
1580 F
= QuadraticField(-1, 'i')
1585 t
= z
.coefficient_tuple()
1590 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1591 [-c
+ d
*i
, a
- b
*i
]])
1592 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1594 # We should have real entries by now, so use the realest field
1595 # we've got for the return value.
1596 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1599 def _unembed_quaternion_matrix(M
):
1601 The inverse of _embed_quaternion_matrix().
1605 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1606 ....: [-2, 1, -4, 3],
1607 ....: [-3, 4, 1, -2],
1608 ....: [-4, -3, 2, 1]])
1609 sage: _unembed_quaternion_matrix(M)
1610 [1 + 2*i + 3*j + 4*k]
1614 Unembedding is the inverse of embedding::
1616 sage: set_random_seed()
1617 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1618 sage: M = random_matrix(Q, 3)
1619 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1625 raise ValueError("the matrix 'M' must be square")
1626 if not n
.mod(4).is_zero():
1627 raise ValueError("the matrix 'M' must be a complex embedding")
1629 Q
= QuaternionAlgebra(QQ
,-1,-1)
1632 # Go top-left to bottom-right (reading order), converting every
1633 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1636 for l
in xrange(n
/4):
1637 for m
in xrange(n
/4):
1638 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1639 if submat
[0,0] != submat
[1,1].conjugate():
1640 raise ValueError('bad on-diagonal submatrix')
1641 if submat
[0,1] != -submat
[1,0].conjugate():
1642 raise ValueError('bad off-diagonal submatrix')
1643 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1644 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1647 return matrix(Q
, n
/4, elements
)
1650 # The usual inner product on R^n.
1652 return x
.vector().inner_product(y
.vector())
1654 # The inner product used for the real symmetric simple EJA.
1655 # We keep it as a separate function because e.g. the complex
1656 # algebra uses the same inner product, except divided by 2.
1657 def _matrix_ip(X
,Y
):
1658 X_mat
= X
.natural_representation()
1659 Y_mat
= Y
.natural_representation()
1660 return (X_mat
*Y_mat
).trace()
1663 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1665 The rank-n simple EJA consisting of real symmetric n-by-n
1666 matrices, the usual symmetric Jordan product, and the trace inner
1667 product. It has dimension `(n^2 + n)/2` over the reals.
1671 sage: J = RealSymmetricEJA(2)
1672 sage: e0, e1, e2 = J.gens()
1682 The degree of this algebra is `(n^2 + n) / 2`::
1684 sage: set_random_seed()
1685 sage: n = ZZ.random_element(1,5)
1686 sage: J = RealSymmetricEJA(n)
1687 sage: J.degree() == (n^2 + n)/2
1690 The Jordan multiplication is what we think it is::
1692 sage: set_random_seed()
1693 sage: n = ZZ.random_element(1,5)
1694 sage: J = RealSymmetricEJA(n)
1695 sage: x = J.random_element()
1696 sage: y = J.random_element()
1697 sage: actual = (x*y).natural_representation()
1698 sage: X = x.natural_representation()
1699 sage: Y = y.natural_representation()
1700 sage: expected = (X*Y + Y*X)/2
1701 sage: actual == expected
1703 sage: J(expected) == x*y
1708 def __classcall_private__(cls
, n
, field
=QQ
):
1709 S
= _real_symmetric_basis(n
, field
=field
)
1710 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1712 fdeja
= super(RealSymmetricEJA
, cls
)
1713 return fdeja
.__classcall
_private
__(cls
,
1719 def inner_product(self
, x
, y
):
1720 return _matrix_ip(x
,y
)
1723 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1725 The rank-n simple EJA consisting of complex Hermitian n-by-n
1726 matrices over the real numbers, the usual symmetric Jordan product,
1727 and the real-part-of-trace inner product. It has dimension `n^2` over
1732 The degree of this algebra is `n^2`::
1734 sage: set_random_seed()
1735 sage: n = ZZ.random_element(1,5)
1736 sage: J = ComplexHermitianEJA(n)
1737 sage: J.degree() == n^2
1740 The Jordan multiplication is what we think it is::
1742 sage: set_random_seed()
1743 sage: n = ZZ.random_element(1,5)
1744 sage: J = ComplexHermitianEJA(n)
1745 sage: x = J.random_element()
1746 sage: y = J.random_element()
1747 sage: actual = (x*y).natural_representation()
1748 sage: X = x.natural_representation()
1749 sage: Y = y.natural_representation()
1750 sage: expected = (X*Y + Y*X)/2
1751 sage: actual == expected
1753 sage: J(expected) == x*y
1758 def __classcall_private__(cls
, n
, field
=QQ
):
1759 S
= _complex_hermitian_basis(n
)
1760 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1762 fdeja
= super(ComplexHermitianEJA
, cls
)
1763 return fdeja
.__classcall
_private
__(cls
,
1769 def inner_product(self
, x
, y
):
1770 # Since a+bi on the diagonal is represented as
1775 # we'll double-count the "a" entries if we take the trace of
1777 return _matrix_ip(x
,y
)/2
1780 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1782 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1783 matrices, the usual symmetric Jordan product, and the
1784 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1789 The degree of this algebra is `n^2`::
1791 sage: set_random_seed()
1792 sage: n = ZZ.random_element(1,5)
1793 sage: J = QuaternionHermitianEJA(n)
1794 sage: J.degree() == 2*(n^2) - n
1797 The Jordan multiplication is what we think it is::
1799 sage: set_random_seed()
1800 sage: n = ZZ.random_element(1,5)
1801 sage: J = QuaternionHermitianEJA(n)
1802 sage: x = J.random_element()
1803 sage: y = J.random_element()
1804 sage: actual = (x*y).natural_representation()
1805 sage: X = x.natural_representation()
1806 sage: Y = y.natural_representation()
1807 sage: expected = (X*Y + Y*X)/2
1808 sage: actual == expected
1810 sage: J(expected) == x*y
1815 def __classcall_private__(cls
, n
, field
=QQ
):
1816 S
= _quaternion_hermitian_basis(n
)
1817 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1819 fdeja
= super(QuaternionHermitianEJA
, cls
)
1820 return fdeja
.__classcall
_private
__(cls
,
1826 def inner_product(self
, x
, y
):
1827 # Since a+bi+cj+dk on the diagonal is represented as
1829 # a + bi +cj + dk = [ a b c d]
1834 # we'll quadruple-count the "a" entries if we take the trace of
1836 return _matrix_ip(x
,y
)/4
1839 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1841 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1842 with the usual inner product and jordan product ``x*y =
1843 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1848 This multiplication table can be verified by hand::
1850 sage: J = JordanSpinEJA(4)
1851 sage: e0,e1,e2,e3 = J.gens()
1869 def __classcall_private__(cls
, n
, field
=QQ
):
1871 id_matrix
= identity_matrix(field
, n
)
1873 ei
= id_matrix
.column(i
)
1874 Qi
= zero_matrix(field
, n
)
1876 Qi
.set_column(0, ei
)
1877 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
1878 # The addition of the diagonal matrix adds an extra ei[0] in the
1879 # upper-left corner of the matrix.
1880 Qi
[0,0] = Qi
[0,0] * ~
field(2)
1883 # The rank of the spin algebra is two, unless we're in a
1884 # one-dimensional ambient space (because the rank is bounded by
1885 # the ambient dimension).
1886 fdeja
= super(JordanSpinEJA
, cls
)
1887 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
1889 def inner_product(self
, x
, y
):
1890 return _usual_ip(x
,y
)