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())
90 def _a_regular_element(self
):
92 Guess a regular element. Needed to compute the basis for our
93 characteristic polynomial coefficients.
96 z
= self
.sum( (i
+1)*gs
[i
] for i
in range(len(gs
)) )
97 if not z
.is_regular():
98 raise ValueError("don't know a regular element")
103 def _charpoly_basis_space(self
):
105 Return the vector space spanned by the basis used in our
106 characteristic polynomial coefficients. This is used not only to
107 compute those coefficients, but also any time we need to
108 evaluate the coefficients (like when we compute the trace or
111 z
= self
._a
_regular
_element
()
112 V
= z
.vector().parent().ambient_vector_space()
113 V1
= V
.span_of_basis( (z
**k
).vector() for k
in range(self
.rank()) )
114 b
= (V1
.basis() + V1
.complement().basis())
115 return V
.span_of_basis(b
)
119 def _charpoly_coeff(self
, i
):
121 Return the coefficient polynomial "a_{i}" of this algebra's
122 general characteristic polynomial.
124 Having this be a separate cached method lets us compute and
125 store the trace/determinant (a_{r-1} and a_{0} respectively)
126 separate from the entire characteristic polynomial.
128 (A_of_x
, x
, xr
, detA
) = self
._charpoly
_matrix
_system
()
129 R
= A_of_x
.base_ring()
131 # Guaranteed by theory
134 # Danger: the in-place modification is done for performance
135 # reasons (reconstructing a matrix with huge polynomial
136 # entries is slow), but I don't know how cached_method works,
137 # so it's highly possible that we're modifying some global
138 # list variable by reference, here. In other words, you
139 # probably shouldn't call this method twice on the same
140 # algebra, at the same time, in two threads
141 Ai_orig
= A_of_x
.column(i
)
142 A_of_x
.set_column(i
,xr
)
143 numerator
= A_of_x
.det()
144 A_of_x
.set_column(i
,Ai_orig
)
146 # We're relying on the theory here to ensure that each a_i is
147 # indeed back in R, and the added negative signs are to make
148 # the whole charpoly expression sum to zero.
149 return R(-numerator
/detA
)
153 def _charpoly_matrix_system(self
):
155 Compute the matrix whose entries A_ij are polynomials in
156 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
157 corresponding to `x^r` and the determinent of the matrix A =
158 [A_ij]. In other words, all of the fixed (cachable) data needed
159 to compute the coefficients of the characteristic polynomial.
164 # Construct a new algebra over a multivariate polynomial ring...
165 names
= ['X' + str(i
) for i
in range(1,n
+1)]
166 R
= PolynomialRing(self
.base_ring(), names
)
167 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
168 self
._multiplication
_table
,
171 idmat
= identity_matrix(J
.base_ring(), n
)
173 W
= self
._charpoly
_basis
_space
()
174 W
= W
.change_ring(R
.fraction_field())
176 # Starting with the standard coordinates x = (X1,X2,...,Xn)
177 # and then converting the entries to W-coordinates allows us
178 # to pass in the standard coordinates to the charpoly and get
179 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
182 # W.coordinates(x^2) eval'd at (standard z-coords)
186 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
188 # We want the middle equivalent thing in our matrix, but use
189 # the first equivalent thing instead so that we can pass in
190 # standard coordinates.
191 x
= J(vector(R
, R
.gens()))
192 l1
= [column_matrix(W
.coordinates((x
**k
).vector())) for k
in range(r
)]
193 l2
= [idmat
.column(k
-1).column() for k
in range(r
+1, n
+1)]
194 A_of_x
= block_matrix(R
, 1, n
, (l1
+ l2
))
195 xr
= W
.coordinates((x
**r
).vector())
196 return (A_of_x
, x
, xr
, A_of_x
.det())
200 def characteristic_polynomial(self
):
205 This implementation doesn't guarantee that the polynomial
206 denominator in the coefficients is not identically zero, so
207 theoretically it could crash. The way that this is handled
208 in e.g. Faraut and Koranyi is to use a basis that guarantees
209 the denominator is non-zero. But, doing so requires knowledge
210 of at least one regular element, and we don't even know how
211 to do that. The trade-off is that, if we use the standard basis,
212 the resulting polynomial will accept the "usual" coordinates. In
213 other words, we don't have to do a change of basis before e.g.
214 computing the trace or determinant.
218 The characteristic polynomial in the spin algebra is given in
219 Alizadeh, Example 11.11::
221 sage: J = JordanSpinEJA(3)
222 sage: p = J.characteristic_polynomial(); p
223 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
224 sage: xvec = J.one().vector()
232 # The list of coefficient polynomials a_1, a_2, ..., a_n.
233 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
235 # We go to a bit of trouble here to reorder the
236 # indeterminates, so that it's easier to evaluate the
237 # characteristic polynomial at x's coordinates and get back
238 # something in terms of t, which is what we want.
240 S
= PolynomialRing(self
.base_ring(),'t')
242 S
= PolynomialRing(S
, R
.variable_names())
245 # Note: all entries past the rth should be zero. The
246 # coefficient of the highest power (x^r) is 1, but it doesn't
247 # appear in the solution vector which contains coefficients
248 # for the other powers (to make them sum to x^r).
250 a
[r
] = 1 # corresponds to x^r
252 # When the rank is equal to the dimension, trying to
253 # assign a[r] goes out-of-bounds.
254 a
.append(1) # corresponds to x^r
256 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
259 def inner_product(self
, x
, y
):
261 The inner product associated with this Euclidean Jordan algebra.
263 Defaults to the trace inner product, but can be overridden by
264 subclasses if they are sure that the necessary properties are
269 The inner product must satisfy its axiom for this algebra to truly
270 be a Euclidean Jordan Algebra::
272 sage: set_random_seed()
273 sage: J = random_eja()
274 sage: x = J.random_element()
275 sage: y = J.random_element()
276 sage: z = J.random_element()
277 sage: (x*y).inner_product(z) == y.inner_product(x*z)
281 if (not x
in self
) or (not y
in self
):
282 raise TypeError("arguments must live in this algebra")
283 return x
.trace_inner_product(y
)
286 def natural_basis(self
):
288 Return a more-natural representation of this algebra's basis.
290 Every finite-dimensional Euclidean Jordan Algebra is a direct
291 sum of five simple algebras, four of which comprise Hermitian
292 matrices. This method returns the original "natural" basis
293 for our underlying vector space. (Typically, the natural basis
294 is used to construct the multiplication table in the first place.)
296 Note that this will always return a matrix. The standard basis
297 in `R^n` will be returned as `n`-by-`1` column matrices.
301 sage: J = RealSymmetricEJA(2)
304 sage: J.natural_basis()
312 sage: J = JordanSpinEJA(2)
315 sage: J.natural_basis()
322 if self
._natural
_basis
is None:
323 return tuple( b
.vector().column() for b
in self
.basis() )
325 return self
._natural
_basis
330 Return the rank of this EJA.
332 if self
._rank
is None:
333 raise ValueError("no rank specified at genesis")
338 class Element(FiniteDimensionalAlgebraElement
):
340 An element of a Euclidean Jordan algebra.
343 def __init__(self
, A
, elt
=None):
347 The identity in `S^n` is converted to the identity in the EJA::
349 sage: J = RealSymmetricEJA(3)
350 sage: I = identity_matrix(QQ,3)
351 sage: J(I) == J.one()
354 This skew-symmetric matrix can't be represented in the EJA::
356 sage: J = RealSymmetricEJA(3)
357 sage: A = matrix(QQ,3, lambda i,j: i-j)
359 Traceback (most recent call last):
361 ArithmeticError: vector is not in free module
364 # Goal: if we're given a matrix, and if it lives in our
365 # parent algebra's "natural ambient space," convert it
366 # into an algebra element.
368 # The catch is, we make a recursive call after converting
369 # the given matrix into a vector that lives in the algebra.
370 # This we need to try the parent class initializer first,
371 # to avoid recursing forever if we're given something that
372 # already fits into the algebra, but also happens to live
373 # in the parent's "natural ambient space" (this happens with
376 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
378 natural_basis
= A
.natural_basis()
379 if elt
in natural_basis
[0].matrix_space():
380 # Thanks for nothing! Matrix spaces aren't vector
381 # spaces in Sage, so we have to figure out its
382 # natural-basis coordinates ourselves.
383 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
384 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
385 coords
= W
.coordinates(_mat2vec(elt
))
386 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
388 def __pow__(self
, n
):
390 Return ``self`` raised to the power ``n``.
392 Jordan algebras are always power-associative; see for
393 example Faraut and Koranyi, Proposition II.1.2 (ii).
397 We have to override this because our superclass uses row vectors
398 instead of column vectors! We, on the other hand, assume column
403 sage: set_random_seed()
404 sage: x = random_eja().random_element()
405 sage: x.operator_matrix()*x.vector() == (x^2).vector()
408 A few examples of power-associativity::
410 sage: set_random_seed()
411 sage: x = random_eja().random_element()
412 sage: x*(x*x)*(x*x) == x^5
414 sage: (x*x)*(x*x*x) == x^5
417 We also know that powers operator-commute (Koecher, Chapter
420 sage: set_random_seed()
421 sage: x = random_eja().random_element()
422 sage: m = ZZ.random_element(0,10)
423 sage: n = ZZ.random_element(0,10)
424 sage: Lxm = (x^m).operator_matrix()
425 sage: Lxn = (x^n).operator_matrix()
426 sage: Lxm*Lxn == Lxn*Lxm
436 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
439 def apply_univariate_polynomial(self
, p
):
441 Apply the univariate polynomial ``p`` to this element.
443 A priori, SageMath won't allow us to apply a univariate
444 polynomial to an element of an EJA, because we don't know
445 that EJAs are rings (they are usually not associative). Of
446 course, we know that EJAs are power-associative, so the
447 operation is ultimately kosher. This function sidesteps
448 the CAS to get the answer we want and expect.
452 sage: R = PolynomialRing(QQ, 't')
454 sage: p = t^4 - t^3 + 5*t - 2
455 sage: J = RealCartesianProductEJA(5)
456 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
461 We should always get back an element of the algebra::
463 sage: set_random_seed()
464 sage: p = PolynomialRing(QQ, 't').random_element()
465 sage: J = random_eja()
466 sage: x = J.random_element()
467 sage: x.apply_univariate_polynomial(p) in J
471 if len(p
.variables()) > 1:
472 raise ValueError("not a univariate polynomial")
475 # Convert the coeficcients to the parent's base ring,
476 # because a priori they might live in an (unnecessarily)
477 # larger ring for which P.sum() would fail below.
478 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
479 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
482 def characteristic_polynomial(self
):
484 Return the characteristic polynomial of this element.
488 The rank of `R^3` is three, and the minimal polynomial of
489 the identity element is `(t-1)` from which it follows that
490 the characteristic polynomial should be `(t-1)^3`::
492 sage: J = RealCartesianProductEJA(3)
493 sage: J.one().characteristic_polynomial()
494 t^3 - 3*t^2 + 3*t - 1
496 Likewise, the characteristic of the zero element in the
497 rank-three algebra `R^{n}` should be `t^{3}`::
499 sage: J = RealCartesianProductEJA(3)
500 sage: J.zero().characteristic_polynomial()
503 The characteristic polynomial of an element should evaluate
504 to zero on that element::
506 sage: set_random_seed()
507 sage: x = RealCartesianProductEJA(3).random_element()
508 sage: p = x.characteristic_polynomial()
509 sage: x.apply_univariate_polynomial(p)
513 p
= self
.parent().characteristic_polynomial()
514 return p(*self
.vector())
517 def inner_product(self
, other
):
519 Return the parent algebra's inner product of myself and ``other``.
523 The inner product in the Jordan spin algebra is the usual
524 inner product on `R^n` (this example only works because the
525 basis for the Jordan algebra is the standard basis in `R^n`)::
527 sage: J = JordanSpinEJA(3)
528 sage: x = vector(QQ,[1,2,3])
529 sage: y = vector(QQ,[4,5,6])
530 sage: x.inner_product(y)
532 sage: J(x).inner_product(J(y))
535 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
536 multiplication is the usual matrix multiplication in `S^n`,
537 so the inner product of the identity matrix with itself
540 sage: J = RealSymmetricEJA(3)
541 sage: J.one().inner_product(J.one())
544 Likewise, the inner product on `C^n` is `<X,Y> =
545 Re(trace(X*Y))`, where we must necessarily take the real
546 part because the product of Hermitian matrices may not be
549 sage: J = ComplexHermitianEJA(3)
550 sage: J.one().inner_product(J.one())
553 Ditto for the quaternions::
555 sage: J = QuaternionHermitianEJA(3)
556 sage: J.one().inner_product(J.one())
561 Ensure that we can always compute an inner product, and that
562 it gives us back a real number::
564 sage: set_random_seed()
565 sage: J = random_eja()
566 sage: x = J.random_element()
567 sage: y = J.random_element()
568 sage: x.inner_product(y) in RR
574 raise TypeError("'other' must live in the same algebra")
576 return P
.inner_product(self
, other
)
579 def operator_commutes_with(self
, other
):
581 Return whether or not this element operator-commutes
586 The definition of a Jordan algebra says that any element
587 operator-commutes with its square::
589 sage: set_random_seed()
590 sage: x = random_eja().random_element()
591 sage: x.operator_commutes_with(x^2)
596 Test Lemma 1 from Chapter III of Koecher::
598 sage: set_random_seed()
599 sage: J = random_eja()
600 sage: u = J.random_element()
601 sage: v = J.random_element()
602 sage: lhs = u.operator_commutes_with(u*v)
603 sage: rhs = v.operator_commutes_with(u^2)
608 if not other
in self
.parent():
609 raise TypeError("'other' must live in the same algebra")
611 A
= self
.operator_matrix()
612 B
= other
.operator_matrix()
618 Return my determinant, the product of my eigenvalues.
622 sage: J = JordanSpinEJA(2)
623 sage: e0,e1 = J.gens()
624 sage: x = sum( J.gens() )
630 sage: J = JordanSpinEJA(3)
631 sage: e0,e1,e2 = J.gens()
632 sage: x = sum( J.gens() )
638 An element is invertible if and only if its determinant is
641 sage: set_random_seed()
642 sage: x = random_eja().random_element()
643 sage: x.is_invertible() == (x.det() != 0)
649 p
= P
._charpoly
_coeff
(0)
650 # The _charpoly_coeff function already adds the factor of
651 # -1 to ensure that _charpoly_coeff(0) is really what
652 # appears in front of t^{0} in the charpoly. However,
653 # we want (-1)^r times THAT for the determinant.
654 return ((-1)**r
)*p(*self
.vector())
659 Return the Jordan-multiplicative inverse of this element.
661 We can't use the superclass method because it relies on the
662 algebra being associative.
666 The inverse in the spin factor algebra is given in Alizadeh's
669 sage: set_random_seed()
670 sage: n = ZZ.random_element(1,10)
671 sage: J = JordanSpinEJA(n)
672 sage: x = J.random_element()
673 sage: while x.is_zero():
674 ....: x = J.random_element()
675 sage: x_vec = x.vector()
677 sage: x_bar = x_vec[1:]
678 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
679 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
680 sage: x_inverse = coeff*inv_vec
681 sage: x.inverse() == J(x_inverse)
686 The identity element is its own inverse::
688 sage: set_random_seed()
689 sage: J = random_eja()
690 sage: J.one().inverse() == J.one()
693 If an element has an inverse, it acts like one::
695 sage: set_random_seed()
696 sage: J = random_eja()
697 sage: x = J.random_element()
698 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
702 if not self
.is_invertible():
703 raise ValueError("element not invertible")
705 if self
.parent().is_associative():
706 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
707 # elt is in the right coordinates, but has the wrong class.
708 return self
.parent()(elt
.inverse().vector())
710 # We do this a little different than the usual recursive
711 # call to a finite-dimensional algebra element, because we
712 # wind up with an inverse that lives in the subalgebra and
713 # we need information about the parent to convert it back.
714 V
= self
.span_of_powers()
715 assoc_subalg
= self
.subalgebra_generated_by()
716 # Mis-design warning: the basis used for span_of_powers()
717 # and subalgebra_generated_by() must be the same, and in
719 elt
= assoc_subalg(V
.coordinates(self
.vector()))
721 # This will be in the subalgebra's coordinates...
722 fda_elt
= FiniteDimensionalAlgebraElement(assoc_subalg
, elt
)
723 subalg_inverse
= fda_elt
.inverse()
725 # So we have to convert back...
726 basis
= [ self
.parent(v
) for v
in V
.basis() ]
727 pairs
= zip(subalg_inverse
.vector(), basis
)
728 return self
.parent().linear_combination(pairs
)
731 def is_invertible(self
):
733 Return whether or not this element is invertible.
735 We can't use the superclass method because it relies on
736 the algebra being associative.
740 The usual way to do this is to check if the determinant is
741 zero, but we need the characteristic polynomial for the
742 determinant. The minimal polynomial is a lot easier to get,
743 so we use Corollary 2 in Chapter V of Koecher to check
744 whether or not the paren't algebra's zero element is a root
745 of this element's minimal polynomial.
749 The identity element is always invertible::
751 sage: set_random_seed()
752 sage: J = random_eja()
753 sage: J.one().is_invertible()
756 The zero element is never invertible::
758 sage: set_random_seed()
759 sage: J = random_eja()
760 sage: J.zero().is_invertible()
764 zero
= self
.parent().zero()
765 p
= self
.minimal_polynomial()
766 return not (p(zero
) == zero
)
769 def is_nilpotent(self
):
771 Return whether or not some power of this element is zero.
773 The superclass method won't work unless we're in an
774 associative algebra, and we aren't. However, we generate
775 an assocoative subalgebra and we're nilpotent there if and
776 only if we're nilpotent here (probably).
780 The identity element is never nilpotent::
782 sage: set_random_seed()
783 sage: random_eja().one().is_nilpotent()
786 The additive identity is always nilpotent::
788 sage: set_random_seed()
789 sage: random_eja().zero().is_nilpotent()
793 # The element we're going to call "is_nilpotent()" on.
794 # Either myself, interpreted as an element of a finite-
795 # dimensional algebra, or an element of an associative
799 if self
.parent().is_associative():
800 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
802 V
= self
.span_of_powers()
803 assoc_subalg
= self
.subalgebra_generated_by()
804 # Mis-design warning: the basis used for span_of_powers()
805 # and subalgebra_generated_by() must be the same, and in
807 elt
= assoc_subalg(V
.coordinates(self
.vector()))
809 # Recursive call, but should work since elt lives in an
810 # associative algebra.
811 return elt
.is_nilpotent()
814 def is_regular(self
):
816 Return whether or not this is a regular element.
820 The identity element always has degree one, but any element
821 linearly-independent from it is regular::
823 sage: J = JordanSpinEJA(5)
824 sage: J.one().is_regular()
826 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
827 sage: for x in J.gens():
828 ....: (J.one() + x).is_regular()
836 return self
.degree() == self
.parent().rank()
841 Compute the degree of this element the straightforward way
842 according to the definition; by appending powers to a list
843 and figuring out its dimension (that is, whether or not
844 they're linearly dependent).
848 sage: J = JordanSpinEJA(4)
849 sage: J.one().degree()
851 sage: e0,e1,e2,e3 = J.gens()
852 sage: (e0 - e1).degree()
855 In the spin factor algebra (of rank two), all elements that
856 aren't multiples of the identity are regular::
858 sage: set_random_seed()
859 sage: n = ZZ.random_element(1,10)
860 sage: J = JordanSpinEJA(n)
861 sage: x = J.random_element()
862 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
866 return self
.span_of_powers().dimension()
869 def minimal_polynomial(self
):
871 Return the minimal polynomial of this element,
872 as a function of the variable `t`.
876 We restrict ourselves to the associative subalgebra
877 generated by this element, and then return the minimal
878 polynomial of this element's operator matrix (in that
879 subalgebra). This works by Baes Proposition 2.3.16.
883 The minimal polynomial of the identity and zero elements are
886 sage: set_random_seed()
887 sage: J = random_eja()
888 sage: J.one().minimal_polynomial()
890 sage: J.zero().minimal_polynomial()
893 The degree of an element is (by one definition) the degree
894 of its minimal polynomial::
896 sage: set_random_seed()
897 sage: x = random_eja().random_element()
898 sage: x.degree() == x.minimal_polynomial().degree()
901 The minimal polynomial and the characteristic polynomial coincide
902 and are known (see Alizadeh, Example 11.11) for all elements of
903 the spin factor algebra that aren't scalar multiples of the
906 sage: set_random_seed()
907 sage: n = ZZ.random_element(2,10)
908 sage: J = JordanSpinEJA(n)
909 sage: y = J.random_element()
910 sage: while y == y.coefficient(0)*J.one():
911 ....: y = J.random_element()
912 sage: y0 = y.vector()[0]
913 sage: y_bar = y.vector()[1:]
914 sage: actual = y.minimal_polynomial()
915 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
916 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
917 sage: bool(actual == expected)
920 The minimal polynomial should always kill its element::
922 sage: set_random_seed()
923 sage: x = random_eja().random_element()
924 sage: p = x.minimal_polynomial()
925 sage: x.apply_univariate_polynomial(p)
929 V
= self
.span_of_powers()
930 assoc_subalg
= self
.subalgebra_generated_by()
931 # Mis-design warning: the basis used for span_of_powers()
932 # and subalgebra_generated_by() must be the same, and in
934 elt
= assoc_subalg(V
.coordinates(self
.vector()))
936 # We get back a symbolic polynomial in 'x' but want a real
938 p_of_x
= elt
.operator_matrix().minimal_polynomial()
939 return p_of_x
.change_variable_name('t')
942 def natural_representation(self
):
944 Return a more-natural representation of this element.
946 Every finite-dimensional Euclidean Jordan Algebra is a
947 direct sum of five simple algebras, four of which comprise
948 Hermitian matrices. This method returns the original
949 "natural" representation of this element as a Hermitian
950 matrix, if it has one. If not, you get the usual representation.
954 sage: J = ComplexHermitianEJA(3)
957 sage: J.one().natural_representation()
967 sage: J = QuaternionHermitianEJA(3)
970 sage: J.one().natural_representation()
971 [1 0 0 0 0 0 0 0 0 0 0 0]
972 [0 1 0 0 0 0 0 0 0 0 0 0]
973 [0 0 1 0 0 0 0 0 0 0 0 0]
974 [0 0 0 1 0 0 0 0 0 0 0 0]
975 [0 0 0 0 1 0 0 0 0 0 0 0]
976 [0 0 0 0 0 1 0 0 0 0 0 0]
977 [0 0 0 0 0 0 1 0 0 0 0 0]
978 [0 0 0 0 0 0 0 1 0 0 0 0]
979 [0 0 0 0 0 0 0 0 1 0 0 0]
980 [0 0 0 0 0 0 0 0 0 1 0 0]
981 [0 0 0 0 0 0 0 0 0 0 1 0]
982 [0 0 0 0 0 0 0 0 0 0 0 1]
985 B
= self
.parent().natural_basis()
986 W
= B
[0].matrix_space()
987 return W
.linear_combination(zip(self
.vector(), B
))
990 def operator_matrix(self
):
992 Return the matrix that represents left- (or right-)
993 multiplication by this element in the parent algebra.
995 We have to override this because the superclass method
996 returns a matrix that acts on row vectors (that is, on
1001 Test the first polarization identity from my notes, Koecher Chapter
1002 III, or from Baes (2.3)::
1004 sage: set_random_seed()
1005 sage: J = random_eja()
1006 sage: x = J.random_element()
1007 sage: y = J.random_element()
1008 sage: Lx = x.operator_matrix()
1009 sage: Ly = y.operator_matrix()
1010 sage: Lxx = (x*x).operator_matrix()
1011 sage: Lxy = (x*y).operator_matrix()
1012 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
1015 Test the second polarization identity from my notes or from
1018 sage: set_random_seed()
1019 sage: J = random_eja()
1020 sage: x = J.random_element()
1021 sage: y = J.random_element()
1022 sage: z = J.random_element()
1023 sage: Lx = x.operator_matrix()
1024 sage: Ly = y.operator_matrix()
1025 sage: Lz = z.operator_matrix()
1026 sage: Lzy = (z*y).operator_matrix()
1027 sage: Lxy = (x*y).operator_matrix()
1028 sage: Lxz = (x*z).operator_matrix()
1029 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
1032 Test the third polarization identity from my notes or from
1035 sage: set_random_seed()
1036 sage: J = random_eja()
1037 sage: u = J.random_element()
1038 sage: y = J.random_element()
1039 sage: z = J.random_element()
1040 sage: Lu = u.operator_matrix()
1041 sage: Ly = y.operator_matrix()
1042 sage: Lz = z.operator_matrix()
1043 sage: Lzy = (z*y).operator_matrix()
1044 sage: Luy = (u*y).operator_matrix()
1045 sage: Luz = (u*z).operator_matrix()
1046 sage: Luyz = (u*(y*z)).operator_matrix()
1047 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
1048 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
1049 sage: bool(lhs == rhs)
1053 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
1054 return fda_elt
.matrix().transpose()
1057 def quadratic_representation(self
, other
=None):
1059 Return the quadratic representation of this element.
1063 The explicit form in the spin factor algebra is given by
1064 Alizadeh's Example 11.12::
1066 sage: set_random_seed()
1067 sage: n = ZZ.random_element(1,10)
1068 sage: J = JordanSpinEJA(n)
1069 sage: x = J.random_element()
1070 sage: x_vec = x.vector()
1072 sage: x_bar = x_vec[1:]
1073 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1074 sage: B = 2*x0*x_bar.row()
1075 sage: C = 2*x0*x_bar.column()
1076 sage: D = identity_matrix(QQ, n-1)
1077 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1078 sage: D = D + 2*x_bar.tensor_product(x_bar)
1079 sage: Q = block_matrix(2,2,[A,B,C,D])
1080 sage: Q == x.quadratic_representation()
1083 Test all of the properties from Theorem 11.2 in Alizadeh::
1085 sage: set_random_seed()
1086 sage: J = random_eja()
1087 sage: x = J.random_element()
1088 sage: y = J.random_element()
1092 sage: actual = x.quadratic_representation(y)
1093 sage: expected = ( (x+y).quadratic_representation()
1094 ....: -x.quadratic_representation()
1095 ....: -y.quadratic_representation() ) / 2
1096 sage: actual == expected
1101 sage: alpha = QQ.random_element()
1102 sage: actual = (alpha*x).quadratic_representation()
1103 sage: expected = (alpha^2)*x.quadratic_representation()
1104 sage: actual == expected
1109 sage: Qy = y.quadratic_representation()
1110 sage: actual = J(Qy*x.vector()).quadratic_representation()
1111 sage: expected = Qy*x.quadratic_representation()*Qy
1112 sage: actual == expected
1117 sage: k = ZZ.random_element(1,10)
1118 sage: actual = (x^k).quadratic_representation()
1119 sage: expected = (x.quadratic_representation())^k
1120 sage: actual == expected
1126 elif not other
in self
.parent():
1127 raise TypeError("'other' must live in the same algebra")
1129 L
= self
.operator_matrix()
1130 M
= other
.operator_matrix()
1131 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
1134 def span_of_powers(self
):
1136 Return the vector space spanned by successive powers of
1139 # The dimension of the subalgebra can't be greater than
1140 # the big algebra, so just put everything into a list
1141 # and let span() get rid of the excess.
1143 # We do the extra ambient_vector_space() in case we're messing
1144 # with polynomials and the direct parent is a module.
1145 V
= self
.vector().parent().ambient_vector_space()
1146 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1149 def subalgebra_generated_by(self
):
1151 Return the associative subalgebra of the parent EJA generated
1156 sage: set_random_seed()
1157 sage: x = random_eja().random_element()
1158 sage: x.subalgebra_generated_by().is_associative()
1161 Squaring in the subalgebra should be the same thing as
1162 squaring in the superalgebra::
1164 sage: set_random_seed()
1165 sage: x = random_eja().random_element()
1166 sage: u = x.subalgebra_generated_by().random_element()
1167 sage: u.operator_matrix()*u.vector() == (u**2).vector()
1171 # First get the subspace spanned by the powers of myself...
1172 V
= self
.span_of_powers()
1173 F
= self
.base_ring()
1175 # Now figure out the entries of the right-multiplication
1176 # matrix for the successive basis elements b0, b1,... of
1179 for b_right
in V
.basis():
1180 eja_b_right
= self
.parent()(b_right
)
1182 # The first row of the right-multiplication matrix by
1183 # b1 is what we get if we apply that matrix to b1. The
1184 # second row of the right multiplication matrix by b1
1185 # is what we get when we apply that matrix to b2...
1187 # IMPORTANT: this assumes that all vectors are COLUMN
1188 # vectors, unlike our superclass (which uses row vectors).
1189 for b_left
in V
.basis():
1190 eja_b_left
= self
.parent()(b_left
)
1191 # Multiply in the original EJA, but then get the
1192 # coordinates from the subalgebra in terms of its
1194 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1195 b_right_rows
.append(this_row
)
1196 b_right_matrix
= matrix(F
, b_right_rows
)
1197 mats
.append(b_right_matrix
)
1199 # It's an algebra of polynomials in one element, and EJAs
1200 # are power-associative.
1202 # TODO: choose generator names intelligently.
1203 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
1206 def subalgebra_idempotent(self
):
1208 Find an idempotent in the associative subalgebra I generate
1209 using Proposition 2.3.5 in Baes.
1213 sage: set_random_seed()
1214 sage: J = RealCartesianProductEJA(5)
1215 sage: c = J.random_element().subalgebra_idempotent()
1218 sage: J = JordanSpinEJA(5)
1219 sage: c = J.random_element().subalgebra_idempotent()
1224 if self
.is_nilpotent():
1225 raise ValueError("this only works with non-nilpotent elements!")
1227 V
= self
.span_of_powers()
1228 J
= self
.subalgebra_generated_by()
1229 # Mis-design warning: the basis used for span_of_powers()
1230 # and subalgebra_generated_by() must be the same, and in
1232 u
= J(V
.coordinates(self
.vector()))
1234 # The image of the matrix of left-u^m-multiplication
1235 # will be minimal for some natural number s...
1237 minimal_dim
= V
.dimension()
1238 for i
in xrange(1, V
.dimension()):
1239 this_dim
= (u
**i
).operator_matrix().image().dimension()
1240 if this_dim
< minimal_dim
:
1241 minimal_dim
= this_dim
1244 # Now minimal_matrix should correspond to the smallest
1245 # non-zero subspace in Baes's (or really, Koecher's)
1248 # However, we need to restrict the matrix to work on the
1249 # subspace... or do we? Can't we just solve, knowing that
1250 # A(c) = u^(s+1) should have a solution in the big space,
1253 # Beware, solve_right() means that we're using COLUMN vectors.
1254 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1256 A
= u_next
.operator_matrix()
1257 c_coordinates
= A
.solve_right(u_next
.vector())
1259 # Now c_coordinates is the idempotent we want, but it's in
1260 # the coordinate system of the subalgebra.
1262 # We need the basis for J, but as elements of the parent algebra.
1264 basis
= [self
.parent(v
) for v
in V
.basis()]
1265 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1270 Return my trace, the sum of my eigenvalues.
1274 sage: J = JordanSpinEJA(3)
1275 sage: x = sum(J.gens())
1281 sage: J = RealCartesianProductEJA(5)
1282 sage: J.one().trace()
1287 The trace of an element is a real number::
1289 sage: set_random_seed()
1290 sage: J = random_eja()
1291 sage: J.random_element().trace() in J.base_ring()
1297 p
= P
._charpoly
_coeff
(r
-1)
1298 # The _charpoly_coeff function already adds the factor of
1299 # -1 to ensure that _charpoly_coeff(r-1) is really what
1300 # appears in front of t^{r-1} in the charpoly. However,
1301 # we want the negative of THAT for the trace.
1302 return -p(*self
.vector())
1305 def trace_inner_product(self
, other
):
1307 Return the trace inner product of myself and ``other``.
1311 The trace inner product is commutative::
1313 sage: set_random_seed()
1314 sage: J = random_eja()
1315 sage: x = J.random_element(); y = J.random_element()
1316 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1319 The trace inner product is bilinear::
1321 sage: set_random_seed()
1322 sage: J = random_eja()
1323 sage: x = J.random_element()
1324 sage: y = J.random_element()
1325 sage: z = J.random_element()
1326 sage: a = QQ.random_element();
1327 sage: actual = (a*(x+z)).trace_inner_product(y)
1328 sage: expected = ( a*x.trace_inner_product(y) +
1329 ....: a*z.trace_inner_product(y) )
1330 sage: actual == expected
1332 sage: actual = x.trace_inner_product(a*(y+z))
1333 sage: expected = ( a*x.trace_inner_product(y) +
1334 ....: a*x.trace_inner_product(z) )
1335 sage: actual == expected
1338 The trace inner product satisfies the compatibility
1339 condition in the definition of a Euclidean Jordan algebra::
1341 sage: set_random_seed()
1342 sage: J = random_eja()
1343 sage: x = J.random_element()
1344 sage: y = J.random_element()
1345 sage: z = J.random_element()
1346 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1350 if not other
in self
.parent():
1351 raise TypeError("'other' must live in the same algebra")
1353 return (self
*other
).trace()
1356 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1358 Return the Euclidean Jordan Algebra corresponding to the set
1359 `R^n` under the Hadamard product.
1361 Note: this is nothing more than the Cartesian product of ``n``
1362 copies of the spin algebra. Once Cartesian product algebras
1363 are implemented, this can go.
1367 This multiplication table can be verified by hand::
1369 sage: J = RealCartesianProductEJA(3)
1370 sage: e0,e1,e2 = J.gens()
1386 def __classcall_private__(cls
, n
, field
=QQ
):
1387 # The FiniteDimensionalAlgebra constructor takes a list of
1388 # matrices, the ith representing right multiplication by the ith
1389 # basis element in the vector space. So if e_1 = (1,0,0), then
1390 # right (Hadamard) multiplication of x by e_1 picks out the first
1391 # component of x; and likewise for the ith basis element e_i.
1392 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1393 for i
in xrange(n
) ]
1395 fdeja
= super(RealCartesianProductEJA
, cls
)
1396 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1398 def inner_product(self
, x
, y
):
1399 return _usual_ip(x
,y
)
1404 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1408 For now, we choose a random natural number ``n`` (greater than zero)
1409 and then give you back one of the following:
1411 * The cartesian product of the rational numbers ``n`` times; this is
1412 ``QQ^n`` with the Hadamard product.
1414 * The Jordan spin algebra on ``QQ^n``.
1416 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1419 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1420 in the space of ``2n``-by-``2n`` real symmetric matrices.
1422 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1423 in the space of ``4n``-by-``4n`` real symmetric matrices.
1425 Later this might be extended to return Cartesian products of the
1431 Euclidean Jordan algebra of degree...
1435 # The max_n component lets us choose different upper bounds on the
1436 # value "n" that gets passed to the constructor. This is needed
1437 # because e.g. R^{10} is reasonable to test, while the Hermitian
1438 # 10-by-10 quaternion matrices are not.
1439 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1441 (RealSymmetricEJA
, 5),
1442 (ComplexHermitianEJA
, 4),
1443 (QuaternionHermitianEJA
, 3)])
1444 n
= ZZ
.random_element(1, max_n
)
1445 return constructor(n
, field
=QQ
)
1449 def _real_symmetric_basis(n
, field
=QQ
):
1451 Return a basis for the space of real symmetric n-by-n matrices.
1453 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1457 for j
in xrange(i
+1):
1458 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1462 # Beware, orthogonal but not normalized!
1463 Sij
= Eij
+ Eij
.transpose()
1468 def _complex_hermitian_basis(n
, field
=QQ
):
1470 Returns a basis for the space of complex Hermitian n-by-n matrices.
1474 sage: set_random_seed()
1475 sage: n = ZZ.random_element(1,5)
1476 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1480 F
= QuadraticField(-1, 'I')
1483 # This is like the symmetric case, but we need to be careful:
1485 # * We want conjugate-symmetry, not just symmetry.
1486 # * The diagonal will (as a result) be real.
1490 for j
in xrange(i
+1):
1491 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1493 Sij
= _embed_complex_matrix(Eij
)
1496 # Beware, orthogonal but not normalized! The second one
1497 # has a minus because it's conjugated.
1498 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1500 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1505 def _quaternion_hermitian_basis(n
, field
=QQ
):
1507 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1511 sage: set_random_seed()
1512 sage: n = ZZ.random_element(1,5)
1513 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1517 Q
= QuaternionAlgebra(QQ
,-1,-1)
1520 # This is like the symmetric case, but we need to be careful:
1522 # * We want conjugate-symmetry, not just symmetry.
1523 # * The diagonal will (as a result) be real.
1527 for j
in xrange(i
+1):
1528 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1530 Sij
= _embed_quaternion_matrix(Eij
)
1533 # Beware, orthogonal but not normalized! The second,
1534 # third, and fourth ones have a minus because they're
1536 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1538 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1540 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1542 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1548 return vector(m
.base_ring(), m
.list())
1551 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1553 def _multiplication_table_from_matrix_basis(basis
):
1555 At least three of the five simple Euclidean Jordan algebras have the
1556 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1557 multiplication on the right is matrix multiplication. Given a basis
1558 for the underlying matrix space, this function returns a
1559 multiplication table (obtained by looping through the basis
1560 elements) for an algebra of those matrices. A reordered copy
1561 of the basis is also returned to work around the fact that
1562 the ``span()`` in this function will change the order of the basis
1563 from what we think it is, to... something else.
1565 # In S^2, for example, we nominally have four coordinates even
1566 # though the space is of dimension three only. The vector space V
1567 # is supposed to hold the entire long vector, and the subspace W
1568 # of V will be spanned by the vectors that arise from symmetric
1569 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1570 field
= basis
[0].base_ring()
1571 dimension
= basis
[0].nrows()
1573 V
= VectorSpace(field
, dimension
**2)
1574 W
= V
.span( _mat2vec(s
) for s
in basis
)
1576 # Taking the span above reorders our basis (thanks, jerk!) so we
1577 # need to put our "matrix basis" in the same order as the
1578 # (reordered) vector basis.
1579 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1583 # Brute force the multiplication-by-s matrix by looping
1584 # through all elements of the basis and doing the computation
1585 # to find out what the corresponding row should be. BEWARE:
1586 # these multiplication tables won't be symmetric! It therefore
1587 # becomes REALLY IMPORTANT that the underlying algebra
1588 # constructor uses ROW vectors and not COLUMN vectors. That's
1589 # why we're computing rows here and not columns.
1592 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1593 Q_rows
.append(W
.coordinates(this_row
))
1594 Q
= matrix(field
, W
.dimension(), Q_rows
)
1600 def _embed_complex_matrix(M
):
1602 Embed the n-by-n complex matrix ``M`` into the space of real
1603 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1604 bi` to the block matrix ``[[a,b],[-b,a]]``.
1608 sage: F = QuadraticField(-1,'i')
1609 sage: x1 = F(4 - 2*i)
1610 sage: x2 = F(1 + 2*i)
1613 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1614 sage: _embed_complex_matrix(M)
1623 Embedding is a homomorphism (isomorphism, in fact)::
1625 sage: set_random_seed()
1626 sage: n = ZZ.random_element(5)
1627 sage: F = QuadraticField(-1, 'i')
1628 sage: X = random_matrix(F, n)
1629 sage: Y = random_matrix(F, n)
1630 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1631 sage: expected = _embed_complex_matrix(X*Y)
1632 sage: actual == expected
1638 raise ValueError("the matrix 'M' must be square")
1639 field
= M
.base_ring()
1644 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1646 # We can drop the imaginaries here.
1647 return block_matrix(field
.base_ring(), n
, blocks
)
1650 def _unembed_complex_matrix(M
):
1652 The inverse of _embed_complex_matrix().
1656 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1657 ....: [-2, 1, -4, 3],
1658 ....: [ 9, 10, 11, 12],
1659 ....: [-10, 9, -12, 11] ])
1660 sage: _unembed_complex_matrix(A)
1662 [ 10*i + 9 12*i + 11]
1666 Unembedding is the inverse of embedding::
1668 sage: set_random_seed()
1669 sage: F = QuadraticField(-1, 'i')
1670 sage: M = random_matrix(F, 3)
1671 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1677 raise ValueError("the matrix 'M' must be square")
1678 if not n
.mod(2).is_zero():
1679 raise ValueError("the matrix 'M' must be a complex embedding")
1681 F
= QuadraticField(-1, 'i')
1684 # Go top-left to bottom-right (reading order), converting every
1685 # 2-by-2 block we see to a single complex element.
1687 for k
in xrange(n
/2):
1688 for j
in xrange(n
/2):
1689 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1690 if submat
[0,0] != submat
[1,1]:
1691 raise ValueError('bad on-diagonal submatrix')
1692 if submat
[0,1] != -submat
[1,0]:
1693 raise ValueError('bad off-diagonal submatrix')
1694 z
= submat
[0,0] + submat
[0,1]*i
1697 return matrix(F
, n
/2, elements
)
1700 def _embed_quaternion_matrix(M
):
1702 Embed the n-by-n quaternion matrix ``M`` into the space of real
1703 matrices of size 4n-by-4n by first sending each quaternion entry
1704 `z = a + bi + cj + dk` to the block-complex matrix
1705 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1710 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1711 sage: i,j,k = Q.gens()
1712 sage: x = 1 + 2*i + 3*j + 4*k
1713 sage: M = matrix(Q, 1, [[x]])
1714 sage: _embed_quaternion_matrix(M)
1720 Embedding is a homomorphism (isomorphism, in fact)::
1722 sage: set_random_seed()
1723 sage: n = ZZ.random_element(5)
1724 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1725 sage: X = random_matrix(Q, n)
1726 sage: Y = random_matrix(Q, n)
1727 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1728 sage: expected = _embed_quaternion_matrix(X*Y)
1729 sage: actual == expected
1733 quaternions
= M
.base_ring()
1736 raise ValueError("the matrix 'M' must be square")
1738 F
= QuadraticField(-1, 'i')
1743 t
= z
.coefficient_tuple()
1748 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1749 [-c
+ d
*i
, a
- b
*i
]])
1750 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1752 # We should have real entries by now, so use the realest field
1753 # we've got for the return value.
1754 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1757 def _unembed_quaternion_matrix(M
):
1759 The inverse of _embed_quaternion_matrix().
1763 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1764 ....: [-2, 1, -4, 3],
1765 ....: [-3, 4, 1, -2],
1766 ....: [-4, -3, 2, 1]])
1767 sage: _unembed_quaternion_matrix(M)
1768 [1 + 2*i + 3*j + 4*k]
1772 Unembedding is the inverse of embedding::
1774 sage: set_random_seed()
1775 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1776 sage: M = random_matrix(Q, 3)
1777 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1783 raise ValueError("the matrix 'M' must be square")
1784 if not n
.mod(4).is_zero():
1785 raise ValueError("the matrix 'M' must be a complex embedding")
1787 Q
= QuaternionAlgebra(QQ
,-1,-1)
1790 # Go top-left to bottom-right (reading order), converting every
1791 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1794 for l
in xrange(n
/4):
1795 for m
in xrange(n
/4):
1796 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1797 if submat
[0,0] != submat
[1,1].conjugate():
1798 raise ValueError('bad on-diagonal submatrix')
1799 if submat
[0,1] != -submat
[1,0].conjugate():
1800 raise ValueError('bad off-diagonal submatrix')
1801 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1802 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1805 return matrix(Q
, n
/4, elements
)
1808 # The usual inner product on R^n.
1810 return x
.vector().inner_product(y
.vector())
1812 # The inner product used for the real symmetric simple EJA.
1813 # We keep it as a separate function because e.g. the complex
1814 # algebra uses the same inner product, except divided by 2.
1815 def _matrix_ip(X
,Y
):
1816 X_mat
= X
.natural_representation()
1817 Y_mat
= Y
.natural_representation()
1818 return (X_mat
*Y_mat
).trace()
1821 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1823 The rank-n simple EJA consisting of real symmetric n-by-n
1824 matrices, the usual symmetric Jordan product, and the trace inner
1825 product. It has dimension `(n^2 + n)/2` over the reals.
1829 sage: J = RealSymmetricEJA(2)
1830 sage: e0, e1, e2 = J.gens()
1840 The degree of this algebra is `(n^2 + n) / 2`::
1842 sage: set_random_seed()
1843 sage: n = ZZ.random_element(1,5)
1844 sage: J = RealSymmetricEJA(n)
1845 sage: J.degree() == (n^2 + n)/2
1848 The Jordan multiplication is what we think it is::
1850 sage: set_random_seed()
1851 sage: n = ZZ.random_element(1,5)
1852 sage: J = RealSymmetricEJA(n)
1853 sage: x = J.random_element()
1854 sage: y = J.random_element()
1855 sage: actual = (x*y).natural_representation()
1856 sage: X = x.natural_representation()
1857 sage: Y = y.natural_representation()
1858 sage: expected = (X*Y + Y*X)/2
1859 sage: actual == expected
1861 sage: J(expected) == x*y
1866 def __classcall_private__(cls
, n
, field
=QQ
):
1867 S
= _real_symmetric_basis(n
, field
=field
)
1868 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1870 fdeja
= super(RealSymmetricEJA
, cls
)
1871 return fdeja
.__classcall
_private
__(cls
,
1877 def inner_product(self
, x
, y
):
1878 return _matrix_ip(x
,y
)
1881 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1883 The rank-n simple EJA consisting of complex Hermitian n-by-n
1884 matrices over the real numbers, the usual symmetric Jordan product,
1885 and the real-part-of-trace inner product. It has dimension `n^2` over
1890 The degree of this algebra is `n^2`::
1892 sage: set_random_seed()
1893 sage: n = ZZ.random_element(1,5)
1894 sage: J = ComplexHermitianEJA(n)
1895 sage: J.degree() == n^2
1898 The Jordan multiplication is what we think it is::
1900 sage: set_random_seed()
1901 sage: n = ZZ.random_element(1,5)
1902 sage: J = ComplexHermitianEJA(n)
1903 sage: x = J.random_element()
1904 sage: y = J.random_element()
1905 sage: actual = (x*y).natural_representation()
1906 sage: X = x.natural_representation()
1907 sage: Y = y.natural_representation()
1908 sage: expected = (X*Y + Y*X)/2
1909 sage: actual == expected
1911 sage: J(expected) == x*y
1916 def __classcall_private__(cls
, n
, field
=QQ
):
1917 S
= _complex_hermitian_basis(n
)
1918 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1920 fdeja
= super(ComplexHermitianEJA
, cls
)
1921 return fdeja
.__classcall
_private
__(cls
,
1927 def inner_product(self
, x
, y
):
1928 # Since a+bi on the diagonal is represented as
1933 # we'll double-count the "a" entries if we take the trace of
1935 return _matrix_ip(x
,y
)/2
1938 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1940 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1941 matrices, the usual symmetric Jordan product, and the
1942 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1947 The degree of this algebra is `n^2`::
1949 sage: set_random_seed()
1950 sage: n = ZZ.random_element(1,5)
1951 sage: J = QuaternionHermitianEJA(n)
1952 sage: J.degree() == 2*(n^2) - n
1955 The Jordan multiplication is what we think it is::
1957 sage: set_random_seed()
1958 sage: n = ZZ.random_element(1,5)
1959 sage: J = QuaternionHermitianEJA(n)
1960 sage: x = J.random_element()
1961 sage: y = J.random_element()
1962 sage: actual = (x*y).natural_representation()
1963 sage: X = x.natural_representation()
1964 sage: Y = y.natural_representation()
1965 sage: expected = (X*Y + Y*X)/2
1966 sage: actual == expected
1968 sage: J(expected) == x*y
1973 def __classcall_private__(cls
, n
, field
=QQ
):
1974 S
= _quaternion_hermitian_basis(n
)
1975 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
1977 fdeja
= super(QuaternionHermitianEJA
, cls
)
1978 return fdeja
.__classcall
_private
__(cls
,
1984 def inner_product(self
, x
, y
):
1985 # Since a+bi+cj+dk on the diagonal is represented as
1987 # a + bi +cj + dk = [ a b c d]
1992 # we'll quadruple-count the "a" entries if we take the trace of
1994 return _matrix_ip(x
,y
)/4
1997 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1999 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2000 with the usual inner product and jordan product ``x*y =
2001 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2006 This multiplication table can be verified by hand::
2008 sage: J = JordanSpinEJA(4)
2009 sage: e0,e1,e2,e3 = J.gens()
2027 def __classcall_private__(cls
, n
, field
=QQ
):
2029 id_matrix
= identity_matrix(field
, n
)
2031 ei
= id_matrix
.column(i
)
2032 Qi
= zero_matrix(field
, n
)
2034 Qi
.set_column(0, ei
)
2035 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
2036 # The addition of the diagonal matrix adds an extra ei[0] in the
2037 # upper-left corner of the matrix.
2038 Qi
[0,0] = Qi
[0,0] * ~
field(2)
2041 # The rank of the spin algebra is two, unless we're in a
2042 # one-dimensional ambient space (because the rank is bounded by
2043 # the ambient dimension).
2044 fdeja
= super(JordanSpinEJA
, cls
)
2045 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
2047 def inner_product(self
, x
, y
):
2048 return _usual_ip(x
,y
)