2 Euclidean Jordan Algebras. These are formally-real Jordan Algebras;
3 specifically those where u^2 + v^2 = 0 implies that u = v = 0. They
4 are used in optimization, and have some additional nice methods beyond
5 what can be supported in a general Jordan Algebra.
8 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
9 from sage
.structure
.element
import is_Matrix
10 from sage
.structure
.category_object
import normalize_names
12 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra
import FiniteDimensionalAlgebra
13 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_element
import FiniteDimensionalAlgebraElement
15 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
17 def __classcall_private__(cls
,
21 assume_associative
=False,
26 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
29 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
30 raise ValueError("input is not a multiplication table")
31 mult_table
= tuple(mult_table
)
33 cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
34 cat
.or_subcategory(category
)
35 if assume_associative
:
36 cat
= cat
.Associative()
38 names
= normalize_names(n
, names
)
40 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
41 return fda
.__classcall
__(cls
,
44 assume_associative
=assume_associative
,
48 natural_basis
=natural_basis
)
55 assume_associative
=False,
62 By definition, Jordan multiplication commutes::
64 sage: set_random_seed()
65 sage: J = random_eja()
66 sage: x = J.random_element()
67 sage: y = J.random_element()
73 self
._natural
_basis
= natural_basis
74 self
._multiplication
_table
= mult_table
75 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
84 Return a string representation of ``self``.
86 fmt
= "Euclidean Jordan algebra of degree {} over {}"
87 return fmt
.format(self
.degree(), self
.base_ring())
92 def _charpoly_coeff(self
, i
):
94 Return the coefficient polynomial "a_{i}" of this algebra's
95 general characteristic polynomial.
97 Having this be a separate cached method lets us compute and
98 store the trace/determinant (a_{r-1} and a_{0} respectively)
99 separate from the entire characteristic polynomial.
101 (A_of_x
, x
) = self
._charpoly
_matrix
()
102 R
= A_of_x
.base_ring()
103 A_cols
= A_of_x
.columns()
104 A_cols
[i
] = (x
**self
.rank()).vector()
105 numerator
= column_matrix(A_of_x
.base_ring(), A_cols
).det()
106 denominator
= A_of_x
.det()
108 # We're relying on the theory here to ensure that each a_i is
109 # indeed back in R, and the added negative signs are to make
110 # the whole charpoly expression sum to zero.
111 return R(-numerator
/denominator
)
115 def _charpoly_matrix(self
):
117 Compute the matrix whose entries A_ij are polynomials in
118 X1,...,XN. This same matrix is used in more than one method and
119 it's not so fast to construct.
124 # Construct a new algebra over a multivariate polynomial ring...
125 names
= ['X' + str(i
) for i
in range(1,n
+1)]
126 R
= PolynomialRing(self
.base_ring(), names
)
127 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
128 self
._multiplication
_table
,
131 idmat
= identity_matrix(J
.base_ring(), n
)
133 x
= J(vector(R
, R
.gens()))
134 l1
= [column_matrix((x
**k
).vector()) for k
in range(r
)]
135 l2
= [idmat
.column(k
-1).column() for k
in range(r
+1, n
+1)]
136 A_of_x
= block_matrix(R
, 1, n
, (l1
+ l2
))
141 def characteristic_polynomial(self
):
145 The characteristic polynomial in the spin algebra is given in
146 Alizadeh, Example 11.11::
148 sage: J = JordanSpinEJA(3)
149 sage: p = J.characteristic_polynomial(); p
150 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
151 sage: xvec = J.one().vector()
159 # The list of coefficient polynomials a_1, a_2, ..., a_n.
160 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
162 # We go to a bit of trouble here to reorder the
163 # indeterminates, so that it's easier to evaluate the
164 # characteristic polynomial at x's coordinates and get back
165 # something in terms of t, which is what we want.
167 S
= PolynomialRing(self
.base_ring(),'t')
169 S
= PolynomialRing(S
, R
.variable_names())
172 # Note: all entries past the rth should be zero. The
173 # coefficient of the highest power (x^r) is 1, but it doesn't
174 # appear in the solution vector which contains coefficients
175 # for the other powers (to make them sum to x^r).
177 a
[r
] = 1 # corresponds to x^r
179 # When the rank is equal to the dimension, trying to
180 # assign a[r] goes out-of-bounds.
181 a
.append(1) # corresponds to x^r
183 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
186 def inner_product(self
, x
, y
):
188 The inner product associated with this Euclidean Jordan algebra.
190 Defaults to the trace inner product, but can be overridden by
191 subclasses if they are sure that the necessary properties are
196 The inner product must satisfy its axiom for this algebra to truly
197 be a Euclidean Jordan Algebra::
199 sage: set_random_seed()
200 sage: J = random_eja()
201 sage: x = J.random_element()
202 sage: y = J.random_element()
203 sage: z = J.random_element()
204 sage: (x*y).inner_product(z) == y.inner_product(x*z)
208 if (not x
in self
) or (not y
in self
):
209 raise TypeError("arguments must live in this algebra")
210 return x
.trace_inner_product(y
)
213 def natural_basis(self
):
215 Return a more-natural representation of this algebra's basis.
217 Every finite-dimensional Euclidean Jordan Algebra is a direct
218 sum of five simple algebras, four of which comprise Hermitian
219 matrices. This method returns the original "natural" basis
220 for our underlying vector space. (Typically, the natural basis
221 is used to construct the multiplication table in the first place.)
223 Note that this will always return a matrix. The standard basis
224 in `R^n` will be returned as `n`-by-`1` column matrices.
228 sage: J = RealSymmetricEJA(2)
231 sage: J.natural_basis()
239 sage: J = JordanSpinEJA(2)
242 sage: J.natural_basis()
249 if self
._natural
_basis
is None:
250 return tuple( b
.vector().column() for b
in self
.basis() )
252 return self
._natural
_basis
257 Return the rank of this EJA.
259 if self
._rank
is None:
260 raise ValueError("no rank specified at genesis")
265 class Element(FiniteDimensionalAlgebraElement
):
267 An element of a Euclidean Jordan algebra.
270 def __init__(self
, A
, elt
=None):
274 The identity in `S^n` is converted to the identity in the EJA::
276 sage: J = RealSymmetricEJA(3)
277 sage: I = identity_matrix(QQ,3)
278 sage: J(I) == J.one()
281 This skew-symmetric matrix can't be represented in the EJA::
283 sage: J = RealSymmetricEJA(3)
284 sage: A = matrix(QQ,3, lambda i,j: i-j)
286 Traceback (most recent call last):
288 ArithmeticError: vector is not in free module
291 # Goal: if we're given a matrix, and if it lives in our
292 # parent algebra's "natural ambient space," convert it
293 # into an algebra element.
295 # The catch is, we make a recursive call after converting
296 # the given matrix into a vector that lives in the algebra.
297 # This we need to try the parent class initializer first,
298 # to avoid recursing forever if we're given something that
299 # already fits into the algebra, but also happens to live
300 # in the parent's "natural ambient space" (this happens with
303 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
305 natural_basis
= A
.natural_basis()
306 if elt
in natural_basis
[0].matrix_space():
307 # Thanks for nothing! Matrix spaces aren't vector
308 # spaces in Sage, so we have to figure out its
309 # natural-basis coordinates ourselves.
310 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
311 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
312 coords
= W
.coordinates(_mat2vec(elt
))
313 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
315 def __pow__(self
, n
):
317 Return ``self`` raised to the power ``n``.
319 Jordan algebras are always power-associative; see for
320 example Faraut and Koranyi, Proposition II.1.2 (ii).
324 We have to override this because our superclass uses row vectors
325 instead of column vectors! We, on the other hand, assume column
330 sage: set_random_seed()
331 sage: x = random_eja().random_element()
332 sage: x.operator_matrix()*x.vector() == (x^2).vector()
335 A few examples of power-associativity::
337 sage: set_random_seed()
338 sage: x = random_eja().random_element()
339 sage: x*(x*x)*(x*x) == x^5
341 sage: (x*x)*(x*x*x) == x^5
344 We also know that powers operator-commute (Koecher, Chapter
347 sage: set_random_seed()
348 sage: x = random_eja().random_element()
349 sage: m = ZZ.random_element(0,10)
350 sage: n = ZZ.random_element(0,10)
351 sage: Lxm = (x^m).operator_matrix()
352 sage: Lxn = (x^n).operator_matrix()
353 sage: Lxm*Lxn == Lxn*Lxm
363 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
366 def apply_univariate_polynomial(self
, p
):
368 Apply the univariate polynomial ``p`` to this element.
370 A priori, SageMath won't allow us to apply a univariate
371 polynomial to an element of an EJA, because we don't know
372 that EJAs are rings (they are usually not associative). Of
373 course, we know that EJAs are power-associative, so the
374 operation is ultimately kosher. This function sidesteps
375 the CAS to get the answer we want and expect.
379 sage: R = PolynomialRing(QQ, 't')
381 sage: p = t^4 - t^3 + 5*t - 2
382 sage: J = RealCartesianProductEJA(5)
383 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
388 We should always get back an element of the algebra::
390 sage: set_random_seed()
391 sage: p = PolynomialRing(QQ, 't').random_element()
392 sage: J = random_eja()
393 sage: x = J.random_element()
394 sage: x.apply_univariate_polynomial(p) in J
398 if len(p
.variables()) > 1:
399 raise ValueError("not a univariate polynomial")
402 # Convert the coeficcients to the parent's base ring,
403 # because a priori they might live in an (unnecessarily)
404 # larger ring for which P.sum() would fail below.
405 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
406 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
409 def characteristic_polynomial(self
):
411 Return the characteristic polynomial of this element.
415 The rank of `R^3` is three, and the minimal polynomial of
416 the identity element is `(t-1)` from which it follows that
417 the characteristic polynomial should be `(t-1)^3`::
419 sage: J = RealCartesianProductEJA(3)
420 sage: J.one().characteristic_polynomial()
421 t^3 - 3*t^2 + 3*t - 1
423 Likewise, the characteristic of the zero element in the
424 rank-three algebra `R^{n}` should be `t^{3}`::
426 sage: J = RealCartesianProductEJA(3)
427 sage: J.zero().characteristic_polynomial()
430 The characteristic polynomial of an element should evaluate
431 to zero on that element::
433 sage: set_random_seed()
434 sage: x = RealCartesianProductEJA(3).random_element()
435 sage: p = x.characteristic_polynomial()
436 sage: x.apply_univariate_polynomial(p)
440 p
= self
.parent().characteristic_polynomial()
441 return p(*self
.vector())
444 def inner_product(self
, other
):
446 Return the parent algebra's inner product of myself and ``other``.
450 The inner product in the Jordan spin algebra is the usual
451 inner product on `R^n` (this example only works because the
452 basis for the Jordan algebra is the standard basis in `R^n`)::
454 sage: J = JordanSpinEJA(3)
455 sage: x = vector(QQ,[1,2,3])
456 sage: y = vector(QQ,[4,5,6])
457 sage: x.inner_product(y)
459 sage: J(x).inner_product(J(y))
462 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
463 multiplication is the usual matrix multiplication in `S^n`,
464 so the inner product of the identity matrix with itself
467 sage: J = RealSymmetricEJA(3)
468 sage: J.one().inner_product(J.one())
471 Likewise, the inner product on `C^n` is `<X,Y> =
472 Re(trace(X*Y))`, where we must necessarily take the real
473 part because the product of Hermitian matrices may not be
476 sage: J = ComplexHermitianEJA(3)
477 sage: J.one().inner_product(J.one())
480 Ditto for the quaternions::
482 sage: J = QuaternionHermitianEJA(3)
483 sage: J.one().inner_product(J.one())
488 Ensure that we can always compute an inner product, and that
489 it gives us back a real number::
491 sage: set_random_seed()
492 sage: J = random_eja()
493 sage: x = J.random_element()
494 sage: y = J.random_element()
495 sage: x.inner_product(y) in RR
501 raise TypeError("'other' must live in the same algebra")
503 return P
.inner_product(self
, other
)
506 def operator_commutes_with(self
, other
):
508 Return whether or not this element operator-commutes
513 The definition of a Jordan algebra says that any element
514 operator-commutes with its square::
516 sage: set_random_seed()
517 sage: x = random_eja().random_element()
518 sage: x.operator_commutes_with(x^2)
523 Test Lemma 1 from Chapter III of Koecher::
525 sage: set_random_seed()
526 sage: J = random_eja()
527 sage: u = J.random_element()
528 sage: v = J.random_element()
529 sage: lhs = u.operator_commutes_with(u*v)
530 sage: rhs = v.operator_commutes_with(u^2)
535 if not other
in self
.parent():
536 raise TypeError("'other' must live in the same algebra")
538 A
= self
.operator_matrix()
539 B
= other
.operator_matrix()
545 Return my determinant, the product of my eigenvalues.
549 sage: J = JordanSpinEJA(2)
550 sage: e0,e1 = J.gens()
551 sage: x = sum( J.gens() )
557 sage: J = JordanSpinEJA(3)
558 sage: e0,e1,e2 = J.gens()
559 sage: x = sum( J.gens() )
565 An element is invertible if and only if its determinant is
568 sage: set_random_seed()
569 sage: x = random_eja().random_element()
570 sage: x.is_invertible() == (x.det() != 0)
576 p
= P
._charpoly
_coeff
(0)
577 # The _charpoly_coeff function already adds the factor of
578 # -1 to ensure that _charpoly_coeff(0) is really what
579 # appears in front of t^{0} in the charpoly. However,
580 # we want (-1)^r times THAT for the determinant.
581 return ((-1)**r
)*p(*self
.vector())
586 Return the Jordan-multiplicative inverse of this element.
588 We can't use the superclass method because it relies on the
589 algebra being associative.
593 The inverse in the spin factor algebra is given in Alizadeh's
596 sage: set_random_seed()
597 sage: n = ZZ.random_element(1,10)
598 sage: J = JordanSpinEJA(n)
599 sage: x = J.random_element()
600 sage: while x.is_zero():
601 ....: x = J.random_element()
602 sage: x_vec = x.vector()
604 sage: x_bar = x_vec[1:]
605 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
606 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
607 sage: x_inverse = coeff*inv_vec
608 sage: x.inverse() == J(x_inverse)
613 The identity element is its own inverse::
615 sage: set_random_seed()
616 sage: J = random_eja()
617 sage: J.one().inverse() == J.one()
620 If an element has an inverse, it acts like one::
622 sage: set_random_seed()
623 sage: J = random_eja()
624 sage: x = J.random_element()
625 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
629 if self
.parent().is_associative():
630 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
633 # TODO: we can do better once the call to is_invertible()
634 # doesn't crash on irregular elements.
635 #if not self.is_invertible():
636 # raise ValueError('element is not invertible')
638 # We do this a little different than the usual recursive
639 # call to a finite-dimensional algebra element, because we
640 # wind up with an inverse that lives in the subalgebra and
641 # we need information about the parent to convert it back.
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 # This will be in the subalgebra's coordinates...
650 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
651 subalg_inverse
= fda_elt
.inverse()
653 # So we have to convert back...
654 basis
= [ self
.parent(v
) for v
in V
.basis() ]
655 pairs
= zip(subalg_inverse
.vector(), basis
)
656 return self
.parent().linear_combination(pairs
)
659 def is_invertible(self
):
661 Return whether or not this element is invertible.
663 We can't use the superclass method because it relies on
664 the algebra being associative.
668 The usual way to do this is to check if the determinant is
669 zero, but we need the characteristic polynomial for the
670 determinant. The minimal polynomial is a lot easier to get,
671 so we use Corollary 2 in Chapter V of Koecher to check
672 whether or not the paren't algebra's zero element is a root
673 of this element's minimal polynomial.
677 The identity element is always invertible::
679 sage: set_random_seed()
680 sage: J = random_eja()
681 sage: J.one().is_invertible()
684 The zero element is never invertible::
686 sage: set_random_seed()
687 sage: J = random_eja()
688 sage: J.zero().is_invertible()
692 zero
= self
.parent().zero()
693 p
= self
.minimal_polynomial()
694 return not (p(zero
) == zero
)
697 def is_nilpotent(self
):
699 Return whether or not some power of this element is zero.
701 The superclass method won't work unless we're in an
702 associative algebra, and we aren't. However, we generate
703 an assocoative subalgebra and we're nilpotent there if and
704 only if we're nilpotent here (probably).
708 The identity element is never nilpotent::
710 sage: set_random_seed()
711 sage: random_eja().one().is_nilpotent()
714 The additive identity is always nilpotent::
716 sage: set_random_seed()
717 sage: random_eja().zero().is_nilpotent()
721 # The element we're going to call "is_nilpotent()" on.
722 # Either myself, interpreted as an element of a finite-
723 # dimensional algebra, or an element of an associative
727 if self
.parent().is_associative():
728 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
730 V
= self
.span_of_powers()
731 assoc_subalg
= self
.subalgebra_generated_by()
732 # Mis-design warning: the basis used for span_of_powers()
733 # and subalgebra_generated_by() must be the same, and in
735 elt
= assoc_subalg(V
.coordinates(self
.vector()))
737 # Recursive call, but should work since elt lives in an
738 # associative algebra.
739 return elt
.is_nilpotent()
742 def is_regular(self
):
744 Return whether or not this is a regular element.
748 The identity element always has degree one, but any element
749 linearly-independent from it is regular::
751 sage: J = JordanSpinEJA(5)
752 sage: J.one().is_regular()
754 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
755 sage: for x in J.gens():
756 ....: (J.one() + x).is_regular()
764 return self
.degree() == self
.parent().rank()
769 Compute the degree of this element the straightforward way
770 according to the definition; by appending powers to a list
771 and figuring out its dimension (that is, whether or not
772 they're linearly dependent).
776 sage: J = JordanSpinEJA(4)
777 sage: J.one().degree()
779 sage: e0,e1,e2,e3 = J.gens()
780 sage: (e0 - e1).degree()
783 In the spin factor algebra (of rank two), all elements that
784 aren't multiples of the identity are regular::
786 sage: set_random_seed()
787 sage: n = ZZ.random_element(1,10)
788 sage: J = JordanSpinEJA(n)
789 sage: x = J.random_element()
790 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
794 return self
.span_of_powers().dimension()
797 def minimal_polynomial(self
):
799 Return the minimal polynomial of this element,
800 as a function of the variable `t`.
804 We restrict ourselves to the associative subalgebra
805 generated by this element, and then return the minimal
806 polynomial of this element's operator matrix (in that
807 subalgebra). This works by Baes Proposition 2.3.16.
811 The minimal polynomial of the identity and zero elements are
814 sage: set_random_seed()
815 sage: J = random_eja()
816 sage: J.one().minimal_polynomial()
818 sage: J.zero().minimal_polynomial()
821 The degree of an element is (by one definition) the degree
822 of its minimal polynomial::
824 sage: set_random_seed()
825 sage: x = random_eja().random_element()
826 sage: x.degree() == x.minimal_polynomial().degree()
829 The minimal polynomial and the characteristic polynomial coincide
830 and are known (see Alizadeh, Example 11.11) for all elements of
831 the spin factor algebra that aren't scalar multiples of the
834 sage: set_random_seed()
835 sage: n = ZZ.random_element(2,10)
836 sage: J = JordanSpinEJA(n)
837 sage: y = J.random_element()
838 sage: while y == y.coefficient(0)*J.one():
839 ....: y = J.random_element()
840 sage: y0 = y.vector()[0]
841 sage: y_bar = y.vector()[1:]
842 sage: actual = y.minimal_polynomial()
843 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
844 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
845 sage: bool(actual == expected)
848 The minimal polynomial should always kill its element::
850 sage: set_random_seed()
851 sage: x = random_eja().random_element()
852 sage: p = x.minimal_polynomial()
853 sage: x.apply_univariate_polynomial(p)
857 V
= self
.span_of_powers()
858 assoc_subalg
= self
.subalgebra_generated_by()
859 # Mis-design warning: the basis used for span_of_powers()
860 # and subalgebra_generated_by() must be the same, and in
862 elt
= assoc_subalg(V
.coordinates(self
.vector()))
864 # We get back a symbolic polynomial in 'x' but want a real
866 p_of_x
= elt
.operator_matrix().minimal_polynomial()
867 return p_of_x
.change_variable_name('t')
870 def natural_representation(self
):
872 Return a more-natural representation of this element.
874 Every finite-dimensional Euclidean Jordan Algebra is a
875 direct sum of five simple algebras, four of which comprise
876 Hermitian matrices. This method returns the original
877 "natural" representation of this element as a Hermitian
878 matrix, if it has one. If not, you get the usual representation.
882 sage: J = ComplexHermitianEJA(3)
885 sage: J.one().natural_representation()
895 sage: J = QuaternionHermitianEJA(3)
898 sage: J.one().natural_representation()
899 [1 0 0 0 0 0 0 0 0 0 0 0]
900 [0 1 0 0 0 0 0 0 0 0 0 0]
901 [0 0 1 0 0 0 0 0 0 0 0 0]
902 [0 0 0 1 0 0 0 0 0 0 0 0]
903 [0 0 0 0 1 0 0 0 0 0 0 0]
904 [0 0 0 0 0 1 0 0 0 0 0 0]
905 [0 0 0 0 0 0 1 0 0 0 0 0]
906 [0 0 0 0 0 0 0 1 0 0 0 0]
907 [0 0 0 0 0 0 0 0 1 0 0 0]
908 [0 0 0 0 0 0 0 0 0 1 0 0]
909 [0 0 0 0 0 0 0 0 0 0 1 0]
910 [0 0 0 0 0 0 0 0 0 0 0 1]
913 B
= self
.parent().natural_basis()
914 W
= B
[0].matrix_space()
915 return W
.linear_combination(zip(self
.vector(), B
))
918 def operator_matrix(self
):
920 Return the matrix that represents left- (or right-)
921 multiplication by this element in the parent algebra.
923 We have to override this because the superclass method
924 returns a matrix that acts on row vectors (that is, on
929 Test the first polarization identity from my notes, Koecher Chapter
930 III, or from Baes (2.3)::
932 sage: set_random_seed()
933 sage: J = random_eja()
934 sage: x = J.random_element()
935 sage: y = J.random_element()
936 sage: Lx = x.operator_matrix()
937 sage: Ly = y.operator_matrix()
938 sage: Lxx = (x*x).operator_matrix()
939 sage: Lxy = (x*y).operator_matrix()
940 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
943 Test the second polarization identity from my notes or from
946 sage: set_random_seed()
947 sage: J = random_eja()
948 sage: x = J.random_element()
949 sage: y = J.random_element()
950 sage: z = J.random_element()
951 sage: Lx = x.operator_matrix()
952 sage: Ly = y.operator_matrix()
953 sage: Lz = z.operator_matrix()
954 sage: Lzy = (z*y).operator_matrix()
955 sage: Lxy = (x*y).operator_matrix()
956 sage: Lxz = (x*z).operator_matrix()
957 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
960 Test the third polarization identity from my notes or from
963 sage: set_random_seed()
964 sage: J = random_eja()
965 sage: u = J.random_element()
966 sage: y = J.random_element()
967 sage: z = J.random_element()
968 sage: Lu = u.operator_matrix()
969 sage: Ly = y.operator_matrix()
970 sage: Lz = z.operator_matrix()
971 sage: Lzy = (z*y).operator_matrix()
972 sage: Luy = (u*y).operator_matrix()
973 sage: Luz = (u*z).operator_matrix()
974 sage: Luyz = (u*(y*z)).operator_matrix()
975 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
976 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
977 sage: bool(lhs == rhs)
981 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
982 return fda_elt
.matrix().transpose()
985 def quadratic_representation(self
, other
=None):
987 Return the quadratic representation of this element.
991 The explicit form in the spin factor algebra is given by
992 Alizadeh's Example 11.12::
994 sage: set_random_seed()
995 sage: n = ZZ.random_element(1,10)
996 sage: J = JordanSpinEJA(n)
997 sage: x = J.random_element()
998 sage: x_vec = x.vector()
1000 sage: x_bar = x_vec[1:]
1001 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1002 sage: B = 2*x0*x_bar.row()
1003 sage: C = 2*x0*x_bar.column()
1004 sage: D = identity_matrix(QQ, n-1)
1005 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1006 sage: D = D + 2*x_bar.tensor_product(x_bar)
1007 sage: Q = block_matrix(2,2,[A,B,C,D])
1008 sage: Q == x.quadratic_representation()
1011 Test all of the properties from Theorem 11.2 in Alizadeh::
1013 sage: set_random_seed()
1014 sage: J = random_eja()
1015 sage: x = J.random_element()
1016 sage: y = J.random_element()
1020 sage: actual = x.quadratic_representation(y)
1021 sage: expected = ( (x+y).quadratic_representation()
1022 ....: -x.quadratic_representation()
1023 ....: -y.quadratic_representation() ) / 2
1024 sage: actual == expected
1029 sage: alpha = QQ.random_element()
1030 sage: actual = (alpha*x).quadratic_representation()
1031 sage: expected = (alpha^2)*x.quadratic_representation()
1032 sage: actual == expected
1037 sage: Qy = y.quadratic_representation()
1038 sage: actual = J(Qy*x.vector()).quadratic_representation()
1039 sage: expected = Qy*x.quadratic_representation()*Qy
1040 sage: actual == expected
1045 sage: k = ZZ.random_element(1,10)
1046 sage: actual = (x^k).quadratic_representation()
1047 sage: expected = (x.quadratic_representation())^k
1048 sage: actual == expected
1054 elif not other
in self
.parent():
1055 raise TypeError("'other' must live in the same algebra")
1057 L
= self
.operator_matrix()
1058 M
= other
.operator_matrix()
1059 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
1062 def span_of_powers(self
):
1064 Return the vector space spanned by successive powers of
1067 # The dimension of the subalgebra can't be greater than
1068 # the big algebra, so just put everything into a list
1069 # and let span() get rid of the excess.
1071 # We do the extra ambient_vector_space() in case we're messing
1072 # with polynomials and the direct parent is a module.
1073 V
= self
.vector().parent().ambient_vector_space()
1074 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1077 def subalgebra_generated_by(self
):
1079 Return the associative subalgebra of the parent EJA generated
1084 sage: set_random_seed()
1085 sage: x = random_eja().random_element()
1086 sage: x.subalgebra_generated_by().is_associative()
1089 Squaring in the subalgebra should be the same thing as
1090 squaring in the superalgebra::
1092 sage: set_random_seed()
1093 sage: x = random_eja().random_element()
1094 sage: u = x.subalgebra_generated_by().random_element()
1095 sage: u.operator_matrix()*u.vector() == (u**2).vector()
1099 # First get the subspace spanned by the powers of myself...
1100 V
= self
.span_of_powers()
1101 F
= self
.base_ring()
1103 # Now figure out the entries of the right-multiplication
1104 # matrix for the successive basis elements b0, b1,... of
1107 for b_right
in V
.basis():
1108 eja_b_right
= self
.parent()(b_right
)
1110 # The first row of the right-multiplication matrix by
1111 # b1 is what we get if we apply that matrix to b1. The
1112 # second row of the right multiplication matrix by b1
1113 # is what we get when we apply that matrix to b2...
1115 # IMPORTANT: this assumes that all vectors are COLUMN
1116 # vectors, unlike our superclass (which uses row vectors).
1117 for b_left
in V
.basis():
1118 eja_b_left
= self
.parent()(b_left
)
1119 # Multiply in the original EJA, but then get the
1120 # coordinates from the subalgebra in terms of its
1122 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1123 b_right_rows
.append(this_row
)
1124 b_right_matrix
= matrix(F
, b_right_rows
)
1125 mats
.append(b_right_matrix
)
1127 # It's an algebra of polynomials in one element, and EJAs
1128 # are power-associative.
1130 # TODO: choose generator names intelligently.
1131 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
1134 def subalgebra_idempotent(self
):
1136 Find an idempotent in the associative subalgebra I generate
1137 using Proposition 2.3.5 in Baes.
1141 sage: set_random_seed()
1142 sage: J = RealCartesianProductEJA(5)
1143 sage: c = J.random_element().subalgebra_idempotent()
1146 sage: J = JordanSpinEJA(5)
1147 sage: c = J.random_element().subalgebra_idempotent()
1152 if self
.is_nilpotent():
1153 raise ValueError("this only works with non-nilpotent elements!")
1155 V
= self
.span_of_powers()
1156 J
= self
.subalgebra_generated_by()
1157 # Mis-design warning: the basis used for span_of_powers()
1158 # and subalgebra_generated_by() must be the same, and in
1160 u
= J(V
.coordinates(self
.vector()))
1162 # The image of the matrix of left-u^m-multiplication
1163 # will be minimal for some natural number s...
1165 minimal_dim
= V
.dimension()
1166 for i
in xrange(1, V
.dimension()):
1167 this_dim
= (u
**i
).operator_matrix().image().dimension()
1168 if this_dim
< minimal_dim
:
1169 minimal_dim
= this_dim
1172 # Now minimal_matrix should correspond to the smallest
1173 # non-zero subspace in Baes's (or really, Koecher's)
1176 # However, we need to restrict the matrix to work on the
1177 # subspace... or do we? Can't we just solve, knowing that
1178 # A(c) = u^(s+1) should have a solution in the big space,
1181 # Beware, solve_right() means that we're using COLUMN vectors.
1182 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1184 A
= u_next
.operator_matrix()
1185 c_coordinates
= A
.solve_right(u_next
.vector())
1187 # Now c_coordinates is the idempotent we want, but it's in
1188 # the coordinate system of the subalgebra.
1190 # We need the basis for J, but as elements of the parent algebra.
1192 basis
= [self
.parent(v
) for v
in V
.basis()]
1193 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1198 Return my trace, the sum of my eigenvalues.
1202 sage: J = JordanSpinEJA(3)
1203 sage: x = sum(J.gens())
1209 sage: J = RealCartesianProductEJA(5)
1210 sage: J.one().trace()
1215 The trace of an element is a real number::
1217 sage: set_random_seed()
1218 sage: J = random_eja()
1219 sage: J.random_element().trace() in J.base_ring()
1225 p
= P
._charpoly
_coeff
(r
-1)
1226 # The _charpoly_coeff function already adds the factor of
1227 # -1 to ensure that _charpoly_coeff(r-1) is really what
1228 # appears in front of t^{r-1} in the charpoly. However,
1229 # we want the negative of THAT for the trace.
1230 return -p(*self
.vector())
1233 def trace_inner_product(self
, other
):
1235 Return the trace inner product of myself and ``other``.
1237 if not other
in self
.parent():
1238 raise TypeError("'other' must live in the same algebra")
1240 return (self
*other
).trace()
1243 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1245 Return the Euclidean Jordan Algebra corresponding to the set
1246 `R^n` under the Hadamard product.
1248 Note: this is nothing more than the Cartesian product of ``n``
1249 copies of the spin algebra. Once Cartesian product algebras
1250 are implemented, this can go.
1254 This multiplication table can be verified by hand::
1256 sage: J = RealCartesianProductEJA(3)
1257 sage: e0,e1,e2 = J.gens()
1273 def __classcall_private__(cls
, n
, field
=QQ
):
1274 # The FiniteDimensionalAlgebra constructor takes a list of
1275 # matrices, the ith representing right multiplication by the ith
1276 # basis element in the vector space. So if e_1 = (1,0,0), then
1277 # right (Hadamard) multiplication of x by e_1 picks out the first
1278 # component of x; and likewise for the ith basis element e_i.
1279 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1280 for i
in xrange(n
) ]
1282 fdeja
= super(RealCartesianProductEJA
, cls
)
1283 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1285 def inner_product(self
, x
, y
):
1286 return _usual_ip(x
,y
)
1291 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1295 For now, we choose a random natural number ``n`` (greater than zero)
1296 and then give you back one of the following:
1298 * The cartesian product of the rational numbers ``n`` times; this is
1299 ``QQ^n`` with the Hadamard product.
1301 * The Jordan spin algebra on ``QQ^n``.
1303 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1306 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1307 in the space of ``2n``-by-``2n`` real symmetric matrices.
1309 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1310 in the space of ``4n``-by-``4n`` real symmetric matrices.
1312 Later this might be extended to return Cartesian products of the
1318 Euclidean Jordan algebra of degree...
1322 # The max_n component lets us choose different upper bounds on the
1323 # value "n" that gets passed to the constructor. This is needed
1324 # because e.g. R^{10} is reasonable to test, while the Hermitian
1325 # 10-by-10 quaternion matrices are not.
1326 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1328 (RealSymmetricEJA
, 5),
1329 (ComplexHermitianEJA
, 4),
1330 (QuaternionHermitianEJA
, 3)])
1331 n
= ZZ
.random_element(1, max_n
)
1332 return constructor(n
, field
=QQ
)
1336 def _real_symmetric_basis(n
, field
=QQ
):
1338 Return a basis for the space of real symmetric n-by-n matrices.
1340 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1344 for j
in xrange(i
+1):
1345 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1349 # Beware, orthogonal but not normalized!
1350 Sij
= Eij
+ Eij
.transpose()
1355 def _complex_hermitian_basis(n
, field
=QQ
):
1357 Returns a basis for the space of complex Hermitian n-by-n matrices.
1361 sage: set_random_seed()
1362 sage: n = ZZ.random_element(1,5)
1363 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1367 F
= QuadraticField(-1, 'I')
1370 # This is like the symmetric case, but we need to be careful:
1372 # * We want conjugate-symmetry, not just symmetry.
1373 # * The diagonal will (as a result) be real.
1377 for j
in xrange(i
+1):
1378 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1380 Sij
= _embed_complex_matrix(Eij
)
1383 # Beware, orthogonal but not normalized! The second one
1384 # has a minus because it's conjugated.
1385 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1387 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1392 def _quaternion_hermitian_basis(n
, field
=QQ
):
1394 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1398 sage: set_random_seed()
1399 sage: n = ZZ.random_element(1,5)
1400 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1404 Q
= QuaternionAlgebra(QQ
,-1,-1)
1407 # This is like the symmetric case, but we need to be careful:
1409 # * We want conjugate-symmetry, not just symmetry.
1410 # * The diagonal will (as a result) be real.
1414 for j
in xrange(i
+1):
1415 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1417 Sij
= _embed_quaternion_matrix(Eij
)
1420 # Beware, orthogonal but not normalized! The second,
1421 # third, and fourth ones have a minus because they're
1423 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1425 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1427 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1429 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1435 return vector(m
.base_ring(), m
.list())
1438 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1440 def _multiplication_table_from_matrix_basis(basis
):
1442 At least three of the five simple Euclidean Jordan algebras have the
1443 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1444 multiplication on the right is matrix multiplication. Given a basis
1445 for the underlying matrix space, this function returns a
1446 multiplication table (obtained by looping through the basis
1447 elements) for an algebra of those matrices. A reordered copy
1448 of the basis is also returned to work around the fact that
1449 the ``span()`` in this function will change the order of the basis
1450 from what we think it is, to... something else.
1452 # In S^2, for example, we nominally have four coordinates even
1453 # though the space is of dimension three only. The vector space V
1454 # is supposed to hold the entire long vector, and the subspace W
1455 # of V will be spanned by the vectors that arise from symmetric
1456 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1457 field
= basis
[0].base_ring()
1458 dimension
= basis
[0].nrows()
1460 V
= VectorSpace(field
, dimension
**2)
1461 W
= V
.span( _mat2vec(s
) for s
in basis
)
1463 # Taking the span above reorders our basis (thanks, jerk!) so we
1464 # need to put our "matrix basis" in the same order as the
1465 # (reordered) vector basis.
1466 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1470 # Brute force the multiplication-by-s matrix by looping
1471 # through all elements of the basis and doing the computation
1472 # to find out what the corresponding row should be. BEWARE:
1473 # these multiplication tables won't be symmetric! It therefore
1474 # becomes REALLY IMPORTANT that the underlying algebra
1475 # constructor uses ROW vectors and not COLUMN vectors. That's
1476 # why we're computing rows here and not columns.
1479 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1480 Q_rows
.append(W
.coordinates(this_row
))
1481 Q
= matrix(field
, W
.dimension(), Q_rows
)
1487 def _embed_complex_matrix(M
):
1489 Embed the n-by-n complex matrix ``M`` into the space of real
1490 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1491 bi` to the block matrix ``[[a,b],[-b,a]]``.
1495 sage: F = QuadraticField(-1,'i')
1496 sage: x1 = F(4 - 2*i)
1497 sage: x2 = F(1 + 2*i)
1500 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1501 sage: _embed_complex_matrix(M)
1510 Embedding is a homomorphism (isomorphism, in fact)::
1512 sage: set_random_seed()
1513 sage: n = ZZ.random_element(5)
1514 sage: F = QuadraticField(-1, 'i')
1515 sage: X = random_matrix(F, n)
1516 sage: Y = random_matrix(F, n)
1517 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1518 sage: expected = _embed_complex_matrix(X*Y)
1519 sage: actual == expected
1525 raise ValueError("the matrix 'M' must be square")
1526 field
= M
.base_ring()
1531 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1533 # We can drop the imaginaries here.
1534 return block_matrix(field
.base_ring(), n
, blocks
)
1537 def _unembed_complex_matrix(M
):
1539 The inverse of _embed_complex_matrix().
1543 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1544 ....: [-2, 1, -4, 3],
1545 ....: [ 9, 10, 11, 12],
1546 ....: [-10, 9, -12, 11] ])
1547 sage: _unembed_complex_matrix(A)
1549 [ 10*i + 9 12*i + 11]
1553 Unembedding is the inverse of embedding::
1555 sage: set_random_seed()
1556 sage: F = QuadraticField(-1, 'i')
1557 sage: M = random_matrix(F, 3)
1558 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1564 raise ValueError("the matrix 'M' must be square")
1565 if not n
.mod(2).is_zero():
1566 raise ValueError("the matrix 'M' must be a complex embedding")
1568 F
= QuadraticField(-1, 'i')
1571 # Go top-left to bottom-right (reading order), converting every
1572 # 2-by-2 block we see to a single complex element.
1574 for k
in xrange(n
/2):
1575 for j
in xrange(n
/2):
1576 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1577 if submat
[0,0] != submat
[1,1]:
1578 raise ValueError('bad on-diagonal submatrix')
1579 if submat
[0,1] != -submat
[1,0]:
1580 raise ValueError('bad off-diagonal submatrix')
1581 z
= submat
[0,0] + submat
[0,1]*i
1584 return matrix(F
, n
/2, elements
)
1587 def _embed_quaternion_matrix(M
):
1589 Embed the n-by-n quaternion matrix ``M`` into the space of real
1590 matrices of size 4n-by-4n by first sending each quaternion entry
1591 `z = a + bi + cj + dk` to the block-complex matrix
1592 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1597 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1598 sage: i,j,k = Q.gens()
1599 sage: x = 1 + 2*i + 3*j + 4*k
1600 sage: M = matrix(Q, 1, [[x]])
1601 sage: _embed_quaternion_matrix(M)
1607 Embedding is a homomorphism (isomorphism, in fact)::
1609 sage: set_random_seed()
1610 sage: n = ZZ.random_element(5)
1611 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1612 sage: X = random_matrix(Q, n)
1613 sage: Y = random_matrix(Q, n)
1614 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1615 sage: expected = _embed_quaternion_matrix(X*Y)
1616 sage: actual == expected
1620 quaternions
= M
.base_ring()
1623 raise ValueError("the matrix 'M' must be square")
1625 F
= QuadraticField(-1, 'i')
1630 t
= z
.coefficient_tuple()
1635 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1636 [-c
+ d
*i
, a
- b
*i
]])
1637 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1639 # We should have real entries by now, so use the realest field
1640 # we've got for the return value.
1641 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1644 def _unembed_quaternion_matrix(M
):
1646 The inverse of _embed_quaternion_matrix().
1650 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1651 ....: [-2, 1, -4, 3],
1652 ....: [-3, 4, 1, -2],
1653 ....: [-4, -3, 2, 1]])
1654 sage: _unembed_quaternion_matrix(M)
1655 [1 + 2*i + 3*j + 4*k]
1659 Unembedding is the inverse of embedding::
1661 sage: set_random_seed()
1662 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1663 sage: M = random_matrix(Q, 3)
1664 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1670 raise ValueError("the matrix 'M' must be square")
1671 if not n
.mod(4).is_zero():
1672 raise ValueError("the matrix 'M' must be a complex embedding")
1674 Q
= QuaternionAlgebra(QQ
,-1,-1)
1677 # Go top-left to bottom-right (reading order), converting every
1678 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1681 for l
in xrange(n
/4):
1682 for m
in xrange(n
/4):
1683 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1684 if submat
[0,0] != submat
[1,1].conjugate():
1685 raise ValueError('bad on-diagonal submatrix')
1686 if submat
[0,1] != -submat
[1,0].conjugate():
1687 raise ValueError('bad off-diagonal submatrix')
1688 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1689 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1692 return matrix(Q
, n
/4, elements
)
1695 # The usual inner product on R^n.
1697 return x
.vector().inner_product(y
.vector())
1699 # The inner product used for the real symmetric simple EJA.
1700 # We keep it as a separate function because e.g. the complex
1701 # algebra uses the same inner product, except divided by 2.
1702 def _matrix_ip(X
,Y
):
1703 X_mat
= X
.natural_representation()
1704 Y_mat
= Y
.natural_representation()
1705 return (X_mat
*Y_mat
).trace()
1708 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1710 The rank-n simple EJA consisting of real symmetric n-by-n
1711 matrices, the usual symmetric Jordan product, and the trace inner
1712 product. It has dimension `(n^2 + n)/2` over the reals.
1716 sage: J = RealSymmetricEJA(2)
1717 sage: e0, e1, e2 = J.gens()
1727 The degree of this algebra is `(n^2 + n) / 2`::
1729 sage: set_random_seed()
1730 sage: n = ZZ.random_element(1,5)
1731 sage: J = RealSymmetricEJA(n)
1732 sage: J.degree() == (n^2 + n)/2
1735 The Jordan multiplication is what we think it is::
1737 sage: set_random_seed()
1738 sage: n = ZZ.random_element(1,5)
1739 sage: J = RealSymmetricEJA(n)
1740 sage: x = J.random_element()
1741 sage: y = J.random_element()
1742 sage: actual = (x*y).natural_representation()
1743 sage: X = x.natural_representation()
1744 sage: Y = y.natural_representation()
1745 sage: expected = (X*Y + Y*X)/2
1746 sage: actual == expected
1748 sage: J(expected) == x*y
1753 def __classcall_private__(cls
, n
, field
=QQ
):
1754 S
= _real_symmetric_basis(n
, field
=field
)
1755 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1757 fdeja
= super(RealSymmetricEJA
, cls
)
1758 return fdeja
.__classcall
_private
__(cls
,
1764 def inner_product(self
, x
, y
):
1765 return _matrix_ip(x
,y
)
1768 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1770 The rank-n simple EJA consisting of complex Hermitian n-by-n
1771 matrices over the real numbers, the usual symmetric Jordan product,
1772 and the real-part-of-trace inner product. It has dimension `n^2` over
1777 The degree of this algebra is `n^2`::
1779 sage: set_random_seed()
1780 sage: n = ZZ.random_element(1,5)
1781 sage: J = ComplexHermitianEJA(n)
1782 sage: J.degree() == n^2
1785 The Jordan multiplication is what we think it is::
1787 sage: set_random_seed()
1788 sage: n = ZZ.random_element(1,5)
1789 sage: J = ComplexHermitianEJA(n)
1790 sage: x = J.random_element()
1791 sage: y = J.random_element()
1792 sage: actual = (x*y).natural_representation()
1793 sage: X = x.natural_representation()
1794 sage: Y = y.natural_representation()
1795 sage: expected = (X*Y + Y*X)/2
1796 sage: actual == expected
1798 sage: J(expected) == x*y
1803 def __classcall_private__(cls
, n
, field
=QQ
):
1804 S
= _complex_hermitian_basis(n
)
1805 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1807 fdeja
= super(ComplexHermitianEJA
, cls
)
1808 return fdeja
.__classcall
_private
__(cls
,
1814 def inner_product(self
, x
, y
):
1815 # Since a+bi on the diagonal is represented as
1820 # we'll double-count the "a" entries if we take the trace of
1822 return _matrix_ip(x
,y
)/2
1825 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1827 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1828 matrices, the usual symmetric Jordan product, and the
1829 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1834 The degree of this algebra is `n^2`::
1836 sage: set_random_seed()
1837 sage: n = ZZ.random_element(1,5)
1838 sage: J = QuaternionHermitianEJA(n)
1839 sage: J.degree() == 2*(n^2) - n
1842 The Jordan multiplication is what we think it is::
1844 sage: set_random_seed()
1845 sage: n = ZZ.random_element(1,5)
1846 sage: J = QuaternionHermitianEJA(n)
1847 sage: x = J.random_element()
1848 sage: y = J.random_element()
1849 sage: actual = (x*y).natural_representation()
1850 sage: X = x.natural_representation()
1851 sage: Y = y.natural_representation()
1852 sage: expected = (X*Y + Y*X)/2
1853 sage: actual == expected
1855 sage: J(expected) == x*y
1860 def __classcall_private__(cls
, n
, field
=QQ
):
1861 S
= _quaternion_hermitian_basis(n
)
1862 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1864 fdeja
= super(QuaternionHermitianEJA
, cls
)
1865 return fdeja
.__classcall
_private
__(cls
,
1871 def inner_product(self
, x
, y
):
1872 # Since a+bi+cj+dk on the diagonal is represented as
1874 # a + bi +cj + dk = [ a b c d]
1879 # we'll quadruple-count the "a" entries if we take the trace of
1881 return _matrix_ip(x
,y
)/4
1884 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1886 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1887 with the usual inner product and jordan product ``x*y =
1888 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1893 This multiplication table can be verified by hand::
1895 sage: J = JordanSpinEJA(4)
1896 sage: e0,e1,e2,e3 = J.gens()
1914 def __classcall_private__(cls
, n
, field
=QQ
):
1916 id_matrix
= identity_matrix(field
, n
)
1918 ei
= id_matrix
.column(i
)
1919 Qi
= zero_matrix(field
, n
)
1921 Qi
.set_column(0, ei
)
1922 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
1923 # The addition of the diagonal matrix adds an extra ei[0] in the
1924 # upper-left corner of the matrix.
1925 Qi
[0,0] = Qi
[0,0] * ~
field(2)
1928 # The rank of the spin algebra is two, unless we're in a
1929 # one-dimensional ambient space (because the rank is bounded by
1930 # the ambient dimension).
1931 fdeja
= super(JordanSpinEJA
, cls
)
1932 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
1934 def inner_product(self
, x
, y
):
1935 return _usual_ip(x
,y
)