1 from sage
.matrix
.constructor
import matrix
2 from sage
.modules
.free_module
import VectorSpace
3 from sage
.modules
.with_basis
.indexed_element
import IndexedFreeModuleElement
5 # TODO: make this unnecessary somehow.
6 from sage
.misc
.lazy_import
import lazy_import
7 lazy_import('mjo.eja.eja_algebra', 'FiniteDimensionalEuclideanJordanAlgebra')
8 lazy_import('mjo.eja.eja_element_subalgebra',
9 'FiniteDimensionalEuclideanJordanElementSubalgebra')
10 from mjo
.eja
.eja_operator
import FiniteDimensionalEuclideanJordanAlgebraOperator
11 from mjo
.eja
.eja_utils
import _mat2vec
13 class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement
):
15 An element of a Euclidean Jordan algebra.
20 Oh man, I should not be doing this. This hides the "disabled"
21 methods ``left_matrix`` and ``matrix`` from introspection;
22 in particular it removes them from tab-completion.
24 return filter(lambda s
: s
not in ['left_matrix', 'matrix'],
32 Return ``self`` raised to the power ``n``.
34 Jordan algebras are always power-associative; see for
35 example Faraut and Korányi, Proposition II.1.2 (ii).
37 We have to override this because our superclass uses row
38 vectors instead of column vectors! We, on the other hand,
39 assume column vectors everywhere.
43 sage: from mjo.eja.eja_algebra import random_eja
47 The definition of `x^2` is the unambiguous `x*x`::
49 sage: set_random_seed()
50 sage: x = random_eja().random_element()
54 A few examples of power-associativity::
56 sage: set_random_seed()
57 sage: x = random_eja().random_element()
58 sage: x*(x*x)*(x*x) == x^5
60 sage: (x*x)*(x*x*x) == x^5
63 We also know that powers operator-commute (Koecher, Chapter
66 sage: set_random_seed()
67 sage: x = random_eja().random_element()
68 sage: m = ZZ.random_element(0,10)
69 sage: n = ZZ.random_element(0,10)
70 sage: Lxm = (x^m).operator()
71 sage: Lxn = (x^n).operator()
72 sage: Lxm*Lxn == Lxn*Lxm
77 return self
.parent().one()
81 return (self
**(n
-1))*self
84 def apply_univariate_polynomial(self
, p
):
86 Apply the univariate polynomial ``p`` to this element.
88 A priori, SageMath won't allow us to apply a univariate
89 polynomial to an element of an EJA, because we don't know
90 that EJAs are rings (they are usually not associative). Of
91 course, we know that EJAs are power-associative, so the
92 operation is ultimately kosher. This function sidesteps
93 the CAS to get the answer we want and expect.
97 sage: from mjo.eja.eja_algebra import (HadamardEJA,
102 sage: R = PolynomialRing(QQ, 't')
104 sage: p = t^4 - t^3 + 5*t - 2
105 sage: J = HadamardEJA(5)
106 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
111 We should always get back an element of the algebra::
113 sage: set_random_seed()
114 sage: p = PolynomialRing(AA, 't').random_element()
115 sage: J = random_eja()
116 sage: x = J.random_element()
117 sage: x.apply_univariate_polynomial(p) in J
121 if len(p
.variables()) > 1:
122 raise ValueError("not a univariate polynomial")
125 # Convert the coeficcients to the parent's base ring,
126 # because a priori they might live in an (unnecessarily)
127 # larger ring for which P.sum() would fail below.
128 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
129 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
132 def characteristic_polynomial(self
):
134 Return the characteristic polynomial of this element.
138 sage: from mjo.eja.eja_algebra import HadamardEJA
142 The rank of `R^3` is three, and the minimal polynomial of
143 the identity element is `(t-1)` from which it follows that
144 the characteristic polynomial should be `(t-1)^3`::
146 sage: J = HadamardEJA(3)
147 sage: J.one().characteristic_polynomial()
148 t^3 - 3*t^2 + 3*t - 1
150 Likewise, the characteristic of the zero element in the
151 rank-three algebra `R^{n}` should be `t^{3}`::
153 sage: J = HadamardEJA(3)
154 sage: J.zero().characteristic_polynomial()
159 The characteristic polynomial of an element should evaluate
160 to zero on that element::
162 sage: set_random_seed()
163 sage: x = HadamardEJA(3).random_element()
164 sage: p = x.characteristic_polynomial()
165 sage: x.apply_univariate_polynomial(p)
168 The characteristic polynomials of the zero and unit elements
169 should be what we think they are in a subalgebra, too::
171 sage: J = HadamardEJA(3)
172 sage: p1 = J.one().characteristic_polynomial()
173 sage: q1 = J.zero().characteristic_polynomial()
174 sage: e0,e1,e2 = J.gens()
175 sage: A = (e0 + 2*e1 + 3*e2).subalgebra_generated_by() # dim 3
176 sage: p2 = A.one().characteristic_polynomial()
177 sage: q2 = A.zero().characteristic_polynomial()
184 p
= self
.parent().characteristic_polynomial_of()
185 return p(*self
.to_vector())
188 def inner_product(self
, other
):
190 Return the parent algebra's inner product of myself and ``other``.
194 sage: from mjo.eja.eja_algebra import (
195 ....: ComplexHermitianEJA,
197 ....: QuaternionHermitianEJA,
198 ....: RealSymmetricEJA,
203 The inner product in the Jordan spin algebra is the usual
204 inner product on `R^n` (this example only works because the
205 basis for the Jordan algebra is the standard basis in `R^n`)::
207 sage: J = JordanSpinEJA(3)
208 sage: x = vector(QQ,[1,2,3])
209 sage: y = vector(QQ,[4,5,6])
210 sage: x.inner_product(y)
212 sage: J.from_vector(x).inner_product(J.from_vector(y))
215 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
216 multiplication is the usual matrix multiplication in `S^n`,
217 so the inner product of the identity matrix with itself
220 sage: J = RealSymmetricEJA(3)
221 sage: J.one().inner_product(J.one())
224 Likewise, the inner product on `C^n` is `<X,Y> =
225 Re(trace(X*Y))`, where we must necessarily take the real
226 part because the product of Hermitian matrices may not be
229 sage: J = ComplexHermitianEJA(3)
230 sage: J.one().inner_product(J.one())
233 Ditto for the quaternions::
235 sage: J = QuaternionHermitianEJA(3)
236 sage: J.one().inner_product(J.one())
241 Ensure that we can always compute an inner product, and that
242 it gives us back a real number::
244 sage: set_random_seed()
245 sage: J = random_eja()
246 sage: x,y = J.random_elements(2)
247 sage: x.inner_product(y) in RLF
253 raise TypeError("'other' must live in the same algebra")
255 return P
.inner_product(self
, other
)
258 def operator_commutes_with(self
, other
):
260 Return whether or not this element operator-commutes
265 sage: from mjo.eja.eja_algebra import random_eja
269 The definition of a Jordan algebra says that any element
270 operator-commutes with its square::
272 sage: set_random_seed()
273 sage: x = random_eja().random_element()
274 sage: x.operator_commutes_with(x^2)
279 Test Lemma 1 from Chapter III of Koecher::
281 sage: set_random_seed()
282 sage: u,v = random_eja().random_elements(2)
283 sage: lhs = u.operator_commutes_with(u*v)
284 sage: rhs = v.operator_commutes_with(u^2)
288 Test the first polarization identity from my notes, Koecher
289 Chapter III, or from Baes (2.3)::
291 sage: set_random_seed()
292 sage: x,y = random_eja().random_elements(2)
293 sage: Lx = x.operator()
294 sage: Ly = y.operator()
295 sage: Lxx = (x*x).operator()
296 sage: Lxy = (x*y).operator()
297 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
300 Test the second polarization identity from my notes or from
303 sage: set_random_seed()
304 sage: x,y,z = random_eja().random_elements(3)
305 sage: Lx = x.operator()
306 sage: Ly = y.operator()
307 sage: Lz = z.operator()
308 sage: Lzy = (z*y).operator()
309 sage: Lxy = (x*y).operator()
310 sage: Lxz = (x*z).operator()
311 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
314 Test the third polarization identity from my notes or from
317 sage: set_random_seed()
318 sage: u,y,z = random_eja().random_elements(3)
319 sage: Lu = u.operator()
320 sage: Ly = y.operator()
321 sage: Lz = z.operator()
322 sage: Lzy = (z*y).operator()
323 sage: Luy = (u*y).operator()
324 sage: Luz = (u*z).operator()
325 sage: Luyz = (u*(y*z)).operator()
326 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
327 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
328 sage: bool(lhs == rhs)
332 if not other
in self
.parent():
333 raise TypeError("'other' must live in the same algebra")
342 Return my determinant, the product of my eigenvalues.
346 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
352 sage: J = JordanSpinEJA(2)
353 sage: e0,e1 = J.gens()
354 sage: x = sum( J.gens() )
360 sage: J = JordanSpinEJA(3)
361 sage: e0,e1,e2 = J.gens()
362 sage: x = sum( J.gens() )
366 The determinant of the sole element in the rank-zero trivial
367 algebra is ``1``, by three paths of reasoning. First, its
368 characteristic polynomial is a constant ``1``, so the constant
369 term in that polynomial is ``1``. Second, the characteristic
370 polynomial evaluated at zero is again ``1``. And finally, the
371 (empty) product of its eigenvalues is likewise just unity::
373 sage: J = TrivialEJA()
379 An element is invertible if and only if its determinant is
382 sage: set_random_seed()
383 sage: x = random_eja().random_element()
384 sage: x.is_invertible() == (x.det() != 0)
387 Ensure that the determinant is multiplicative on an associative
388 subalgebra as in Faraut and Korányi's Proposition II.2.2::
390 sage: set_random_seed()
391 sage: J = random_eja().random_element().subalgebra_generated_by()
392 sage: x,y = J.random_elements(2)
393 sage: (x*y).det() == x.det()*y.det()
400 # Special case, since we don't get the a0=1
401 # coefficient when the rank of the algebra
403 return P
.base_ring().one()
405 p
= P
._charpoly
_coefficients
()[0]
406 # The _charpoly_coeff function already adds the factor of -1
407 # to ensure that _charpoly_coefficients()[0] is really what
408 # appears in front of t^{0} in the charpoly. However, we want
409 # (-1)^r times THAT for the determinant.
410 return ((-1)**r
)*p(*self
.to_vector())
415 Return the Jordan-multiplicative inverse of this element.
419 We appeal to the quadratic representation as in Koecher's
420 Theorem 12 in Chapter III, Section 5.
424 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
430 The inverse in the spin factor algebra is given in Alizadeh's
433 sage: set_random_seed()
434 sage: J = JordanSpinEJA.random_instance()
435 sage: x = J.random_element()
436 sage: while not x.is_invertible():
437 ....: x = J.random_element()
438 sage: x_vec = x.to_vector()
440 sage: x_bar = x_vec[1:]
441 sage: coeff = x0.inner_product(x0) - x_bar.inner_product(x_bar)
442 sage: x_inverse = x_vec.parent()(x0.list() + (-x_bar).list())
443 sage: if not coeff.is_zero(): x_inverse = x_inverse/coeff
444 sage: x.inverse() == J.from_vector(x_inverse)
447 Trying to invert a non-invertible element throws an error:
449 sage: JordanSpinEJA(3).zero().inverse()
450 Traceback (most recent call last):
452 ValueError: element is not invertible
456 The identity element is its own inverse::
458 sage: set_random_seed()
459 sage: J = random_eja()
460 sage: J.one().inverse() == J.one()
463 If an element has an inverse, it acts like one::
465 sage: set_random_seed()
466 sage: J = random_eja()
467 sage: x = J.random_element()
468 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
471 The inverse of the inverse is what we started with::
473 sage: set_random_seed()
474 sage: J = random_eja()
475 sage: x = J.random_element()
476 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
479 Proposition II.2.3 in Faraut and Korányi says that the inverse
480 of an element is the inverse of its left-multiplication operator
481 applied to the algebra's identity, when that inverse exists::
483 sage: set_random_seed()
484 sage: J = random_eja()
485 sage: x = J.random_element()
486 sage: (not x.operator().is_invertible()) or (
487 ....: x.operator().inverse()(J.one()) == x.inverse() )
490 Proposition II.2.4 in Faraut and Korányi gives a formula for
491 the inverse based on the characteristic polynomial and the
492 Cayley-Hamilton theorem for Euclidean Jordan algebras::
494 sage: set_random_seed()
495 sage: J = ComplexHermitianEJA(3)
496 sage: x = J.random_element()
497 sage: while not x.is_invertible():
498 ....: x = J.random_element()
500 sage: a = x.characteristic_polynomial().coefficients(sparse=False)
501 sage: expected = (-1)^(r+1)/x.det()
502 sage: expected *= sum( a[i+1]*x^i for i in range(r) )
503 sage: x.inverse() == expected
507 if not self
.is_invertible():
508 raise ValueError("element is not invertible")
510 if self
.parent()._charpoly
_coefficients
.is_in_cache():
511 # We can invert using our charpoly if it will be fast to
512 # compute. If the coefficients are cached, our rank had
514 r
= self
.parent().rank()
515 a
= self
.characteristic_polynomial().coefficients(sparse
=False)
516 return (-1)**(r
+1)*sum(a
[i
+1]*self
**i
for i
in range(r
))/self
.det()
518 return (~self
.quadratic_representation())(self
)
521 def is_invertible(self
):
523 Return whether or not this element is invertible.
527 The usual way to do this is to check if the determinant is
528 zero, but we need the characteristic polynomial for the
529 determinant. The minimal polynomial is a lot easier to get,
530 so we use Corollary 2 in Chapter V of Koecher to check
531 whether or not the paren't algebra's zero element is a root
532 of this element's minimal polynomial.
534 That is... unless the coefficients of our algebra's
535 "characteristic polynomial of" function are already cached!
536 In that case, we just use the determinant (which will be fast
539 Beware that we can't use the superclass method, because it
540 relies on the algebra being associative.
544 sage: from mjo.eja.eja_algebra import random_eja
548 The identity element is always invertible::
550 sage: set_random_seed()
551 sage: J = random_eja()
552 sage: J.one().is_invertible()
555 The zero element is never invertible in a non-trivial algebra::
557 sage: set_random_seed()
558 sage: J = random_eja()
559 sage: (not J.is_trivial()) and J.zero().is_invertible()
564 if self
.parent().is_trivial():
569 if self
.parent()._charpoly
_coefficients
.is_in_cache():
570 # The determinant will be quicker than computing the minimal
571 # polynomial from scratch, most likely.
572 return (not self
.det().is_zero())
574 # In fact, we only need to know if the constant term is non-zero,
575 # so we can pass in the field's zero element instead.
576 zero
= self
.base_ring().zero()
577 p
= self
.minimal_polynomial()
578 return not (p(zero
) == zero
)
581 def is_primitive_idempotent(self
):
583 Return whether or not this element is a primitive (or minimal)
586 A primitive idempotent is a non-zero idempotent that is not
587 the sum of two other non-zero idempotents. Remark 2.7.15 in
588 Baes shows that this is what he refers to as a "minimal
591 An element of a Euclidean Jordan algebra is a minimal idempotent
592 if it :meth:`is_idempotent` and if its Peirce subalgebra
593 corresponding to the eigenvalue ``1`` has dimension ``1`` (Baes,
598 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
599 ....: RealSymmetricEJA,
605 This method is sloooooow.
609 The spectral decomposition of a non-regular element should always
610 contain at least one non-minimal idempotent::
612 sage: J = RealSymmetricEJA(3)
613 sage: x = sum(J.gens())
616 sage: [ c.is_primitive_idempotent()
617 ....: for (l,c) in x.spectral_decomposition() ]
620 On the other hand, the spectral decomposition of a regular
621 element should always be in terms of minimal idempotents::
623 sage: J = JordanSpinEJA(4)
624 sage: x = sum( i*J.gens()[i] for i in range(len(J.gens())) )
627 sage: [ c.is_primitive_idempotent()
628 ....: for (l,c) in x.spectral_decomposition() ]
633 The identity element is minimal only in an EJA of rank one::
635 sage: set_random_seed()
636 sage: J = random_eja()
637 sage: J.rank() == 1 or not J.one().is_primitive_idempotent()
640 A non-idempotent cannot be a minimal idempotent::
642 sage: set_random_seed()
643 sage: J = JordanSpinEJA(4)
644 sage: x = J.random_element()
645 sage: (not x.is_idempotent()) and x.is_primitive_idempotent()
648 Proposition 2.7.19 in Baes says that an element is a minimal
649 idempotent if and only if it's idempotent with trace equal to
652 sage: set_random_seed()
653 sage: J = JordanSpinEJA(4)
654 sage: x = J.random_element()
655 sage: expected = (x.is_idempotent() and x.trace() == 1)
656 sage: actual = x.is_primitive_idempotent()
657 sage: actual == expected
660 Primitive idempotents must be non-zero::
662 sage: set_random_seed()
663 sage: J = random_eja()
664 sage: J.zero().is_idempotent()
666 sage: J.zero().is_primitive_idempotent()
669 As a consequence of the fact that primitive idempotents must
670 be non-zero, there are no primitive idempotents in a trivial
671 Euclidean Jordan algebra::
673 sage: J = TrivialEJA()
674 sage: J.one().is_idempotent()
676 sage: J.one().is_primitive_idempotent()
680 if not self
.is_idempotent():
686 (_
,_
,J1
) = self
.parent().peirce_decomposition(self
)
687 return (J1
.dimension() == 1)
690 def is_nilpotent(self
):
692 Return whether or not some power of this element is zero.
696 We use Theorem 5 in Chapter III of Koecher, which says that
697 an element ``x`` is nilpotent if and only if ``x.operator()``
698 is nilpotent. And it is a basic fact of linear algebra that
699 an operator on an `n`-dimensional space is nilpotent if and
700 only if, when raised to the `n`th power, it equals the zero
701 operator (for example, see Axler Corollary 8.8).
705 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
710 sage: J = JordanSpinEJA(3)
711 sage: x = sum(J.gens())
712 sage: x.is_nilpotent()
717 The identity element is never nilpotent, except in a trivial EJA::
719 sage: set_random_seed()
720 sage: J = random_eja()
721 sage: J.one().is_nilpotent() and not J.is_trivial()
724 The additive identity is always nilpotent::
726 sage: set_random_seed()
727 sage: random_eja().zero().is_nilpotent()
732 zero_operator
= P
.zero().operator()
733 return self
.operator()**P
.dimension() == zero_operator
736 def is_regular(self
):
738 Return whether or not this is a regular element.
742 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
747 The identity element always has degree one, but any element
748 linearly-independent from it is regular::
750 sage: J = JordanSpinEJA(5)
751 sage: J.one().is_regular()
753 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
754 sage: for x in J.gens():
755 ....: (J.one() + x).is_regular()
764 The zero element should never be regular, unless the parent
765 algebra has dimension less than or equal to one::
767 sage: set_random_seed()
768 sage: J = random_eja()
769 sage: J.dimension() <= 1 or not J.zero().is_regular()
772 The unit element isn't regular unless the algebra happens to
773 consist of only its scalar multiples::
775 sage: set_random_seed()
776 sage: J = random_eja()
777 sage: J.dimension() <= 1 or not J.one().is_regular()
781 return self
.degree() == self
.parent().rank()
786 Return the degree of this element, which is defined to be
787 the degree of its minimal polynomial.
791 For now, we skip the messy minimal polynomial computation
792 and instead return the dimension of the vector space spanned
793 by the powers of this element. The latter is a bit more
794 straightforward to compute.
798 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
803 sage: J = JordanSpinEJA(4)
804 sage: J.one().degree()
806 sage: e0,e1,e2,e3 = J.gens()
807 sage: (e0 - e1).degree()
810 In the spin factor algebra (of rank two), all elements that
811 aren't multiples of the identity are regular::
813 sage: set_random_seed()
814 sage: J = JordanSpinEJA.random_instance()
815 sage: n = J.dimension()
816 sage: x = J.random_element()
817 sage: x.degree() == min(n,2) or (x == x.coefficient(0)*J.one())
822 The zero and unit elements are both of degree one in nontrivial
825 sage: set_random_seed()
826 sage: J = random_eja()
827 sage: d = J.zero().degree()
828 sage: (J.is_trivial() and d == 0) or d == 1
830 sage: d = J.one().degree()
831 sage: (J.is_trivial() and d == 0) or d == 1
834 Our implementation agrees with the definition::
836 sage: set_random_seed()
837 sage: x = random_eja().random_element()
838 sage: x.degree() == x.minimal_polynomial().degree()
842 if self
.is_zero() and not self
.parent().is_trivial():
843 # The minimal polynomial of zero in a nontrivial algebra
844 # is "t"; in a trivial algebra it's "1" by convention
845 # (it's an empty product).
847 return self
.subalgebra_generated_by().dimension()
850 def left_matrix(self
):
852 Our parent class defines ``left_matrix`` and ``matrix``
853 methods whose names are misleading. We don't want them.
855 raise NotImplementedError("use operator().matrix() instead")
860 def minimal_polynomial(self
):
862 Return the minimal polynomial of this element,
863 as a function of the variable `t`.
867 We restrict ourselves to the associative subalgebra
868 generated by this element, and then return the minimal
869 polynomial of this element's operator matrix (in that
870 subalgebra). This works by Baes Proposition 2.3.16.
874 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
875 ....: RealSymmetricEJA,
881 Keeping in mind that the polynomial ``1`` evaluates the identity
882 element (also the zero element) of the trivial algebra, it is clear
883 that the polynomial ``1`` is the minimal polynomial of the only
884 element in a trivial algebra::
886 sage: J = TrivialEJA()
887 sage: J.one().minimal_polynomial()
889 sage: J.zero().minimal_polynomial()
894 The minimal polynomial of the identity and zero elements are
895 always the same, except in trivial algebras where the minimal
896 polynomial of the unit/zero element is ``1``::
898 sage: set_random_seed()
899 sage: J = random_eja()
900 sage: mu = J.one().minimal_polynomial()
901 sage: t = mu.parent().gen()
902 sage: mu + int(J.is_trivial())*(t-2)
904 sage: mu = J.zero().minimal_polynomial()
905 sage: t = mu.parent().gen()
906 sage: mu + int(J.is_trivial())*(t-1)
909 The degree of an element is (by one definition) the degree
910 of its minimal polynomial::
912 sage: set_random_seed()
913 sage: x = random_eja().random_element()
914 sage: x.degree() == x.minimal_polynomial().degree()
917 The minimal polynomial and the characteristic polynomial coincide
918 and are known (see Alizadeh, Example 11.11) for all elements of
919 the spin factor algebra that aren't scalar multiples of the
920 identity. We require the dimension of the algebra to be at least
921 two here so that said elements actually exist::
923 sage: set_random_seed()
924 sage: n_max = max(2, JordanSpinEJA._max_random_instance_size())
925 sage: n = ZZ.random_element(2, n_max)
926 sage: J = JordanSpinEJA(n)
927 sage: y = J.random_element()
928 sage: while y == y.coefficient(0)*J.one():
929 ....: y = J.random_element()
930 sage: y0 = y.to_vector()[0]
931 sage: y_bar = y.to_vector()[1:]
932 sage: actual = y.minimal_polynomial()
933 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
934 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
935 sage: bool(actual == expected)
938 The minimal polynomial should always kill its element::
940 sage: set_random_seed()
941 sage: x = random_eja().random_element()
942 sage: p = x.minimal_polynomial()
943 sage: x.apply_univariate_polynomial(p)
946 The minimal polynomial is invariant under a change of basis,
947 and in particular, a re-scaling of the basis::
949 sage: set_random_seed()
950 sage: n_max = RealSymmetricEJA._max_random_instance_size()
951 sage: n = ZZ.random_element(1, n_max)
952 sage: J1 = RealSymmetricEJA(n)
953 sage: J2 = RealSymmetricEJA(n,normalize_basis=False)
954 sage: X = random_matrix(AA,n)
955 sage: X = X*X.transpose()
958 sage: x1.minimal_polynomial() == x2.minimal_polynomial()
963 # We would generate a zero-dimensional subalgebra
964 # where the minimal polynomial would be constant.
965 # That might be correct, but only if *this* algebra
967 if not self
.parent().is_trivial():
968 # Pretty sure we know what the minimal polynomial of
969 # the zero operator is going to be. This ensures
970 # consistency of e.g. the polynomial variable returned
971 # in the "normal" case without us having to think about it.
972 return self
.operator().minimal_polynomial()
974 A
= self
.subalgebra_generated_by(orthonormalize_basis
=False)
975 return A(self
).operator().minimal_polynomial()
979 def natural_representation(self
):
981 Return a more-natural representation of this element.
983 Every finite-dimensional Euclidean Jordan Algebra is a
984 direct sum of five simple algebras, four of which comprise
985 Hermitian matrices. This method returns the original
986 "natural" representation of this element as a Hermitian
987 matrix, if it has one. If not, you get the usual representation.
991 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
992 ....: QuaternionHermitianEJA)
996 sage: J = ComplexHermitianEJA(3)
999 sage: J.one().natural_representation()
1009 sage: J = QuaternionHermitianEJA(3)
1012 sage: J.one().natural_representation()
1013 [1 0 0 0 0 0 0 0 0 0 0 0]
1014 [0 1 0 0 0 0 0 0 0 0 0 0]
1015 [0 0 1 0 0 0 0 0 0 0 0 0]
1016 [0 0 0 1 0 0 0 0 0 0 0 0]
1017 [0 0 0 0 1 0 0 0 0 0 0 0]
1018 [0 0 0 0 0 1 0 0 0 0 0 0]
1019 [0 0 0 0 0 0 1 0 0 0 0 0]
1020 [0 0 0 0 0 0 0 1 0 0 0 0]
1021 [0 0 0 0 0 0 0 0 1 0 0 0]
1022 [0 0 0 0 0 0 0 0 0 1 0 0]
1023 [0 0 0 0 0 0 0 0 0 0 1 0]
1024 [0 0 0 0 0 0 0 0 0 0 0 1]
1027 B
= self
.parent().natural_basis()
1028 W
= self
.parent().natural_basis_space()
1030 # This is just a manual "from_vector()", but of course
1031 # matrix spaces aren't vector spaces in sage, so they
1032 # don't have a from_vector() method.
1033 return W
.linear_combination(zip(B
,self
.to_vector()))
1038 The norm of this element with respect to :meth:`inner_product`.
1042 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1047 sage: J = HadamardEJA(2)
1048 sage: x = sum(J.gens())
1054 sage: J = JordanSpinEJA(4)
1055 sage: x = sum(J.gens())
1060 return self
.inner_product(self
).sqrt()
1065 Return the left-multiplication-by-this-element
1066 operator on the ambient algebra.
1070 sage: from mjo.eja.eja_algebra import random_eja
1074 sage: set_random_seed()
1075 sage: J = random_eja()
1076 sage: x,y = J.random_elements(2)
1077 sage: x.operator()(y) == x*y
1079 sage: y.operator()(x) == x*y
1084 left_mult_by_self
= lambda y
: self
*y
1085 L
= P
.module_morphism(function
=left_mult_by_self
, codomain
=P
)
1086 return FiniteDimensionalEuclideanJordanAlgebraOperator(
1092 def quadratic_representation(self
, other
=None):
1094 Return the quadratic representation of this element.
1098 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1103 The explicit form in the spin factor algebra is given by
1104 Alizadeh's Example 11.12::
1106 sage: set_random_seed()
1107 sage: x = JordanSpinEJA.random_instance().random_element()
1108 sage: x_vec = x.to_vector()
1109 sage: Q = matrix.identity(x.base_ring(), 0)
1110 sage: n = x_vec.degree()
1113 ....: x_bar = x_vec[1:]
1114 ....: A = matrix(x.base_ring(), 1, [x_vec.inner_product(x_vec)])
1115 ....: B = 2*x0*x_bar.row()
1116 ....: C = 2*x0*x_bar.column()
1117 ....: D = matrix.identity(x.base_ring(), n-1)
1118 ....: D = (x0^2 - x_bar.inner_product(x_bar))*D
1119 ....: D = D + 2*x_bar.tensor_product(x_bar)
1120 ....: Q = matrix.block(2,2,[A,B,C,D])
1121 sage: Q == x.quadratic_representation().matrix()
1124 Test all of the properties from Theorem 11.2 in Alizadeh::
1126 sage: set_random_seed()
1127 sage: J = random_eja()
1128 sage: x,y = J.random_elements(2)
1129 sage: Lx = x.operator()
1130 sage: Lxx = (x*x).operator()
1131 sage: Qx = x.quadratic_representation()
1132 sage: Qy = y.quadratic_representation()
1133 sage: Qxy = x.quadratic_representation(y)
1134 sage: Qex = J.one().quadratic_representation(x)
1135 sage: n = ZZ.random_element(10)
1136 sage: Qxn = (x^n).quadratic_representation()
1140 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1143 Property 2 (multiply on the right for :trac:`28272`):
1145 sage: alpha = J.base_ring().random_element()
1146 sage: (alpha*x).quadratic_representation() == Qx*(alpha^2)
1151 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
1154 sage: not x.is_invertible() or (
1157 ....: x.inverse().quadratic_representation() )
1160 sage: Qxy(J.one()) == x*y
1165 sage: not x.is_invertible() or (
1166 ....: x.quadratic_representation(x.inverse())*Qx
1167 ....: == Qx*x.quadratic_representation(x.inverse()) )
1170 sage: not x.is_invertible() or (
1171 ....: x.quadratic_representation(x.inverse())*Qx
1173 ....: 2*Lx*Qex - Qx )
1176 sage: 2*Lx*Qex - Qx == Lxx
1181 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
1191 sage: not x.is_invertible() or (
1192 ....: Qx*x.inverse().operator() == Lx )
1197 sage: not x.operator_commutes_with(y) or (
1198 ....: Qx(y)^n == Qxn(y^n) )
1204 elif not other
in self
.parent():
1205 raise TypeError("'other' must live in the same algebra")
1208 M
= other
.operator()
1209 return ( L
*M
+ M
*L
- (self
*other
).operator() )
1213 def spectral_decomposition(self
):
1215 Return the unique spectral decomposition of this element.
1219 Following Faraut and Korányi's Theorem III.1.1, we restrict this
1220 element's left-multiplication-by operator to the subalgebra it
1221 generates. We then compute the spectral decomposition of that
1222 operator, and the spectral projectors we get back must be the
1223 left-multiplication-by operators for the idempotents we
1224 seek. Thus applying them to the identity element gives us those
1227 Since the eigenvalues are required to be distinct, we take
1228 the spectral decomposition of the zero element to be zero
1229 times the identity element of the algebra (which is idempotent,
1234 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1238 The spectral decomposition of the identity is ``1`` times itself,
1239 and the spectral decomposition of zero is ``0`` times the identity::
1241 sage: J = RealSymmetricEJA(3)
1244 sage: J.one().spectral_decomposition()
1246 sage: J.zero().spectral_decomposition()
1251 sage: J = RealSymmetricEJA(4)
1252 sage: x = sum(J.gens())
1253 sage: sd = x.spectral_decomposition()
1258 sage: c0.inner_product(c1) == 0
1260 sage: c0.is_idempotent()
1262 sage: c1.is_idempotent()
1264 sage: c0 + c1 == J.one()
1266 sage: l0*c0 + l1*c1 == x
1269 The spectral decomposition should work in subalgebras, too::
1271 sage: J = RealSymmetricEJA(4)
1272 sage: (e0, e1, e2, e3, e4, e5, e6, e7, e8, e9) = J.gens()
1273 sage: A = 2*e5 - 2*e8
1274 sage: (lambda1, c1) = A.spectral_decomposition()[1]
1275 sage: (J0, J5, J1) = J.peirce_decomposition(c1)
1276 sage: (f0, f1, f2) = J1.gens()
1277 sage: f0.spectral_decomposition()
1281 A
= self
.subalgebra_generated_by(orthonormalize_basis
=True)
1283 for (evalue
, proj
) in A(self
).operator().spectral_decomposition():
1284 result
.append( (evalue
, proj(A
.one()).superalgebra_element()) )
1287 def subalgebra_generated_by(self
, orthonormalize_basis
=False):
1289 Return the associative subalgebra of the parent EJA generated
1292 Since our parent algebra is unital, we want "subalgebra" to mean
1293 "unital subalgebra" as well; thus the subalgebra that an element
1294 generates will itself be a Euclidean Jordan algebra after
1295 restricting the algebra operations appropriately. This is the
1296 subalgebra that Faraut and Korányi work with in section II.2, for
1301 sage: from mjo.eja.eja_algebra import random_eja
1305 This subalgebra, being composed of only powers, is associative::
1307 sage: set_random_seed()
1308 sage: x0 = random_eja().random_element()
1309 sage: A = x0.subalgebra_generated_by()
1310 sage: x,y,z = A.random_elements(3)
1311 sage: (x*y)*z == x*(y*z)
1314 Squaring in the subalgebra should work the same as in
1317 sage: set_random_seed()
1318 sage: x = random_eja().random_element()
1319 sage: A = x.subalgebra_generated_by()
1320 sage: A(x^2) == A(x)*A(x)
1323 By definition, the subalgebra generated by the zero element is
1324 the one-dimensional algebra generated by the identity
1325 element... unless the original algebra was trivial, in which
1326 case the subalgebra is trivial too::
1328 sage: set_random_seed()
1329 sage: A = random_eja().zero().subalgebra_generated_by()
1330 sage: (A.is_trivial() and A.dimension() == 0) or A.dimension() == 1
1334 return FiniteDimensionalEuclideanJordanElementSubalgebra(self
, orthonormalize_basis
)
1337 def subalgebra_idempotent(self
):
1339 Find an idempotent in the associative subalgebra I generate
1340 using Proposition 2.3.5 in Baes.
1344 sage: from mjo.eja.eja_algebra import random_eja
1348 Ensure that we can find an idempotent in a non-trivial algebra
1349 where there are non-nilpotent elements, or that we get the dumb
1350 solution in the trivial algebra::
1352 sage: set_random_seed()
1353 sage: J = random_eja()
1354 sage: x = J.random_element()
1355 sage: while x.is_nilpotent() and not J.is_trivial():
1356 ....: x = J.random_element()
1357 sage: c = x.subalgebra_idempotent()
1362 if self
.parent().is_trivial():
1365 if self
.is_nilpotent():
1366 raise ValueError("this only works with non-nilpotent elements!")
1368 J
= self
.subalgebra_generated_by()
1371 # The image of the matrix of left-u^m-multiplication
1372 # will be minimal for some natural number s...
1374 minimal_dim
= J
.dimension()
1375 for i
in range(1, minimal_dim
):
1376 this_dim
= (u
**i
).operator().matrix().image().dimension()
1377 if this_dim
< minimal_dim
:
1378 minimal_dim
= this_dim
1381 # Now minimal_matrix should correspond to the smallest
1382 # non-zero subspace in Baes's (or really, Koecher's)
1385 # However, we need to restrict the matrix to work on the
1386 # subspace... or do we? Can't we just solve, knowing that
1387 # A(c) = u^(s+1) should have a solution in the big space,
1390 # Beware, solve_right() means that we're using COLUMN vectors.
1391 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1393 A
= u_next
.operator().matrix()
1394 c
= J
.from_vector(A
.solve_right(u_next
.to_vector()))
1396 # Now c is the idempotent we want, but it still lives in the subalgebra.
1397 return c
.superalgebra_element()
1402 Return my trace, the sum of my eigenvalues.
1404 In a trivial algebra, however you want to look at it, the trace is
1405 an empty sum for which we declare the result to be zero.
1409 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1416 sage: J = TrivialEJA()
1417 sage: J.zero().trace()
1421 sage: J = JordanSpinEJA(3)
1422 sage: x = sum(J.gens())
1428 sage: J = HadamardEJA(5)
1429 sage: J.one().trace()
1434 The trace of an element is a real number::
1436 sage: set_random_seed()
1437 sage: J = random_eja()
1438 sage: J.random_element().trace() in RLF
1446 # Special case for the trivial algebra where
1447 # the trace is an empty sum.
1448 return P
.base_ring().zero()
1450 p
= P
._charpoly
_coefficients
()[r
-1]
1451 # The _charpoly_coeff function already adds the factor of
1452 # -1 to ensure that _charpoly_coeff(r-1) is really what
1453 # appears in front of t^{r-1} in the charpoly. However,
1454 # we want the negative of THAT for the trace.
1455 return -p(*self
.to_vector())
1458 def trace_inner_product(self
, other
):
1460 Return the trace inner product of myself and ``other``.
1464 sage: from mjo.eja.eja_algebra import random_eja
1468 The trace inner product is commutative, bilinear, and associative::
1470 sage: set_random_seed()
1471 sage: J = random_eja()
1472 sage: x,y,z = J.random_elements(3)
1474 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1477 sage: a = J.base_ring().random_element();
1478 sage: actual = (a*(x+z)).trace_inner_product(y)
1479 sage: expected = ( a*x.trace_inner_product(y) +
1480 ....: a*z.trace_inner_product(y) )
1481 sage: actual == expected
1483 sage: actual = x.trace_inner_product(a*(y+z))
1484 sage: expected = ( a*x.trace_inner_product(y) +
1485 ....: a*x.trace_inner_product(z) )
1486 sage: actual == expected
1489 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1493 if not other
in self
.parent():
1494 raise TypeError("'other' must live in the same algebra")
1496 return (self
*other
).trace()
1499 def trace_norm(self
):
1501 The norm of this element with respect to :meth:`trace_inner_product`.
1505 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1510 sage: J = HadamardEJA(2)
1511 sage: x = sum(J.gens())
1512 sage: x.trace_norm()
1517 sage: J = JordanSpinEJA(4)
1518 sage: x = sum(J.gens())
1519 sage: x.trace_norm()
1523 return self
.trace_inner_product(self
).sqrt()