]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_element.py
eja: add the trace (matrix) operator inner product.
[sage.d.git] / mjo / eja / eja_element.py
1 from sage.matrix.constructor import matrix
2 from sage.misc.cachefunc import cached_method
3 from sage.modules.free_module import VectorSpace
4 from sage.modules.with_basis.indexed_element import IndexedFreeModuleElement
5
6 from mjo.eja.eja_operator import FiniteDimensionalEJAOperator
7 from mjo.eja.eja_utils import _scale
8
9
10 class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
11 """
12 An element of a Euclidean Jordan algebra.
13 """
14
15 def __dir__(self):
16 """
17 Oh man, I should not be doing this. This hides the "disabled"
18 methods ``left_matrix`` and ``matrix`` from introspection;
19 in particular it removes them from tab-completion.
20 """
21 return filter(lambda s: s not in ['left_matrix', 'matrix'],
22 dir(self.__class__) )
23
24
25
26
27 def __pow__(self, n):
28 """
29 Return ``self`` raised to the power ``n``.
30
31 Jordan algebras are always power-associative; see for
32 example Faraut and Korányi, Proposition II.1.2 (ii).
33
34 We have to override this because our superclass uses row
35 vectors instead of column vectors! We, on the other hand,
36 assume column vectors everywhere.
37
38 SETUP::
39
40 sage: from mjo.eja.eja_algebra import random_eja
41
42 TESTS:
43
44 The definition of `x^2` is the unambiguous `x*x`::
45
46 sage: x = random_eja().random_element()
47 sage: x*x == (x^2)
48 True
49
50 A few examples of power-associativity::
51
52 sage: x = random_eja().random_element()
53 sage: x*(x*x)*(x*x) == x^5
54 True
55 sage: (x*x)*(x*x*x) == x^5
56 True
57
58 We also know that powers operator-commute (Koecher, Chapter
59 III, Corollary 1)::
60
61 sage: x = random_eja().random_element()
62 sage: m = ZZ.random_element(0,10)
63 sage: n = ZZ.random_element(0,10)
64 sage: Lxm = (x^m).operator()
65 sage: Lxn = (x^n).operator()
66 sage: Lxm*Lxn == Lxn*Lxm
67 True
68
69 """
70 if n == 0:
71 return self.parent().one()
72 elif n == 1:
73 return self
74 else:
75 return (self**(n-1))*self
76
77
78 def apply_univariate_polynomial(self, p):
79 """
80 Apply the univariate polynomial ``p`` to this element.
81
82 A priori, SageMath won't allow us to apply a univariate
83 polynomial to an element of an EJA, because we don't know
84 that EJAs are rings (they are usually not associative). Of
85 course, we know that EJAs are power-associative, so the
86 operation is ultimately kosher. This function sidesteps
87 the CAS to get the answer we want and expect.
88
89 SETUP::
90
91 sage: from mjo.eja.eja_algebra import (HadamardEJA,
92 ....: random_eja)
93
94 EXAMPLES::
95
96 sage: R = PolynomialRing(QQ, 't')
97 sage: t = R.gen(0)
98 sage: p = t^4 - t^3 + 5*t - 2
99 sage: J = HadamardEJA(5)
100 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
101 True
102
103 TESTS:
104
105 We should always get back an element of the algebra::
106
107 sage: p = PolynomialRing(AA, 't').random_element()
108 sage: J = random_eja()
109 sage: x = J.random_element()
110 sage: x.apply_univariate_polynomial(p) in J
111 True
112
113 """
114 if len(p.variables()) > 1:
115 raise ValueError("not a univariate polynomial")
116 P = self.parent()
117 R = P.base_ring()
118 # Convert the coeficcients to the parent's base ring,
119 # because a priori they might live in an (unnecessarily)
120 # larger ring for which P.sum() would fail below.
121 cs = [ R(c) for c in p.coefficients(sparse=False) ]
122 return P.sum( cs[k]*(self**k) for k in range(len(cs)) )
123
124
125 def characteristic_polynomial(self):
126 """
127 Return the characteristic polynomial of this element.
128
129 SETUP::
130
131 sage: from mjo.eja.eja_algebra import (random_eja,
132 ....: HadamardEJA)
133
134 EXAMPLES:
135
136 The rank of `R^3` is three, and the minimal polynomial of
137 the identity element is `(t-1)` from which it follows that
138 the characteristic polynomial should be `(t-1)^3`::
139
140 sage: J = HadamardEJA(3)
141 sage: J.one().characteristic_polynomial()
142 t^3 - 3*t^2 + 3*t - 1
143
144 Likewise, the characteristic of the zero element in the
145 rank-three algebra `R^{n}` should be `t^{3}`::
146
147 sage: J = HadamardEJA(3)
148 sage: J.zero().characteristic_polynomial()
149 t^3
150
151 TESTS:
152
153 The characteristic polynomial of an element should evaluate
154 to zero on that element::
155
156 sage: x = random_eja().random_element()
157 sage: p = x.characteristic_polynomial()
158 sage: x.apply_univariate_polynomial(p).is_zero()
159 True
160
161 The characteristic polynomials of the zero and unit elements
162 should be what we think they are in a subalgebra, too::
163
164 sage: J = HadamardEJA(3)
165 sage: p1 = J.one().characteristic_polynomial()
166 sage: q1 = J.zero().characteristic_polynomial()
167 sage: b0,b1,b2 = J.gens()
168 sage: A = (b0 + 2*b1 + 3*b2).subalgebra_generated_by() # dim 3
169 sage: p2 = A.one().characteristic_polynomial()
170 sage: q2 = A.zero().characteristic_polynomial()
171 sage: p1 == p2
172 True
173 sage: q1 == q2
174 True
175
176 """
177 p = self.parent().characteristic_polynomial_of()
178 return p(*self.to_vector())
179
180
181 def inner_product(self, other):
182 """
183 Return the parent algebra's inner product of myself and ``other``.
184
185 SETUP::
186
187 sage: from mjo.eja.eja_algebra import (
188 ....: ComplexHermitianEJA,
189 ....: JordanSpinEJA,
190 ....: QuaternionHermitianEJA,
191 ....: RealSymmetricEJA,
192 ....: random_eja)
193
194 EXAMPLES:
195
196 The inner product in the Jordan spin algebra is the usual
197 inner product on `R^n` (this example only works because the
198 basis for the Jordan algebra is the standard basis in `R^n`)::
199
200 sage: J = JordanSpinEJA(3)
201 sage: x = vector(QQ,[1,2,3])
202 sage: y = vector(QQ,[4,5,6])
203 sage: x.inner_product(y)
204 32
205 sage: J.from_vector(x).inner_product(J.from_vector(y))
206 32
207
208 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
209 multiplication is the usual matrix multiplication in `S^n`,
210 so the inner product of the identity matrix with itself
211 should be the `n`::
212
213 sage: J = RealSymmetricEJA(3)
214 sage: J.one().inner_product(J.one())
215 3
216
217 Likewise, the inner product on `C^n` is `<X,Y> =
218 Re(trace(X*Y))`, where we must necessarily take the real
219 part because the product of Hermitian matrices may not be
220 Hermitian::
221
222 sage: J = ComplexHermitianEJA(3)
223 sage: J.one().inner_product(J.one())
224 3
225
226 Ditto for the quaternions::
227
228 sage: J = QuaternionHermitianEJA(2)
229 sage: J.one().inner_product(J.one())
230 2
231
232 TESTS:
233
234 Ensure that we can always compute an inner product, and that
235 it gives us back a real number::
236
237 sage: J = random_eja()
238 sage: x,y = J.random_elements(2)
239 sage: x.inner_product(y) in RLF
240 True
241
242 """
243 P = self.parent()
244 if not other in P:
245 raise TypeError("'other' must live in the same algebra")
246
247 return P.inner_product(self, other)
248
249
250 def operator_commutes_with(self, other):
251 """
252 Return whether or not this element operator-commutes
253 with ``other``.
254
255 SETUP::
256
257 sage: from mjo.eja.eja_algebra import random_eja
258
259 EXAMPLES:
260
261 The definition of a Jordan algebra says that any element
262 operator-commutes with its square::
263
264 sage: x = random_eja().random_element()
265 sage: x.operator_commutes_with(x^2)
266 True
267
268 TESTS:
269
270 Test Lemma 1 from Chapter III of Koecher::
271
272 sage: u,v = random_eja().random_elements(2)
273 sage: lhs = u.operator_commutes_with(u*v)
274 sage: rhs = v.operator_commutes_with(u^2)
275 sage: lhs == rhs
276 True
277
278 Test the first polarization identity from my notes, Koecher
279 Chapter III, or from Baes (2.3)::
280
281 sage: x,y = random_eja().random_elements(2)
282 sage: Lx = x.operator()
283 sage: Ly = y.operator()
284 sage: Lxx = (x*x).operator()
285 sage: Lxy = (x*y).operator()
286 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
287 True
288
289 Test the second polarization identity from my notes or from
290 Baes (2.4)::
291
292 sage: x,y,z = random_eja().random_elements(3) # long time
293 sage: Lx = x.operator() # long time
294 sage: Ly = y.operator() # long time
295 sage: Lz = z.operator() # long time
296 sage: Lzy = (z*y).operator() # long time
297 sage: Lxy = (x*y).operator() # long time
298 sage: Lxz = (x*z).operator() # long time
299 sage: lhs = Lx*Lzy + Lz*Lxy + Ly*Lxz # long time
300 sage: rhs = Lzy*Lx + Lxy*Lz + Lxz*Ly # long time
301 sage: bool(lhs == rhs) # long time
302 True
303
304 Test the third polarization identity from my notes or from
305 Baes (2.5)::
306
307 sage: u,y,z = random_eja().random_elements(3) # long time
308 sage: Lu = u.operator() # long time
309 sage: Ly = y.operator() # long time
310 sage: Lz = z.operator() # long time
311 sage: Lzy = (z*y).operator() # long time
312 sage: Luy = (u*y).operator() # long time
313 sage: Luz = (u*z).operator() # long time
314 sage: Luyz = (u*(y*z)).operator() # long time
315 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz # long time
316 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly # long time
317 sage: bool(lhs == rhs) # long time
318 True
319
320 """
321 if not other in self.parent():
322 raise TypeError("'other' must live in the same algebra")
323
324 A = self.operator()
325 B = other.operator()
326 return (A*B == B*A)
327
328
329 def det(self):
330 """
331 Return my determinant, the product of my eigenvalues.
332
333 SETUP::
334
335 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
336 ....: TrivialEJA,
337 ....: RealSymmetricEJA,
338 ....: ComplexHermitianEJA,
339 ....: random_eja)
340
341 EXAMPLES::
342
343 sage: J = JordanSpinEJA(2)
344 sage: x = sum( J.gens() )
345 sage: x.det()
346 0
347
348 ::
349
350 sage: J = JordanSpinEJA(3)
351 sage: x = sum( J.gens() )
352 sage: x.det()
353 -1
354
355 The determinant of the sole element in the rank-zero trivial
356 algebra is ``1``, by three paths of reasoning. First, its
357 characteristic polynomial is a constant ``1``, so the constant
358 term in that polynomial is ``1``. Second, the characteristic
359 polynomial evaluated at zero is again ``1``. And finally, the
360 (empty) product of its eigenvalues is likewise just unity::
361
362 sage: J = TrivialEJA()
363 sage: J.zero().det()
364 1
365
366 TESTS:
367
368 An element is invertible if and only if its determinant is
369 non-zero::
370
371 sage: x = random_eja().random_element()
372 sage: x.is_invertible() == (x.det() != 0)
373 True
374
375 Ensure that the determinant is multiplicative on an associative
376 subalgebra as in Faraut and Korányi's Proposition II.2.2::
377
378 sage: x0 = random_eja().random_element()
379 sage: J = x0.subalgebra_generated_by(orthonormalize=False)
380 sage: x,y = J.random_elements(2)
381 sage: (x*y).det() == x.det()*y.det()
382 True
383
384 The determinant in real matrix algebras is the usual determinant::
385
386 sage: X = matrix.random(QQ,3)
387 sage: X = X + X.T
388 sage: J1 = RealSymmetricEJA(3)
389 sage: J2 = RealSymmetricEJA(3,field=QQ,orthonormalize=False)
390 sage: expected = X.det()
391 sage: actual1 = J1(X).det()
392 sage: actual2 = J2(X).det()
393 sage: actual1 == expected
394 True
395 sage: actual2 == expected
396 True
397
398 """
399 P = self.parent()
400 r = P.rank()
401
402 if r == 0:
403 # Special case, since we don't get the a0=1
404 # coefficient when the rank of the algebra
405 # is zero.
406 return P.base_ring().one()
407
408 p = P._charpoly_coefficients()[0]
409 # The _charpoly_coeff function already adds the factor of -1
410 # to ensure that _charpoly_coefficients()[0] is really what
411 # appears in front of t^{0} in the charpoly. However, we want
412 # (-1)^r times THAT for the determinant.
413 return ((-1)**r)*p(*self.to_vector())
414
415
416 @cached_method
417 def inverse(self):
418 """
419 Return the Jordan-multiplicative inverse of this element.
420
421 ALGORITHM:
422
423 In general we appeal to the quadratic representation as in
424 Koecher's Theorem 12 in Chapter III, Section 5. But if the
425 parent algebra's "characteristic polynomial of" coefficients
426 happen to be cached, then we use Proposition II.2.4 in Faraut
427 and Korányi which gives a formula for the inverse based on the
428 characteristic polynomial and the Cayley-Hamilton theorem for
429 Euclidean Jordan algebras::
430
431 SETUP::
432
433 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
434 ....: JordanSpinEJA,
435 ....: random_eja)
436
437 EXAMPLES:
438
439 The inverse in the spin factor algebra is given in Alizadeh's
440 Example 11.11::
441
442 sage: J = JordanSpinEJA.random_instance()
443 sage: x = J.random_element()
444 sage: while not x.is_invertible():
445 ....: x = J.random_element()
446 sage: x_vec = x.to_vector()
447 sage: x0 = x_vec[:1]
448 sage: x_bar = x_vec[1:]
449 sage: coeff = x0.inner_product(x0) - x_bar.inner_product(x_bar)
450 sage: x_inverse = x_vec.parent()(x0.list() + (-x_bar).list())
451 sage: if not coeff.is_zero(): x_inverse = x_inverse/coeff
452 sage: x.inverse() == J.from_vector(x_inverse)
453 True
454
455 Trying to invert a non-invertible element throws an error:
456
457 sage: JordanSpinEJA(3).zero().inverse()
458 Traceback (most recent call last):
459 ...
460 ZeroDivisionError: element is not invertible
461
462 TESTS:
463
464 The identity element is its own inverse::
465
466 sage: J = random_eja()
467 sage: J.one().inverse() == J.one()
468 True
469
470 If an element has an inverse, it acts like one::
471
472 sage: J = random_eja()
473 sage: x = J.random_element()
474 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
475 True
476
477 The inverse of the inverse is what we started with::
478
479 sage: J = random_eja()
480 sage: x = J.random_element()
481 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
482 True
483
484 Proposition II.2.3 in Faraut and Korányi says that the inverse
485 of an element is the inverse of its left-multiplication operator
486 applied to the algebra's identity, when that inverse exists::
487
488 sage: J = random_eja() # long time
489 sage: x = J.random_element() # long time
490 sage: (not x.operator().is_invertible()) or ( # long time
491 ....: x.operator().inverse()(J.one()) # long time
492 ....: == # long time
493 ....: x.inverse() ) # long time
494 True
495
496 Check that the fast (cached) and slow algorithms give the same
497 answer::
498
499 sage: J = random_eja(field=QQ, orthonormalize=False) # long time
500 sage: x = J.random_element() # long time
501 sage: while not x.is_invertible(): # long time
502 ....: x = J.random_element() # long time
503 sage: slow = x.inverse() # long time
504 sage: _ = J._charpoly_coefficients() # long time
505 sage: fast = x.inverse() # long time
506 sage: slow == fast # long time
507 True
508 """
509 not_invertible_msg = "element is not invertible"
510
511 algebra = self.parent()
512 if algebra._charpoly_coefficients.is_in_cache():
513 # We can invert using our charpoly if it will be fast to
514 # compute. If the coefficients are cached, our rank had
515 # better be too!
516 if self.det().is_zero():
517 raise ZeroDivisionError(not_invertible_msg)
518 r = algebra.rank()
519 a = self.characteristic_polynomial().coefficients(sparse=False)
520 return (-1)**(r+1)*algebra.sum(a[i+1]*self**i
521 for i in range(r))/self.det()
522
523 try:
524 inv = (~self.quadratic_representation())(self)
525 self.is_invertible.set_cache(True)
526 return inv
527 except ZeroDivisionError:
528 self.is_invertible.set_cache(False)
529 raise ZeroDivisionError(not_invertible_msg)
530
531
532 @cached_method
533 def is_invertible(self):
534 """
535 Return whether or not this element is invertible.
536
537 ALGORITHM:
538
539 If computing my determinant will be fast, we do so and compare
540 with zero (Proposition II.2.4 in Faraut and
541 Koranyi). Otherwise, Proposition II.3.2 in Faraut and Koranyi
542 reduces the problem to the invertibility of my quadratic
543 representation.
544
545 SETUP::
546
547 sage: from mjo.eja.eja_algebra import random_eja
548
549 TESTS:
550
551 The identity element is always invertible::
552
553 sage: J = random_eja()
554 sage: J.one().is_invertible()
555 True
556
557 The zero element is never invertible in a non-trivial algebra::
558
559 sage: J = random_eja()
560 sage: (not J.is_trivial()) and J.zero().is_invertible()
561 False
562
563 Test that the fast (cached) and slow algorithms give the same
564 answer::
565
566 sage: J = random_eja(field=QQ, orthonormalize=False) # long time
567 sage: x = J.random_element() # long time
568 sage: slow = x.is_invertible() # long time
569 sage: _ = J._charpoly_coefficients() # long time
570 sage: fast = x.is_invertible() # long time
571 sage: slow == fast # long time
572 True
573 """
574 if self.is_zero():
575 if self.parent().is_trivial():
576 return True
577 else:
578 return False
579
580 if self.parent()._charpoly_coefficients.is_in_cache():
581 # The determinant will be quicker than inverting the
582 # quadratic representation, most likely.
583 return (not self.det().is_zero())
584
585 # The easiest way to determine if I'm invertible is to try.
586 try:
587 inv = (~self.quadratic_representation())(self)
588 self.inverse.set_cache(inv)
589 return True
590 except ZeroDivisionError:
591 return False
592
593
594 def is_primitive_idempotent(self):
595 """
596 Return whether or not this element is a primitive (or minimal)
597 idempotent.
598
599 A primitive idempotent is a non-zero idempotent that is not
600 the sum of two other non-zero idempotents. Remark 2.7.15 in
601 Baes shows that this is what he refers to as a "minimal
602 idempotent."
603
604 An element of a Euclidean Jordan algebra is a minimal idempotent
605 if it :meth:`is_idempotent` and if its Peirce subalgebra
606 corresponding to the eigenvalue ``1`` has dimension ``1`` (Baes,
607 Proposition 2.7.17).
608
609 SETUP::
610
611 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
612 ....: RealSymmetricEJA,
613 ....: TrivialEJA,
614 ....: random_eja)
615
616 WARNING::
617
618 This method is sloooooow.
619
620 EXAMPLES:
621
622 The spectral decomposition of a non-regular element should always
623 contain at least one non-minimal idempotent::
624
625 sage: J = RealSymmetricEJA(3)
626 sage: x = sum(J.gens())
627 sage: x.is_regular()
628 False
629 sage: [ c.is_primitive_idempotent()
630 ....: for (l,c) in x.spectral_decomposition() ]
631 [False, True]
632
633 On the other hand, the spectral decomposition of a regular
634 element should always be in terms of minimal idempotents::
635
636 sage: J = JordanSpinEJA(4)
637 sage: x = sum( i*J.monomial(i) for i in range(len(J.gens())) )
638 sage: x.is_regular()
639 True
640 sage: [ c.is_primitive_idempotent()
641 ....: for (l,c) in x.spectral_decomposition() ]
642 [True, True]
643
644 TESTS:
645
646 The identity element is minimal only in an EJA of rank one::
647
648 sage: J = random_eja()
649 sage: J.rank() == 1 or not J.one().is_primitive_idempotent()
650 True
651
652 A non-idempotent cannot be a minimal idempotent::
653
654 sage: J = JordanSpinEJA(4)
655 sage: x = J.random_element()
656 sage: (not x.is_idempotent()) and x.is_primitive_idempotent()
657 False
658
659 Proposition 2.7.19 in Baes says that an element is a minimal
660 idempotent if and only if it's idempotent with trace equal to
661 unity::
662
663 sage: J = JordanSpinEJA(4)
664 sage: x = J.random_element()
665 sage: expected = (x.is_idempotent() and x.trace() == 1)
666 sage: actual = x.is_primitive_idempotent()
667 sage: actual == expected
668 True
669
670 Primitive idempotents must be non-zero::
671
672 sage: J = random_eja()
673 sage: J.zero().is_idempotent()
674 True
675 sage: J.zero().is_primitive_idempotent()
676 False
677
678 As a consequence of the fact that primitive idempotents must
679 be non-zero, there are no primitive idempotents in a trivial
680 Euclidean Jordan algebra::
681
682 sage: J = TrivialEJA()
683 sage: J.one().is_idempotent()
684 True
685 sage: J.one().is_primitive_idempotent()
686 False
687
688 """
689 if not self.is_idempotent():
690 return False
691
692 if self.is_zero():
693 return False
694
695 (_,_,J1) = self.parent().peirce_decomposition(self)
696 return (J1.dimension() == 1)
697
698
699 def is_nilpotent(self):
700 """
701 Return whether or not some power of this element is zero.
702
703 ALGORITHM:
704
705 We use Theorem 5 in Chapter III of Koecher, which says that
706 an element ``x`` is nilpotent if and only if ``x.operator()``
707 is nilpotent. And it is a basic fact of linear algebra that
708 an operator on an `n`-dimensional space is nilpotent if and
709 only if, when raised to the `n`th power, it equals the zero
710 operator (for example, see Axler Corollary 8.8).
711
712 SETUP::
713
714 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
715 ....: random_eja)
716
717 EXAMPLES::
718
719 sage: J = JordanSpinEJA(3)
720 sage: x = sum(J.gens())
721 sage: x.is_nilpotent()
722 False
723
724 TESTS:
725
726 The identity element is never nilpotent, except in a trivial EJA::
727
728 sage: J = random_eja()
729 sage: J.one().is_nilpotent() and not J.is_trivial()
730 False
731
732 The additive identity is always nilpotent::
733
734 sage: random_eja().zero().is_nilpotent()
735 True
736
737 """
738 P = self.parent()
739 zero_operator = P.zero().operator()
740 return self.operator()**P.dimension() == zero_operator
741
742
743 def is_regular(self):
744 """
745 Return whether or not this is a regular element.
746
747 SETUP::
748
749 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
750 ....: random_eja)
751
752 EXAMPLES:
753
754 The identity element always has degree one, but any element
755 linearly-independent from it is regular::
756
757 sage: J = JordanSpinEJA(5)
758 sage: J.one().is_regular()
759 False
760 sage: b0, b1, b2, b3, b4 = J.gens()
761 sage: b0 == J.one()
762 True
763 sage: for x in J.gens():
764 ....: (J.one() + x).is_regular()
765 False
766 True
767 True
768 True
769 True
770
771 TESTS:
772
773 The zero element should never be regular, unless the parent
774 algebra has dimension less than or equal to one::
775
776 sage: J = random_eja()
777 sage: J.dimension() <= 1 or not J.zero().is_regular()
778 True
779
780 The unit element isn't regular unless the algebra happens to
781 consist of only its scalar multiples::
782
783 sage: J = random_eja()
784 sage: J.dimension() <= 1 or not J.one().is_regular()
785 True
786
787 """
788 return self.degree() == self.parent().rank()
789
790
791 def degree(self):
792 """
793 Return the degree of this element, which is defined to be
794 the degree of its minimal polynomial.
795
796 ALGORITHM:
797
798 .........
799
800 SETUP::
801
802 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
803 ....: random_eja)
804
805 EXAMPLES::
806
807 sage: J = JordanSpinEJA(4)
808 sage: J.one().degree()
809 1
810 sage: b0,b1,b2,b3 = J.gens()
811 sage: (b0 - b1).degree()
812 2
813
814 In the spin factor algebra (of rank two), all elements that
815 aren't multiples of the identity are regular::
816
817 sage: J = JordanSpinEJA.random_instance()
818 sage: n = J.dimension()
819 sage: x = J.random_element()
820 sage: x.degree() == min(n,2) or (x == x.coefficient(0)*J.one())
821 True
822
823 TESTS:
824
825 The zero and unit elements are both of degree one in nontrivial
826 algebras::
827
828 sage: J = random_eja()
829 sage: d = J.zero().degree()
830 sage: (J.is_trivial() and d == 0) or d == 1
831 True
832 sage: d = J.one().degree()
833 sage: (J.is_trivial() and d == 0) or d == 1
834 True
835
836 Our implementation agrees with the definition::
837
838 sage: x = random_eja().random_element()
839 sage: x.degree() == x.minimal_polynomial().degree()
840 True
841
842 """
843 n = self.parent().dimension()
844
845 if n == 0:
846 # The minimal polynomial is an empty product, i.e. the
847 # constant polynomial "1" having degree zero.
848 return 0
849 elif self.is_zero():
850 # The minimal polynomial of zero in a nontrivial algebra
851 # is "t", and is of degree one.
852 return 1
853 elif n == 1:
854 # If this is a nonzero element of a nontrivial algebra, it
855 # has degree at least one. It follows that, in an algebra
856 # of dimension one, the degree must be actually one.
857 return 1
858
859 # BEWARE: The subalgebra_generated_by() method uses the result
860 # of this method to construct a basis for the subalgebra. That
861 # means, in particular, that we cannot implement this method
862 # as ``self.subalgebra_generated_by().dimension()``.
863
864 # Algorithm: keep appending (vector representations of) powers
865 # self as rows to a matrix and echelonizing it. When its rank
866 # stops increasing, we've reached a redundancy.
867
868 # Given the special cases above, we can assume that "self" is
869 # nonzero, the algebra is nontrivial, and that its dimension
870 # is at least two.
871 M = matrix([(self.parent().one()).to_vector()])
872 old_rank = 1
873
874 # Specifying the row-reduction algorithm can e.g. help over
875 # AA because it avoids the RecursionError that gets thrown
876 # when we have to look too hard for a root.
877 #
878 # Beware: QQ supports an entirely different set of "algorithm"
879 # keywords than do AA and RR.
880 algo = None
881 from sage.rings.all import QQ
882 if self.parent().base_ring() is not QQ:
883 algo = "scaled_partial_pivoting"
884
885 for d in range(1,n):
886 M = matrix(M.rows() + [(self**d).to_vector()])
887 M.echelonize(algo)
888 new_rank = M.rank()
889 if new_rank == old_rank:
890 return new_rank
891 else:
892 old_rank = new_rank
893
894 return n
895
896
897
898 def left_matrix(self):
899 """
900 Our parent class defines ``left_matrix`` and ``matrix``
901 methods whose names are misleading. We don't want them.
902 """
903 raise NotImplementedError("use operator().matrix() instead")
904
905 matrix = left_matrix
906
907
908 def minimal_polynomial(self):
909 """
910 Return the minimal polynomial of this element,
911 as a function of the variable `t`.
912
913 ALGORITHM:
914
915 We restrict ourselves to the associative subalgebra
916 generated by this element, and then return the minimal
917 polynomial of this element's operator matrix (in that
918 subalgebra). This works by Baes Proposition 2.3.16.
919
920 SETUP::
921
922 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
923 ....: RealSymmetricEJA,
924 ....: TrivialEJA,
925 ....: random_eja)
926
927 EXAMPLES:
928
929 Keeping in mind that the polynomial ``1`` evaluates the identity
930 element (also the zero element) of the trivial algebra, it is clear
931 that the polynomial ``1`` is the minimal polynomial of the only
932 element in a trivial algebra::
933
934 sage: J = TrivialEJA()
935 sage: J.one().minimal_polynomial()
936 1
937 sage: J.zero().minimal_polynomial()
938 1
939
940 TESTS:
941
942 The minimal polynomial of the identity and zero elements are
943 always the same, except in trivial algebras where the minimal
944 polynomial of the unit/zero element is ``1``::
945
946 sage: J = random_eja()
947 sage: mu = J.one().minimal_polynomial()
948 sage: t = mu.parent().gen()
949 sage: mu + int(J.is_trivial())*(t-2)
950 t - 1
951 sage: mu = J.zero().minimal_polynomial()
952 sage: t = mu.parent().gen()
953 sage: mu + int(J.is_trivial())*(t-1)
954 t
955
956 The degree of an element is (by one definition) the degree
957 of its minimal polynomial::
958
959 sage: x = random_eja().random_element()
960 sage: x.degree() == x.minimal_polynomial().degree()
961 True
962
963 The minimal polynomial and the characteristic polynomial coincide
964 and are known (see Alizadeh, Example 11.11) for all elements of
965 the spin factor algebra that aren't scalar multiples of the
966 identity. We require the dimension of the algebra to be at least
967 two here so that said elements actually exist::
968
969 sage: d_max = JordanSpinEJA._max_random_instance_dimension()
970 sage: n = ZZ.random_element(2, max(2,d_max))
971 sage: J = JordanSpinEJA(n)
972 sage: y = J.random_element()
973 sage: while y == y.coefficient(0)*J.one():
974 ....: y = J.random_element()
975 sage: y0 = y.to_vector()[0]
976 sage: y_bar = y.to_vector()[1:]
977 sage: actual = y.minimal_polynomial()
978 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
979 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
980 sage: bool(actual == expected)
981 True
982
983 The minimal polynomial should always kill its element::
984
985 sage: x = random_eja().random_element() # long time
986 sage: p = x.minimal_polynomial() # long time
987 sage: x.apply_univariate_polynomial(p) # long time
988 0
989
990 The minimal polynomial is invariant under a change of basis,
991 and in particular, a re-scaling of the basis::
992
993 sage: d_max = RealSymmetricEJA._max_random_instance_dimension()
994 sage: d = ZZ.random_element(1, d_max)
995 sage: n = RealSymmetricEJA._max_random_instance_size(d)
996 sage: J1 = RealSymmetricEJA(n)
997 sage: J2 = RealSymmetricEJA(n,orthonormalize=False)
998 sage: X = random_matrix(AA,n)
999 sage: X = X*X.transpose()
1000 sage: x1 = J1(X)
1001 sage: x2 = J2(X)
1002 sage: x1.minimal_polynomial() == x2.minimal_polynomial()
1003 True
1004
1005 """
1006 if self.is_zero():
1007 # Pretty sure we know what the minimal polynomial of
1008 # the zero operator is going to be. This ensures
1009 # consistency of e.g. the polynomial variable returned
1010 # in the "normal" case without us having to think about it.
1011 return self.operator().minimal_polynomial()
1012
1013 # If we don't orthonormalize the subalgebra's basis, then the
1014 # first two monomials in the subalgebra will be self^0 and
1015 # self^1... assuming that self^1 is not a scalar multiple of
1016 # self^0 (the unit element). We special case these to avoid
1017 # having to solve a system to coerce self into the subalgebra.
1018 A = self.subalgebra_generated_by(orthonormalize=False)
1019
1020 if A.dimension() == 1:
1021 # Does a solve to find the scalar multiple alpha such that
1022 # alpha*unit = self. We have to do this because the basis
1023 # for the subalgebra will be [ self^0 ], and not [ self^1 ]!
1024 unit = self.parent().one()
1025 alpha = self.to_vector() / unit.to_vector()
1026 return (unit.operator()*alpha).minimal_polynomial()
1027 else:
1028 # If the dimension of the subalgebra is >= 2, then we just
1029 # use the second basis element.
1030 return A.monomial(1).operator().minimal_polynomial()
1031
1032
1033
1034 def to_matrix(self):
1035 """
1036 Return an (often more natural) representation of this element as a
1037 matrix.
1038
1039 Every finite-dimensional Euclidean Jordan Algebra is a direct
1040 sum of five simple algebras, four of which comprise Hermitian
1041 matrices. This method returns a "natural" matrix
1042 representation of this element as either a Hermitian matrix or
1043 column vector.
1044
1045 SETUP::
1046
1047 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
1048 ....: HadamardEJA,
1049 ....: QuaternionHermitianEJA,
1050 ....: RealSymmetricEJA)
1051
1052 EXAMPLES::
1053
1054 sage: J = ComplexHermitianEJA(3)
1055 sage: J.one()
1056 b0 + b3 + b8
1057 sage: J.one().to_matrix()
1058 +---+---+---+
1059 | 1 | 0 | 0 |
1060 +---+---+---+
1061 | 0 | 1 | 0 |
1062 +---+---+---+
1063 | 0 | 0 | 1 |
1064 +---+---+---+
1065
1066 ::
1067
1068 sage: J = QuaternionHermitianEJA(2)
1069 sage: J.one()
1070 b0 + b5
1071 sage: J.one().to_matrix()
1072 +---+---+
1073 | 1 | 0 |
1074 +---+---+
1075 | 0 | 1 |
1076 +---+---+
1077
1078 This also works in Cartesian product algebras::
1079
1080 sage: J1 = HadamardEJA(1)
1081 sage: J2 = RealSymmetricEJA(2)
1082 sage: J = cartesian_product([J1,J2])
1083 sage: x = sum(J.gens())
1084 sage: x.to_matrix()[0]
1085 [1]
1086 sage: x.to_matrix()[1]
1087 [ 1 0.7071067811865475?]
1088 [0.7071067811865475? 1]
1089
1090 """
1091 B = self.parent().matrix_basis()
1092 W = self.parent().matrix_space()
1093
1094 # This is just a manual "from_vector()", but of course
1095 # matrix spaces aren't vector spaces in sage, so they
1096 # don't have a from_vector() method.
1097 return W.linear_combination( zip(B, self.to_vector()) )
1098
1099
1100
1101 def norm(self):
1102 """
1103 The norm of this element with respect to :meth:`inner_product`.
1104
1105 SETUP::
1106
1107 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1108 ....: HadamardEJA)
1109
1110 EXAMPLES::
1111
1112 sage: J = HadamardEJA(2)
1113 sage: x = sum(J.gens())
1114 sage: x.norm()
1115 1.414213562373095?
1116
1117 ::
1118
1119 sage: J = JordanSpinEJA(4)
1120 sage: x = sum(J.gens())
1121 sage: x.norm()
1122 2
1123
1124 """
1125 return self.inner_product(self).sqrt()
1126
1127
1128 def operator(self):
1129 """
1130 Return the left-multiplication-by-this-element
1131 operator on the ambient algebra.
1132
1133 SETUP::
1134
1135 sage: from mjo.eja.eja_algebra import random_eja
1136
1137 TESTS::
1138
1139 sage: J = random_eja()
1140 sage: x,y = J.random_elements(2)
1141 sage: x.operator()(y) == x*y
1142 True
1143 sage: y.operator()(x) == x*y
1144 True
1145
1146 """
1147 P = self.parent()
1148 left_mult_by_self = lambda y: self*y
1149 L = P.module_morphism(function=left_mult_by_self, codomain=P)
1150 return FiniteDimensionalEJAOperator(P, P, L.matrix() )
1151
1152
1153 def quadratic_representation(self, other=None):
1154 """
1155 Return the quadratic representation of this element.
1156
1157 SETUP::
1158
1159 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1160 ....: random_eja)
1161
1162 EXAMPLES:
1163
1164 The explicit form in the spin factor algebra is given by
1165 Alizadeh's Example 11.12::
1166
1167 sage: x = JordanSpinEJA.random_instance().random_element()
1168 sage: x_vec = x.to_vector()
1169 sage: Q = matrix.identity(x.base_ring(), 0)
1170 sage: n = x_vec.degree()
1171 sage: if n > 0:
1172 ....: x0 = x_vec[0]
1173 ....: x_bar = x_vec[1:]
1174 ....: A = matrix(x.base_ring(), 1, [x_vec.inner_product(x_vec)])
1175 ....: B = 2*x0*x_bar.row()
1176 ....: C = 2*x0*x_bar.column()
1177 ....: D = matrix.identity(x.base_ring(), n-1)
1178 ....: D = (x0^2 - x_bar.inner_product(x_bar))*D
1179 ....: D = D + 2*x_bar.tensor_product(x_bar)
1180 ....: Q = matrix.block(2,2,[A,B,C,D])
1181 sage: Q == x.quadratic_representation().matrix()
1182 True
1183
1184 Test all of the properties from Theorem 11.2 in Alizadeh::
1185
1186 sage: J = random_eja()
1187 sage: x,y = J.random_elements(2)
1188 sage: Lx = x.operator()
1189 sage: Lxx = (x*x).operator()
1190 sage: Qx = x.quadratic_representation()
1191 sage: Qy = y.quadratic_representation()
1192 sage: Qxy = x.quadratic_representation(y)
1193 sage: Qex = J.one().quadratic_representation(x)
1194 sage: n = ZZ.random_element(10)
1195 sage: Qxn = (x^n).quadratic_representation()
1196
1197 Property 1:
1198
1199 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1200 True
1201
1202 Property 2 (multiply on the right for :trac:`28272`):
1203
1204 sage: alpha = J.base_ring().random_element()
1205 sage: (alpha*x).quadratic_representation() == Qx*(alpha^2)
1206 True
1207
1208 Property 3:
1209
1210 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
1211 True
1212
1213 sage: not x.is_invertible() or (
1214 ....: ~Qx
1215 ....: ==
1216 ....: x.inverse().quadratic_representation() )
1217 True
1218
1219 sage: Qxy(J.one()) == x*y
1220 True
1221
1222 Property 4:
1223
1224 sage: not x.is_invertible() or (
1225 ....: x.quadratic_representation(x.inverse())*Qx
1226 ....: == Qx*x.quadratic_representation(x.inverse()) )
1227 True
1228
1229 sage: not x.is_invertible() or (
1230 ....: x.quadratic_representation(x.inverse())*Qx
1231 ....: ==
1232 ....: 2*Lx*Qex - Qx )
1233 True
1234
1235 sage: 2*Lx*Qex - Qx == Lxx
1236 True
1237
1238 Property 5:
1239
1240 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
1241 True
1242
1243 Property 6:
1244
1245 sage: Qxn == (Qx)^n
1246 True
1247
1248 Property 7:
1249
1250 sage: not x.is_invertible() or (
1251 ....: Qx*x.inverse().operator() == Lx )
1252 True
1253
1254 Property 8:
1255
1256 sage: not x.operator_commutes_with(y) or (
1257 ....: Qx(y)^n == Qxn(y^n) )
1258 True
1259
1260 """
1261 if other is None:
1262 other=self
1263 elif not other in self.parent():
1264 raise TypeError("'other' must live in the same algebra")
1265
1266 L = self.operator()
1267 M = other.operator()
1268 return ( L*M + M*L - (self*other).operator() )
1269
1270
1271
1272 def spectral_decomposition(self):
1273 """
1274 Return the unique spectral decomposition of this element.
1275
1276 ALGORITHM:
1277
1278 Following Faraut and Korányi's Theorem III.1.1, we restrict this
1279 element's left-multiplication-by operator to the subalgebra it
1280 generates. We then compute the spectral decomposition of that
1281 operator, and the spectral projectors we get back must be the
1282 left-multiplication-by operators for the idempotents we
1283 seek. Thus applying them to the identity element gives us those
1284 idempotents.
1285
1286 Since the eigenvalues are required to be distinct, we take
1287 the spectral decomposition of the zero element to be zero
1288 times the identity element of the algebra (which is idempotent,
1289 obviously).
1290
1291 SETUP::
1292
1293 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1294
1295 EXAMPLES:
1296
1297 The spectral decomposition of the identity is ``1`` times itself,
1298 and the spectral decomposition of zero is ``0`` times the identity::
1299
1300 sage: J = RealSymmetricEJA(3)
1301 sage: J.one()
1302 b0 + b2 + b5
1303 sage: J.one().spectral_decomposition()
1304 [(1, b0 + b2 + b5)]
1305 sage: J.zero().spectral_decomposition()
1306 [(0, b0 + b2 + b5)]
1307
1308 TESTS::
1309
1310 sage: J = RealSymmetricEJA(4)
1311 sage: x = sum(J.gens())
1312 sage: sd = x.spectral_decomposition()
1313 sage: l0 = sd[0][0]
1314 sage: l1 = sd[1][0]
1315 sage: c0 = sd[0][1]
1316 sage: c1 = sd[1][1]
1317 sage: c0.inner_product(c1) == 0
1318 True
1319 sage: c0.is_idempotent()
1320 True
1321 sage: c1.is_idempotent()
1322 True
1323 sage: c0 + c1 == J.one()
1324 True
1325 sage: l0*c0 + l1*c1 == x
1326 True
1327
1328 The spectral decomposition should work in subalgebras, too::
1329
1330 sage: J = RealSymmetricEJA(4)
1331 sage: (b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) = J.gens()
1332 sage: A = 2*b5 - 2*b8
1333 sage: (lambda1, c1) = A.spectral_decomposition()[1]
1334 sage: (J0, J5, J1) = J.peirce_decomposition(c1)
1335 sage: (f0, f1, f2) = J1.gens()
1336 sage: f0.spectral_decomposition()
1337 [(0, 1.000000000000000?*c2), (1, 1.000000000000000?*c0)]
1338
1339 """
1340 A = self.subalgebra_generated_by(orthonormalize=True)
1341 result = []
1342 for (evalue, proj) in A(self).operator().spectral_decomposition():
1343 result.append( (evalue, proj(A.one()).superalgebra_element()) )
1344 return result
1345
1346 def subalgebra_generated_by(self, **kwargs):
1347 """
1348 Return the associative subalgebra of the parent EJA generated
1349 by this element.
1350
1351 Since our parent algebra is unital, we want "subalgebra" to mean
1352 "unital subalgebra" as well; thus the subalgebra that an element
1353 generates will itself be a Euclidean Jordan algebra after
1354 restricting the algebra operations appropriately. This is the
1355 subalgebra that Faraut and Korányi work with in section II.2, for
1356 example.
1357
1358 SETUP::
1359
1360 sage: from mjo.eja.eja_algebra import (random_eja,
1361 ....: HadamardEJA,
1362 ....: RealSymmetricEJA)
1363
1364 EXAMPLES:
1365
1366 We can create subalgebras of Cartesian product EJAs that are not
1367 themselves Cartesian product EJAs (they're just "regular" EJAs)::
1368
1369 sage: J1 = HadamardEJA(3)
1370 sage: J2 = RealSymmetricEJA(2)
1371 sage: J = cartesian_product([J1,J2])
1372 sage: J.one().subalgebra_generated_by()
1373 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
1374
1375 TESTS:
1376
1377 This subalgebra, being composed of only powers, is associative::
1378
1379 sage: x0 = random_eja().random_element()
1380 sage: A = x0.subalgebra_generated_by(orthonormalize=False)
1381 sage: x,y,z = A.random_elements(3)
1382 sage: (x*y)*z == x*(y*z)
1383 True
1384
1385 Squaring in the subalgebra should work the same as in
1386 the superalgebra::
1387
1388 sage: x = random_eja().random_element()
1389 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1390 sage: A(x^2) == A(x)*A(x)
1391 True
1392
1393 By definition, the subalgebra generated by the zero element is
1394 the one-dimensional algebra generated by the identity
1395 element... unless the original algebra was trivial, in which
1396 case the subalgebra is trivial too::
1397
1398 sage: A = random_eja().zero().subalgebra_generated_by()
1399 sage: (A.is_trivial() and A.dimension() == 0) or A.dimension() == 1
1400 True
1401
1402 """
1403 powers = tuple( self**k for k in range(self.degree()) )
1404 A = self.parent().subalgebra(powers,
1405 associative=True,
1406 check_field=False,
1407 check_axioms=False,
1408 **kwargs)
1409 A.one.set_cache(A(self.parent().one()))
1410 return A
1411
1412
1413 def subalgebra_idempotent(self):
1414 """
1415 Find an idempotent in the associative subalgebra I generate
1416 using Proposition 2.3.5 in Baes.
1417
1418 SETUP::
1419
1420 sage: from mjo.eja.eja_algebra import random_eja
1421
1422 TESTS:
1423
1424 Ensure that we can find an idempotent in a non-trivial algebra
1425 where there are non-nilpotent elements, or that we get the dumb
1426 solution in the trivial algebra::
1427
1428 sage: J = random_eja(field=QQ, orthonormalize=False)
1429 sage: x = J.random_element()
1430 sage: while x.is_nilpotent() and not J.is_trivial():
1431 ....: x = J.random_element()
1432 sage: c = x.subalgebra_idempotent()
1433 sage: c^2 == c
1434 True
1435
1436 """
1437 if self.parent().is_trivial():
1438 return self
1439
1440 if self.is_nilpotent():
1441 raise ValueError("this only works with non-nilpotent elements!")
1442
1443 J = self.subalgebra_generated_by()
1444 u = J(self)
1445
1446 # The image of the matrix of left-u^m-multiplication
1447 # will be minimal for some natural number s...
1448 s = 0
1449 minimal_dim = J.dimension()
1450 for i in range(1, minimal_dim):
1451 this_dim = (u**i).operator().matrix().image().dimension()
1452 if this_dim < minimal_dim:
1453 minimal_dim = this_dim
1454 s = i
1455
1456 # Now minimal_matrix should correspond to the smallest
1457 # non-zero subspace in Baes's (or really, Koecher's)
1458 # proposition.
1459 #
1460 # However, we need to restrict the matrix to work on the
1461 # subspace... or do we? Can't we just solve, knowing that
1462 # A(c) = u^(s+1) should have a solution in the big space,
1463 # too?
1464 #
1465 # Beware, solve_right() means that we're using COLUMN vectors.
1466 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1467 u_next = u**(s+1)
1468 A = u_next.operator().matrix()
1469 c = J.from_vector(A.solve_right(u_next.to_vector()))
1470
1471 # Now c is the idempotent we want, but it still lives in the subalgebra.
1472 return c.superalgebra_element()
1473
1474
1475 def trace(self):
1476 """
1477 Return my trace, the sum of my eigenvalues.
1478
1479 In a trivial algebra, however you want to look at it, the trace is
1480 an empty sum for which we declare the result to be zero.
1481
1482 SETUP::
1483
1484 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1485 ....: HadamardEJA,
1486 ....: TrivialEJA,
1487 ....: random_eja)
1488
1489 EXAMPLES::
1490
1491 sage: J = TrivialEJA()
1492 sage: J.zero().trace()
1493 0
1494
1495 ::
1496 sage: J = JordanSpinEJA(3)
1497 sage: x = sum(J.gens())
1498 sage: x.trace()
1499 2
1500
1501 ::
1502
1503 sage: J = HadamardEJA(5)
1504 sage: J.one().trace()
1505 5
1506
1507 TESTS:
1508
1509 The trace of an element is a real number::
1510
1511 sage: J = random_eja()
1512 sage: J.random_element().trace() in RLF
1513 True
1514
1515 The trace is linear::
1516
1517 sage: J = random_eja()
1518 sage: x,y = J.random_elements(2)
1519 sage: alpha = J.base_ring().random_element()
1520 sage: (alpha*x + y).trace() == alpha*x.trace() + y.trace()
1521 True
1522
1523 The trace of a square is nonnegative::
1524
1525 sage: x = random_eja().random_element()
1526 sage: (x*x).trace() >= 0
1527 True
1528
1529 """
1530 P = self.parent()
1531 r = P.rank()
1532
1533 if r == 0:
1534 # Special case for the trivial algebra where
1535 # the trace is an empty sum.
1536 return P.base_ring().zero()
1537
1538 p = P._charpoly_coefficients()[r-1]
1539 # The _charpoly_coeff function already adds the factor of
1540 # -1 to ensure that _charpoly_coeff(r-1) is really what
1541 # appears in front of t^{r-1} in the charpoly. However,
1542 # we want the negative of THAT for the trace.
1543 return -p(*self.to_vector())
1544
1545 def operator_inner_product(self, other):
1546 r"""
1547 Return the operator inner product of myself and ``other``.
1548
1549 The "operator inner product," whose name is not standard, is
1550 defined be the usual linear-algebraic trace of the
1551 ``(x*y).operator()``.
1552
1553 Proposition III.1.5 in Faraut and Korányi shows that on any
1554 Euclidean Jordan algebra, this is another associative inner
1555 product under which the cone of squares is symmetric.
1556
1557 This *probably* works even if the basis hasn't been
1558 orthonormalized because the eigenvalues of the corresponding
1559 matrix don't change when the basis does (they're preserved by
1560 any similarity transformation).
1561
1562 SETUP::
1563
1564 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1565 ....: RealSymmetricEJA,
1566 ....: ComplexHermitianEJA,
1567 ....: random_eja)
1568
1569 EXAMPLES:
1570
1571 Proposition III.4.2 of Faraut and Korányi shows that on a
1572 simple algebra of rank `r` and dimension `n`, this inner
1573 product is `n/r` times the canonical
1574 :meth:`trace_inner_product`::
1575
1576 sage: J = JordanSpinEJA(4, field=QQ)
1577 sage: x,y = J.random_elements(2)
1578 sage: n = J.dimension()
1579 sage: r = J.rank()
1580 sage: actual = x.operator_inner_product(y)
1581 sage: expected = (n/r)*x.trace_inner_product(y)
1582 sage: actual == expected
1583 True
1584
1585 ::
1586
1587 sage: J = RealSymmetricEJA(3)
1588 sage: x,y = J.random_elements(2)
1589 sage: n = J.dimension()
1590 sage: r = J.rank()
1591 sage: actual = x.operator_inner_product(y)
1592 sage: expected = (n/r)*x.trace_inner_product(y)
1593 sage: actual == expected
1594 True
1595
1596 ::
1597
1598 sage: J = ComplexHermitianEJA(3, field=QQ, orthonormalize=False)
1599 sage: x,y = J.random_elements(2)
1600 sage: n = J.dimension()
1601 sage: r = J.rank()
1602 sage: actual = x.operator_inner_product(y)
1603 sage: expected = (n/r)*x.trace_inner_product(y)
1604 sage: actual == expected
1605 True
1606
1607 TESTS:
1608
1609 The operator inner product is commutative, bilinear, and
1610 associative::
1611
1612 sage: J = random_eja()
1613 sage: x,y,z = J.random_elements(3)
1614 sage: # commutative
1615 sage: x.operator_inner_product(y) == y.operator_inner_product(x)
1616 True
1617 sage: # bilinear
1618 sage: a = J.base_ring().random_element()
1619 sage: actual = (a*(x+z)).operator_inner_product(y)
1620 sage: expected = ( a*x.operator_inner_product(y) +
1621 ....: a*z.operator_inner_product(y) )
1622 sage: actual == expected
1623 True
1624 sage: actual = x.operator_inner_product(a*(y+z))
1625 sage: expected = ( a*x.operator_inner_product(y) +
1626 ....: a*x.operator_inner_product(z) )
1627 sage: actual == expected
1628 True
1629 sage: # associative
1630 sage: actual = (x*y).operator_inner_product(z)
1631 sage: expected = y.operator_inner_product(x*z)
1632 sage: actual == expected
1633 True
1634
1635 """
1636 if not other in self.parent():
1637 raise TypeError("'other' must live in the same algebra")
1638
1639 return (self*other).operator().matrix().trace()
1640
1641
1642 def trace_inner_product(self, other):
1643 """
1644 Return the trace inner product of myself and ``other``.
1645
1646 SETUP::
1647
1648 sage: from mjo.eja.eja_algebra import random_eja
1649
1650 TESTS:
1651
1652 The trace inner product is commutative, bilinear, and associative::
1653
1654 sage: J = random_eja()
1655 sage: x,y,z = J.random_elements(3)
1656 sage: # commutative
1657 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1658 True
1659 sage: # bilinear
1660 sage: a = J.base_ring().random_element()
1661 sage: actual = (a*(x+z)).trace_inner_product(y)
1662 sage: expected = ( a*x.trace_inner_product(y) +
1663 ....: a*z.trace_inner_product(y) )
1664 sage: actual == expected
1665 True
1666 sage: actual = x.trace_inner_product(a*(y+z))
1667 sage: expected = ( a*x.trace_inner_product(y) +
1668 ....: a*x.trace_inner_product(z) )
1669 sage: actual == expected
1670 True
1671 sage: # associative
1672 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1673 True
1674
1675 """
1676 if not other in self.parent():
1677 raise TypeError("'other' must live in the same algebra")
1678
1679 return (self*other).trace()
1680
1681
1682 def trace_norm(self):
1683 """
1684 The norm of this element with respect to :meth:`trace_inner_product`.
1685
1686 SETUP::
1687
1688 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1689 ....: HadamardEJA)
1690
1691 EXAMPLES::
1692
1693 sage: J = HadamardEJA(2)
1694 sage: x = sum(J.gens())
1695 sage: x.trace_norm()
1696 1.414213562373095?
1697
1698 ::
1699
1700 sage: J = JordanSpinEJA(4)
1701 sage: x = sum(J.gens())
1702 sage: x.trace_norm()
1703 2.828427124746190?
1704
1705 """
1706 return self.trace_inner_product(self).sqrt()
1707
1708
1709 class CartesianProductEJAElement(FiniteDimensionalEJAElement):
1710 def det(self):
1711 r"""
1712 Compute the determinant of this product-element using the
1713 determianants of its factors.
1714
1715 This result Follows from the spectral decomposition of (say)
1716 the pair `(x,y)` in terms of the Jordan frame `\left\{ (c_1,
1717 0),(c_2, 0),...,(0,d_1),(0,d_2),... \right\}.
1718 """
1719 from sage.misc.misc_c import prod
1720 return prod( f.det() for f in self.cartesian_factors() )
1721
1722 def to_matrix(self):
1723 # An override is necessary to call our custom _scale().
1724 B = self.parent().matrix_basis()
1725 W = self.parent().matrix_space()
1726
1727 # Aaaaand linear combinations don't work in Cartesian
1728 # product spaces, even though they provide a method with
1729 # that name. This is hidden behind an "if" because the
1730 # _scale() function is slow.
1731 pairs = zip(B, self.to_vector())
1732 return W.sum( _scale(b, alpha) for (b,alpha) in pairs )