]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/euclidean_jordan_algebra.py
eja: turn the other simple EJA constructors into classes.
[sage.d.git] / mjo / eja / euclidean_jordan_algebra.py
1 """
2 Euclidean Jordan Algebras. These are formally-real Jordan Algebras;
3 specifically those where u^2 + v^2 = 0 implies that u = v = 0. They
4 are used in optimization, and have some additional nice methods beyond
5 what can be supported in a general Jordan Algebra.
6 """
7
8 from sage.categories.magmatic_algebras import MagmaticAlgebras
9 from sage.structure.element import is_Matrix
10 from sage.structure.category_object import normalize_names
11
12 from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra import FiniteDimensionalAlgebra
13 from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement
14
15 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra):
16 @staticmethod
17 def __classcall_private__(cls,
18 field,
19 mult_table,
20 names='e',
21 assume_associative=False,
22 category=None,
23 rank=None,
24 natural_basis=None,
25 inner_product=None):
26 n = len(mult_table)
27 mult_table = [b.base_extend(field) for b in mult_table]
28 for b in mult_table:
29 b.set_immutable()
30 if not (is_Matrix(b) and b.dimensions() == (n, n)):
31 raise ValueError("input is not a multiplication table")
32 mult_table = tuple(mult_table)
33
34 cat = MagmaticAlgebras(field).FiniteDimensional().WithBasis()
35 cat.or_subcategory(category)
36 if assume_associative:
37 cat = cat.Associative()
38
39 names = normalize_names(n, names)
40
41 fda = super(FiniteDimensionalEuclideanJordanAlgebra, cls)
42 return fda.__classcall__(cls,
43 field,
44 mult_table,
45 assume_associative=assume_associative,
46 names=names,
47 category=cat,
48 rank=rank,
49 natural_basis=natural_basis,
50 inner_product=inner_product)
51
52
53 def __init__(self,
54 field,
55 mult_table,
56 names='e',
57 assume_associative=False,
58 category=None,
59 rank=None,
60 natural_basis=None,
61 inner_product=None):
62 """
63 EXAMPLES:
64
65 By definition, Jordan multiplication commutes::
66
67 sage: set_random_seed()
68 sage: J = random_eja()
69 sage: x = J.random_element()
70 sage: y = J.random_element()
71 sage: x*y == y*x
72 True
73
74 """
75 self._rank = rank
76 self._natural_basis = natural_basis
77 self._inner_product = inner_product
78 fda = super(FiniteDimensionalEuclideanJordanAlgebra, self)
79 fda.__init__(field,
80 mult_table,
81 names=names,
82 category=category)
83
84
85 def _repr_(self):
86 """
87 Return a string representation of ``self``.
88 """
89 fmt = "Euclidean Jordan algebra of degree {} over {}"
90 return fmt.format(self.degree(), self.base_ring())
91
92
93 def inner_product(self, x, y):
94 """
95 The inner product associated with this Euclidean Jordan algebra.
96
97 Will default to the trace inner product if nothing else.
98
99 EXAMPLES:
100
101 The inner product must satisfy its axiom for this algebra to truly
102 be a Euclidean Jordan Algebra::
103
104 sage: set_random_seed()
105 sage: J = random_eja()
106 sage: x = J.random_element()
107 sage: y = J.random_element()
108 sage: z = J.random_element()
109 sage: (x*y).inner_product(z) == y.inner_product(x*z)
110 True
111
112 """
113 if (not x in self) or (not y in self):
114 raise TypeError("arguments must live in this algebra")
115 if self._inner_product is None:
116 return x.trace_inner_product(y)
117 else:
118 return self._inner_product(x,y)
119
120
121 def natural_basis(self):
122 """
123 Return a more-natural representation of this algebra's basis.
124
125 Every finite-dimensional Euclidean Jordan Algebra is a direct
126 sum of five simple algebras, four of which comprise Hermitian
127 matrices. This method returns the original "natural" basis
128 for our underlying vector space. (Typically, the natural basis
129 is used to construct the multiplication table in the first place.)
130
131 Note that this will always return a matrix. The standard basis
132 in `R^n` will be returned as `n`-by-`1` column matrices.
133
134 EXAMPLES::
135
136 sage: J = RealSymmetricEJA(2)
137 sage: J.basis()
138 Family (e0, e1, e2)
139 sage: J.natural_basis()
140 (
141 [1 0] [0 1] [0 0]
142 [0 0], [1 0], [0 1]
143 )
144
145 ::
146
147 sage: J = JordanSpinEJA(2)
148 sage: J.basis()
149 Family (e0, e1)
150 sage: J.natural_basis()
151 (
152 [1] [0]
153 [0], [1]
154 )
155
156 """
157 if self._natural_basis is None:
158 return tuple( b.vector().column() for b in self.basis() )
159 else:
160 return self._natural_basis
161
162
163 def rank(self):
164 """
165 Return the rank of this EJA.
166 """
167 if self._rank is None:
168 raise ValueError("no rank specified at genesis")
169 else:
170 return self._rank
171
172
173 class Element(FiniteDimensionalAlgebraElement):
174 """
175 An element of a Euclidean Jordan algebra.
176 """
177
178 def __init__(self, A, elt=None):
179 """
180 EXAMPLES:
181
182 The identity in `S^n` is converted to the identity in the EJA::
183
184 sage: J = RealSymmetricEJA(3)
185 sage: I = identity_matrix(QQ,3)
186 sage: J(I) == J.one()
187 True
188
189 This skew-symmetric matrix can't be represented in the EJA::
190
191 sage: J = RealSymmetricEJA(3)
192 sage: A = matrix(QQ,3, lambda i,j: i-j)
193 sage: J(A)
194 Traceback (most recent call last):
195 ...
196 ArithmeticError: vector is not in free module
197
198 """
199 # Goal: if we're given a matrix, and if it lives in our
200 # parent algebra's "natural ambient space," convert it
201 # into an algebra element.
202 #
203 # The catch is, we make a recursive call after converting
204 # the given matrix into a vector that lives in the algebra.
205 # This we need to try the parent class initializer first,
206 # to avoid recursing forever if we're given something that
207 # already fits into the algebra, but also happens to live
208 # in the parent's "natural ambient space" (this happens with
209 # vectors in R^n).
210 try:
211 FiniteDimensionalAlgebraElement.__init__(self, A, elt)
212 except ValueError:
213 natural_basis = A.natural_basis()
214 if elt in natural_basis[0].matrix_space():
215 # Thanks for nothing! Matrix spaces aren't vector
216 # spaces in Sage, so we have to figure out its
217 # natural-basis coordinates ourselves.
218 V = VectorSpace(elt.base_ring(), elt.nrows()**2)
219 W = V.span( _mat2vec(s) for s in natural_basis )
220 coords = W.coordinates(_mat2vec(elt))
221 FiniteDimensionalAlgebraElement.__init__(self, A, coords)
222
223 def __pow__(self, n):
224 """
225 Return ``self`` raised to the power ``n``.
226
227 Jordan algebras are always power-associative; see for
228 example Faraut and Koranyi, Proposition II.1.2 (ii).
229
230 .. WARNING:
231
232 We have to override this because our superclass uses row vectors
233 instead of column vectors! We, on the other hand, assume column
234 vectors everywhere.
235
236 EXAMPLES::
237
238 sage: set_random_seed()
239 sage: x = random_eja().random_element()
240 sage: x.operator_matrix()*x.vector() == (x^2).vector()
241 True
242
243 A few examples of power-associativity::
244
245 sage: set_random_seed()
246 sage: x = random_eja().random_element()
247 sage: x*(x*x)*(x*x) == x^5
248 True
249 sage: (x*x)*(x*x*x) == x^5
250 True
251
252 We also know that powers operator-commute (Koecher, Chapter
253 III, Corollary 1)::
254
255 sage: set_random_seed()
256 sage: x = random_eja().random_element()
257 sage: m = ZZ.random_element(0,10)
258 sage: n = ZZ.random_element(0,10)
259 sage: Lxm = (x^m).operator_matrix()
260 sage: Lxn = (x^n).operator_matrix()
261 sage: Lxm*Lxn == Lxn*Lxm
262 True
263
264 """
265 A = self.parent()
266 if n == 0:
267 return A.one()
268 elif n == 1:
269 return self
270 else:
271 return A( (self.operator_matrix()**(n-1))*self.vector() )
272
273
274 def characteristic_polynomial(self):
275 """
276 Return my characteristic polynomial (if I'm a regular
277 element).
278
279 Eventually this should be implemented in terms of the parent
280 algebra's characteristic polynomial that works for ALL
281 elements.
282 """
283 if self.is_regular():
284 return self.minimal_polynomial()
285 else:
286 raise NotImplementedError('irregular element')
287
288
289 def inner_product(self, other):
290 """
291 Return the parent algebra's inner product of myself and ``other``.
292
293 EXAMPLES:
294
295 The inner product in the Jordan spin algebra is the usual
296 inner product on `R^n` (this example only works because the
297 basis for the Jordan algebra is the standard basis in `R^n`)::
298
299 sage: J = JordanSpinEJA(3)
300 sage: x = vector(QQ,[1,2,3])
301 sage: y = vector(QQ,[4,5,6])
302 sage: x.inner_product(y)
303 32
304 sage: J(x).inner_product(J(y))
305 32
306
307 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
308 multiplication is the usual matrix multiplication in `S^n`,
309 so the inner product of the identity matrix with itself
310 should be the `n`::
311
312 sage: J = RealSymmetricEJA(3)
313 sage: J.one().inner_product(J.one())
314 3
315
316 Likewise, the inner product on `C^n` is `<X,Y> =
317 Re(trace(X*Y))`, where we must necessarily take the real
318 part because the product of Hermitian matrices may not be
319 Hermitian::
320
321 sage: J = ComplexHermitianEJA(3)
322 sage: J.one().inner_product(J.one())
323 3
324
325 Ditto for the quaternions::
326
327 sage: J = QuaternionHermitianEJA(3)
328 sage: J.one().inner_product(J.one())
329 3
330
331 TESTS:
332
333 Ensure that we can always compute an inner product, and that
334 it gives us back a real number::
335
336 sage: set_random_seed()
337 sage: J = random_eja()
338 sage: x = J.random_element()
339 sage: y = J.random_element()
340 sage: x.inner_product(y) in RR
341 True
342
343 """
344 P = self.parent()
345 if not other in P:
346 raise TypeError("'other' must live in the same algebra")
347
348 return P.inner_product(self, other)
349
350
351 def operator_commutes_with(self, other):
352 """
353 Return whether or not this element operator-commutes
354 with ``other``.
355
356 EXAMPLES:
357
358 The definition of a Jordan algebra says that any element
359 operator-commutes with its square::
360
361 sage: set_random_seed()
362 sage: x = random_eja().random_element()
363 sage: x.operator_commutes_with(x^2)
364 True
365
366 TESTS:
367
368 Test Lemma 1 from Chapter III of Koecher::
369
370 sage: set_random_seed()
371 sage: J = random_eja()
372 sage: u = J.random_element()
373 sage: v = J.random_element()
374 sage: lhs = u.operator_commutes_with(u*v)
375 sage: rhs = v.operator_commutes_with(u^2)
376 sage: lhs == rhs
377 True
378
379 """
380 if not other in self.parent():
381 raise TypeError("'other' must live in the same algebra")
382
383 A = self.operator_matrix()
384 B = other.operator_matrix()
385 return (A*B == B*A)
386
387
388 def det(self):
389 """
390 Return my determinant, the product of my eigenvalues.
391
392 EXAMPLES::
393
394 sage: J = JordanSpinEJA(2)
395 sage: e0,e1 = J.gens()
396 sage: x = e0 + e1
397 sage: x.det()
398 0
399 sage: J = JordanSpinEJA(3)
400 sage: e0,e1,e2 = J.gens()
401 sage: x = e0 + e1 + e2
402 sage: x.det()
403 -1
404
405 """
406 cs = self.characteristic_polynomial().coefficients(sparse=False)
407 r = len(cs) - 1
408 if r >= 0:
409 return cs[0] * (-1)**r
410 else:
411 raise ValueError('charpoly had no coefficients')
412
413
414 def inverse(self):
415 """
416 Return the Jordan-multiplicative inverse of this element.
417
418 We can't use the superclass method because it relies on the
419 algebra being associative.
420
421 EXAMPLES:
422
423 The inverse in the spin factor algebra is given in Alizadeh's
424 Example 11.11::
425
426 sage: set_random_seed()
427 sage: n = ZZ.random_element(1,10)
428 sage: J = JordanSpinEJA(n)
429 sage: x = J.random_element()
430 sage: while x.is_zero():
431 ....: x = J.random_element()
432 sage: x_vec = x.vector()
433 sage: x0 = x_vec[0]
434 sage: x_bar = x_vec[1:]
435 sage: coeff = 1/(x0^2 - x_bar.inner_product(x_bar))
436 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
437 sage: x_inverse = coeff*inv_vec
438 sage: x.inverse() == J(x_inverse)
439 True
440
441 TESTS:
442
443 The identity element is its own inverse::
444
445 sage: set_random_seed()
446 sage: J = random_eja()
447 sage: J.one().inverse() == J.one()
448 True
449
450 If an element has an inverse, it acts like one. TODO: this
451 can be a lot less ugly once ``is_invertible`` doesn't crash
452 on irregular elements::
453
454 sage: set_random_seed()
455 sage: J = random_eja()
456 sage: x = J.random_element()
457 sage: try:
458 ....: x.inverse()*x == J.one()
459 ....: except:
460 ....: True
461 True
462
463 """
464 if self.parent().is_associative():
465 elt = FiniteDimensionalAlgebraElement(self.parent(), self)
466 return elt.inverse()
467
468 # TODO: we can do better once the call to is_invertible()
469 # doesn't crash on irregular elements.
470 #if not self.is_invertible():
471 # raise ValueError('element is not invertible')
472
473 # We do this a little different than the usual recursive
474 # call to a finite-dimensional algebra element, because we
475 # wind up with an inverse that lives in the subalgebra and
476 # we need information about the parent to convert it back.
477 V = self.span_of_powers()
478 assoc_subalg = self.subalgebra_generated_by()
479 # Mis-design warning: the basis used for span_of_powers()
480 # and subalgebra_generated_by() must be the same, and in
481 # the same order!
482 elt = assoc_subalg(V.coordinates(self.vector()))
483
484 # This will be in the subalgebra's coordinates...
485 fda_elt = FiniteDimensionalAlgebraElement(assoc_subalg, elt)
486 subalg_inverse = fda_elt.inverse()
487
488 # So we have to convert back...
489 basis = [ self.parent(v) for v in V.basis() ]
490 pairs = zip(subalg_inverse.vector(), basis)
491 return self.parent().linear_combination(pairs)
492
493
494 def is_invertible(self):
495 """
496 Return whether or not this element is invertible.
497
498 We can't use the superclass method because it relies on
499 the algebra being associative.
500 """
501 return not self.det().is_zero()
502
503
504 def is_nilpotent(self):
505 """
506 Return whether or not some power of this element is zero.
507
508 The superclass method won't work unless we're in an
509 associative algebra, and we aren't. However, we generate
510 an assocoative subalgebra and we're nilpotent there if and
511 only if we're nilpotent here (probably).
512
513 TESTS:
514
515 The identity element is never nilpotent::
516
517 sage: set_random_seed()
518 sage: random_eja().one().is_nilpotent()
519 False
520
521 The additive identity is always nilpotent::
522
523 sage: set_random_seed()
524 sage: random_eja().zero().is_nilpotent()
525 True
526
527 """
528 # The element we're going to call "is_nilpotent()" on.
529 # Either myself, interpreted as an element of a finite-
530 # dimensional algebra, or an element of an associative
531 # subalgebra.
532 elt = None
533
534 if self.parent().is_associative():
535 elt = FiniteDimensionalAlgebraElement(self.parent(), self)
536 else:
537 V = self.span_of_powers()
538 assoc_subalg = self.subalgebra_generated_by()
539 # Mis-design warning: the basis used for span_of_powers()
540 # and subalgebra_generated_by() must be the same, and in
541 # the same order!
542 elt = assoc_subalg(V.coordinates(self.vector()))
543
544 # Recursive call, but should work since elt lives in an
545 # associative algebra.
546 return elt.is_nilpotent()
547
548
549 def is_regular(self):
550 """
551 Return whether or not this is a regular element.
552
553 EXAMPLES:
554
555 The identity element always has degree one, but any element
556 linearly-independent from it is regular::
557
558 sage: J = JordanSpinEJA(5)
559 sage: J.one().is_regular()
560 False
561 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
562 sage: for x in J.gens():
563 ....: (J.one() + x).is_regular()
564 False
565 True
566 True
567 True
568 True
569
570 """
571 return self.degree() == self.parent().rank()
572
573
574 def degree(self):
575 """
576 Compute the degree of this element the straightforward way
577 according to the definition; by appending powers to a list
578 and figuring out its dimension (that is, whether or not
579 they're linearly dependent).
580
581 EXAMPLES::
582
583 sage: J = JordanSpinEJA(4)
584 sage: J.one().degree()
585 1
586 sage: e0,e1,e2,e3 = J.gens()
587 sage: (e0 - e1).degree()
588 2
589
590 In the spin factor algebra (of rank two), all elements that
591 aren't multiples of the identity are regular::
592
593 sage: set_random_seed()
594 sage: n = ZZ.random_element(1,10)
595 sage: J = JordanSpinEJA(n)
596 sage: x = J.random_element()
597 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
598 True
599
600 """
601 return self.span_of_powers().dimension()
602
603
604 def minimal_polynomial(self):
605 """
606 EXAMPLES::
607
608 sage: set_random_seed()
609 sage: x = random_eja().random_element()
610 sage: x.degree() == x.minimal_polynomial().degree()
611 True
612
613 ::
614
615 sage: set_random_seed()
616 sage: x = random_eja().random_element()
617 sage: x.degree() == x.minimal_polynomial().degree()
618 True
619
620 The minimal polynomial and the characteristic polynomial coincide
621 and are known (see Alizadeh, Example 11.11) for all elements of
622 the spin factor algebra that aren't scalar multiples of the
623 identity::
624
625 sage: set_random_seed()
626 sage: n = ZZ.random_element(2,10)
627 sage: J = JordanSpinEJA(n)
628 sage: y = J.random_element()
629 sage: while y == y.coefficient(0)*J.one():
630 ....: y = J.random_element()
631 sage: y0 = y.vector()[0]
632 sage: y_bar = y.vector()[1:]
633 sage: actual = y.minimal_polynomial()
634 sage: x = SR.symbol('x', domain='real')
635 sage: expected = x^2 - 2*y0*x + (y0^2 - norm(y_bar)^2)
636 sage: bool(actual == expected)
637 True
638
639 """
640 # The element we're going to call "minimal_polynomial()" on.
641 # Either myself, interpreted as an element of a finite-
642 # dimensional algebra, or an element of an associative
643 # subalgebra.
644 elt = None
645
646 if self.parent().is_associative():
647 elt = FiniteDimensionalAlgebraElement(self.parent(), self)
648 else:
649 V = self.span_of_powers()
650 assoc_subalg = self.subalgebra_generated_by()
651 # Mis-design warning: the basis used for span_of_powers()
652 # and subalgebra_generated_by() must be the same, and in
653 # the same order!
654 elt = assoc_subalg(V.coordinates(self.vector()))
655
656 # Recursive call, but should work since elt lives in an
657 # associative algebra.
658 return elt.minimal_polynomial()
659
660
661 def natural_representation(self):
662 """
663 Return a more-natural representation of this element.
664
665 Every finite-dimensional Euclidean Jordan Algebra is a
666 direct sum of five simple algebras, four of which comprise
667 Hermitian matrices. This method returns the original
668 "natural" representation of this element as a Hermitian
669 matrix, if it has one. If not, you get the usual representation.
670
671 EXAMPLES::
672
673 sage: J = ComplexHermitianEJA(3)
674 sage: J.one()
675 e0 + e5 + e8
676 sage: J.one().natural_representation()
677 [1 0 0 0 0 0]
678 [0 1 0 0 0 0]
679 [0 0 1 0 0 0]
680 [0 0 0 1 0 0]
681 [0 0 0 0 1 0]
682 [0 0 0 0 0 1]
683
684 ::
685
686 sage: J = QuaternionHermitianEJA(3)
687 sage: J.one()
688 e0 + e9 + e14
689 sage: J.one().natural_representation()
690 [1 0 0 0 0 0 0 0 0 0 0 0]
691 [0 1 0 0 0 0 0 0 0 0 0 0]
692 [0 0 1 0 0 0 0 0 0 0 0 0]
693 [0 0 0 1 0 0 0 0 0 0 0 0]
694 [0 0 0 0 1 0 0 0 0 0 0 0]
695 [0 0 0 0 0 1 0 0 0 0 0 0]
696 [0 0 0 0 0 0 1 0 0 0 0 0]
697 [0 0 0 0 0 0 0 1 0 0 0 0]
698 [0 0 0 0 0 0 0 0 1 0 0 0]
699 [0 0 0 0 0 0 0 0 0 1 0 0]
700 [0 0 0 0 0 0 0 0 0 0 1 0]
701 [0 0 0 0 0 0 0 0 0 0 0 1]
702
703 """
704 B = self.parent().natural_basis()
705 W = B[0].matrix_space()
706 return W.linear_combination(zip(self.vector(), B))
707
708
709 def operator_matrix(self):
710 """
711 Return the matrix that represents left- (or right-)
712 multiplication by this element in the parent algebra.
713
714 We have to override this because the superclass method
715 returns a matrix that acts on row vectors (that is, on
716 the right).
717
718 EXAMPLES:
719
720 Test the first polarization identity from my notes, Koecher Chapter
721 III, or from Baes (2.3)::
722
723 sage: set_random_seed()
724 sage: J = random_eja()
725 sage: x = J.random_element()
726 sage: y = J.random_element()
727 sage: Lx = x.operator_matrix()
728 sage: Ly = y.operator_matrix()
729 sage: Lxx = (x*x).operator_matrix()
730 sage: Lxy = (x*y).operator_matrix()
731 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
732 True
733
734 Test the second polarization identity from my notes or from
735 Baes (2.4)::
736
737 sage: set_random_seed()
738 sage: J = random_eja()
739 sage: x = J.random_element()
740 sage: y = J.random_element()
741 sage: z = J.random_element()
742 sage: Lx = x.operator_matrix()
743 sage: Ly = y.operator_matrix()
744 sage: Lz = z.operator_matrix()
745 sage: Lzy = (z*y).operator_matrix()
746 sage: Lxy = (x*y).operator_matrix()
747 sage: Lxz = (x*z).operator_matrix()
748 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
749 True
750
751 Test the third polarization identity from my notes or from
752 Baes (2.5)::
753
754 sage: set_random_seed()
755 sage: J = random_eja()
756 sage: u = J.random_element()
757 sage: y = J.random_element()
758 sage: z = J.random_element()
759 sage: Lu = u.operator_matrix()
760 sage: Ly = y.operator_matrix()
761 sage: Lz = z.operator_matrix()
762 sage: Lzy = (z*y).operator_matrix()
763 sage: Luy = (u*y).operator_matrix()
764 sage: Luz = (u*z).operator_matrix()
765 sage: Luyz = (u*(y*z)).operator_matrix()
766 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
767 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
768 sage: bool(lhs == rhs)
769 True
770
771 """
772 fda_elt = FiniteDimensionalAlgebraElement(self.parent(), self)
773 return fda_elt.matrix().transpose()
774
775
776 def quadratic_representation(self, other=None):
777 """
778 Return the quadratic representation of this element.
779
780 EXAMPLES:
781
782 The explicit form in the spin factor algebra is given by
783 Alizadeh's Example 11.12::
784
785 sage: set_random_seed()
786 sage: n = ZZ.random_element(1,10)
787 sage: J = JordanSpinEJA(n)
788 sage: x = J.random_element()
789 sage: x_vec = x.vector()
790 sage: x0 = x_vec[0]
791 sage: x_bar = x_vec[1:]
792 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
793 sage: B = 2*x0*x_bar.row()
794 sage: C = 2*x0*x_bar.column()
795 sage: D = identity_matrix(QQ, n-1)
796 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
797 sage: D = D + 2*x_bar.tensor_product(x_bar)
798 sage: Q = block_matrix(2,2,[A,B,C,D])
799 sage: Q == x.quadratic_representation()
800 True
801
802 Test all of the properties from Theorem 11.2 in Alizadeh::
803
804 sage: set_random_seed()
805 sage: J = random_eja()
806 sage: x = J.random_element()
807 sage: y = J.random_element()
808
809 Property 1:
810
811 sage: actual = x.quadratic_representation(y)
812 sage: expected = ( (x+y).quadratic_representation()
813 ....: -x.quadratic_representation()
814 ....: -y.quadratic_representation() ) / 2
815 sage: actual == expected
816 True
817
818 Property 2:
819
820 sage: alpha = QQ.random_element()
821 sage: actual = (alpha*x).quadratic_representation()
822 sage: expected = (alpha^2)*x.quadratic_representation()
823 sage: actual == expected
824 True
825
826 Property 5:
827
828 sage: Qy = y.quadratic_representation()
829 sage: actual = J(Qy*x.vector()).quadratic_representation()
830 sage: expected = Qy*x.quadratic_representation()*Qy
831 sage: actual == expected
832 True
833
834 Property 6:
835
836 sage: k = ZZ.random_element(1,10)
837 sage: actual = (x^k).quadratic_representation()
838 sage: expected = (x.quadratic_representation())^k
839 sage: actual == expected
840 True
841
842 """
843 if other is None:
844 other=self
845 elif not other in self.parent():
846 raise TypeError("'other' must live in the same algebra")
847
848 L = self.operator_matrix()
849 M = other.operator_matrix()
850 return ( L*M + M*L - (self*other).operator_matrix() )
851
852
853 def span_of_powers(self):
854 """
855 Return the vector space spanned by successive powers of
856 this element.
857 """
858 # The dimension of the subalgebra can't be greater than
859 # the big algebra, so just put everything into a list
860 # and let span() get rid of the excess.
861 V = self.vector().parent()
862 return V.span( (self**d).vector() for d in xrange(V.dimension()) )
863
864
865 def subalgebra_generated_by(self):
866 """
867 Return the associative subalgebra of the parent EJA generated
868 by this element.
869
870 TESTS::
871
872 sage: set_random_seed()
873 sage: x = random_eja().random_element()
874 sage: x.subalgebra_generated_by().is_associative()
875 True
876
877 Squaring in the subalgebra should be the same thing as
878 squaring in the superalgebra::
879
880 sage: set_random_seed()
881 sage: x = random_eja().random_element()
882 sage: u = x.subalgebra_generated_by().random_element()
883 sage: u.operator_matrix()*u.vector() == (u**2).vector()
884 True
885
886 """
887 # First get the subspace spanned by the powers of myself...
888 V = self.span_of_powers()
889 F = self.base_ring()
890
891 # Now figure out the entries of the right-multiplication
892 # matrix for the successive basis elements b0, b1,... of
893 # that subspace.
894 mats = []
895 for b_right in V.basis():
896 eja_b_right = self.parent()(b_right)
897 b_right_rows = []
898 # The first row of the right-multiplication matrix by
899 # b1 is what we get if we apply that matrix to b1. The
900 # second row of the right multiplication matrix by b1
901 # is what we get when we apply that matrix to b2...
902 #
903 # IMPORTANT: this assumes that all vectors are COLUMN
904 # vectors, unlike our superclass (which uses row vectors).
905 for b_left in V.basis():
906 eja_b_left = self.parent()(b_left)
907 # Multiply in the original EJA, but then get the
908 # coordinates from the subalgebra in terms of its
909 # basis.
910 this_row = V.coordinates((eja_b_left*eja_b_right).vector())
911 b_right_rows.append(this_row)
912 b_right_matrix = matrix(F, b_right_rows)
913 mats.append(b_right_matrix)
914
915 # It's an algebra of polynomials in one element, and EJAs
916 # are power-associative.
917 #
918 # TODO: choose generator names intelligently.
919 return FiniteDimensionalEuclideanJordanAlgebra(F, mats, assume_associative=True, names='f')
920
921
922 def subalgebra_idempotent(self):
923 """
924 Find an idempotent in the associative subalgebra I generate
925 using Proposition 2.3.5 in Baes.
926
927 TESTS::
928
929 sage: set_random_seed()
930 sage: J = eja_rn(5)
931 sage: c = J.random_element().subalgebra_idempotent()
932 sage: c^2 == c
933 True
934 sage: J = JordanSpinEJA(5)
935 sage: c = J.random_element().subalgebra_idempotent()
936 sage: c^2 == c
937 True
938
939 """
940 if self.is_nilpotent():
941 raise ValueError("this only works with non-nilpotent elements!")
942
943 V = self.span_of_powers()
944 J = self.subalgebra_generated_by()
945 # Mis-design warning: the basis used for span_of_powers()
946 # and subalgebra_generated_by() must be the same, and in
947 # the same order!
948 u = J(V.coordinates(self.vector()))
949
950 # The image of the matrix of left-u^m-multiplication
951 # will be minimal for some natural number s...
952 s = 0
953 minimal_dim = V.dimension()
954 for i in xrange(1, V.dimension()):
955 this_dim = (u**i).operator_matrix().image().dimension()
956 if this_dim < minimal_dim:
957 minimal_dim = this_dim
958 s = i
959
960 # Now minimal_matrix should correspond to the smallest
961 # non-zero subspace in Baes's (or really, Koecher's)
962 # proposition.
963 #
964 # However, we need to restrict the matrix to work on the
965 # subspace... or do we? Can't we just solve, knowing that
966 # A(c) = u^(s+1) should have a solution in the big space,
967 # too?
968 #
969 # Beware, solve_right() means that we're using COLUMN vectors.
970 # Our FiniteDimensionalAlgebraElement superclass uses rows.
971 u_next = u**(s+1)
972 A = u_next.operator_matrix()
973 c_coordinates = A.solve_right(u_next.vector())
974
975 # Now c_coordinates is the idempotent we want, but it's in
976 # the coordinate system of the subalgebra.
977 #
978 # We need the basis for J, but as elements of the parent algebra.
979 #
980 basis = [self.parent(v) for v in V.basis()]
981 return self.parent().linear_combination(zip(c_coordinates, basis))
982
983
984 def trace(self):
985 """
986 Return my trace, the sum of my eigenvalues.
987
988 EXAMPLES::
989
990 sage: J = JordanSpinEJA(3)
991 sage: e0,e1,e2 = J.gens()
992 sage: x = e0 + e1 + e2
993 sage: x.trace()
994 2
995
996 """
997 cs = self.characteristic_polynomial().coefficients(sparse=False)
998 if len(cs) >= 2:
999 return -1*cs[-2]
1000 else:
1001 raise ValueError('charpoly had fewer than 2 coefficients')
1002
1003
1004 def trace_inner_product(self, other):
1005 """
1006 Return the trace inner product of myself and ``other``.
1007 """
1008 if not other in self.parent():
1009 raise TypeError("'other' must live in the same algebra")
1010
1011 return (self*other).trace()
1012
1013
1014 def eja_rn(dimension, field=QQ):
1015 """
1016 Return the Euclidean Jordan Algebra corresponding to the set
1017 `R^n` under the Hadamard product.
1018
1019 EXAMPLES:
1020
1021 This multiplication table can be verified by hand::
1022
1023 sage: J = eja_rn(3)
1024 sage: e0,e1,e2 = J.gens()
1025 sage: e0*e0
1026 e0
1027 sage: e0*e1
1028 0
1029 sage: e0*e2
1030 0
1031 sage: e1*e1
1032 e1
1033 sage: e1*e2
1034 0
1035 sage: e2*e2
1036 e2
1037
1038 """
1039 # The FiniteDimensionalAlgebra constructor takes a list of
1040 # matrices, the ith representing right multiplication by the ith
1041 # basis element in the vector space. So if e_1 = (1,0,0), then
1042 # right (Hadamard) multiplication of x by e_1 picks out the first
1043 # component of x; and likewise for the ith basis element e_i.
1044 Qs = [ matrix(field, dimension, dimension, lambda k,j: 1*(k == j == i))
1045 for i in xrange(dimension) ]
1046
1047 return FiniteDimensionalEuclideanJordanAlgebra(field,
1048 Qs,
1049 rank=dimension,
1050 inner_product=_usual_ip)
1051
1052
1053
1054 def random_eja():
1055 """
1056 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1057
1058 ALGORITHM:
1059
1060 For now, we choose a random natural number ``n`` (greater than zero)
1061 and then give you back one of the following:
1062
1063 * The cartesian product of the rational numbers ``n`` times; this is
1064 ``QQ^n`` with the Hadamard product.
1065
1066 * The Jordan spin algebra on ``QQ^n``.
1067
1068 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1069 product.
1070
1071 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1072 in the space of ``2n``-by-``2n`` real symmetric matrices.
1073
1074 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1075 in the space of ``4n``-by-``4n`` real symmetric matrices.
1076
1077 Later this might be extended to return Cartesian products of the
1078 EJAs above.
1079
1080 TESTS::
1081
1082 sage: random_eja()
1083 Euclidean Jordan algebra of degree...
1084
1085 """
1086 n = ZZ.random_element(1,5)
1087 constructor = choice([eja_rn,
1088 JordanSpinEJA,
1089 RealSymmetricEJA,
1090 ComplexHermitianEJA,
1091 QuaternionHermitianEJA])
1092 return constructor(n, field=QQ)
1093
1094
1095
1096 def _real_symmetric_basis(n, field=QQ):
1097 """
1098 Return a basis for the space of real symmetric n-by-n matrices.
1099 """
1100 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1101 # coordinates.
1102 S = []
1103 for i in xrange(n):
1104 for j in xrange(i+1):
1105 Eij = matrix(field, n, lambda k,l: k==i and l==j)
1106 if i == j:
1107 Sij = Eij
1108 else:
1109 # Beware, orthogonal but not normalized!
1110 Sij = Eij + Eij.transpose()
1111 S.append(Sij)
1112 return tuple(S)
1113
1114
1115 def _complex_hermitian_basis(n, field=QQ):
1116 """
1117 Returns a basis for the space of complex Hermitian n-by-n matrices.
1118
1119 TESTS::
1120
1121 sage: set_random_seed()
1122 sage: n = ZZ.random_element(1,5)
1123 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1124 True
1125
1126 """
1127 F = QuadraticField(-1, 'I')
1128 I = F.gen()
1129
1130 # This is like the symmetric case, but we need to be careful:
1131 #
1132 # * We want conjugate-symmetry, not just symmetry.
1133 # * The diagonal will (as a result) be real.
1134 #
1135 S = []
1136 for i in xrange(n):
1137 for j in xrange(i+1):
1138 Eij = matrix(field, n, lambda k,l: k==i and l==j)
1139 if i == j:
1140 Sij = _embed_complex_matrix(Eij)
1141 S.append(Sij)
1142 else:
1143 # Beware, orthogonal but not normalized! The second one
1144 # has a minus because it's conjugated.
1145 Sij_real = _embed_complex_matrix(Eij + Eij.transpose())
1146 S.append(Sij_real)
1147 Sij_imag = _embed_complex_matrix(I*Eij - I*Eij.transpose())
1148 S.append(Sij_imag)
1149 return tuple(S)
1150
1151
1152 def _quaternion_hermitian_basis(n, field=QQ):
1153 """
1154 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1155
1156 TESTS::
1157
1158 sage: set_random_seed()
1159 sage: n = ZZ.random_element(1,5)
1160 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1161 True
1162
1163 """
1164 Q = QuaternionAlgebra(QQ,-1,-1)
1165 I,J,K = Q.gens()
1166
1167 # This is like the symmetric case, but we need to be careful:
1168 #
1169 # * We want conjugate-symmetry, not just symmetry.
1170 # * The diagonal will (as a result) be real.
1171 #
1172 S = []
1173 for i in xrange(n):
1174 for j in xrange(i+1):
1175 Eij = matrix(Q, n, lambda k,l: k==i and l==j)
1176 if i == j:
1177 Sij = _embed_quaternion_matrix(Eij)
1178 S.append(Sij)
1179 else:
1180 # Beware, orthogonal but not normalized! The second,
1181 # third, and fourth ones have a minus because they're
1182 # conjugated.
1183 Sij_real = _embed_quaternion_matrix(Eij + Eij.transpose())
1184 S.append(Sij_real)
1185 Sij_I = _embed_quaternion_matrix(I*Eij - I*Eij.transpose())
1186 S.append(Sij_I)
1187 Sij_J = _embed_quaternion_matrix(J*Eij - J*Eij.transpose())
1188 S.append(Sij_J)
1189 Sij_K = _embed_quaternion_matrix(K*Eij - K*Eij.transpose())
1190 S.append(Sij_K)
1191 return tuple(S)
1192
1193
1194 def _mat2vec(m):
1195 return vector(m.base_ring(), m.list())
1196
1197 def _vec2mat(v):
1198 return matrix(v.base_ring(), sqrt(v.degree()), v.list())
1199
1200 def _multiplication_table_from_matrix_basis(basis):
1201 """
1202 At least three of the five simple Euclidean Jordan algebras have the
1203 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1204 multiplication on the right is matrix multiplication. Given a basis
1205 for the underlying matrix space, this function returns a
1206 multiplication table (obtained by looping through the basis
1207 elements) for an algebra of those matrices. A reordered copy
1208 of the basis is also returned to work around the fact that
1209 the ``span()`` in this function will change the order of the basis
1210 from what we think it is, to... something else.
1211 """
1212 # In S^2, for example, we nominally have four coordinates even
1213 # though the space is of dimension three only. The vector space V
1214 # is supposed to hold the entire long vector, and the subspace W
1215 # of V will be spanned by the vectors that arise from symmetric
1216 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1217 field = basis[0].base_ring()
1218 dimension = basis[0].nrows()
1219
1220 V = VectorSpace(field, dimension**2)
1221 W = V.span( _mat2vec(s) for s in basis )
1222
1223 # Taking the span above reorders our basis (thanks, jerk!) so we
1224 # need to put our "matrix basis" in the same order as the
1225 # (reordered) vector basis.
1226 S = tuple( _vec2mat(b) for b in W.basis() )
1227
1228 Qs = []
1229 for s in S:
1230 # Brute force the multiplication-by-s matrix by looping
1231 # through all elements of the basis and doing the computation
1232 # to find out what the corresponding row should be. BEWARE:
1233 # these multiplication tables won't be symmetric! It therefore
1234 # becomes REALLY IMPORTANT that the underlying algebra
1235 # constructor uses ROW vectors and not COLUMN vectors. That's
1236 # why we're computing rows here and not columns.
1237 Q_rows = []
1238 for t in S:
1239 this_row = _mat2vec((s*t + t*s)/2)
1240 Q_rows.append(W.coordinates(this_row))
1241 Q = matrix(field, W.dimension(), Q_rows)
1242 Qs.append(Q)
1243
1244 return (Qs, S)
1245
1246
1247 def _embed_complex_matrix(M):
1248 """
1249 Embed the n-by-n complex matrix ``M`` into the space of real
1250 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1251 bi` to the block matrix ``[[a,b],[-b,a]]``.
1252
1253 EXAMPLES::
1254
1255 sage: F = QuadraticField(-1,'i')
1256 sage: x1 = F(4 - 2*i)
1257 sage: x2 = F(1 + 2*i)
1258 sage: x3 = F(-i)
1259 sage: x4 = F(6)
1260 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1261 sage: _embed_complex_matrix(M)
1262 [ 4 -2| 1 2]
1263 [ 2 4|-2 1]
1264 [-----+-----]
1265 [ 0 -1| 6 0]
1266 [ 1 0| 0 6]
1267
1268 TESTS:
1269
1270 Embedding is a homomorphism (isomorphism, in fact)::
1271
1272 sage: set_random_seed()
1273 sage: n = ZZ.random_element(5)
1274 sage: F = QuadraticField(-1, 'i')
1275 sage: X = random_matrix(F, n)
1276 sage: Y = random_matrix(F, n)
1277 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1278 sage: expected = _embed_complex_matrix(X*Y)
1279 sage: actual == expected
1280 True
1281
1282 """
1283 n = M.nrows()
1284 if M.ncols() != n:
1285 raise ValueError("the matrix 'M' must be square")
1286 field = M.base_ring()
1287 blocks = []
1288 for z in M.list():
1289 a = z.real()
1290 b = z.imag()
1291 blocks.append(matrix(field, 2, [[a,b],[-b,a]]))
1292
1293 # We can drop the imaginaries here.
1294 return block_matrix(field.base_ring(), n, blocks)
1295
1296
1297 def _unembed_complex_matrix(M):
1298 """
1299 The inverse of _embed_complex_matrix().
1300
1301 EXAMPLES::
1302
1303 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1304 ....: [-2, 1, -4, 3],
1305 ....: [ 9, 10, 11, 12],
1306 ....: [-10, 9, -12, 11] ])
1307 sage: _unembed_complex_matrix(A)
1308 [ 2*i + 1 4*i + 3]
1309 [ 10*i + 9 12*i + 11]
1310
1311 TESTS:
1312
1313 Unembedding is the inverse of embedding::
1314
1315 sage: set_random_seed()
1316 sage: F = QuadraticField(-1, 'i')
1317 sage: M = random_matrix(F, 3)
1318 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1319 True
1320
1321 """
1322 n = ZZ(M.nrows())
1323 if M.ncols() != n:
1324 raise ValueError("the matrix 'M' must be square")
1325 if not n.mod(2).is_zero():
1326 raise ValueError("the matrix 'M' must be a complex embedding")
1327
1328 F = QuadraticField(-1, 'i')
1329 i = F.gen()
1330
1331 # Go top-left to bottom-right (reading order), converting every
1332 # 2-by-2 block we see to a single complex element.
1333 elements = []
1334 for k in xrange(n/2):
1335 for j in xrange(n/2):
1336 submat = M[2*k:2*k+2,2*j:2*j+2]
1337 if submat[0,0] != submat[1,1]:
1338 raise ValueError('bad on-diagonal submatrix')
1339 if submat[0,1] != -submat[1,0]:
1340 raise ValueError('bad off-diagonal submatrix')
1341 z = submat[0,0] + submat[0,1]*i
1342 elements.append(z)
1343
1344 return matrix(F, n/2, elements)
1345
1346
1347 def _embed_quaternion_matrix(M):
1348 """
1349 Embed the n-by-n quaternion matrix ``M`` into the space of real
1350 matrices of size 4n-by-4n by first sending each quaternion entry
1351 `z = a + bi + cj + dk` to the block-complex matrix
1352 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1353 a real matrix.
1354
1355 EXAMPLES::
1356
1357 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1358 sage: i,j,k = Q.gens()
1359 sage: x = 1 + 2*i + 3*j + 4*k
1360 sage: M = matrix(Q, 1, [[x]])
1361 sage: _embed_quaternion_matrix(M)
1362 [ 1 2 3 4]
1363 [-2 1 -4 3]
1364 [-3 4 1 -2]
1365 [-4 -3 2 1]
1366
1367 Embedding is a homomorphism (isomorphism, in fact)::
1368
1369 sage: set_random_seed()
1370 sage: n = ZZ.random_element(5)
1371 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1372 sage: X = random_matrix(Q, n)
1373 sage: Y = random_matrix(Q, n)
1374 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1375 sage: expected = _embed_quaternion_matrix(X*Y)
1376 sage: actual == expected
1377 True
1378
1379 """
1380 quaternions = M.base_ring()
1381 n = M.nrows()
1382 if M.ncols() != n:
1383 raise ValueError("the matrix 'M' must be square")
1384
1385 F = QuadraticField(-1, 'i')
1386 i = F.gen()
1387
1388 blocks = []
1389 for z in M.list():
1390 t = z.coefficient_tuple()
1391 a = t[0]
1392 b = t[1]
1393 c = t[2]
1394 d = t[3]
1395 cplx_matrix = matrix(F, 2, [[ a + b*i, c + d*i],
1396 [-c + d*i, a - b*i]])
1397 blocks.append(_embed_complex_matrix(cplx_matrix))
1398
1399 # We should have real entries by now, so use the realest field
1400 # we've got for the return value.
1401 return block_matrix(quaternions.base_ring(), n, blocks)
1402
1403
1404 def _unembed_quaternion_matrix(M):
1405 """
1406 The inverse of _embed_quaternion_matrix().
1407
1408 EXAMPLES::
1409
1410 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1411 ....: [-2, 1, -4, 3],
1412 ....: [-3, 4, 1, -2],
1413 ....: [-4, -3, 2, 1]])
1414 sage: _unembed_quaternion_matrix(M)
1415 [1 + 2*i + 3*j + 4*k]
1416
1417 TESTS:
1418
1419 Unembedding is the inverse of embedding::
1420
1421 sage: set_random_seed()
1422 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1423 sage: M = random_matrix(Q, 3)
1424 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1425 True
1426
1427 """
1428 n = ZZ(M.nrows())
1429 if M.ncols() != n:
1430 raise ValueError("the matrix 'M' must be square")
1431 if not n.mod(4).is_zero():
1432 raise ValueError("the matrix 'M' must be a complex embedding")
1433
1434 Q = QuaternionAlgebra(QQ,-1,-1)
1435 i,j,k = Q.gens()
1436
1437 # Go top-left to bottom-right (reading order), converting every
1438 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1439 # quaternion block.
1440 elements = []
1441 for l in xrange(n/4):
1442 for m in xrange(n/4):
1443 submat = _unembed_complex_matrix(M[4*l:4*l+4,4*m:4*m+4])
1444 if submat[0,0] != submat[1,1].conjugate():
1445 raise ValueError('bad on-diagonal submatrix')
1446 if submat[0,1] != -submat[1,0].conjugate():
1447 raise ValueError('bad off-diagonal submatrix')
1448 z = submat[0,0].real() + submat[0,0].imag()*i
1449 z += submat[0,1].real()*j + submat[0,1].imag()*k
1450 elements.append(z)
1451
1452 return matrix(Q, n/4, elements)
1453
1454
1455 # The usual inner product on R^n.
1456 def _usual_ip(x,y):
1457 return x.vector().inner_product(y.vector())
1458
1459 # The inner product used for the real symmetric simple EJA.
1460 # We keep it as a separate function because e.g. the complex
1461 # algebra uses the same inner product, except divided by 2.
1462 def _matrix_ip(X,Y):
1463 X_mat = X.natural_representation()
1464 Y_mat = Y.natural_representation()
1465 return (X_mat*Y_mat).trace()
1466
1467
1468 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
1469 """
1470 The rank-n simple EJA consisting of real symmetric n-by-n
1471 matrices, the usual symmetric Jordan product, and the trace inner
1472 product. It has dimension `(n^2 + n)/2` over the reals.
1473
1474 EXAMPLES::
1475
1476 sage: J = RealSymmetricEJA(2)
1477 sage: e0, e1, e2 = J.gens()
1478 sage: e0*e0
1479 e0
1480 sage: e1*e1
1481 e0 + e2
1482 sage: e2*e2
1483 e2
1484
1485 TESTS:
1486
1487 The degree of this algebra is `(n^2 + n) / 2`::
1488
1489 sage: set_random_seed()
1490 sage: n = ZZ.random_element(1,5)
1491 sage: J = RealSymmetricEJA(n)
1492 sage: J.degree() == (n^2 + n)/2
1493 True
1494
1495 The Jordan multiplication is what we think it is::
1496
1497 sage: set_random_seed()
1498 sage: n = ZZ.random_element(1,5)
1499 sage: J = RealSymmetricEJA(n)
1500 sage: x = J.random_element()
1501 sage: y = J.random_element()
1502 sage: actual = (x*y).natural_representation()
1503 sage: X = x.natural_representation()
1504 sage: Y = y.natural_representation()
1505 sage: expected = (X*Y + Y*X)/2
1506 sage: actual == expected
1507 True
1508 sage: J(expected) == x*y
1509 True
1510
1511 """
1512 @staticmethod
1513 def __classcall_private__(cls, n, field=QQ):
1514 S = _real_symmetric_basis(n, field=field)
1515 (Qs, T) = _multiplication_table_from_matrix_basis(S)
1516
1517 fdeja = super(RealSymmetricEJA, cls)
1518 return fdeja.__classcall_private__(cls,
1519 field,
1520 Qs,
1521 rank=n,
1522 natural_basis=T)
1523
1524 def inner_product(self, x, y):
1525 return _matrix_ip(x,y)
1526
1527
1528 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
1529 """
1530 The rank-n simple EJA consisting of complex Hermitian n-by-n
1531 matrices over the real numbers, the usual symmetric Jordan product,
1532 and the real-part-of-trace inner product. It has dimension `n^2` over
1533 the reals.
1534
1535 TESTS:
1536
1537 The degree of this algebra is `n^2`::
1538
1539 sage: set_random_seed()
1540 sage: n = ZZ.random_element(1,5)
1541 sage: J = ComplexHermitianEJA(n)
1542 sage: J.degree() == n^2
1543 True
1544
1545 The Jordan multiplication is what we think it is::
1546
1547 sage: set_random_seed()
1548 sage: n = ZZ.random_element(1,5)
1549 sage: J = ComplexHermitianEJA(n)
1550 sage: x = J.random_element()
1551 sage: y = J.random_element()
1552 sage: actual = (x*y).natural_representation()
1553 sage: X = x.natural_representation()
1554 sage: Y = y.natural_representation()
1555 sage: expected = (X*Y + Y*X)/2
1556 sage: actual == expected
1557 True
1558 sage: J(expected) == x*y
1559 True
1560
1561 """
1562 @staticmethod
1563 def __classcall_private__(cls, n, field=QQ):
1564 S = _complex_hermitian_basis(n)
1565 (Qs, T) = _multiplication_table_from_matrix_basis(S)
1566
1567 fdeja = super(ComplexHermitianEJA, cls)
1568 return fdeja.__classcall_private__(cls,
1569 field,
1570 Qs,
1571 rank=n,
1572 natural_basis=T)
1573
1574 def inner_product(self, x, y):
1575 # Since a+bi on the diagonal is represented as
1576 #
1577 # a + bi = [ a b ]
1578 # [ -b a ],
1579 #
1580 # we'll double-count the "a" entries if we take the trace of
1581 # the embedding.
1582 return _matrix_ip(x,y)/2
1583
1584
1585 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
1586 """
1587 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1588 matrices, the usual symmetric Jordan product, and the
1589 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1590 the reals.
1591
1592 TESTS:
1593
1594 The degree of this algebra is `n^2`::
1595
1596 sage: set_random_seed()
1597 sage: n = ZZ.random_element(1,5)
1598 sage: J = QuaternionHermitianEJA(n)
1599 sage: J.degree() == 2*(n^2) - n
1600 True
1601
1602 The Jordan multiplication is what we think it is::
1603
1604 sage: set_random_seed()
1605 sage: n = ZZ.random_element(1,5)
1606 sage: J = QuaternionHermitianEJA(n)
1607 sage: x = J.random_element()
1608 sage: y = J.random_element()
1609 sage: actual = (x*y).natural_representation()
1610 sage: X = x.natural_representation()
1611 sage: Y = y.natural_representation()
1612 sage: expected = (X*Y + Y*X)/2
1613 sage: actual == expected
1614 True
1615 sage: J(expected) == x*y
1616 True
1617
1618 """
1619 @staticmethod
1620 def __classcall_private__(cls, n, field=QQ):
1621 S = _quaternion_hermitian_basis(n)
1622 (Qs, T) = _multiplication_table_from_matrix_basis(S)
1623
1624 fdeja = super(QuaternionHermitianEJA, cls)
1625 return fdeja.__classcall_private__(cls,
1626 field,
1627 Qs,
1628 rank=n,
1629 natural_basis=T)
1630
1631 def inner_product(self, x, y):
1632 # Since a+bi+cj+dk on the diagonal is represented as
1633 #
1634 # a + bi +cj + dk = [ a b c d]
1635 # [ -b a -d c]
1636 # [ -c d a -b]
1637 # [ -d -c b a],
1638 #
1639 # we'll quadruple-count the "a" entries if we take the trace of
1640 # the embedding.
1641 return _matrix_ip(x,y)/4
1642
1643
1644 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
1645 """
1646 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1647 with the usual inner product and jordan product ``x*y =
1648 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1649 the reals.
1650
1651 EXAMPLES:
1652
1653 This multiplication table can be verified by hand::
1654
1655 sage: J = JordanSpinEJA(4)
1656 sage: e0,e1,e2,e3 = J.gens()
1657 sage: e0*e0
1658 e0
1659 sage: e0*e1
1660 e1
1661 sage: e0*e2
1662 e2
1663 sage: e0*e3
1664 e3
1665 sage: e1*e2
1666 0
1667 sage: e1*e3
1668 0
1669 sage: e2*e3
1670 0
1671
1672 """
1673 @staticmethod
1674 def __classcall_private__(cls, n, field=QQ):
1675 Qs = []
1676 id_matrix = identity_matrix(field, n)
1677 for i in xrange(n):
1678 ei = id_matrix.column(i)
1679 Qi = zero_matrix(field, n)
1680 Qi.set_row(0, ei)
1681 Qi.set_column(0, ei)
1682 Qi += diagonal_matrix(n, [ei[0]]*n)
1683 # The addition of the diagonal matrix adds an extra ei[0] in the
1684 # upper-left corner of the matrix.
1685 Qi[0,0] = Qi[0,0] * ~field(2)
1686 Qs.append(Qi)
1687
1688 fdeja = super(JordanSpinEJA, cls)
1689 return fdeja.__classcall_private__(cls, field, Qs)
1690
1691 def rank(self):
1692 """
1693 Return the rank of this Jordan Spin Algebra.
1694
1695 The rank of the spin algebra is two, unless we're in a
1696 one-dimensional ambient space (because the rank is bounded by
1697 the ambient dimension).
1698 """
1699 return min(self.dimension(),2)
1700
1701 def inner_product(self, x, y):
1702 return _usual_ip(x,y)