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_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 Koranyi, 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
.operator()**(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 (RealCartesianProductEJA,
102 sage: R = PolynomialRing(QQ, 't')
104 sage: p = t^4 - t^3 + 5*t - 2
105 sage: J = RealCartesianProductEJA(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(QQ, '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 RealCartesianProductEJA
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 = RealCartesianProductEJA(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 = RealCartesianProductEJA(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 = RealCartesianProductEJA(3).random_element()
164 sage: p = x.characteristic_polynomial()
165 sage: x.apply_univariate_polynomial(p)
169 p
= self
.parent().characteristic_polynomial()
170 return p(*self
.to_vector())
173 def inner_product(self
, other
):
175 Return the parent algebra's inner product of myself and ``other``.
179 sage: from mjo.eja.eja_algebra import (
180 ....: ComplexHermitianEJA,
182 ....: QuaternionHermitianEJA,
183 ....: RealSymmetricEJA,
188 The inner product in the Jordan spin algebra is the usual
189 inner product on `R^n` (this example only works because the
190 basis for the Jordan algebra is the standard basis in `R^n`)::
192 sage: J = JordanSpinEJA(3)
193 sage: x = vector(QQ,[1,2,3])
194 sage: y = vector(QQ,[4,5,6])
195 sage: x.inner_product(y)
197 sage: J.from_vector(x).inner_product(J.from_vector(y))
200 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
201 multiplication is the usual matrix multiplication in `S^n`,
202 so the inner product of the identity matrix with itself
205 sage: J = RealSymmetricEJA(3)
206 sage: J.one().inner_product(J.one())
209 Likewise, the inner product on `C^n` is `<X,Y> =
210 Re(trace(X*Y))`, where we must necessarily take the real
211 part because the product of Hermitian matrices may not be
214 sage: J = ComplexHermitianEJA(3)
215 sage: J.one().inner_product(J.one())
218 Ditto for the quaternions::
220 sage: J = QuaternionHermitianEJA(3)
221 sage: J.one().inner_product(J.one())
226 Ensure that we can always compute an inner product, and that
227 it gives us back a real number::
229 sage: set_random_seed()
230 sage: J = random_eja()
231 sage: x = J.random_element()
232 sage: y = J.random_element()
233 sage: x.inner_product(y) in RR
239 raise TypeError("'other' must live in the same algebra")
241 return P
.inner_product(self
, other
)
244 def operator_commutes_with(self
, other
):
246 Return whether or not this element operator-commutes
251 sage: from mjo.eja.eja_algebra import random_eja
255 The definition of a Jordan algebra says that any element
256 operator-commutes with its square::
258 sage: set_random_seed()
259 sage: x = random_eja().random_element()
260 sage: x.operator_commutes_with(x^2)
265 Test Lemma 1 from Chapter III of Koecher::
267 sage: set_random_seed()
268 sage: J = random_eja()
269 sage: u = J.random_element()
270 sage: v = J.random_element()
271 sage: lhs = u.operator_commutes_with(u*v)
272 sage: rhs = v.operator_commutes_with(u^2)
276 Test the first polarization identity from my notes, Koecher
277 Chapter III, or from Baes (2.3)::
279 sage: set_random_seed()
280 sage: J = random_eja()
281 sage: x = J.random_element()
282 sage: y = J.random_element()
283 sage: Lx = x.operator()
284 sage: Ly = y.operator()
285 sage: Lxx = (x*x).operator()
286 sage: Lxy = (x*y).operator()
287 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
290 Test the second polarization identity from my notes or from
293 sage: set_random_seed()
294 sage: J = random_eja()
295 sage: x = J.random_element()
296 sage: y = J.random_element()
297 sage: z = J.random_element()
298 sage: Lx = x.operator()
299 sage: Ly = y.operator()
300 sage: Lz = z.operator()
301 sage: Lzy = (z*y).operator()
302 sage: Lxy = (x*y).operator()
303 sage: Lxz = (x*z).operator()
304 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
307 Test the third polarization identity from my notes or from
310 sage: set_random_seed()
311 sage: J = random_eja()
312 sage: u = J.random_element()
313 sage: y = J.random_element()
314 sage: z = J.random_element()
315 sage: Lu = u.operator()
316 sage: Ly = y.operator()
317 sage: Lz = z.operator()
318 sage: Lzy = (z*y).operator()
319 sage: Luy = (u*y).operator()
320 sage: Luz = (u*z).operator()
321 sage: Luyz = (u*(y*z)).operator()
322 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
323 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
324 sage: bool(lhs == rhs)
328 if not other
in self
.parent():
329 raise TypeError("'other' must live in the same algebra")
338 Return my determinant, the product of my eigenvalues.
342 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
347 sage: J = JordanSpinEJA(2)
348 sage: e0,e1 = J.gens()
349 sage: x = sum( J.gens() )
355 sage: J = JordanSpinEJA(3)
356 sage: e0,e1,e2 = J.gens()
357 sage: x = sum( J.gens() )
363 An element is invertible if and only if its determinant is
366 sage: set_random_seed()
367 sage: x = random_eja().random_element()
368 sage: x.is_invertible() == (x.det() != 0)
374 p
= P
._charpoly
_coeff
(0)
375 # The _charpoly_coeff function already adds the factor of
376 # -1 to ensure that _charpoly_coeff(0) is really what
377 # appears in front of t^{0} in the charpoly. However,
378 # we want (-1)^r times THAT for the determinant.
379 return ((-1)**r
)*p(*self
.to_vector())
384 Return the Jordan-multiplicative inverse of this element.
388 We appeal to the quadratic representation as in Koecher's
389 Theorem 12 in Chapter III, Section 5.
393 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
398 The inverse in the spin factor algebra is given in Alizadeh's
401 sage: set_random_seed()
402 sage: n = ZZ.random_element(1,10)
403 sage: J = JordanSpinEJA(n)
404 sage: x = J.random_element()
405 sage: while not x.is_invertible():
406 ....: x = J.random_element()
407 sage: x_vec = x.to_vector()
409 sage: x_bar = x_vec[1:]
410 sage: coeff = ~(x0^2 - x_bar.inner_product(x_bar))
411 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
412 sage: x_inverse = coeff*inv_vec
413 sage: x.inverse() == J.from_vector(x_inverse)
418 The identity element is its own inverse::
420 sage: set_random_seed()
421 sage: J = random_eja()
422 sage: J.one().inverse() == J.one()
425 If an element has an inverse, it acts like one::
427 sage: set_random_seed()
428 sage: J = random_eja()
429 sage: x = J.random_element()
430 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
433 The inverse of the inverse is what we started with::
435 sage: set_random_seed()
436 sage: J = random_eja()
437 sage: x = J.random_element()
438 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
441 The zero element is never invertible::
443 sage: set_random_seed()
444 sage: J = random_eja().zero().inverse()
445 Traceback (most recent call last):
447 ValueError: element is not invertible
450 if not self
.is_invertible():
451 raise ValueError("element is not invertible")
453 return (~self
.quadratic_representation())(self
)
456 def is_invertible(self
):
458 Return whether or not this element is invertible.
462 The usual way to do this is to check if the determinant is
463 zero, but we need the characteristic polynomial for the
464 determinant. The minimal polynomial is a lot easier to get,
465 so we use Corollary 2 in Chapter V of Koecher to check
466 whether or not the paren't algebra's zero element is a root
467 of this element's minimal polynomial.
469 Beware that we can't use the superclass method, because it
470 relies on the algebra being associative.
474 sage: from mjo.eja.eja_algebra import random_eja
478 The identity element is always invertible::
480 sage: set_random_seed()
481 sage: J = random_eja()
482 sage: J.one().is_invertible()
485 The zero element is never invertible::
487 sage: set_random_seed()
488 sage: J = random_eja()
489 sage: J.zero().is_invertible()
493 zero
= self
.parent().zero()
494 p
= self
.minimal_polynomial()
495 return not (p(zero
) == zero
)
498 def is_nilpotent(self
):
500 Return whether or not some power of this element is zero.
504 We use Theorem 5 in Chapter III of Koecher, which says that
505 an element ``x`` is nilpotent if and only if ``x.operator()``
506 is nilpotent. And it is a basic fact of linear algebra that
507 an operator on an `n`-dimensional space is nilpotent if and
508 only if, when raised to the `n`th power, it equals the zero
509 operator (for example, see Axler Corollary 8.8).
513 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
518 sage: J = JordanSpinEJA(3)
519 sage: x = sum(J.gens())
520 sage: x.is_nilpotent()
525 The identity element is never nilpotent::
527 sage: set_random_seed()
528 sage: random_eja().one().is_nilpotent()
531 The additive identity is always nilpotent::
533 sage: set_random_seed()
534 sage: random_eja().zero().is_nilpotent()
539 zero_operator
= P
.zero().operator()
540 return self
.operator()**P
.dimension() == zero_operator
543 def is_regular(self
):
545 Return whether or not this is a regular element.
549 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
554 The identity element always has degree one, but any element
555 linearly-independent from it is regular::
557 sage: J = JordanSpinEJA(5)
558 sage: J.one().is_regular()
560 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
561 sage: for x in J.gens():
562 ....: (J.one() + x).is_regular()
571 The zero element should never be regular, unless the parent
572 algebra has dimension one::
574 sage: set_random_seed()
575 sage: J = random_eja()
576 sage: J.dimension() == 1 or not J.zero().is_regular()
579 The unit element isn't regular unless the algebra happens to
580 consist of only its scalar multiples::
582 sage: set_random_seed()
583 sage: J = random_eja()
584 sage: J.dimension() == 1 or not J.one().is_regular()
588 return self
.degree() == self
.parent().rank()
593 Return the degree of this element, which is defined to be
594 the degree of its minimal polynomial.
598 For now, we skip the messy minimal polynomial computation
599 and instead return the dimension of the vector space spanned
600 by the powers of this element. The latter is a bit more
601 straightforward to compute.
605 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
610 sage: J = JordanSpinEJA(4)
611 sage: J.one().degree()
613 sage: e0,e1,e2,e3 = J.gens()
614 sage: (e0 - e1).degree()
617 In the spin factor algebra (of rank two), all elements that
618 aren't multiples of the identity are regular::
620 sage: set_random_seed()
621 sage: n = ZZ.random_element(1,10)
622 sage: J = JordanSpinEJA(n)
623 sage: x = J.random_element()
624 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
629 The zero and unit elements are both of degree one::
631 sage: set_random_seed()
632 sage: J = random_eja()
633 sage: J.zero().degree()
635 sage: J.one().degree()
638 Our implementation agrees with the definition::
640 sage: set_random_seed()
641 sage: x = random_eja().random_element()
642 sage: x.degree() == x.minimal_polynomial().degree()
646 return self
.subalgebra_generated_by().dimension()
649 def left_matrix(self
):
651 Our parent class defines ``left_matrix`` and ``matrix``
652 methods whose names are misleading. We don't want them.
654 raise NotImplementedError("use operator().matrix() instead")
659 def minimal_polynomial(self
):
661 Return the minimal polynomial of this element,
662 as a function of the variable `t`.
666 We restrict ourselves to the associative subalgebra
667 generated by this element, and then return the minimal
668 polynomial of this element's operator matrix (in that
669 subalgebra). This works by Baes Proposition 2.3.16.
673 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
678 The minimal polynomial of the identity and zero elements are
681 sage: set_random_seed()
682 sage: J = random_eja()
683 sage: J.one().minimal_polynomial()
685 sage: J.zero().minimal_polynomial()
688 The degree of an element is (by one definition) the degree
689 of its minimal polynomial::
691 sage: set_random_seed()
692 sage: x = random_eja().random_element()
693 sage: x.degree() == x.minimal_polynomial().degree()
696 The minimal polynomial and the characteristic polynomial coincide
697 and are known (see Alizadeh, Example 11.11) for all elements of
698 the spin factor algebra that aren't scalar multiples of the
701 sage: set_random_seed()
702 sage: n = ZZ.random_element(2,10)
703 sage: J = JordanSpinEJA(n)
704 sage: y = J.random_element()
705 sage: while y == y.coefficient(0)*J.one():
706 ....: y = J.random_element()
707 sage: y0 = y.to_vector()[0]
708 sage: y_bar = y.to_vector()[1:]
709 sage: actual = y.minimal_polynomial()
710 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
711 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
712 sage: bool(actual == expected)
715 The minimal polynomial should always kill its element::
717 sage: set_random_seed()
718 sage: x = random_eja().random_element()
719 sage: p = x.minimal_polynomial()
720 sage: x.apply_univariate_polynomial(p)
724 A
= self
.subalgebra_generated_by()
725 return A(self
).operator().minimal_polynomial()
729 def natural_representation(self
):
731 Return a more-natural representation of this element.
733 Every finite-dimensional Euclidean Jordan Algebra is a
734 direct sum of five simple algebras, four of which comprise
735 Hermitian matrices. This method returns the original
736 "natural" representation of this element as a Hermitian
737 matrix, if it has one. If not, you get the usual representation.
741 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
742 ....: QuaternionHermitianEJA)
746 sage: J = ComplexHermitianEJA(3)
749 sage: J.one().natural_representation()
759 sage: J = QuaternionHermitianEJA(3)
762 sage: J.one().natural_representation()
763 [1 0 0 0 0 0 0 0 0 0 0 0]
764 [0 1 0 0 0 0 0 0 0 0 0 0]
765 [0 0 1 0 0 0 0 0 0 0 0 0]
766 [0 0 0 1 0 0 0 0 0 0 0 0]
767 [0 0 0 0 1 0 0 0 0 0 0 0]
768 [0 0 0 0 0 1 0 0 0 0 0 0]
769 [0 0 0 0 0 0 1 0 0 0 0 0]
770 [0 0 0 0 0 0 0 1 0 0 0 0]
771 [0 0 0 0 0 0 0 0 1 0 0 0]
772 [0 0 0 0 0 0 0 0 0 1 0 0]
773 [0 0 0 0 0 0 0 0 0 0 1 0]
774 [0 0 0 0 0 0 0 0 0 0 0 1]
777 B
= self
.parent().natural_basis()
778 W
= B
[0].matrix_space()
779 return W
.linear_combination(zip(B
,self
.to_vector()))
784 Return the left-multiplication-by-this-element
785 operator on the ambient algebra.
789 sage: from mjo.eja.eja_algebra import random_eja
793 sage: set_random_seed()
794 sage: J = random_eja()
795 sage: x = J.random_element()
796 sage: y = J.random_element()
797 sage: x.operator()(y) == x*y
799 sage: y.operator()(x) == x*y
804 return FiniteDimensionalEuclideanJordanAlgebraOperator(
810 def quadratic_representation(self
, other
=None):
812 Return the quadratic representation of this element.
816 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
821 The explicit form in the spin factor algebra is given by
822 Alizadeh's Example 11.12::
824 sage: set_random_seed()
825 sage: n = ZZ.random_element(1,10)
826 sage: J = JordanSpinEJA(n)
827 sage: x = J.random_element()
828 sage: x_vec = x.to_vector()
830 sage: x_bar = x_vec[1:]
831 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
832 sage: B = 2*x0*x_bar.row()
833 sage: C = 2*x0*x_bar.column()
834 sage: D = matrix.identity(QQ, n-1)
835 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
836 sage: D = D + 2*x_bar.tensor_product(x_bar)
837 sage: Q = matrix.block(2,2,[A,B,C,D])
838 sage: Q == x.quadratic_representation().matrix()
841 Test all of the properties from Theorem 11.2 in Alizadeh::
843 sage: set_random_seed()
844 sage: J = random_eja()
845 sage: x = J.random_element()
846 sage: y = J.random_element()
847 sage: Lx = x.operator()
848 sage: Lxx = (x*x).operator()
849 sage: Qx = x.quadratic_representation()
850 sage: Qy = y.quadratic_representation()
851 sage: Qxy = x.quadratic_representation(y)
852 sage: Qex = J.one().quadratic_representation(x)
853 sage: n = ZZ.random_element(10)
854 sage: Qxn = (x^n).quadratic_representation()
858 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
861 Property 2 (multiply on the right for :trac:`28272`):
863 sage: alpha = QQ.random_element()
864 sage: (alpha*x).quadratic_representation() == Qx*(alpha^2)
869 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
872 sage: not x.is_invertible() or (
875 ....: x.inverse().quadratic_representation() )
878 sage: Qxy(J.one()) == x*y
883 sage: not x.is_invertible() or (
884 ....: x.quadratic_representation(x.inverse())*Qx
885 ....: == Qx*x.quadratic_representation(x.inverse()) )
888 sage: not x.is_invertible() or (
889 ....: x.quadratic_representation(x.inverse())*Qx
891 ....: 2*x.operator()*Qex - Qx )
894 sage: 2*x.operator()*Qex - Qx == Lxx
899 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
909 sage: not x.is_invertible() or (
910 ....: Qx*x.inverse().operator() == Lx )
915 sage: not x.operator_commutes_with(y) or (
916 ....: Qx(y)^n == Qxn(y^n) )
922 elif not other
in self
.parent():
923 raise TypeError("'other' must live in the same algebra")
927 return ( L
*M
+ M
*L
- (self
*other
).operator() )
932 def subalgebra_generated_by(self
):
934 Return the associative subalgebra of the parent EJA generated
939 sage: from mjo.eja.eja_algebra import random_eja
943 This subalgebra, being composed of only powers, is associative::
945 sage: set_random_seed()
946 sage: x0 = random_eja().random_element()
947 sage: A = x0.subalgebra_generated_by()
948 sage: x = A.random_element()
949 sage: y = A.random_element()
950 sage: z = A.random_element()
951 sage: (x*y)*z == x*(y*z)
954 Squaring in the subalgebra should work the same as in
957 sage: set_random_seed()
958 sage: x = random_eja().random_element()
959 sage: A = x.subalgebra_generated_by()
960 sage: A(x^2) == A(x)*A(x)
964 return FiniteDimensionalEuclideanJordanElementSubalgebra(self
)
967 def subalgebra_idempotent(self
):
969 Find an idempotent in the associative subalgebra I generate
970 using Proposition 2.3.5 in Baes.
974 sage: from mjo.eja.eja_algebra import random_eja
978 sage: set_random_seed()
979 sage: J = random_eja()
980 sage: x = J.random_element()
981 sage: while x.is_nilpotent():
982 ....: x = J.random_element()
983 sage: c = x.subalgebra_idempotent()
988 if self
.is_nilpotent():
989 raise ValueError("this only works with non-nilpotent elements!")
991 J
= self
.subalgebra_generated_by()
994 # The image of the matrix of left-u^m-multiplication
995 # will be minimal for some natural number s...
997 minimal_dim
= J
.dimension()
998 for i
in xrange(1, minimal_dim
):
999 this_dim
= (u
**i
).operator().matrix().image().dimension()
1000 if this_dim
< minimal_dim
:
1001 minimal_dim
= this_dim
1004 # Now minimal_matrix should correspond to the smallest
1005 # non-zero subspace in Baes's (or really, Koecher's)
1008 # However, we need to restrict the matrix to work on the
1009 # subspace... or do we? Can't we just solve, knowing that
1010 # A(c) = u^(s+1) should have a solution in the big space,
1013 # Beware, solve_right() means that we're using COLUMN vectors.
1014 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1016 A
= u_next
.operator().matrix()
1017 c
= J
.from_vector(A
.solve_right(u_next
.to_vector()))
1019 # Now c is the idempotent we want, but it still lives in the subalgebra.
1020 return c
.superalgebra_element()
1025 Return my trace, the sum of my eigenvalues.
1029 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1030 ....: RealCartesianProductEJA,
1035 sage: J = JordanSpinEJA(3)
1036 sage: x = sum(J.gens())
1042 sage: J = RealCartesianProductEJA(5)
1043 sage: J.one().trace()
1048 The trace of an element is a real number::
1050 sage: set_random_seed()
1051 sage: J = random_eja()
1052 sage: J.random_element().trace() in J.base_ring()
1058 p
= P
._charpoly
_coeff
(r
-1)
1059 # The _charpoly_coeff function already adds the factor of
1060 # -1 to ensure that _charpoly_coeff(r-1) is really what
1061 # appears in front of t^{r-1} in the charpoly. However,
1062 # we want the negative of THAT for the trace.
1063 return -p(*self
.to_vector())
1066 def trace_inner_product(self
, other
):
1068 Return the trace inner product of myself and ``other``.
1072 sage: from mjo.eja.eja_algebra import random_eja
1076 The trace inner product is commutative::
1078 sage: set_random_seed()
1079 sage: J = random_eja()
1080 sage: x = J.random_element(); y = J.random_element()
1081 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1084 The trace inner product is bilinear::
1086 sage: set_random_seed()
1087 sage: J = random_eja()
1088 sage: x = J.random_element()
1089 sage: y = J.random_element()
1090 sage: z = J.random_element()
1091 sage: a = QQ.random_element();
1092 sage: actual = (a*(x+z)).trace_inner_product(y)
1093 sage: expected = ( a*x.trace_inner_product(y) +
1094 ....: a*z.trace_inner_product(y) )
1095 sage: actual == expected
1097 sage: actual = x.trace_inner_product(a*(y+z))
1098 sage: expected = ( a*x.trace_inner_product(y) +
1099 ....: a*x.trace_inner_product(z) )
1100 sage: actual == expected
1103 The trace inner product satisfies the compatibility
1104 condition in the definition of a Euclidean Jordan algebra::
1106 sage: set_random_seed()
1107 sage: J = random_eja()
1108 sage: x = J.random_element()
1109 sage: y = J.random_element()
1110 sage: z = J.random_element()
1111 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1115 if not other
in self
.parent():
1116 raise TypeError("'other' must live in the same algebra")
1118 return (self
*other
).trace()