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
14 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_morphism
import FiniteDimensionalAlgebraMorphism
17 class FiniteDimensionalEuclideanJordanAlgebraMorphism(FiniteDimensionalAlgebraMorphism
):
19 A very thin wrapper around FiniteDimensionalAlgebraMorphism that
20 does only three things:
22 1. Avoids the ``unitary`` and ``check`` arguments to the constructor
23 that will always be ``False``. This is necessary because these
24 are homomorphisms with respect to ADDITION, but the SageMath
25 machinery wants to check that they're homomorphisms with respect
26 to (Jordan) MULTIPLICATION. That obviously doesn't work.
28 2. Inputs and outputs the underlying matrix with respect to COLUMN
29 vectors, unlike the parent class.
31 3. Allows us to add morphisms in the obvious way.
33 4. Allows us to invert morphisms.
35 If this seems a bit heavyweight, it is. I would have been happy to
36 use a the ring morphism that underlies the finite-dimensional
37 algebra morphism, but they don't seem to be callable on elements of
38 our EJA, and you can't add/invert them.
41 def __add__(self
, other
):
43 Add two EJA morphisms in the obvious way.
47 sage: J = RealSymmetricEJA(3)
50 sage: x.operator() + y.operator()
51 Morphism from Euclidean Jordan algebra of degree 6 over Rational
52 Field to Euclidean Jordan algebra of degree 6 over Rational Field
63 sage: set_random_seed()
64 sage: J = random_eja()
65 sage: x = J.random_element()
66 sage: y = J.random_element()
67 sage: (x.operator() + y.operator()) in J.Hom(J)
73 raise ValueError("summands must live in the same space")
75 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
77 self
.matrix() + other
.matrix() )
80 def __init__(self
, parent
, f
):
81 FiniteDimensionalAlgebraMorphism
.__init
__(self
,
90 We override only the representation that is shown to the user,
91 because we want the matrix to be with respect to COLUMN vectors.
95 Ensure that we see the transpose of the underlying matrix object:
97 sage: J = RealSymmetricEJA(3)
98 sage: x = J.linear_combination(zip(range(len(J.gens())), J.gens()))
99 sage: L = x.operator()
101 Morphism from Euclidean Jordan algebra of degree 6 over Rational
102 Field to Euclidean Jordan algebra of degree 6 over Rational Field
119 return "Morphism from {} to {} given by matrix\n{}".format(
120 self
.domain(), self
.codomain(), self
.matrix())
124 Return the matrix of this morphism with respect to a left-action
127 return FiniteDimensionalAlgebraMorphism
.matrix(self
).transpose()
130 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
132 def __classcall_private__(cls
,
136 assume_associative
=False,
141 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
144 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
145 raise ValueError("input is not a multiplication table")
146 mult_table
= tuple(mult_table
)
148 cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
149 cat
.or_subcategory(category
)
150 if assume_associative
:
151 cat
= cat
.Associative()
153 names
= normalize_names(n
, names
)
155 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
156 return fda
.__classcall
__(cls
,
159 assume_associative
=assume_associative
,
163 natural_basis
=natural_basis
)
170 assume_associative
=False,
177 By definition, Jordan multiplication commutes::
179 sage: set_random_seed()
180 sage: J = random_eja()
181 sage: x = J.random_element()
182 sage: y = J.random_element()
188 self
._natural
_basis
= natural_basis
189 self
._multiplication
_table
= mult_table
190 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
199 Return a string representation of ``self``.
201 fmt
= "Euclidean Jordan algebra of degree {} over {}"
202 return fmt
.format(self
.degree(), self
.base_ring())
205 def _a_regular_element(self
):
207 Guess a regular element. Needed to compute the basis for our
208 characteristic polynomial coefficients.
211 z
= self
.sum( (i
+1)*gs
[i
] for i
in range(len(gs
)) )
212 if not z
.is_regular():
213 raise ValueError("don't know a regular element")
218 def _charpoly_basis_space(self
):
220 Return the vector space spanned by the basis used in our
221 characteristic polynomial coefficients. This is used not only to
222 compute those coefficients, but also any time we need to
223 evaluate the coefficients (like when we compute the trace or
226 z
= self
._a
_regular
_element
()
227 V
= z
.vector().parent().ambient_vector_space()
228 V1
= V
.span_of_basis( (z
**k
).vector() for k
in range(self
.rank()) )
229 b
= (V1
.basis() + V1
.complement().basis())
230 return V
.span_of_basis(b
)
234 def _charpoly_coeff(self
, i
):
236 Return the coefficient polynomial "a_{i}" of this algebra's
237 general characteristic polynomial.
239 Having this be a separate cached method lets us compute and
240 store the trace/determinant (a_{r-1} and a_{0} respectively)
241 separate from the entire characteristic polynomial.
243 (A_of_x
, x
, xr
, detA
) = self
._charpoly
_matrix
_system
()
244 R
= A_of_x
.base_ring()
246 # Guaranteed by theory
249 # Danger: the in-place modification is done for performance
250 # reasons (reconstructing a matrix with huge polynomial
251 # entries is slow), but I don't know how cached_method works,
252 # so it's highly possible that we're modifying some global
253 # list variable by reference, here. In other words, you
254 # probably shouldn't call this method twice on the same
255 # algebra, at the same time, in two threads
256 Ai_orig
= A_of_x
.column(i
)
257 A_of_x
.set_column(i
,xr
)
258 numerator
= A_of_x
.det()
259 A_of_x
.set_column(i
,Ai_orig
)
261 # We're relying on the theory here to ensure that each a_i is
262 # indeed back in R, and the added negative signs are to make
263 # the whole charpoly expression sum to zero.
264 return R(-numerator
/detA
)
268 def _charpoly_matrix_system(self
):
270 Compute the matrix whose entries A_ij are polynomials in
271 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
272 corresponding to `x^r` and the determinent of the matrix A =
273 [A_ij]. In other words, all of the fixed (cachable) data needed
274 to compute the coefficients of the characteristic polynomial.
279 # Construct a new algebra over a multivariate polynomial ring...
280 names
= ['X' + str(i
) for i
in range(1,n
+1)]
281 R
= PolynomialRing(self
.base_ring(), names
)
282 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
283 self
._multiplication
_table
,
286 idmat
= identity_matrix(J
.base_ring(), n
)
288 W
= self
._charpoly
_basis
_space
()
289 W
= W
.change_ring(R
.fraction_field())
291 # Starting with the standard coordinates x = (X1,X2,...,Xn)
292 # and then converting the entries to W-coordinates allows us
293 # to pass in the standard coordinates to the charpoly and get
294 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
297 # W.coordinates(x^2) eval'd at (standard z-coords)
301 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
303 # We want the middle equivalent thing in our matrix, but use
304 # the first equivalent thing instead so that we can pass in
305 # standard coordinates.
306 x
= J(vector(R
, R
.gens()))
307 l1
= [column_matrix(W
.coordinates((x
**k
).vector())) for k
in range(r
)]
308 l2
= [idmat
.column(k
-1).column() for k
in range(r
+1, n
+1)]
309 A_of_x
= block_matrix(R
, 1, n
, (l1
+ l2
))
310 xr
= W
.coordinates((x
**r
).vector())
311 return (A_of_x
, x
, xr
, A_of_x
.det())
315 def characteristic_polynomial(self
):
320 This implementation doesn't guarantee that the polynomial
321 denominator in the coefficients is not identically zero, so
322 theoretically it could crash. The way that this is handled
323 in e.g. Faraut and Koranyi is to use a basis that guarantees
324 the denominator is non-zero. But, doing so requires knowledge
325 of at least one regular element, and we don't even know how
326 to do that. The trade-off is that, if we use the standard basis,
327 the resulting polynomial will accept the "usual" coordinates. In
328 other words, we don't have to do a change of basis before e.g.
329 computing the trace or determinant.
333 The characteristic polynomial in the spin algebra is given in
334 Alizadeh, Example 11.11::
336 sage: J = JordanSpinEJA(3)
337 sage: p = J.characteristic_polynomial(); p
338 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
339 sage: xvec = J.one().vector()
347 # The list of coefficient polynomials a_1, a_2, ..., a_n.
348 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
350 # We go to a bit of trouble here to reorder the
351 # indeterminates, so that it's easier to evaluate the
352 # characteristic polynomial at x's coordinates and get back
353 # something in terms of t, which is what we want.
355 S
= PolynomialRing(self
.base_ring(),'t')
357 S
= PolynomialRing(S
, R
.variable_names())
360 # Note: all entries past the rth should be zero. The
361 # coefficient of the highest power (x^r) is 1, but it doesn't
362 # appear in the solution vector which contains coefficients
363 # for the other powers (to make them sum to x^r).
365 a
[r
] = 1 # corresponds to x^r
367 # When the rank is equal to the dimension, trying to
368 # assign a[r] goes out-of-bounds.
369 a
.append(1) # corresponds to x^r
371 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
374 def inner_product(self
, x
, y
):
376 The inner product associated with this Euclidean Jordan algebra.
378 Defaults to the trace inner product, but can be overridden by
379 subclasses if they are sure that the necessary properties are
384 The inner product must satisfy its axiom for this algebra to truly
385 be a Euclidean Jordan Algebra::
387 sage: set_random_seed()
388 sage: J = random_eja()
389 sage: x = J.random_element()
390 sage: y = J.random_element()
391 sage: z = J.random_element()
392 sage: (x*y).inner_product(z) == y.inner_product(x*z)
396 if (not x
in self
) or (not y
in self
):
397 raise TypeError("arguments must live in this algebra")
398 return x
.trace_inner_product(y
)
401 def natural_basis(self
):
403 Return a more-natural representation of this algebra's basis.
405 Every finite-dimensional Euclidean Jordan Algebra is a direct
406 sum of five simple algebras, four of which comprise Hermitian
407 matrices. This method returns the original "natural" basis
408 for our underlying vector space. (Typically, the natural basis
409 is used to construct the multiplication table in the first place.)
411 Note that this will always return a matrix. The standard basis
412 in `R^n` will be returned as `n`-by-`1` column matrices.
416 sage: J = RealSymmetricEJA(2)
419 sage: J.natural_basis()
427 sage: J = JordanSpinEJA(2)
430 sage: J.natural_basis()
437 if self
._natural
_basis
is None:
438 return tuple( b
.vector().column() for b
in self
.basis() )
440 return self
._natural
_basis
445 Return the rank of this EJA.
447 if self
._rank
is None:
448 raise ValueError("no rank specified at genesis")
453 class Element(FiniteDimensionalAlgebraElement
):
455 An element of a Euclidean Jordan algebra.
460 Oh man, I should not be doing this. This hides the "disabled"
461 methods ``left_matrix`` and ``matrix`` from introspection;
462 in particular it removes them from tab-completion.
464 return filter(lambda s
: s
not in ['left_matrix', 'matrix'],
465 dir(self
.__class
__) )
468 def __init__(self
, A
, elt
=None):
472 The identity in `S^n` is converted to the identity in the EJA::
474 sage: J = RealSymmetricEJA(3)
475 sage: I = identity_matrix(QQ,3)
476 sage: J(I) == J.one()
479 This skew-symmetric matrix can't be represented in the EJA::
481 sage: J = RealSymmetricEJA(3)
482 sage: A = matrix(QQ,3, lambda i,j: i-j)
484 Traceback (most recent call last):
486 ArithmeticError: vector is not in free module
489 # Goal: if we're given a matrix, and if it lives in our
490 # parent algebra's "natural ambient space," convert it
491 # into an algebra element.
493 # The catch is, we make a recursive call after converting
494 # the given matrix into a vector that lives in the algebra.
495 # This we need to try the parent class initializer first,
496 # to avoid recursing forever if we're given something that
497 # already fits into the algebra, but also happens to live
498 # in the parent's "natural ambient space" (this happens with
501 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
503 natural_basis
= A
.natural_basis()
504 if elt
in natural_basis
[0].matrix_space():
505 # Thanks for nothing! Matrix spaces aren't vector
506 # spaces in Sage, so we have to figure out its
507 # natural-basis coordinates ourselves.
508 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
509 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
510 coords
= W
.coordinates(_mat2vec(elt
))
511 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
513 def __pow__(self
, n
):
515 Return ``self`` raised to the power ``n``.
517 Jordan algebras are always power-associative; see for
518 example Faraut and Koranyi, Proposition II.1.2 (ii).
522 We have to override this because our superclass uses row vectors
523 instead of column vectors! We, on the other hand, assume column
528 sage: set_random_seed()
529 sage: x = random_eja().random_element()
530 sage: x.operator_matrix()*x.vector() == (x^2).vector()
533 A few examples of power-associativity::
535 sage: set_random_seed()
536 sage: x = random_eja().random_element()
537 sage: x*(x*x)*(x*x) == x^5
539 sage: (x*x)*(x*x*x) == x^5
542 We also know that powers operator-commute (Koecher, Chapter
545 sage: set_random_seed()
546 sage: x = random_eja().random_element()
547 sage: m = ZZ.random_element(0,10)
548 sage: n = ZZ.random_element(0,10)
549 sage: Lxm = (x^m).operator_matrix()
550 sage: Lxn = (x^n).operator_matrix()
551 sage: Lxm*Lxn == Lxn*Lxm
561 return A( (self
.operator_matrix()**(n
-1))*self
.vector() )
564 def apply_univariate_polynomial(self
, p
):
566 Apply the univariate polynomial ``p`` to this element.
568 A priori, SageMath won't allow us to apply a univariate
569 polynomial to an element of an EJA, because we don't know
570 that EJAs are rings (they are usually not associative). Of
571 course, we know that EJAs are power-associative, so the
572 operation is ultimately kosher. This function sidesteps
573 the CAS to get the answer we want and expect.
577 sage: R = PolynomialRing(QQ, 't')
579 sage: p = t^4 - t^3 + 5*t - 2
580 sage: J = RealCartesianProductEJA(5)
581 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
586 We should always get back an element of the algebra::
588 sage: set_random_seed()
589 sage: p = PolynomialRing(QQ, 't').random_element()
590 sage: J = random_eja()
591 sage: x = J.random_element()
592 sage: x.apply_univariate_polynomial(p) in J
596 if len(p
.variables()) > 1:
597 raise ValueError("not a univariate polynomial")
600 # Convert the coeficcients to the parent's base ring,
601 # because a priori they might live in an (unnecessarily)
602 # larger ring for which P.sum() would fail below.
603 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
604 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
607 def characteristic_polynomial(self
):
609 Return the characteristic polynomial of this element.
613 The rank of `R^3` is three, and the minimal polynomial of
614 the identity element is `(t-1)` from which it follows that
615 the characteristic polynomial should be `(t-1)^3`::
617 sage: J = RealCartesianProductEJA(3)
618 sage: J.one().characteristic_polynomial()
619 t^3 - 3*t^2 + 3*t - 1
621 Likewise, the characteristic of the zero element in the
622 rank-three algebra `R^{n}` should be `t^{3}`::
624 sage: J = RealCartesianProductEJA(3)
625 sage: J.zero().characteristic_polynomial()
628 The characteristic polynomial of an element should evaluate
629 to zero on that element::
631 sage: set_random_seed()
632 sage: x = RealCartesianProductEJA(3).random_element()
633 sage: p = x.characteristic_polynomial()
634 sage: x.apply_univariate_polynomial(p)
638 p
= self
.parent().characteristic_polynomial()
639 return p(*self
.vector())
642 def inner_product(self
, other
):
644 Return the parent algebra's inner product of myself and ``other``.
648 The inner product in the Jordan spin algebra is the usual
649 inner product on `R^n` (this example only works because the
650 basis for the Jordan algebra is the standard basis in `R^n`)::
652 sage: J = JordanSpinEJA(3)
653 sage: x = vector(QQ,[1,2,3])
654 sage: y = vector(QQ,[4,5,6])
655 sage: x.inner_product(y)
657 sage: J(x).inner_product(J(y))
660 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
661 multiplication is the usual matrix multiplication in `S^n`,
662 so the inner product of the identity matrix with itself
665 sage: J = RealSymmetricEJA(3)
666 sage: J.one().inner_product(J.one())
669 Likewise, the inner product on `C^n` is `<X,Y> =
670 Re(trace(X*Y))`, where we must necessarily take the real
671 part because the product of Hermitian matrices may not be
674 sage: J = ComplexHermitianEJA(3)
675 sage: J.one().inner_product(J.one())
678 Ditto for the quaternions::
680 sage: J = QuaternionHermitianEJA(3)
681 sage: J.one().inner_product(J.one())
686 Ensure that we can always compute an inner product, and that
687 it gives us back a real number::
689 sage: set_random_seed()
690 sage: J = random_eja()
691 sage: x = J.random_element()
692 sage: y = J.random_element()
693 sage: x.inner_product(y) in RR
699 raise TypeError("'other' must live in the same algebra")
701 return P
.inner_product(self
, other
)
704 def operator_commutes_with(self
, other
):
706 Return whether or not this element operator-commutes
711 The definition of a Jordan algebra says that any element
712 operator-commutes with its square::
714 sage: set_random_seed()
715 sage: x = random_eja().random_element()
716 sage: x.operator_commutes_with(x^2)
721 Test Lemma 1 from Chapter III of Koecher::
723 sage: set_random_seed()
724 sage: J = random_eja()
725 sage: u = J.random_element()
726 sage: v = J.random_element()
727 sage: lhs = u.operator_commutes_with(u*v)
728 sage: rhs = v.operator_commutes_with(u^2)
733 if not other
in self
.parent():
734 raise TypeError("'other' must live in the same algebra")
736 A
= self
.operator_matrix()
737 B
= other
.operator_matrix()
743 Return my determinant, the product of my eigenvalues.
747 sage: J = JordanSpinEJA(2)
748 sage: e0,e1 = J.gens()
749 sage: x = sum( J.gens() )
755 sage: J = JordanSpinEJA(3)
756 sage: e0,e1,e2 = J.gens()
757 sage: x = sum( J.gens() )
763 An element is invertible if and only if its determinant is
766 sage: set_random_seed()
767 sage: x = random_eja().random_element()
768 sage: x.is_invertible() == (x.det() != 0)
774 p
= P
._charpoly
_coeff
(0)
775 # The _charpoly_coeff function already adds the factor of
776 # -1 to ensure that _charpoly_coeff(0) is really what
777 # appears in front of t^{0} in the charpoly. However,
778 # we want (-1)^r times THAT for the determinant.
779 return ((-1)**r
)*p(*self
.vector())
784 Return the Jordan-multiplicative inverse of this element.
788 We appeal to the quadratic representation as in Koecher's
789 Theorem 12 in Chapter III, Section 5.
793 The inverse in the spin factor algebra is given in Alizadeh's
796 sage: set_random_seed()
797 sage: n = ZZ.random_element(1,10)
798 sage: J = JordanSpinEJA(n)
799 sage: x = J.random_element()
800 sage: while x.is_zero():
801 ....: x = J.random_element()
802 sage: x_vec = x.vector()
804 sage: x_bar = x_vec[1:]
805 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
806 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
807 sage: x_inverse = coeff*inv_vec
808 sage: x.inverse() == J(x_inverse)
813 The identity element is its own inverse::
815 sage: set_random_seed()
816 sage: J = random_eja()
817 sage: J.one().inverse() == J.one()
820 If an element has an inverse, it acts like one::
822 sage: set_random_seed()
823 sage: J = random_eja()
824 sage: x = J.random_element()
825 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
828 The inverse of the inverse is what we started with::
830 sage: set_random_seed()
831 sage: J = random_eja()
832 sage: x = J.random_element()
833 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
836 The zero element is never invertible::
838 sage: set_random_seed()
839 sage: J = random_eja().zero().inverse()
840 Traceback (most recent call last):
842 ValueError: element is not invertible
845 if not self
.is_invertible():
846 raise ValueError("element is not invertible")
849 return P(self
.quadratic_representation().inverse()*self
.vector())
852 def is_invertible(self
):
854 Return whether or not this element is invertible.
856 We can't use the superclass method because it relies on
857 the algebra being associative.
861 The usual way to do this is to check if the determinant is
862 zero, but we need the characteristic polynomial for the
863 determinant. The minimal polynomial is a lot easier to get,
864 so we use Corollary 2 in Chapter V of Koecher to check
865 whether or not the paren't algebra's zero element is a root
866 of this element's minimal polynomial.
870 The identity element is always invertible::
872 sage: set_random_seed()
873 sage: J = random_eja()
874 sage: J.one().is_invertible()
877 The zero element is never invertible::
879 sage: set_random_seed()
880 sage: J = random_eja()
881 sage: J.zero().is_invertible()
885 zero
= self
.parent().zero()
886 p
= self
.minimal_polynomial()
887 return not (p(zero
) == zero
)
890 def is_nilpotent(self
):
892 Return whether or not some power of this element is zero.
894 The superclass method won't work unless we're in an
895 associative algebra, and we aren't. However, we generate
896 an assocoative subalgebra and we're nilpotent there if and
897 only if we're nilpotent here (probably).
901 The identity element is never nilpotent::
903 sage: set_random_seed()
904 sage: random_eja().one().is_nilpotent()
907 The additive identity is always nilpotent::
909 sage: set_random_seed()
910 sage: random_eja().zero().is_nilpotent()
914 # The element we're going to call "is_nilpotent()" on.
915 # Either myself, interpreted as an element of a finite-
916 # dimensional algebra, or an element of an associative
920 if self
.parent().is_associative():
921 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
923 V
= self
.span_of_powers()
924 assoc_subalg
= self
.subalgebra_generated_by()
925 # Mis-design warning: the basis used for span_of_powers()
926 # and subalgebra_generated_by() must be the same, and in
928 elt
= assoc_subalg(V
.coordinates(self
.vector()))
930 # Recursive call, but should work since elt lives in an
931 # associative algebra.
932 return elt
.is_nilpotent()
935 def is_regular(self
):
937 Return whether or not this is a regular element.
941 The identity element always has degree one, but any element
942 linearly-independent from it is regular::
944 sage: J = JordanSpinEJA(5)
945 sage: J.one().is_regular()
947 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
948 sage: for x in J.gens():
949 ....: (J.one() + x).is_regular()
957 return self
.degree() == self
.parent().rank()
962 Compute the degree of this element the straightforward way
963 according to the definition; by appending powers to a list
964 and figuring out its dimension (that is, whether or not
965 they're linearly dependent).
969 sage: J = JordanSpinEJA(4)
970 sage: J.one().degree()
972 sage: e0,e1,e2,e3 = J.gens()
973 sage: (e0 - e1).degree()
976 In the spin factor algebra (of rank two), all elements that
977 aren't multiples of the identity are regular::
979 sage: set_random_seed()
980 sage: n = ZZ.random_element(1,10)
981 sage: J = JordanSpinEJA(n)
982 sage: x = J.random_element()
983 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
987 return self
.span_of_powers().dimension()
990 def left_matrix(self
):
992 Our parent class defines ``left_matrix`` and ``matrix``
993 methods whose names are misleading. We don't want them.
995 raise NotImplementedError("use operator_matrix() instead")
1000 def minimal_polynomial(self
):
1002 Return the minimal polynomial of this element,
1003 as a function of the variable `t`.
1007 We restrict ourselves to the associative subalgebra
1008 generated by this element, and then return the minimal
1009 polynomial of this element's operator matrix (in that
1010 subalgebra). This works by Baes Proposition 2.3.16.
1014 The minimal polynomial of the identity and zero elements are
1017 sage: set_random_seed()
1018 sage: J = random_eja()
1019 sage: J.one().minimal_polynomial()
1021 sage: J.zero().minimal_polynomial()
1024 The degree of an element is (by one definition) the degree
1025 of its minimal polynomial::
1027 sage: set_random_seed()
1028 sage: x = random_eja().random_element()
1029 sage: x.degree() == x.minimal_polynomial().degree()
1032 The minimal polynomial and the characteristic polynomial coincide
1033 and are known (see Alizadeh, Example 11.11) for all elements of
1034 the spin factor algebra that aren't scalar multiples of the
1037 sage: set_random_seed()
1038 sage: n = ZZ.random_element(2,10)
1039 sage: J = JordanSpinEJA(n)
1040 sage: y = J.random_element()
1041 sage: while y == y.coefficient(0)*J.one():
1042 ....: y = J.random_element()
1043 sage: y0 = y.vector()[0]
1044 sage: y_bar = y.vector()[1:]
1045 sage: actual = y.minimal_polynomial()
1046 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
1047 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
1048 sage: bool(actual == expected)
1051 The minimal polynomial should always kill its element::
1053 sage: set_random_seed()
1054 sage: x = random_eja().random_element()
1055 sage: p = x.minimal_polynomial()
1056 sage: x.apply_univariate_polynomial(p)
1060 V
= self
.span_of_powers()
1061 assoc_subalg
= self
.subalgebra_generated_by()
1062 # Mis-design warning: the basis used for span_of_powers()
1063 # and subalgebra_generated_by() must be the same, and in
1065 elt
= assoc_subalg(V
.coordinates(self
.vector()))
1067 # We get back a symbolic polynomial in 'x' but want a real
1068 # polynomial in 't'.
1069 p_of_x
= elt
.operator_matrix().minimal_polynomial()
1070 return p_of_x
.change_variable_name('t')
1073 def natural_representation(self
):
1075 Return a more-natural representation of this element.
1077 Every finite-dimensional Euclidean Jordan Algebra is a
1078 direct sum of five simple algebras, four of which comprise
1079 Hermitian matrices. This method returns the original
1080 "natural" representation of this element as a Hermitian
1081 matrix, if it has one. If not, you get the usual representation.
1085 sage: J = ComplexHermitianEJA(3)
1088 sage: J.one().natural_representation()
1098 sage: J = QuaternionHermitianEJA(3)
1101 sage: J.one().natural_representation()
1102 [1 0 0 0 0 0 0 0 0 0 0 0]
1103 [0 1 0 0 0 0 0 0 0 0 0 0]
1104 [0 0 1 0 0 0 0 0 0 0 0 0]
1105 [0 0 0 1 0 0 0 0 0 0 0 0]
1106 [0 0 0 0 1 0 0 0 0 0 0 0]
1107 [0 0 0 0 0 1 0 0 0 0 0 0]
1108 [0 0 0 0 0 0 1 0 0 0 0 0]
1109 [0 0 0 0 0 0 0 1 0 0 0 0]
1110 [0 0 0 0 0 0 0 0 1 0 0 0]
1111 [0 0 0 0 0 0 0 0 0 1 0 0]
1112 [0 0 0 0 0 0 0 0 0 0 1 0]
1113 [0 0 0 0 0 0 0 0 0 0 0 1]
1116 B
= self
.parent().natural_basis()
1117 W
= B
[0].matrix_space()
1118 return W
.linear_combination(zip(self
.vector(), B
))
1123 Return the left-multiplication-by-this-element
1124 operator on the ambient algebra.
1128 sage: set_random_seed()
1129 sage: J = random_eja()
1130 sage: x = J.random_element()
1131 sage: y = J.random_element()
1132 sage: x.operator()(y) == x*y
1134 sage: y.operator()(x) == x*y
1139 return FiniteDimensionalEuclideanJordanAlgebraMorphism(
1141 self
.operator_matrix() )
1145 def operator_matrix(self
):
1147 Return the matrix that represents left- (or right-)
1148 multiplication by this element in the parent algebra.
1150 We implement this ourselves to work around the fact that
1151 our parent class represents everything with row vectors.
1155 Test the first polarization identity from my notes, Koecher Chapter
1156 III, or from Baes (2.3)::
1158 sage: set_random_seed()
1159 sage: J = random_eja()
1160 sage: x = J.random_element()
1161 sage: y = J.random_element()
1162 sage: Lx = x.operator_matrix()
1163 sage: Ly = y.operator_matrix()
1164 sage: Lxx = (x*x).operator_matrix()
1165 sage: Lxy = (x*y).operator_matrix()
1166 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
1169 Test the second polarization identity from my notes or from
1172 sage: set_random_seed()
1173 sage: J = random_eja()
1174 sage: x = J.random_element()
1175 sage: y = J.random_element()
1176 sage: z = J.random_element()
1177 sage: Lx = x.operator_matrix()
1178 sage: Ly = y.operator_matrix()
1179 sage: Lz = z.operator_matrix()
1180 sage: Lzy = (z*y).operator_matrix()
1181 sage: Lxy = (x*y).operator_matrix()
1182 sage: Lxz = (x*z).operator_matrix()
1183 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
1186 Test the third polarization identity from my notes or from
1189 sage: set_random_seed()
1190 sage: J = random_eja()
1191 sage: u = J.random_element()
1192 sage: y = J.random_element()
1193 sage: z = J.random_element()
1194 sage: Lu = u.operator_matrix()
1195 sage: Ly = y.operator_matrix()
1196 sage: Lz = z.operator_matrix()
1197 sage: Lzy = (z*y).operator_matrix()
1198 sage: Luy = (u*y).operator_matrix()
1199 sage: Luz = (u*z).operator_matrix()
1200 sage: Luyz = (u*(y*z)).operator_matrix()
1201 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
1202 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
1203 sage: bool(lhs == rhs)
1207 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
1208 return fda_elt
.matrix().transpose()
1211 def quadratic_representation(self
, other
=None):
1213 Return the quadratic representation of this element.
1217 The explicit form in the spin factor algebra is given by
1218 Alizadeh's Example 11.12::
1220 sage: set_random_seed()
1221 sage: n = ZZ.random_element(1,10)
1222 sage: J = JordanSpinEJA(n)
1223 sage: x = J.random_element()
1224 sage: x_vec = x.vector()
1226 sage: x_bar = x_vec[1:]
1227 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1228 sage: B = 2*x0*x_bar.row()
1229 sage: C = 2*x0*x_bar.column()
1230 sage: D = identity_matrix(QQ, n-1)
1231 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1232 sage: D = D + 2*x_bar.tensor_product(x_bar)
1233 sage: Q = block_matrix(2,2,[A,B,C,D])
1234 sage: Q == x.quadratic_representation()
1237 Test all of the properties from Theorem 11.2 in Alizadeh::
1239 sage: set_random_seed()
1240 sage: J = random_eja()
1241 sage: x = J.random_element()
1242 sage: y = J.random_element()
1243 sage: Lx = x.operator_matrix()
1244 sage: Lxx = (x*x).operator_matrix()
1245 sage: Qx = x.quadratic_representation()
1246 sage: Qy = y.quadratic_representation()
1247 sage: Qxy = x.quadratic_representation(y)
1248 sage: Qex = J.one().quadratic_representation(x)
1249 sage: n = ZZ.random_element(10)
1250 sage: Qxn = (x^n).quadratic_representation()
1254 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1259 sage: alpha = QQ.random_element()
1260 sage: (alpha*x).quadratic_representation() == (alpha^2)*Qx
1265 sage: not x.is_invertible() or (
1266 ....: Qx*x.inverse().vector() == x.vector() )
1269 sage: not x.is_invertible() or (
1272 ....: x.inverse().quadratic_representation() )
1275 sage: Qxy*(J.one().vector()) == (x*y).vector()
1280 sage: not x.is_invertible() or (
1281 ....: x.quadratic_representation(x.inverse())*Qx
1282 ....: == Qx*x.quadratic_representation(x.inverse()) )
1285 sage: not x.is_invertible() or (
1286 ....: x.quadratic_representation(x.inverse())*Qx
1288 ....: 2*x.operator_matrix()*Qex - Qx )
1291 sage: 2*x.operator_matrix()*Qex - Qx == Lxx
1296 sage: J(Qy*x.vector()).quadratic_representation() == Qy*Qx*Qy
1306 sage: not x.is_invertible() or (
1307 ....: Qx*x.inverse().operator_matrix() == Lx )
1312 sage: not x.operator_commutes_with(y) or (
1313 ....: J(Qx*y.vector())^n == J(Qxn*(y^n).vector()) )
1319 elif not other
in self
.parent():
1320 raise TypeError("'other' must live in the same algebra")
1322 L
= self
.operator_matrix()
1323 M
= other
.operator_matrix()
1324 return ( L
*M
+ M
*L
- (self
*other
).operator_matrix() )
1327 def span_of_powers(self
):
1329 Return the vector space spanned by successive powers of
1332 # The dimension of the subalgebra can't be greater than
1333 # the big algebra, so just put everything into a list
1334 # and let span() get rid of the excess.
1336 # We do the extra ambient_vector_space() in case we're messing
1337 # with polynomials and the direct parent is a module.
1338 V
= self
.vector().parent().ambient_vector_space()
1339 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1342 def subalgebra_generated_by(self
):
1344 Return the associative subalgebra of the parent EJA generated
1349 sage: set_random_seed()
1350 sage: x = random_eja().random_element()
1351 sage: x.subalgebra_generated_by().is_associative()
1354 Squaring in the subalgebra should be the same thing as
1355 squaring in the superalgebra::
1357 sage: set_random_seed()
1358 sage: x = random_eja().random_element()
1359 sage: u = x.subalgebra_generated_by().random_element()
1360 sage: u.operator_matrix()*u.vector() == (u**2).vector()
1364 # First get the subspace spanned by the powers of myself...
1365 V
= self
.span_of_powers()
1366 F
= self
.base_ring()
1368 # Now figure out the entries of the right-multiplication
1369 # matrix for the successive basis elements b0, b1,... of
1372 for b_right
in V
.basis():
1373 eja_b_right
= self
.parent()(b_right
)
1375 # The first row of the right-multiplication matrix by
1376 # b1 is what we get if we apply that matrix to b1. The
1377 # second row of the right multiplication matrix by b1
1378 # is what we get when we apply that matrix to b2...
1380 # IMPORTANT: this assumes that all vectors are COLUMN
1381 # vectors, unlike our superclass (which uses row vectors).
1382 for b_left
in V
.basis():
1383 eja_b_left
= self
.parent()(b_left
)
1384 # Multiply in the original EJA, but then get the
1385 # coordinates from the subalgebra in terms of its
1387 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1388 b_right_rows
.append(this_row
)
1389 b_right_matrix
= matrix(F
, b_right_rows
)
1390 mats
.append(b_right_matrix
)
1392 # It's an algebra of polynomials in one element, and EJAs
1393 # are power-associative.
1395 # TODO: choose generator names intelligently.
1396 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
1399 def subalgebra_idempotent(self
):
1401 Find an idempotent in the associative subalgebra I generate
1402 using Proposition 2.3.5 in Baes.
1406 sage: set_random_seed()
1407 sage: J = random_eja()
1408 sage: x = J.random_element()
1409 sage: while x.is_nilpotent():
1410 ....: x = J.random_element()
1411 sage: c = x.subalgebra_idempotent()
1416 if self
.is_nilpotent():
1417 raise ValueError("this only works with non-nilpotent elements!")
1419 V
= self
.span_of_powers()
1420 J
= self
.subalgebra_generated_by()
1421 # Mis-design warning: the basis used for span_of_powers()
1422 # and subalgebra_generated_by() must be the same, and in
1424 u
= J(V
.coordinates(self
.vector()))
1426 # The image of the matrix of left-u^m-multiplication
1427 # will be minimal for some natural number s...
1429 minimal_dim
= V
.dimension()
1430 for i
in xrange(1, V
.dimension()):
1431 this_dim
= (u
**i
).operator_matrix().image().dimension()
1432 if this_dim
< minimal_dim
:
1433 minimal_dim
= this_dim
1436 # Now minimal_matrix should correspond to the smallest
1437 # non-zero subspace in Baes's (or really, Koecher's)
1440 # However, we need to restrict the matrix to work on the
1441 # subspace... or do we? Can't we just solve, knowing that
1442 # A(c) = u^(s+1) should have a solution in the big space,
1445 # Beware, solve_right() means that we're using COLUMN vectors.
1446 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1448 A
= u_next
.operator_matrix()
1449 c_coordinates
= A
.solve_right(u_next
.vector())
1451 # Now c_coordinates is the idempotent we want, but it's in
1452 # the coordinate system of the subalgebra.
1454 # We need the basis for J, but as elements of the parent algebra.
1456 basis
= [self
.parent(v
) for v
in V
.basis()]
1457 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1462 Return my trace, the sum of my eigenvalues.
1466 sage: J = JordanSpinEJA(3)
1467 sage: x = sum(J.gens())
1473 sage: J = RealCartesianProductEJA(5)
1474 sage: J.one().trace()
1479 The trace of an element is a real number::
1481 sage: set_random_seed()
1482 sage: J = random_eja()
1483 sage: J.random_element().trace() in J.base_ring()
1489 p
= P
._charpoly
_coeff
(r
-1)
1490 # The _charpoly_coeff function already adds the factor of
1491 # -1 to ensure that _charpoly_coeff(r-1) is really what
1492 # appears in front of t^{r-1} in the charpoly. However,
1493 # we want the negative of THAT for the trace.
1494 return -p(*self
.vector())
1497 def trace_inner_product(self
, other
):
1499 Return the trace inner product of myself and ``other``.
1503 The trace inner product is commutative::
1505 sage: set_random_seed()
1506 sage: J = random_eja()
1507 sage: x = J.random_element(); y = J.random_element()
1508 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1511 The trace inner product is bilinear::
1513 sage: set_random_seed()
1514 sage: J = random_eja()
1515 sage: x = J.random_element()
1516 sage: y = J.random_element()
1517 sage: z = J.random_element()
1518 sage: a = QQ.random_element();
1519 sage: actual = (a*(x+z)).trace_inner_product(y)
1520 sage: expected = ( a*x.trace_inner_product(y) +
1521 ....: a*z.trace_inner_product(y) )
1522 sage: actual == expected
1524 sage: actual = x.trace_inner_product(a*(y+z))
1525 sage: expected = ( a*x.trace_inner_product(y) +
1526 ....: a*x.trace_inner_product(z) )
1527 sage: actual == expected
1530 The trace inner product satisfies the compatibility
1531 condition in the definition of a Euclidean Jordan algebra::
1533 sage: set_random_seed()
1534 sage: J = random_eja()
1535 sage: x = J.random_element()
1536 sage: y = J.random_element()
1537 sage: z = J.random_element()
1538 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1542 if not other
in self
.parent():
1543 raise TypeError("'other' must live in the same algebra")
1545 return (self
*other
).trace()
1548 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1550 Return the Euclidean Jordan Algebra corresponding to the set
1551 `R^n` under the Hadamard product.
1553 Note: this is nothing more than the Cartesian product of ``n``
1554 copies of the spin algebra. Once Cartesian product algebras
1555 are implemented, this can go.
1559 This multiplication table can be verified by hand::
1561 sage: J = RealCartesianProductEJA(3)
1562 sage: e0,e1,e2 = J.gens()
1578 def __classcall_private__(cls
, n
, field
=QQ
):
1579 # The FiniteDimensionalAlgebra constructor takes a list of
1580 # matrices, the ith representing right multiplication by the ith
1581 # basis element in the vector space. So if e_1 = (1,0,0), then
1582 # right (Hadamard) multiplication of x by e_1 picks out the first
1583 # component of x; and likewise for the ith basis element e_i.
1584 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1585 for i
in xrange(n
) ]
1587 fdeja
= super(RealCartesianProductEJA
, cls
)
1588 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1590 def inner_product(self
, x
, y
):
1591 return _usual_ip(x
,y
)
1596 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1600 For now, we choose a random natural number ``n`` (greater than zero)
1601 and then give you back one of the following:
1603 * The cartesian product of the rational numbers ``n`` times; this is
1604 ``QQ^n`` with the Hadamard product.
1606 * The Jordan spin algebra on ``QQ^n``.
1608 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1611 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1612 in the space of ``2n``-by-``2n`` real symmetric matrices.
1614 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1615 in the space of ``4n``-by-``4n`` real symmetric matrices.
1617 Later this might be extended to return Cartesian products of the
1623 Euclidean Jordan algebra of degree...
1627 # The max_n component lets us choose different upper bounds on the
1628 # value "n" that gets passed to the constructor. This is needed
1629 # because e.g. R^{10} is reasonable to test, while the Hermitian
1630 # 10-by-10 quaternion matrices are not.
1631 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1633 (RealSymmetricEJA
, 5),
1634 (ComplexHermitianEJA
, 4),
1635 (QuaternionHermitianEJA
, 3)])
1636 n
= ZZ
.random_element(1, max_n
)
1637 return constructor(n
, field
=QQ
)
1641 def _real_symmetric_basis(n
, field
=QQ
):
1643 Return a basis for the space of real symmetric n-by-n matrices.
1645 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1649 for j
in xrange(i
+1):
1650 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1654 # Beware, orthogonal but not normalized!
1655 Sij
= Eij
+ Eij
.transpose()
1660 def _complex_hermitian_basis(n
, field
=QQ
):
1662 Returns a basis for the space of complex Hermitian n-by-n matrices.
1666 sage: set_random_seed()
1667 sage: n = ZZ.random_element(1,5)
1668 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1672 F
= QuadraticField(-1, 'I')
1675 # This is like the symmetric case, but we need to be careful:
1677 # * We want conjugate-symmetry, not just symmetry.
1678 # * The diagonal will (as a result) be real.
1682 for j
in xrange(i
+1):
1683 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1685 Sij
= _embed_complex_matrix(Eij
)
1688 # Beware, orthogonal but not normalized! The second one
1689 # has a minus because it's conjugated.
1690 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1692 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1697 def _quaternion_hermitian_basis(n
, field
=QQ
):
1699 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1703 sage: set_random_seed()
1704 sage: n = ZZ.random_element(1,5)
1705 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1709 Q
= QuaternionAlgebra(QQ
,-1,-1)
1712 # This is like the symmetric case, but we need to be careful:
1714 # * We want conjugate-symmetry, not just symmetry.
1715 # * The diagonal will (as a result) be real.
1719 for j
in xrange(i
+1):
1720 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1722 Sij
= _embed_quaternion_matrix(Eij
)
1725 # Beware, orthogonal but not normalized! The second,
1726 # third, and fourth ones have a minus because they're
1728 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1730 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1732 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1734 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1740 return vector(m
.base_ring(), m
.list())
1743 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1745 def _multiplication_table_from_matrix_basis(basis
):
1747 At least three of the five simple Euclidean Jordan algebras have the
1748 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1749 multiplication on the right is matrix multiplication. Given a basis
1750 for the underlying matrix space, this function returns a
1751 multiplication table (obtained by looping through the basis
1752 elements) for an algebra of those matrices. A reordered copy
1753 of the basis is also returned to work around the fact that
1754 the ``span()`` in this function will change the order of the basis
1755 from what we think it is, to... something else.
1757 # In S^2, for example, we nominally have four coordinates even
1758 # though the space is of dimension three only. The vector space V
1759 # is supposed to hold the entire long vector, and the subspace W
1760 # of V will be spanned by the vectors that arise from symmetric
1761 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1762 field
= basis
[0].base_ring()
1763 dimension
= basis
[0].nrows()
1765 V
= VectorSpace(field
, dimension
**2)
1766 W
= V
.span( _mat2vec(s
) for s
in basis
)
1768 # Taking the span above reorders our basis (thanks, jerk!) so we
1769 # need to put our "matrix basis" in the same order as the
1770 # (reordered) vector basis.
1771 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1775 # Brute force the multiplication-by-s matrix by looping
1776 # through all elements of the basis and doing the computation
1777 # to find out what the corresponding row should be. BEWARE:
1778 # these multiplication tables won't be symmetric! It therefore
1779 # becomes REALLY IMPORTANT that the underlying algebra
1780 # constructor uses ROW vectors and not COLUMN vectors. That's
1781 # why we're computing rows here and not columns.
1784 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1785 Q_rows
.append(W
.coordinates(this_row
))
1786 Q
= matrix(field
, W
.dimension(), Q_rows
)
1792 def _embed_complex_matrix(M
):
1794 Embed the n-by-n complex matrix ``M`` into the space of real
1795 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1796 bi` to the block matrix ``[[a,b],[-b,a]]``.
1800 sage: F = QuadraticField(-1,'i')
1801 sage: x1 = F(4 - 2*i)
1802 sage: x2 = F(1 + 2*i)
1805 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1806 sage: _embed_complex_matrix(M)
1815 Embedding is a homomorphism (isomorphism, in fact)::
1817 sage: set_random_seed()
1818 sage: n = ZZ.random_element(5)
1819 sage: F = QuadraticField(-1, 'i')
1820 sage: X = random_matrix(F, n)
1821 sage: Y = random_matrix(F, n)
1822 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1823 sage: expected = _embed_complex_matrix(X*Y)
1824 sage: actual == expected
1830 raise ValueError("the matrix 'M' must be square")
1831 field
= M
.base_ring()
1836 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1838 # We can drop the imaginaries here.
1839 return block_matrix(field
.base_ring(), n
, blocks
)
1842 def _unembed_complex_matrix(M
):
1844 The inverse of _embed_complex_matrix().
1848 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1849 ....: [-2, 1, -4, 3],
1850 ....: [ 9, 10, 11, 12],
1851 ....: [-10, 9, -12, 11] ])
1852 sage: _unembed_complex_matrix(A)
1854 [ 10*i + 9 12*i + 11]
1858 Unembedding is the inverse of embedding::
1860 sage: set_random_seed()
1861 sage: F = QuadraticField(-1, 'i')
1862 sage: M = random_matrix(F, 3)
1863 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1869 raise ValueError("the matrix 'M' must be square")
1870 if not n
.mod(2).is_zero():
1871 raise ValueError("the matrix 'M' must be a complex embedding")
1873 F
= QuadraticField(-1, 'i')
1876 # Go top-left to bottom-right (reading order), converting every
1877 # 2-by-2 block we see to a single complex element.
1879 for k
in xrange(n
/2):
1880 for j
in xrange(n
/2):
1881 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1882 if submat
[0,0] != submat
[1,1]:
1883 raise ValueError('bad on-diagonal submatrix')
1884 if submat
[0,1] != -submat
[1,0]:
1885 raise ValueError('bad off-diagonal submatrix')
1886 z
= submat
[0,0] + submat
[0,1]*i
1889 return matrix(F
, n
/2, elements
)
1892 def _embed_quaternion_matrix(M
):
1894 Embed the n-by-n quaternion matrix ``M`` into the space of real
1895 matrices of size 4n-by-4n by first sending each quaternion entry
1896 `z = a + bi + cj + dk` to the block-complex matrix
1897 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1902 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1903 sage: i,j,k = Q.gens()
1904 sage: x = 1 + 2*i + 3*j + 4*k
1905 sage: M = matrix(Q, 1, [[x]])
1906 sage: _embed_quaternion_matrix(M)
1912 Embedding is a homomorphism (isomorphism, in fact)::
1914 sage: set_random_seed()
1915 sage: n = ZZ.random_element(5)
1916 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1917 sage: X = random_matrix(Q, n)
1918 sage: Y = random_matrix(Q, n)
1919 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1920 sage: expected = _embed_quaternion_matrix(X*Y)
1921 sage: actual == expected
1925 quaternions
= M
.base_ring()
1928 raise ValueError("the matrix 'M' must be square")
1930 F
= QuadraticField(-1, 'i')
1935 t
= z
.coefficient_tuple()
1940 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1941 [-c
+ d
*i
, a
- b
*i
]])
1942 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1944 # We should have real entries by now, so use the realest field
1945 # we've got for the return value.
1946 return block_matrix(quaternions
.base_ring(), n
, blocks
)
1949 def _unembed_quaternion_matrix(M
):
1951 The inverse of _embed_quaternion_matrix().
1955 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1956 ....: [-2, 1, -4, 3],
1957 ....: [-3, 4, 1, -2],
1958 ....: [-4, -3, 2, 1]])
1959 sage: _unembed_quaternion_matrix(M)
1960 [1 + 2*i + 3*j + 4*k]
1964 Unembedding is the inverse of embedding::
1966 sage: set_random_seed()
1967 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1968 sage: M = random_matrix(Q, 3)
1969 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1975 raise ValueError("the matrix 'M' must be square")
1976 if not n
.mod(4).is_zero():
1977 raise ValueError("the matrix 'M' must be a complex embedding")
1979 Q
= QuaternionAlgebra(QQ
,-1,-1)
1982 # Go top-left to bottom-right (reading order), converting every
1983 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1986 for l
in xrange(n
/4):
1987 for m
in xrange(n
/4):
1988 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1989 if submat
[0,0] != submat
[1,1].conjugate():
1990 raise ValueError('bad on-diagonal submatrix')
1991 if submat
[0,1] != -submat
[1,0].conjugate():
1992 raise ValueError('bad off-diagonal submatrix')
1993 z
= submat
[0,0].real() + submat
[0,0].imag()*i
1994 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
1997 return matrix(Q
, n
/4, elements
)
2000 # The usual inner product on R^n.
2002 return x
.vector().inner_product(y
.vector())
2004 # The inner product used for the real symmetric simple EJA.
2005 # We keep it as a separate function because e.g. the complex
2006 # algebra uses the same inner product, except divided by 2.
2007 def _matrix_ip(X
,Y
):
2008 X_mat
= X
.natural_representation()
2009 Y_mat
= Y
.natural_representation()
2010 return (X_mat
*Y_mat
).trace()
2013 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2015 The rank-n simple EJA consisting of real symmetric n-by-n
2016 matrices, the usual symmetric Jordan product, and the trace inner
2017 product. It has dimension `(n^2 + n)/2` over the reals.
2021 sage: J = RealSymmetricEJA(2)
2022 sage: e0, e1, e2 = J.gens()
2032 The degree of this algebra is `(n^2 + n) / 2`::
2034 sage: set_random_seed()
2035 sage: n = ZZ.random_element(1,5)
2036 sage: J = RealSymmetricEJA(n)
2037 sage: J.degree() == (n^2 + n)/2
2040 The Jordan multiplication is what we think it is::
2042 sage: set_random_seed()
2043 sage: n = ZZ.random_element(1,5)
2044 sage: J = RealSymmetricEJA(n)
2045 sage: x = J.random_element()
2046 sage: y = J.random_element()
2047 sage: actual = (x*y).natural_representation()
2048 sage: X = x.natural_representation()
2049 sage: Y = y.natural_representation()
2050 sage: expected = (X*Y + Y*X)/2
2051 sage: actual == expected
2053 sage: J(expected) == x*y
2058 def __classcall_private__(cls
, n
, field
=QQ
):
2059 S
= _real_symmetric_basis(n
, field
=field
)
2060 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2062 fdeja
= super(RealSymmetricEJA
, cls
)
2063 return fdeja
.__classcall
_private
__(cls
,
2069 def inner_product(self
, x
, y
):
2070 return _matrix_ip(x
,y
)
2073 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2075 The rank-n simple EJA consisting of complex Hermitian n-by-n
2076 matrices over the real numbers, the usual symmetric Jordan product,
2077 and the real-part-of-trace inner product. It has dimension `n^2` over
2082 The degree of this algebra is `n^2`::
2084 sage: set_random_seed()
2085 sage: n = ZZ.random_element(1,5)
2086 sage: J = ComplexHermitianEJA(n)
2087 sage: J.degree() == n^2
2090 The Jordan multiplication is what we think it is::
2092 sage: set_random_seed()
2093 sage: n = ZZ.random_element(1,5)
2094 sage: J = ComplexHermitianEJA(n)
2095 sage: x = J.random_element()
2096 sage: y = J.random_element()
2097 sage: actual = (x*y).natural_representation()
2098 sage: X = x.natural_representation()
2099 sage: Y = y.natural_representation()
2100 sage: expected = (X*Y + Y*X)/2
2101 sage: actual == expected
2103 sage: J(expected) == x*y
2108 def __classcall_private__(cls
, n
, field
=QQ
):
2109 S
= _complex_hermitian_basis(n
)
2110 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2112 fdeja
= super(ComplexHermitianEJA
, cls
)
2113 return fdeja
.__classcall
_private
__(cls
,
2119 def inner_product(self
, x
, y
):
2120 # Since a+bi on the diagonal is represented as
2125 # we'll double-count the "a" entries if we take the trace of
2127 return _matrix_ip(x
,y
)/2
2130 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2132 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2133 matrices, the usual symmetric Jordan product, and the
2134 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2139 The degree of this algebra is `n^2`::
2141 sage: set_random_seed()
2142 sage: n = ZZ.random_element(1,5)
2143 sage: J = QuaternionHermitianEJA(n)
2144 sage: J.degree() == 2*(n^2) - n
2147 The Jordan multiplication is what we think it is::
2149 sage: set_random_seed()
2150 sage: n = ZZ.random_element(1,5)
2151 sage: J = QuaternionHermitianEJA(n)
2152 sage: x = J.random_element()
2153 sage: y = J.random_element()
2154 sage: actual = (x*y).natural_representation()
2155 sage: X = x.natural_representation()
2156 sage: Y = y.natural_representation()
2157 sage: expected = (X*Y + Y*X)/2
2158 sage: actual == expected
2160 sage: J(expected) == x*y
2165 def __classcall_private__(cls
, n
, field
=QQ
):
2166 S
= _quaternion_hermitian_basis(n
)
2167 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2169 fdeja
= super(QuaternionHermitianEJA
, cls
)
2170 return fdeja
.__classcall
_private
__(cls
,
2176 def inner_product(self
, x
, y
):
2177 # Since a+bi+cj+dk on the diagonal is represented as
2179 # a + bi +cj + dk = [ a b c d]
2184 # we'll quadruple-count the "a" entries if we take the trace of
2186 return _matrix_ip(x
,y
)/4
2189 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2191 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2192 with the usual inner product and jordan product ``x*y =
2193 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2198 This multiplication table can be verified by hand::
2200 sage: J = JordanSpinEJA(4)
2201 sage: e0,e1,e2,e3 = J.gens()
2219 def __classcall_private__(cls
, n
, field
=QQ
):
2221 id_matrix
= identity_matrix(field
, n
)
2223 ei
= id_matrix
.column(i
)
2224 Qi
= zero_matrix(field
, n
)
2226 Qi
.set_column(0, ei
)
2227 Qi
+= diagonal_matrix(n
, [ei
[0]]*n
)
2228 # The addition of the diagonal matrix adds an extra ei[0] in the
2229 # upper-left corner of the matrix.
2230 Qi
[0,0] = Qi
[0,0] * ~
field(2)
2233 # The rank of the spin algebra is two, unless we're in a
2234 # one-dimensional ambient space (because the rank is bounded by
2235 # the ambient dimension).
2236 fdeja
= super(JordanSpinEJA
, cls
)
2237 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
2239 def inner_product(self
, x
, y
):
2240 return _usual_ip(x
,y
)