]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_algebra.py
eja: get rid of the KnownRankEJA class.
[sage.d.git] / mjo / eja / eja_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 itertools import repeat
9
10 from sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra
11 from sage.categories.magmatic_algebras import MagmaticAlgebras
12 from sage.combinat.free_module import CombinatorialFreeModule
13 from sage.matrix.constructor import matrix
14 from sage.matrix.matrix_space import MatrixSpace
15 from sage.misc.cachefunc import cached_method
16 from sage.misc.lazy_import import lazy_import
17 from sage.misc.prandom import choice
18 from sage.misc.table import table
19 from sage.modules.free_module import FreeModule, VectorSpace
20 from sage.rings.all import (ZZ, QQ, AA, QQbar, RR, RLF, CLF,
21 PolynomialRing,
22 QuadraticField)
23 from mjo.eja.eja_element import FiniteDimensionalEuclideanJordanAlgebraElement
24 lazy_import('mjo.eja.eja_subalgebra',
25 'FiniteDimensionalEuclideanJordanSubalgebra')
26 from mjo.eja.eja_utils import _mat2vec
27
28 class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
29
30 def _coerce_map_from_base_ring(self):
31 """
32 Disable the map from the base ring into the algebra.
33
34 Performing a nonsense conversion like this automatically
35 is counterpedagogical. The fallback is to try the usual
36 element constructor, which should also fail.
37
38 SETUP::
39
40 sage: from mjo.eja.eja_algebra import random_eja
41
42 TESTS::
43
44 sage: set_random_seed()
45 sage: J = random_eja()
46 sage: J(1)
47 Traceback (most recent call last):
48 ...
49 ValueError: not a naturally-represented algebra element
50
51 """
52 return None
53
54 def __init__(self,
55 field,
56 mult_table,
57 prefix='e',
58 category=None,
59 natural_basis=None,
60 check=True):
61 """
62 SETUP::
63
64 sage: from mjo.eja.eja_algebra import (JordanSpinEJA, random_eja)
65
66 EXAMPLES:
67
68 By definition, Jordan multiplication commutes::
69
70 sage: set_random_seed()
71 sage: J = random_eja()
72 sage: x,y = J.random_elements(2)
73 sage: x*y == y*x
74 True
75
76 TESTS:
77
78 The ``field`` we're given must be real::
79
80 sage: JordanSpinEJA(2,QQbar)
81 Traceback (most recent call last):
82 ...
83 ValueError: field is not real
84
85 """
86 if check:
87 if not field.is_subring(RR):
88 # Note: this does return true for the real algebraic
89 # field, and any quadratic field where we've specified
90 # a real embedding.
91 raise ValueError('field is not real')
92
93 self._natural_basis = natural_basis
94
95 if category is None:
96 category = MagmaticAlgebras(field).FiniteDimensional()
97 category = category.WithBasis().Unital()
98
99 fda = super(FiniteDimensionalEuclideanJordanAlgebra, self)
100 fda.__init__(field,
101 range(len(mult_table)),
102 prefix=prefix,
103 category=category)
104 self.print_options(bracket='')
105
106 # The multiplication table we're given is necessarily in terms
107 # of vectors, because we don't have an algebra yet for
108 # anything to be an element of. However, it's faster in the
109 # long run to have the multiplication table be in terms of
110 # algebra elements. We do this after calling the superclass
111 # constructor so that from_vector() knows what to do.
112 self._multiplication_table = [
113 list(map(lambda x: self.from_vector(x), ls))
114 for ls in mult_table
115 ]
116
117
118 def _element_constructor_(self, elt):
119 """
120 Construct an element of this algebra from its natural
121 representation.
122
123 This gets called only after the parent element _call_ method
124 fails to find a coercion for the argument.
125
126 SETUP::
127
128 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
129 ....: HadamardEJA,
130 ....: RealSymmetricEJA)
131
132 EXAMPLES:
133
134 The identity in `S^n` is converted to the identity in the EJA::
135
136 sage: J = RealSymmetricEJA(3)
137 sage: I = matrix.identity(QQ,3)
138 sage: J(I) == J.one()
139 True
140
141 This skew-symmetric matrix can't be represented in the EJA::
142
143 sage: J = RealSymmetricEJA(3)
144 sage: A = matrix(QQ,3, lambda i,j: i-j)
145 sage: J(A)
146 Traceback (most recent call last):
147 ...
148 ArithmeticError: vector is not in free module
149
150 TESTS:
151
152 Ensure that we can convert any element of the two non-matrix
153 simple algebras (whose natural representations are their usual
154 vector representations) back and forth faithfully::
155
156 sage: set_random_seed()
157 sage: J = HadamardEJA.random_instance()
158 sage: x = J.random_element()
159 sage: J(x.to_vector().column()) == x
160 True
161 sage: J = JordanSpinEJA.random_instance()
162 sage: x = J.random_element()
163 sage: J(x.to_vector().column()) == x
164 True
165
166 """
167 msg = "not a naturally-represented algebra element"
168 if elt == 0:
169 # The superclass implementation of random_element()
170 # needs to be able to coerce "0" into the algebra.
171 return self.zero()
172 elif elt in self.base_ring():
173 # Ensure that no base ring -> algebra coercion is performed
174 # by this method. There's some stupidity in sage that would
175 # otherwise propagate to this method; for example, sage thinks
176 # that the integer 3 belongs to the space of 2-by-2 matrices.
177 raise ValueError(msg)
178
179 natural_basis = self.natural_basis()
180 basis_space = natural_basis[0].matrix_space()
181 if elt not in basis_space:
182 raise ValueError(msg)
183
184 # Thanks for nothing! Matrix spaces aren't vector spaces in
185 # Sage, so we have to figure out its natural-basis coordinates
186 # ourselves. We use the basis space's ring instead of the
187 # element's ring because the basis space might be an algebraic
188 # closure whereas the base ring of the 3-by-3 identity matrix
189 # could be QQ instead of QQbar.
190 V = VectorSpace(basis_space.base_ring(), elt.nrows()*elt.ncols())
191 W = V.span_of_basis( _mat2vec(s) for s in natural_basis )
192 coords = W.coordinate_vector(_mat2vec(elt))
193 return self.from_vector(coords)
194
195 @staticmethod
196 def _max_test_case_size():
197 """
198 Return an integer "size" that is an upper bound on the size of
199 this algebra when it is used in a random test
200 case. Unfortunately, the term "size" is quite vague -- when
201 dealing with `R^n` under either the Hadamard or Jordan spin
202 product, the "size" refers to the dimension `n`. When dealing
203 with a matrix algebra (real symmetric or complex/quaternion
204 Hermitian), it refers to the size of the matrix, which is
205 far less than the dimension of the underlying vector space.
206
207 We default to five in this class, which is safe in `R^n`. The
208 matrix algebra subclasses (or any class where the "size" is
209 interpreted to be far less than the dimension) should override
210 with a smaller number.
211 """
212 return 5
213
214 def _repr_(self):
215 """
216 Return a string representation of ``self``.
217
218 SETUP::
219
220 sage: from mjo.eja.eja_algebra import JordanSpinEJA
221
222 TESTS:
223
224 Ensure that it says what we think it says::
225
226 sage: JordanSpinEJA(2, field=AA)
227 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
228 sage: JordanSpinEJA(3, field=RDF)
229 Euclidean Jordan algebra of dimension 3 over Real Double Field
230
231 """
232 fmt = "Euclidean Jordan algebra of dimension {} over {}"
233 return fmt.format(self.dimension(), self.base_ring())
234
235 def product_on_basis(self, i, j):
236 return self._multiplication_table[i][j]
237
238 def _a_regular_element(self):
239 """
240 Guess a regular element. Needed to compute the basis for our
241 characteristic polynomial coefficients.
242
243 SETUP::
244
245 sage: from mjo.eja.eja_algebra import random_eja
246
247 TESTS:
248
249 Ensure that this hacky method succeeds for every algebra that we
250 know how to construct::
251
252 sage: set_random_seed()
253 sage: J = random_eja()
254 sage: J._a_regular_element().is_regular()
255 True
256
257 """
258 gs = self.gens()
259 z = self.sum( (i+1)*gs[i] for i in range(len(gs)) )
260 if not z.is_regular():
261 raise ValueError("don't know a regular element")
262 return z
263
264
265 @cached_method
266 def _charpoly_basis_space(self):
267 """
268 Return the vector space spanned by the basis used in our
269 characteristic polynomial coefficients. This is used not only to
270 compute those coefficients, but also any time we need to
271 evaluate the coefficients (like when we compute the trace or
272 determinant).
273 """
274 z = self._a_regular_element()
275 # Don't use the parent vector space directly here in case this
276 # happens to be a subalgebra. In that case, we would be e.g.
277 # two-dimensional but span_of_basis() would expect three
278 # coordinates.
279 V = VectorSpace(self.base_ring(), self.vector_space().dimension())
280 basis = [ (z**k).to_vector() for k in range(self.rank()) ]
281 V1 = V.span_of_basis( basis )
282 b = (V1.basis() + V1.complement().basis())
283 return V.span_of_basis(b)
284
285
286
287 @cached_method
288 def _charpoly_coeff(self, i):
289 """
290 Return the coefficient polynomial "a_{i}" of this algebra's
291 general characteristic polynomial.
292
293 Having this be a separate cached method lets us compute and
294 store the trace/determinant (a_{r-1} and a_{0} respectively)
295 separate from the entire characteristic polynomial.
296 """
297 (A_of_x, x, xr, detA) = self._charpoly_matrix_system()
298 R = A_of_x.base_ring()
299
300 if i == self.rank():
301 return R.one()
302 if i > self.rank():
303 # Guaranteed by theory
304 return R.zero()
305
306 # Danger: the in-place modification is done for performance
307 # reasons (reconstructing a matrix with huge polynomial
308 # entries is slow), but I don't know how cached_method works,
309 # so it's highly possible that we're modifying some global
310 # list variable by reference, here. In other words, you
311 # probably shouldn't call this method twice on the same
312 # algebra, at the same time, in two threads
313 Ai_orig = A_of_x.column(i)
314 A_of_x.set_column(i,xr)
315 numerator = A_of_x.det()
316 A_of_x.set_column(i,Ai_orig)
317
318 # We're relying on the theory here to ensure that each a_i is
319 # indeed back in R, and the added negative signs are to make
320 # the whole charpoly expression sum to zero.
321 return R(-numerator/detA)
322
323
324 @cached_method
325 def _charpoly_matrix_system(self):
326 """
327 Compute the matrix whose entries A_ij are polynomials in
328 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
329 corresponding to `x^r` and the determinent of the matrix A =
330 [A_ij]. In other words, all of the fixed (cachable) data needed
331 to compute the coefficients of the characteristic polynomial.
332 """
333 r = self.rank()
334 n = self.dimension()
335
336 # Turn my vector space into a module so that "vectors" can
337 # have multivatiate polynomial entries.
338 names = tuple('X' + str(i) for i in range(1,n+1))
339 R = PolynomialRing(self.base_ring(), names)
340
341 # Using change_ring() on the parent's vector space doesn't work
342 # here because, in a subalgebra, that vector space has a basis
343 # and change_ring() tries to bring the basis along with it. And
344 # that doesn't work unless the new ring is a PID, which it usually
345 # won't be.
346 V = FreeModule(R,n)
347
348 # Now let x = (X1,X2,...,Xn) be the vector whose entries are
349 # indeterminates...
350 x = V(names)
351
352 # And figure out the "left multiplication by x" matrix in
353 # that setting.
354 lmbx_cols = []
355 monomial_matrices = [ self.monomial(i).operator().matrix()
356 for i in range(n) ] # don't recompute these!
357 for k in range(n):
358 ek = self.monomial(k).to_vector()
359 lmbx_cols.append(
360 sum( x[i]*(monomial_matrices[i]*ek)
361 for i in range(n) ) )
362 Lx = matrix.column(R, lmbx_cols)
363
364 # Now we can compute powers of x "symbolically"
365 x_powers = [self.one().to_vector(), x]
366 for d in range(2, r+1):
367 x_powers.append( Lx*(x_powers[-1]) )
368
369 idmat = matrix.identity(R, n)
370
371 W = self._charpoly_basis_space()
372 W = W.change_ring(R.fraction_field())
373
374 # Starting with the standard coordinates x = (X1,X2,...,Xn)
375 # and then converting the entries to W-coordinates allows us
376 # to pass in the standard coordinates to the charpoly and get
377 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
378 # we have
379 #
380 # W.coordinates(x^2) eval'd at (standard z-coords)
381 # =
382 # W-coords of (z^2)
383 # =
384 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
385 #
386 # We want the middle equivalent thing in our matrix, but use
387 # the first equivalent thing instead so that we can pass in
388 # standard coordinates.
389 x_powers = [ W.coordinate_vector(xp) for xp in x_powers ]
390 l2 = [idmat.column(k-1) for k in range(r+1, n+1)]
391 A_of_x = matrix.column(R, n, (x_powers[:r] + l2))
392 return (A_of_x, x, x_powers[r], A_of_x.det())
393
394
395 @cached_method
396 def characteristic_polynomial(self):
397 """
398 Return a characteristic polynomial that works for all elements
399 of this algebra.
400
401 The resulting polynomial has `n+1` variables, where `n` is the
402 dimension of this algebra. The first `n` variables correspond to
403 the coordinates of an algebra element: when evaluated at the
404 coordinates of an algebra element with respect to a certain
405 basis, the result is a univariate polynomial (in the one
406 remaining variable ``t``), namely the characteristic polynomial
407 of that element.
408
409 SETUP::
410
411 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
412
413 EXAMPLES:
414
415 The characteristic polynomial in the spin algebra is given in
416 Alizadeh, Example 11.11::
417
418 sage: J = JordanSpinEJA(3)
419 sage: p = J.characteristic_polynomial(); p
420 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
421 sage: xvec = J.one().to_vector()
422 sage: p(*xvec)
423 t^2 - 2*t + 1
424
425 By definition, the characteristic polynomial is a monic
426 degree-zero polynomial in a rank-zero algebra. Note that
427 Cayley-Hamilton is indeed satisfied since the polynomial
428 ``1`` evaluates to the identity element of the algebra on
429 any argument::
430
431 sage: J = TrivialEJA()
432 sage: J.characteristic_polynomial()
433 1
434
435 """
436 r = self.rank()
437 n = self.dimension()
438
439 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_n.
440 a = [ self._charpoly_coeff(i) for i in range(r+1) ]
441
442 # We go to a bit of trouble here to reorder the
443 # indeterminates, so that it's easier to evaluate the
444 # characteristic polynomial at x's coordinates and get back
445 # something in terms of t, which is what we want.
446 R = a[0].parent()
447 S = PolynomialRing(self.base_ring(),'t')
448 t = S.gen(0)
449 S = PolynomialRing(S, R.variable_names())
450 t = S(t)
451
452 return sum( a[k]*(t**k) for k in range(len(a)) )
453
454
455 def inner_product(self, x, y):
456 """
457 The inner product associated with this Euclidean Jordan algebra.
458
459 Defaults to the trace inner product, but can be overridden by
460 subclasses if they are sure that the necessary properties are
461 satisfied.
462
463 SETUP::
464
465 sage: from mjo.eja.eja_algebra import random_eja
466
467 EXAMPLES:
468
469 Our inner product is "associative," which means the following for
470 a symmetric bilinear form::
471
472 sage: set_random_seed()
473 sage: J = random_eja()
474 sage: x,y,z = J.random_elements(3)
475 sage: (x*y).inner_product(z) == y.inner_product(x*z)
476 True
477
478 """
479 X = x.natural_representation()
480 Y = y.natural_representation()
481 return self.natural_inner_product(X,Y)
482
483
484 def is_trivial(self):
485 """
486 Return whether or not this algebra is trivial.
487
488 A trivial algebra contains only the zero element.
489
490 SETUP::
491
492 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
493 ....: TrivialEJA)
494
495 EXAMPLES::
496
497 sage: J = ComplexHermitianEJA(3)
498 sage: J.is_trivial()
499 False
500
501 ::
502
503 sage: J = TrivialEJA()
504 sage: J.is_trivial()
505 True
506
507 """
508 return self.dimension() == 0
509
510
511 def multiplication_table(self):
512 """
513 Return a visual representation of this algebra's multiplication
514 table (on basis elements).
515
516 SETUP::
517
518 sage: from mjo.eja.eja_algebra import JordanSpinEJA
519
520 EXAMPLES::
521
522 sage: J = JordanSpinEJA(4)
523 sage: J.multiplication_table()
524 +----++----+----+----+----+
525 | * || e0 | e1 | e2 | e3 |
526 +====++====+====+====+====+
527 | e0 || e0 | e1 | e2 | e3 |
528 +----++----+----+----+----+
529 | e1 || e1 | e0 | 0 | 0 |
530 +----++----+----+----+----+
531 | e2 || e2 | 0 | e0 | 0 |
532 +----++----+----+----+----+
533 | e3 || e3 | 0 | 0 | e0 |
534 +----++----+----+----+----+
535
536 """
537 M = list(self._multiplication_table) # copy
538 for i in range(len(M)):
539 # M had better be "square"
540 M[i] = [self.monomial(i)] + M[i]
541 M = [["*"] + list(self.gens())] + M
542 return table(M, header_row=True, header_column=True, frame=True)
543
544
545 def natural_basis(self):
546 """
547 Return a more-natural representation of this algebra's basis.
548
549 Every finite-dimensional Euclidean Jordan Algebra is a direct
550 sum of five simple algebras, four of which comprise Hermitian
551 matrices. This method returns the original "natural" basis
552 for our underlying vector space. (Typically, the natural basis
553 is used to construct the multiplication table in the first place.)
554
555 Note that this will always return a matrix. The standard basis
556 in `R^n` will be returned as `n`-by-`1` column matrices.
557
558 SETUP::
559
560 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
561 ....: RealSymmetricEJA)
562
563 EXAMPLES::
564
565 sage: J = RealSymmetricEJA(2)
566 sage: J.basis()
567 Finite family {0: e0, 1: e1, 2: e2}
568 sage: J.natural_basis()
569 (
570 [1 0] [ 0 0.7071067811865475?] [0 0]
571 [0 0], [0.7071067811865475? 0], [0 1]
572 )
573
574 ::
575
576 sage: J = JordanSpinEJA(2)
577 sage: J.basis()
578 Finite family {0: e0, 1: e1}
579 sage: J.natural_basis()
580 (
581 [1] [0]
582 [0], [1]
583 )
584
585 """
586 if self._natural_basis is None:
587 M = self.natural_basis_space()
588 return tuple( M(b.to_vector()) for b in self.basis() )
589 else:
590 return self._natural_basis
591
592
593 def natural_basis_space(self):
594 """
595 Return the matrix space in which this algebra's natural basis
596 elements live.
597 """
598 if self._natural_basis is None or len(self._natural_basis) == 0:
599 return MatrixSpace(self.base_ring(), self.dimension(), 1)
600 else:
601 return self._natural_basis[0].matrix_space()
602
603
604 @staticmethod
605 def natural_inner_product(X,Y):
606 """
607 Compute the inner product of two naturally-represented elements.
608
609 For example in the real symmetric matrix EJA, this will compute
610 the trace inner-product of two n-by-n symmetric matrices. The
611 default should work for the real cartesian product EJA, the
612 Jordan spin EJA, and the real symmetric matrices. The others
613 will have to be overridden.
614 """
615 return (X.conjugate_transpose()*Y).trace()
616
617
618 @cached_method
619 def one(self):
620 """
621 Return the unit element of this algebra.
622
623 SETUP::
624
625 sage: from mjo.eja.eja_algebra import (HadamardEJA,
626 ....: random_eja)
627
628 EXAMPLES::
629
630 sage: J = HadamardEJA(5)
631 sage: J.one()
632 e0 + e1 + e2 + e3 + e4
633
634 TESTS:
635
636 The identity element acts like the identity::
637
638 sage: set_random_seed()
639 sage: J = random_eja()
640 sage: x = J.random_element()
641 sage: J.one()*x == x and x*J.one() == x
642 True
643
644 The matrix of the unit element's operator is the identity::
645
646 sage: set_random_seed()
647 sage: J = random_eja()
648 sage: actual = J.one().operator().matrix()
649 sage: expected = matrix.identity(J.base_ring(), J.dimension())
650 sage: actual == expected
651 True
652
653 """
654 # We can brute-force compute the matrices of the operators
655 # that correspond to the basis elements of this algebra.
656 # If some linear combination of those basis elements is the
657 # algebra identity, then the same linear combination of
658 # their matrices has to be the identity matrix.
659 #
660 # Of course, matrices aren't vectors in sage, so we have to
661 # appeal to the "long vectors" isometry.
662 oper_vecs = [ _mat2vec(g.operator().matrix()) for g in self.gens() ]
663
664 # Now we use basis linear algebra to find the coefficients,
665 # of the matrices-as-vectors-linear-combination, which should
666 # work for the original algebra basis too.
667 A = matrix.column(self.base_ring(), oper_vecs)
668
669 # We used the isometry on the left-hand side already, but we
670 # still need to do it for the right-hand side. Recall that we
671 # wanted something that summed to the identity matrix.
672 b = _mat2vec( matrix.identity(self.base_ring(), self.dimension()) )
673
674 # Now if there's an identity element in the algebra, this should work.
675 coeffs = A.solve_right(b)
676 return self.linear_combination(zip(self.gens(), coeffs))
677
678
679 def peirce_decomposition(self, c):
680 """
681 The Peirce decomposition of this algebra relative to the
682 idempotent ``c``.
683
684 In the future, this can be extended to a complete system of
685 orthogonal idempotents.
686
687 INPUT:
688
689 - ``c`` -- an idempotent of this algebra.
690
691 OUTPUT:
692
693 A triple (J0, J5, J1) containing two subalgebras and one subspace
694 of this algebra,
695
696 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
697 corresponding to the eigenvalue zero.
698
699 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
700 corresponding to the eigenvalue one-half.
701
702 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
703 corresponding to the eigenvalue one.
704
705 These are the only possible eigenspaces for that operator, and this
706 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
707 orthogonal, and are subalgebras of this algebra with the appropriate
708 restrictions.
709
710 SETUP::
711
712 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
713
714 EXAMPLES:
715
716 The canonical example comes from the symmetric matrices, which
717 decompose into diagonal and off-diagonal parts::
718
719 sage: J = RealSymmetricEJA(3)
720 sage: C = matrix(QQ, [ [1,0,0],
721 ....: [0,1,0],
722 ....: [0,0,0] ])
723 sage: c = J(C)
724 sage: J0,J5,J1 = J.peirce_decomposition(c)
725 sage: J0
726 Euclidean Jordan algebra of dimension 1...
727 sage: J5
728 Vector space of degree 6 and dimension 2...
729 sage: J1
730 Euclidean Jordan algebra of dimension 3...
731
732 TESTS:
733
734 Every algebra decomposes trivially with respect to its identity
735 element::
736
737 sage: set_random_seed()
738 sage: J = random_eja()
739 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
740 sage: J0.dimension() == 0 and J5.dimension() == 0
741 True
742 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
743 True
744
745 The identity elements in the two subalgebras are the
746 projections onto their respective subspaces of the
747 superalgebra's identity element::
748
749 sage: set_random_seed()
750 sage: J = random_eja()
751 sage: x = J.random_element()
752 sage: if not J.is_trivial():
753 ....: while x.is_nilpotent():
754 ....: x = J.random_element()
755 sage: c = x.subalgebra_idempotent()
756 sage: J0,J5,J1 = J.peirce_decomposition(c)
757 sage: J1(c) == J1.one()
758 True
759 sage: J0(J.one() - c) == J0.one()
760 True
761
762 """
763 if not c.is_idempotent():
764 raise ValueError("element is not idempotent: %s" % c)
765
766 # Default these to what they should be if they turn out to be
767 # trivial, because eigenspaces_left() won't return eigenvalues
768 # corresponding to trivial spaces (e.g. it returns only the
769 # eigenspace corresponding to lambda=1 if you take the
770 # decomposition relative to the identity element).
771 trivial = FiniteDimensionalEuclideanJordanSubalgebra(self, ())
772 J0 = trivial # eigenvalue zero
773 J5 = VectorSpace(self.base_ring(), 0) # eigenvalue one-half
774 J1 = trivial # eigenvalue one
775
776 for (eigval, eigspace) in c.operator().matrix().right_eigenspaces():
777 if eigval == ~(self.base_ring()(2)):
778 J5 = eigspace
779 else:
780 gens = tuple( self.from_vector(b) for b in eigspace.basis() )
781 subalg = FiniteDimensionalEuclideanJordanSubalgebra(self, gens)
782 if eigval == 0:
783 J0 = subalg
784 elif eigval == 1:
785 J1 = subalg
786 else:
787 raise ValueError("unexpected eigenvalue: %s" % eigval)
788
789 return (J0, J5, J1)
790
791
792 def random_elements(self, count):
793 """
794 Return ``count`` random elements as a tuple.
795
796 SETUP::
797
798 sage: from mjo.eja.eja_algebra import JordanSpinEJA
799
800 EXAMPLES::
801
802 sage: J = JordanSpinEJA(3)
803 sage: x,y,z = J.random_elements(3)
804 sage: all( [ x in J, y in J, z in J ])
805 True
806 sage: len( J.random_elements(10) ) == 10
807 True
808
809 """
810 return tuple( self.random_element() for idx in range(count) )
811
812 @classmethod
813 def random_instance(cls, field=AA, **kwargs):
814 """
815 Return a random instance of this type of algebra.
816
817 Beware, this will crash for "most instances" because the
818 constructor below looks wrong.
819 """
820 if cls is TrivialEJA:
821 # The TrivialEJA class doesn't take an "n" argument because
822 # there's only one.
823 return cls(field)
824
825 n = ZZ.random_element(cls._max_test_case_size()) + 1
826 return cls(n, field, **kwargs)
827
828 @cached_method
829 def rank(self):
830 """
831 Return the rank of this EJA.
832
833 ALGORITHM:
834
835 We first compute the polynomial "column matrices" `p_{k}` that
836 evaluate to `x^k` on the coordinates of `x`. Then, we begin
837 adding them to a matrix one at a time, and trying to solve the
838 system that makes `p_{0}`,`p_{1}`,..., `p_{s-1}` add up to
839 `p_{s}`. This will succeed only when `s` is the rank of the
840 algebra, as proven in a recent draft paper of mine.
841
842 SETUP::
843
844 sage: from mjo.eja.eja_algebra import (HadamardEJA,
845 ....: JordanSpinEJA,
846 ....: RealSymmetricEJA,
847 ....: ComplexHermitianEJA,
848 ....: QuaternionHermitianEJA,
849 ....: random_eja)
850
851 EXAMPLES:
852
853 The rank of the Jordan spin algebra is always two::
854
855 sage: JordanSpinEJA(2).rank()
856 2
857 sage: JordanSpinEJA(3).rank()
858 2
859 sage: JordanSpinEJA(4).rank()
860 2
861
862 The rank of the `n`-by-`n` Hermitian real, complex, or
863 quaternion matrices is `n`::
864
865 sage: RealSymmetricEJA(4).rank()
866 4
867 sage: ComplexHermitianEJA(3).rank()
868 3
869 sage: QuaternionHermitianEJA(2).rank()
870 2
871
872 TESTS:
873
874 Ensure that every EJA that we know how to construct has a
875 positive integer rank, unless the algebra is trivial in
876 which case its rank will be zero::
877
878 sage: set_random_seed()
879 sage: J = random_eja()
880 sage: r = J.rank()
881 sage: r in ZZ
882 True
883 sage: r > 0 or (r == 0 and J.is_trivial())
884 True
885
886 Ensure that computing the rank actually works, since the ranks
887 of all simple algebras are known and will be cached by default::
888
889 sage: J = HadamardEJA(4)
890 sage: J.rank.clear_cache()
891 sage: J.rank()
892 4
893
894 ::
895
896 sage: J = JordanSpinEJA(4)
897 sage: J.rank.clear_cache()
898 sage: J.rank()
899 2
900
901 ::
902
903 sage: J = RealSymmetricEJA(3)
904 sage: J.rank.clear_cache()
905 sage: J.rank()
906 3
907
908 ::
909
910 sage: J = ComplexHermitianEJA(2)
911 sage: J.rank.clear_cache()
912 sage: J.rank()
913 2
914
915 ::
916
917 sage: J = QuaternionHermitianEJA(2)
918 sage: J.rank.clear_cache()
919 sage: J.rank()
920 2
921
922 """
923 n = self.dimension()
924 if n == 0:
925 return 0
926 elif n == 1:
927 return 1
928
929 var_names = [ "X" + str(z) for z in range(1,n+1) ]
930 R = PolynomialRing(self.base_ring(), var_names)
931 vars = R.gens()
932
933 def L_x_i_j(i,j):
934 # From a result in my book, these are the entries of the
935 # basis representation of L_x.
936 return sum( vars[k]*self.monomial(k).operator().matrix()[i,j]
937 for k in range(n) )
938
939 L_x = matrix(R, n, n, L_x_i_j)
940 x_powers = [ vars[k]*(L_x**k)*self.one().to_vector()
941 for k in range(n) ]
942
943 # Can assume n >= 2
944 M = matrix([x_powers[0]])
945 old_rank = 1
946
947 for d in range(1,n):
948 M = matrix(M.rows() + [x_powers[d]])
949 M.echelonize()
950 # TODO: we've basically solved the system here.
951 # We should save the echelonized matrix somehow
952 # so that it can be reused in the charpoly method.
953 new_rank = M.rank()
954 if new_rank == old_rank:
955 return new_rank
956 else:
957 old_rank = new_rank
958
959 return n
960
961
962 def vector_space(self):
963 """
964 Return the vector space that underlies this algebra.
965
966 SETUP::
967
968 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
969
970 EXAMPLES::
971
972 sage: J = RealSymmetricEJA(2)
973 sage: J.vector_space()
974 Vector space of dimension 3 over...
975
976 """
977 return self.zero().to_vector().parent().ambient_vector_space()
978
979
980 Element = FiniteDimensionalEuclideanJordanAlgebraElement
981
982
983 class HadamardEJA(FiniteDimensionalEuclideanJordanAlgebra):
984 """
985 Return the Euclidean Jordan Algebra corresponding to the set
986 `R^n` under the Hadamard product.
987
988 Note: this is nothing more than the Cartesian product of ``n``
989 copies of the spin algebra. Once Cartesian product algebras
990 are implemented, this can go.
991
992 SETUP::
993
994 sage: from mjo.eja.eja_algebra import HadamardEJA
995
996 EXAMPLES:
997
998 This multiplication table can be verified by hand::
999
1000 sage: J = HadamardEJA(3)
1001 sage: e0,e1,e2 = J.gens()
1002 sage: e0*e0
1003 e0
1004 sage: e0*e1
1005 0
1006 sage: e0*e2
1007 0
1008 sage: e1*e1
1009 e1
1010 sage: e1*e2
1011 0
1012 sage: e2*e2
1013 e2
1014
1015 TESTS:
1016
1017 We can change the generator prefix::
1018
1019 sage: HadamardEJA(3, prefix='r').gens()
1020 (r0, r1, r2)
1021
1022 """
1023 def __init__(self, n, field=AA, **kwargs):
1024 V = VectorSpace(field, n)
1025 mult_table = [ [ V.gen(i)*(i == j) for j in range(n) ]
1026 for i in range(n) ]
1027
1028 fdeja = super(HadamardEJA, self)
1029 fdeja.__init__(field, mult_table, **kwargs)
1030 self.rank.set_cache(n)
1031
1032 def inner_product(self, x, y):
1033 """
1034 Faster to reimplement than to use natural representations.
1035
1036 SETUP::
1037
1038 sage: from mjo.eja.eja_algebra import HadamardEJA
1039
1040 TESTS:
1041
1042 Ensure that this is the usual inner product for the algebras
1043 over `R^n`::
1044
1045 sage: set_random_seed()
1046 sage: J = HadamardEJA.random_instance()
1047 sage: x,y = J.random_elements(2)
1048 sage: X = x.natural_representation()
1049 sage: Y = y.natural_representation()
1050 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
1051 True
1052
1053 """
1054 return x.to_vector().inner_product(y.to_vector())
1055
1056
1057 def random_eja(field=AA, nontrivial=False):
1058 """
1059 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1060
1061 SETUP::
1062
1063 sage: from mjo.eja.eja_algebra import random_eja
1064
1065 TESTS::
1066
1067 sage: random_eja()
1068 Euclidean Jordan algebra of dimension...
1069
1070 """
1071 eja_classes = [HadamardEJA,
1072 JordanSpinEJA,
1073 RealSymmetricEJA,
1074 ComplexHermitianEJA,
1075 QuaternionHermitianEJA]
1076 if not nontrivial:
1077 eja_classes.append(TrivialEJA)
1078 classname = choice(eja_classes)
1079 return classname.random_instance(field=field)
1080
1081
1082
1083
1084
1085
1086 class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra):
1087 @staticmethod
1088 def _max_test_case_size():
1089 # Play it safe, since this will be squared and the underlying
1090 # field can have dimension 4 (quaternions) too.
1091 return 2
1092
1093 def __init__(self, field, basis, normalize_basis=True, **kwargs):
1094 """
1095 Compared to the superclass constructor, we take a basis instead of
1096 a multiplication table because the latter can be computed in terms
1097 of the former when the product is known (like it is here).
1098 """
1099 # Used in this class's fast _charpoly_coeff() override.
1100 self._basis_normalizers = None
1101
1102 # We're going to loop through this a few times, so now's a good
1103 # time to ensure that it isn't a generator expression.
1104 basis = tuple(basis)
1105
1106 if len(basis) > 1 and normalize_basis:
1107 # We'll need sqrt(2) to normalize the basis, and this
1108 # winds up in the multiplication table, so the whole
1109 # algebra needs to be over the field extension.
1110 R = PolynomialRing(field, 'z')
1111 z = R.gen()
1112 p = z**2 - 2
1113 if p.is_irreducible():
1114 field = field.extension(p, 'sqrt2', embedding=RLF(2).sqrt())
1115 basis = tuple( s.change_ring(field) for s in basis )
1116 self._basis_normalizers = tuple(
1117 ~(self.natural_inner_product(s,s).sqrt()) for s in basis )
1118 basis = tuple(s*c for (s,c) in zip(basis,self._basis_normalizers))
1119
1120 Qs = self.multiplication_table_from_matrix_basis(basis)
1121
1122 fdeja = super(MatrixEuclideanJordanAlgebra, self)
1123 fdeja.__init__(field, Qs, natural_basis=basis, **kwargs)
1124 return
1125
1126
1127 @cached_method
1128 def rank(self):
1129 r"""
1130 Override the parent method with something that tries to compute
1131 over a faster (non-extension) field.
1132 """
1133 if self._basis_normalizers is None:
1134 # We didn't normalize, so assume that the basis we started
1135 # with had entries in a nice field.
1136 return super(MatrixEuclideanJordanAlgebra, self).rank()
1137 else:
1138 basis = ( (b/n) for (b,n) in zip(self.natural_basis(),
1139 self._basis_normalizers) )
1140
1141 # Do this over the rationals and convert back at the end.
1142 # Only works because we know the entries of the basis are
1143 # integers.
1144 J = MatrixEuclideanJordanAlgebra(QQ,
1145 basis,
1146 normalize_basis=False)
1147 return J.rank()
1148
1149 @cached_method
1150 def _charpoly_coeff(self, i):
1151 """
1152 Override the parent method with something that tries to compute
1153 over a faster (non-extension) field.
1154 """
1155 if self._basis_normalizers is None:
1156 # We didn't normalize, so assume that the basis we started
1157 # with had entries in a nice field.
1158 return super(MatrixEuclideanJordanAlgebra, self)._charpoly_coeff(i)
1159 else:
1160 basis = ( (b/n) for (b,n) in zip(self.natural_basis(),
1161 self._basis_normalizers) )
1162
1163 # Do this over the rationals and convert back at the end.
1164 J = MatrixEuclideanJordanAlgebra(QQ,
1165 basis,
1166 normalize_basis=False)
1167 (_,x,_,_) = J._charpoly_matrix_system()
1168 p = J._charpoly_coeff(i)
1169 # p might be missing some vars, have to substitute "optionally"
1170 pairs = zip(x.base_ring().gens(), self._basis_normalizers)
1171 substitutions = { v: v*c for (v,c) in pairs }
1172 result = p.subs(substitutions)
1173
1174 # The result of "subs" can be either a coefficient-ring
1175 # element or a polynomial. Gotta handle both cases.
1176 if result in QQ:
1177 return self.base_ring()(result)
1178 else:
1179 return result.change_ring(self.base_ring())
1180
1181
1182 @staticmethod
1183 def multiplication_table_from_matrix_basis(basis):
1184 """
1185 At least three of the five simple Euclidean Jordan algebras have the
1186 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1187 multiplication on the right is matrix multiplication. Given a basis
1188 for the underlying matrix space, this function returns a
1189 multiplication table (obtained by looping through the basis
1190 elements) for an algebra of those matrices.
1191 """
1192 # In S^2, for example, we nominally have four coordinates even
1193 # though the space is of dimension three only. The vector space V
1194 # is supposed to hold the entire long vector, and the subspace W
1195 # of V will be spanned by the vectors that arise from symmetric
1196 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1197 field = basis[0].base_ring()
1198 dimension = basis[0].nrows()
1199
1200 V = VectorSpace(field, dimension**2)
1201 W = V.span_of_basis( _mat2vec(s) for s in basis )
1202 n = len(basis)
1203 mult_table = [[W.zero() for j in range(n)] for i in range(n)]
1204 for i in range(n):
1205 for j in range(n):
1206 mat_entry = (basis[i]*basis[j] + basis[j]*basis[i])/2
1207 mult_table[i][j] = W.coordinate_vector(_mat2vec(mat_entry))
1208
1209 return mult_table
1210
1211
1212 @staticmethod
1213 def real_embed(M):
1214 """
1215 Embed the matrix ``M`` into a space of real matrices.
1216
1217 The matrix ``M`` can have entries in any field at the moment:
1218 the real numbers, complex numbers, or quaternions. And although
1219 they are not a field, we can probably support octonions at some
1220 point, too. This function returns a real matrix that "acts like"
1221 the original with respect to matrix multiplication; i.e.
1222
1223 real_embed(M*N) = real_embed(M)*real_embed(N)
1224
1225 """
1226 raise NotImplementedError
1227
1228
1229 @staticmethod
1230 def real_unembed(M):
1231 """
1232 The inverse of :meth:`real_embed`.
1233 """
1234 raise NotImplementedError
1235
1236
1237 @classmethod
1238 def natural_inner_product(cls,X,Y):
1239 Xu = cls.real_unembed(X)
1240 Yu = cls.real_unembed(Y)
1241 tr = (Xu*Yu).trace()
1242
1243 if tr in RLF:
1244 # It's real already.
1245 return tr
1246
1247 # Otherwise, try the thing that works for complex numbers; and
1248 # if that doesn't work, the thing that works for quaternions.
1249 try:
1250 return tr.vector()[0] # real part, imag part is index 1
1251 except AttributeError:
1252 # A quaternions doesn't have a vector() method, but does
1253 # have coefficient_tuple() method that returns the
1254 # coefficients of 1, i, j, and k -- in that order.
1255 return tr.coefficient_tuple()[0]
1256
1257
1258 class RealMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
1259 @staticmethod
1260 def real_embed(M):
1261 """
1262 The identity function, for embedding real matrices into real
1263 matrices.
1264 """
1265 return M
1266
1267 @staticmethod
1268 def real_unembed(M):
1269 """
1270 The identity function, for unembedding real matrices from real
1271 matrices.
1272 """
1273 return M
1274
1275
1276 class RealSymmetricEJA(RealMatrixEuclideanJordanAlgebra):
1277 """
1278 The rank-n simple EJA consisting of real symmetric n-by-n
1279 matrices, the usual symmetric Jordan product, and the trace inner
1280 product. It has dimension `(n^2 + n)/2` over the reals.
1281
1282 SETUP::
1283
1284 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1285
1286 EXAMPLES::
1287
1288 sage: J = RealSymmetricEJA(2)
1289 sage: e0, e1, e2 = J.gens()
1290 sage: e0*e0
1291 e0
1292 sage: e1*e1
1293 1/2*e0 + 1/2*e2
1294 sage: e2*e2
1295 e2
1296
1297 In theory, our "field" can be any subfield of the reals::
1298
1299 sage: RealSymmetricEJA(2, RDF)
1300 Euclidean Jordan algebra of dimension 3 over Real Double Field
1301 sage: RealSymmetricEJA(2, RR)
1302 Euclidean Jordan algebra of dimension 3 over Real Field with
1303 53 bits of precision
1304
1305 TESTS:
1306
1307 The dimension of this algebra is `(n^2 + n) / 2`::
1308
1309 sage: set_random_seed()
1310 sage: n_max = RealSymmetricEJA._max_test_case_size()
1311 sage: n = ZZ.random_element(1, n_max)
1312 sage: J = RealSymmetricEJA(n)
1313 sage: J.dimension() == (n^2 + n)/2
1314 True
1315
1316 The Jordan multiplication is what we think it is::
1317
1318 sage: set_random_seed()
1319 sage: J = RealSymmetricEJA.random_instance()
1320 sage: x,y = J.random_elements(2)
1321 sage: actual = (x*y).natural_representation()
1322 sage: X = x.natural_representation()
1323 sage: Y = y.natural_representation()
1324 sage: expected = (X*Y + Y*X)/2
1325 sage: actual == expected
1326 True
1327 sage: J(expected) == x*y
1328 True
1329
1330 We can change the generator prefix::
1331
1332 sage: RealSymmetricEJA(3, prefix='q').gens()
1333 (q0, q1, q2, q3, q4, q5)
1334
1335 Our natural basis is normalized with respect to the natural inner
1336 product unless we specify otherwise::
1337
1338 sage: set_random_seed()
1339 sage: J = RealSymmetricEJA.random_instance()
1340 sage: all( b.norm() == 1 for b in J.gens() )
1341 True
1342
1343 Since our natural basis is normalized with respect to the natural
1344 inner product, and since we know that this algebra is an EJA, any
1345 left-multiplication operator's matrix will be symmetric because
1346 natural->EJA basis representation is an isometry and within the EJA
1347 the operator is self-adjoint by the Jordan axiom::
1348
1349 sage: set_random_seed()
1350 sage: x = RealSymmetricEJA.random_instance().random_element()
1351 sage: x.operator().matrix().is_symmetric()
1352 True
1353
1354 """
1355 @classmethod
1356 def _denormalized_basis(cls, n, field):
1357 """
1358 Return a basis for the space of real symmetric n-by-n matrices.
1359
1360 SETUP::
1361
1362 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1363
1364 TESTS::
1365
1366 sage: set_random_seed()
1367 sage: n = ZZ.random_element(1,5)
1368 sage: B = RealSymmetricEJA._denormalized_basis(n,QQ)
1369 sage: all( M.is_symmetric() for M in B)
1370 True
1371
1372 """
1373 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1374 # coordinates.
1375 S = []
1376 for i in range(n):
1377 for j in range(i+1):
1378 Eij = matrix(field, n, lambda k,l: k==i and l==j)
1379 if i == j:
1380 Sij = Eij
1381 else:
1382 Sij = Eij + Eij.transpose()
1383 S.append(Sij)
1384 return S
1385
1386
1387 @staticmethod
1388 def _max_test_case_size():
1389 return 4 # Dimension 10
1390
1391
1392 def __init__(self, n, field=AA, **kwargs):
1393 basis = self._denormalized_basis(n, field)
1394 super(RealSymmetricEJA, self).__init__(field, basis, **kwargs)
1395 self.rank.set_cache(n)
1396
1397
1398 class ComplexMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
1399 @staticmethod
1400 def real_embed(M):
1401 """
1402 Embed the n-by-n complex matrix ``M`` into the space of real
1403 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1404 bi` to the block matrix ``[[a,b],[-b,a]]``.
1405
1406 SETUP::
1407
1408 sage: from mjo.eja.eja_algebra import \
1409 ....: ComplexMatrixEuclideanJordanAlgebra
1410
1411 EXAMPLES::
1412
1413 sage: F = QuadraticField(-1, 'I')
1414 sage: x1 = F(4 - 2*i)
1415 sage: x2 = F(1 + 2*i)
1416 sage: x3 = F(-i)
1417 sage: x4 = F(6)
1418 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1419 sage: ComplexMatrixEuclideanJordanAlgebra.real_embed(M)
1420 [ 4 -2| 1 2]
1421 [ 2 4|-2 1]
1422 [-----+-----]
1423 [ 0 -1| 6 0]
1424 [ 1 0| 0 6]
1425
1426 TESTS:
1427
1428 Embedding is a homomorphism (isomorphism, in fact)::
1429
1430 sage: set_random_seed()
1431 sage: n_max = ComplexMatrixEuclideanJordanAlgebra._max_test_case_size()
1432 sage: n = ZZ.random_element(n_max)
1433 sage: F = QuadraticField(-1, 'I')
1434 sage: X = random_matrix(F, n)
1435 sage: Y = random_matrix(F, n)
1436 sage: Xe = ComplexMatrixEuclideanJordanAlgebra.real_embed(X)
1437 sage: Ye = ComplexMatrixEuclideanJordanAlgebra.real_embed(Y)
1438 sage: XYe = ComplexMatrixEuclideanJordanAlgebra.real_embed(X*Y)
1439 sage: Xe*Ye == XYe
1440 True
1441
1442 """
1443 n = M.nrows()
1444 if M.ncols() != n:
1445 raise ValueError("the matrix 'M' must be square")
1446
1447 # We don't need any adjoined elements...
1448 field = M.base_ring().base_ring()
1449
1450 blocks = []
1451 for z in M.list():
1452 a = z.list()[0] # real part, I guess
1453 b = z.list()[1] # imag part, I guess
1454 blocks.append(matrix(field, 2, [[a,b],[-b,a]]))
1455
1456 return matrix.block(field, n, blocks)
1457
1458
1459 @staticmethod
1460 def real_unembed(M):
1461 """
1462 The inverse of _embed_complex_matrix().
1463
1464 SETUP::
1465
1466 sage: from mjo.eja.eja_algebra import \
1467 ....: ComplexMatrixEuclideanJordanAlgebra
1468
1469 EXAMPLES::
1470
1471 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1472 ....: [-2, 1, -4, 3],
1473 ....: [ 9, 10, 11, 12],
1474 ....: [-10, 9, -12, 11] ])
1475 sage: ComplexMatrixEuclideanJordanAlgebra.real_unembed(A)
1476 [ 2*I + 1 4*I + 3]
1477 [ 10*I + 9 12*I + 11]
1478
1479 TESTS:
1480
1481 Unembedding is the inverse of embedding::
1482
1483 sage: set_random_seed()
1484 sage: F = QuadraticField(-1, 'I')
1485 sage: M = random_matrix(F, 3)
1486 sage: Me = ComplexMatrixEuclideanJordanAlgebra.real_embed(M)
1487 sage: ComplexMatrixEuclideanJordanAlgebra.real_unembed(Me) == M
1488 True
1489
1490 """
1491 n = ZZ(M.nrows())
1492 if M.ncols() != n:
1493 raise ValueError("the matrix 'M' must be square")
1494 if not n.mod(2).is_zero():
1495 raise ValueError("the matrix 'M' must be a complex embedding")
1496
1497 # If "M" was normalized, its base ring might have roots
1498 # adjoined and they can stick around after unembedding.
1499 field = M.base_ring()
1500 R = PolynomialRing(field, 'z')
1501 z = R.gen()
1502 if field is AA:
1503 # Sage doesn't know how to embed AA into QQbar, i.e. how
1504 # to adjoin sqrt(-1) to AA.
1505 F = QQbar
1506 else:
1507 F = field.extension(z**2 + 1, 'I', embedding=CLF(-1).sqrt())
1508 i = F.gen()
1509
1510 # Go top-left to bottom-right (reading order), converting every
1511 # 2-by-2 block we see to a single complex element.
1512 elements = []
1513 for k in range(n/2):
1514 for j in range(n/2):
1515 submat = M[2*k:2*k+2,2*j:2*j+2]
1516 if submat[0,0] != submat[1,1]:
1517 raise ValueError('bad on-diagonal submatrix')
1518 if submat[0,1] != -submat[1,0]:
1519 raise ValueError('bad off-diagonal submatrix')
1520 z = submat[0,0] + submat[0,1]*i
1521 elements.append(z)
1522
1523 return matrix(F, n/2, elements)
1524
1525
1526 @classmethod
1527 def natural_inner_product(cls,X,Y):
1528 """
1529 Compute a natural inner product in this algebra directly from
1530 its real embedding.
1531
1532 SETUP::
1533
1534 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1535
1536 TESTS:
1537
1538 This gives the same answer as the slow, default method implemented
1539 in :class:`MatrixEuclideanJordanAlgebra`::
1540
1541 sage: set_random_seed()
1542 sage: J = ComplexHermitianEJA.random_instance()
1543 sage: x,y = J.random_elements(2)
1544 sage: Xe = x.natural_representation()
1545 sage: Ye = y.natural_representation()
1546 sage: X = ComplexHermitianEJA.real_unembed(Xe)
1547 sage: Y = ComplexHermitianEJA.real_unembed(Ye)
1548 sage: expected = (X*Y).trace().real()
1549 sage: actual = ComplexHermitianEJA.natural_inner_product(Xe,Ye)
1550 sage: actual == expected
1551 True
1552
1553 """
1554 return RealMatrixEuclideanJordanAlgebra.natural_inner_product(X,Y)/2
1555
1556
1557 class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra):
1558 """
1559 The rank-n simple EJA consisting of complex Hermitian n-by-n
1560 matrices over the real numbers, the usual symmetric Jordan product,
1561 and the real-part-of-trace inner product. It has dimension `n^2` over
1562 the reals.
1563
1564 SETUP::
1565
1566 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1567
1568 EXAMPLES:
1569
1570 In theory, our "field" can be any subfield of the reals::
1571
1572 sage: ComplexHermitianEJA(2, RDF)
1573 Euclidean Jordan algebra of dimension 4 over Real Double Field
1574 sage: ComplexHermitianEJA(2, RR)
1575 Euclidean Jordan algebra of dimension 4 over Real Field with
1576 53 bits of precision
1577
1578 TESTS:
1579
1580 The dimension of this algebra is `n^2`::
1581
1582 sage: set_random_seed()
1583 sage: n_max = ComplexHermitianEJA._max_test_case_size()
1584 sage: n = ZZ.random_element(1, n_max)
1585 sage: J = ComplexHermitianEJA(n)
1586 sage: J.dimension() == n^2
1587 True
1588
1589 The Jordan multiplication is what we think it is::
1590
1591 sage: set_random_seed()
1592 sage: J = ComplexHermitianEJA.random_instance()
1593 sage: x,y = J.random_elements(2)
1594 sage: actual = (x*y).natural_representation()
1595 sage: X = x.natural_representation()
1596 sage: Y = y.natural_representation()
1597 sage: expected = (X*Y + Y*X)/2
1598 sage: actual == expected
1599 True
1600 sage: J(expected) == x*y
1601 True
1602
1603 We can change the generator prefix::
1604
1605 sage: ComplexHermitianEJA(2, prefix='z').gens()
1606 (z0, z1, z2, z3)
1607
1608 Our natural basis is normalized with respect to the natural inner
1609 product unless we specify otherwise::
1610
1611 sage: set_random_seed()
1612 sage: J = ComplexHermitianEJA.random_instance()
1613 sage: all( b.norm() == 1 for b in J.gens() )
1614 True
1615
1616 Since our natural basis is normalized with respect to the natural
1617 inner product, and since we know that this algebra is an EJA, any
1618 left-multiplication operator's matrix will be symmetric because
1619 natural->EJA basis representation is an isometry and within the EJA
1620 the operator is self-adjoint by the Jordan axiom::
1621
1622 sage: set_random_seed()
1623 sage: x = ComplexHermitianEJA.random_instance().random_element()
1624 sage: x.operator().matrix().is_symmetric()
1625 True
1626
1627 """
1628
1629 @classmethod
1630 def _denormalized_basis(cls, n, field):
1631 """
1632 Returns a basis for the space of complex Hermitian n-by-n matrices.
1633
1634 Why do we embed these? Basically, because all of numerical linear
1635 algebra assumes that you're working with vectors consisting of `n`
1636 entries from a field and scalars from the same field. There's no way
1637 to tell SageMath that (for example) the vectors contain complex
1638 numbers, while the scalar field is real.
1639
1640 SETUP::
1641
1642 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1643
1644 TESTS::
1645
1646 sage: set_random_seed()
1647 sage: n = ZZ.random_element(1,5)
1648 sage: field = QuadraticField(2, 'sqrt2')
1649 sage: B = ComplexHermitianEJA._denormalized_basis(n, field)
1650 sage: all( M.is_symmetric() for M in B)
1651 True
1652
1653 """
1654 R = PolynomialRing(field, 'z')
1655 z = R.gen()
1656 F = field.extension(z**2 + 1, 'I')
1657 I = F.gen()
1658
1659 # This is like the symmetric case, but we need to be careful:
1660 #
1661 # * We want conjugate-symmetry, not just symmetry.
1662 # * The diagonal will (as a result) be real.
1663 #
1664 S = []
1665 for i in range(n):
1666 for j in range(i+1):
1667 Eij = matrix(F, n, lambda k,l: k==i and l==j)
1668 if i == j:
1669 Sij = cls.real_embed(Eij)
1670 S.append(Sij)
1671 else:
1672 # The second one has a minus because it's conjugated.
1673 Sij_real = cls.real_embed(Eij + Eij.transpose())
1674 S.append(Sij_real)
1675 Sij_imag = cls.real_embed(I*Eij - I*Eij.transpose())
1676 S.append(Sij_imag)
1677
1678 # Since we embedded these, we can drop back to the "field" that we
1679 # started with instead of the complex extension "F".
1680 return ( s.change_ring(field) for s in S )
1681
1682
1683 def __init__(self, n, field=AA, **kwargs):
1684 basis = self._denormalized_basis(n,field)
1685 super(ComplexHermitianEJA,self).__init__(field, basis, **kwargs)
1686 self.rank.set_cache(n)
1687
1688
1689 class QuaternionMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra):
1690 @staticmethod
1691 def real_embed(M):
1692 """
1693 Embed the n-by-n quaternion matrix ``M`` into the space of real
1694 matrices of size 4n-by-4n by first sending each quaternion entry `z
1695 = a + bi + cj + dk` to the block-complex matrix ``[[a + bi,
1696 c+di],[-c + di, a-bi]]`, and then embedding those into a real
1697 matrix.
1698
1699 SETUP::
1700
1701 sage: from mjo.eja.eja_algebra import \
1702 ....: QuaternionMatrixEuclideanJordanAlgebra
1703
1704 EXAMPLES::
1705
1706 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1707 sage: i,j,k = Q.gens()
1708 sage: x = 1 + 2*i + 3*j + 4*k
1709 sage: M = matrix(Q, 1, [[x]])
1710 sage: QuaternionMatrixEuclideanJordanAlgebra.real_embed(M)
1711 [ 1 2 3 4]
1712 [-2 1 -4 3]
1713 [-3 4 1 -2]
1714 [-4 -3 2 1]
1715
1716 Embedding is a homomorphism (isomorphism, in fact)::
1717
1718 sage: set_random_seed()
1719 sage: n_max = QuaternionMatrixEuclideanJordanAlgebra._max_test_case_size()
1720 sage: n = ZZ.random_element(n_max)
1721 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1722 sage: X = random_matrix(Q, n)
1723 sage: Y = random_matrix(Q, n)
1724 sage: Xe = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X)
1725 sage: Ye = QuaternionMatrixEuclideanJordanAlgebra.real_embed(Y)
1726 sage: XYe = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X*Y)
1727 sage: Xe*Ye == XYe
1728 True
1729
1730 """
1731 quaternions = M.base_ring()
1732 n = M.nrows()
1733 if M.ncols() != n:
1734 raise ValueError("the matrix 'M' must be square")
1735
1736 F = QuadraticField(-1, 'I')
1737 i = F.gen()
1738
1739 blocks = []
1740 for z in M.list():
1741 t = z.coefficient_tuple()
1742 a = t[0]
1743 b = t[1]
1744 c = t[2]
1745 d = t[3]
1746 cplxM = matrix(F, 2, [[ a + b*i, c + d*i],
1747 [-c + d*i, a - b*i]])
1748 realM = ComplexMatrixEuclideanJordanAlgebra.real_embed(cplxM)
1749 blocks.append(realM)
1750
1751 # We should have real entries by now, so use the realest field
1752 # we've got for the return value.
1753 return matrix.block(quaternions.base_ring(), n, blocks)
1754
1755
1756
1757 @staticmethod
1758 def real_unembed(M):
1759 """
1760 The inverse of _embed_quaternion_matrix().
1761
1762 SETUP::
1763
1764 sage: from mjo.eja.eja_algebra import \
1765 ....: QuaternionMatrixEuclideanJordanAlgebra
1766
1767 EXAMPLES::
1768
1769 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1770 ....: [-2, 1, -4, 3],
1771 ....: [-3, 4, 1, -2],
1772 ....: [-4, -3, 2, 1]])
1773 sage: QuaternionMatrixEuclideanJordanAlgebra.real_unembed(M)
1774 [1 + 2*i + 3*j + 4*k]
1775
1776 TESTS:
1777
1778 Unembedding is the inverse of embedding::
1779
1780 sage: set_random_seed()
1781 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1782 sage: M = random_matrix(Q, 3)
1783 sage: Me = QuaternionMatrixEuclideanJordanAlgebra.real_embed(M)
1784 sage: QuaternionMatrixEuclideanJordanAlgebra.real_unembed(Me) == M
1785 True
1786
1787 """
1788 n = ZZ(M.nrows())
1789 if M.ncols() != n:
1790 raise ValueError("the matrix 'M' must be square")
1791 if not n.mod(4).is_zero():
1792 raise ValueError("the matrix 'M' must be a quaternion embedding")
1793
1794 # Use the base ring of the matrix to ensure that its entries can be
1795 # multiplied by elements of the quaternion algebra.
1796 field = M.base_ring()
1797 Q = QuaternionAlgebra(field,-1,-1)
1798 i,j,k = Q.gens()
1799
1800 # Go top-left to bottom-right (reading order), converting every
1801 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1802 # quaternion block.
1803 elements = []
1804 for l in range(n/4):
1805 for m in range(n/4):
1806 submat = ComplexMatrixEuclideanJordanAlgebra.real_unembed(
1807 M[4*l:4*l+4,4*m:4*m+4] )
1808 if submat[0,0] != submat[1,1].conjugate():
1809 raise ValueError('bad on-diagonal submatrix')
1810 if submat[0,1] != -submat[1,0].conjugate():
1811 raise ValueError('bad off-diagonal submatrix')
1812 z = submat[0,0].real()
1813 z += submat[0,0].imag()*i
1814 z += submat[0,1].real()*j
1815 z += submat[0,1].imag()*k
1816 elements.append(z)
1817
1818 return matrix(Q, n/4, elements)
1819
1820
1821 @classmethod
1822 def natural_inner_product(cls,X,Y):
1823 """
1824 Compute a natural inner product in this algebra directly from
1825 its real embedding.
1826
1827 SETUP::
1828
1829 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1830
1831 TESTS:
1832
1833 This gives the same answer as the slow, default method implemented
1834 in :class:`MatrixEuclideanJordanAlgebra`::
1835
1836 sage: set_random_seed()
1837 sage: J = QuaternionHermitianEJA.random_instance()
1838 sage: x,y = J.random_elements(2)
1839 sage: Xe = x.natural_representation()
1840 sage: Ye = y.natural_representation()
1841 sage: X = QuaternionHermitianEJA.real_unembed(Xe)
1842 sage: Y = QuaternionHermitianEJA.real_unembed(Ye)
1843 sage: expected = (X*Y).trace().coefficient_tuple()[0]
1844 sage: actual = QuaternionHermitianEJA.natural_inner_product(Xe,Ye)
1845 sage: actual == expected
1846 True
1847
1848 """
1849 return RealMatrixEuclideanJordanAlgebra.natural_inner_product(X,Y)/4
1850
1851
1852 class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra):
1853 """
1854 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1855 matrices, the usual symmetric Jordan product, and the
1856 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1857 the reals.
1858
1859 SETUP::
1860
1861 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1862
1863 EXAMPLES:
1864
1865 In theory, our "field" can be any subfield of the reals::
1866
1867 sage: QuaternionHermitianEJA(2, RDF)
1868 Euclidean Jordan algebra of dimension 6 over Real Double Field
1869 sage: QuaternionHermitianEJA(2, RR)
1870 Euclidean Jordan algebra of dimension 6 over Real Field with
1871 53 bits of precision
1872
1873 TESTS:
1874
1875 The dimension of this algebra is `2*n^2 - n`::
1876
1877 sage: set_random_seed()
1878 sage: n_max = QuaternionHermitianEJA._max_test_case_size()
1879 sage: n = ZZ.random_element(1, n_max)
1880 sage: J = QuaternionHermitianEJA(n)
1881 sage: J.dimension() == 2*(n^2) - n
1882 True
1883
1884 The Jordan multiplication is what we think it is::
1885
1886 sage: set_random_seed()
1887 sage: J = QuaternionHermitianEJA.random_instance()
1888 sage: x,y = J.random_elements(2)
1889 sage: actual = (x*y).natural_representation()
1890 sage: X = x.natural_representation()
1891 sage: Y = y.natural_representation()
1892 sage: expected = (X*Y + Y*X)/2
1893 sage: actual == expected
1894 True
1895 sage: J(expected) == x*y
1896 True
1897
1898 We can change the generator prefix::
1899
1900 sage: QuaternionHermitianEJA(2, prefix='a').gens()
1901 (a0, a1, a2, a3, a4, a5)
1902
1903 Our natural basis is normalized with respect to the natural inner
1904 product unless we specify otherwise::
1905
1906 sage: set_random_seed()
1907 sage: J = QuaternionHermitianEJA.random_instance()
1908 sage: all( b.norm() == 1 for b in J.gens() )
1909 True
1910
1911 Since our natural basis is normalized with respect to the natural
1912 inner product, and since we know that this algebra is an EJA, any
1913 left-multiplication operator's matrix will be symmetric because
1914 natural->EJA basis representation is an isometry and within the EJA
1915 the operator is self-adjoint by the Jordan axiom::
1916
1917 sage: set_random_seed()
1918 sage: x = QuaternionHermitianEJA.random_instance().random_element()
1919 sage: x.operator().matrix().is_symmetric()
1920 True
1921
1922 """
1923 @classmethod
1924 def _denormalized_basis(cls, n, field):
1925 """
1926 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1927
1928 Why do we embed these? Basically, because all of numerical
1929 linear algebra assumes that you're working with vectors consisting
1930 of `n` entries from a field and scalars from the same field. There's
1931 no way to tell SageMath that (for example) the vectors contain
1932 complex numbers, while the scalar field is real.
1933
1934 SETUP::
1935
1936 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1937
1938 TESTS::
1939
1940 sage: set_random_seed()
1941 sage: n = ZZ.random_element(1,5)
1942 sage: B = QuaternionHermitianEJA._denormalized_basis(n,QQ)
1943 sage: all( M.is_symmetric() for M in B )
1944 True
1945
1946 """
1947 Q = QuaternionAlgebra(QQ,-1,-1)
1948 I,J,K = Q.gens()
1949
1950 # This is like the symmetric case, but we need to be careful:
1951 #
1952 # * We want conjugate-symmetry, not just symmetry.
1953 # * The diagonal will (as a result) be real.
1954 #
1955 S = []
1956 for i in range(n):
1957 for j in range(i+1):
1958 Eij = matrix(Q, n, lambda k,l: k==i and l==j)
1959 if i == j:
1960 Sij = cls.real_embed(Eij)
1961 S.append(Sij)
1962 else:
1963 # The second, third, and fourth ones have a minus
1964 # because they're conjugated.
1965 Sij_real = cls.real_embed(Eij + Eij.transpose())
1966 S.append(Sij_real)
1967 Sij_I = cls.real_embed(I*Eij - I*Eij.transpose())
1968 S.append(Sij_I)
1969 Sij_J = cls.real_embed(J*Eij - J*Eij.transpose())
1970 S.append(Sij_J)
1971 Sij_K = cls.real_embed(K*Eij - K*Eij.transpose())
1972 S.append(Sij_K)
1973
1974 # Since we embedded these, we can drop back to the "field" that we
1975 # started with instead of the quaternion algebra "Q".
1976 return ( s.change_ring(field) for s in S )
1977
1978
1979 def __init__(self, n, field=AA, **kwargs):
1980 basis = self._denormalized_basis(n,field)
1981 super(QuaternionHermitianEJA,self).__init__(field, basis, **kwargs)
1982 self.rank.set_cache(n)
1983
1984
1985 class BilinearFormEJA(FiniteDimensionalEuclideanJordanAlgebra):
1986 r"""
1987 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1988 with the half-trace inner product and jordan product ``x*y =
1989 (x0*y0 + <B*x_bar,y_bar>, x0*y_bar + y0*x_bar)`` where ``B`` is a
1990 symmetric positive-definite "bilinear form" matrix. It has
1991 dimension `n` over the reals, and reduces to the ``JordanSpinEJA``
1992 when ``B`` is the identity matrix of order ``n-1``.
1993
1994 SETUP::
1995
1996 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1997 ....: JordanSpinEJA)
1998
1999 EXAMPLES:
2000
2001 When no bilinear form is specified, the identity matrix is used,
2002 and the resulting algebra is the Jordan spin algebra::
2003
2004 sage: J0 = BilinearFormEJA(3)
2005 sage: J1 = JordanSpinEJA(3)
2006 sage: J0.multiplication_table() == J0.multiplication_table()
2007 True
2008
2009 TESTS:
2010
2011 We can create a zero-dimensional algebra::
2012
2013 sage: J = BilinearFormEJA(0)
2014 sage: J.basis()
2015 Finite family {}
2016
2017 We can check the multiplication condition given in the Jordan, von
2018 Neumann, and Wigner paper (and also discussed on my "On the
2019 symmetry..." paper). Note that this relies heavily on the standard
2020 choice of basis, as does anything utilizing the bilinear form matrix::
2021
2022 sage: set_random_seed()
2023 sage: n = ZZ.random_element(5)
2024 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2025 sage: B = M.transpose()*M
2026 sage: J = BilinearFormEJA(n, B=B)
2027 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
2028 sage: V = J.vector_space()
2029 sage: sis = [ J.from_vector(V([0] + (M.inverse()*ei).list()))
2030 ....: for ei in eis ]
2031 sage: actual = [ sis[i]*sis[j]
2032 ....: for i in range(n-1)
2033 ....: for j in range(n-1) ]
2034 sage: expected = [ J.one() if i == j else J.zero()
2035 ....: for i in range(n-1)
2036 ....: for j in range(n-1) ]
2037 sage: actual == expected
2038 True
2039 """
2040 def __init__(self, n, field=AA, B=None, **kwargs):
2041 if B is None:
2042 self._B = matrix.identity(field, max(0,n-1))
2043 else:
2044 self._B = B
2045
2046 V = VectorSpace(field, n)
2047 mult_table = [[V.zero() for j in range(n)] for i in range(n)]
2048 for i in range(n):
2049 for j in range(n):
2050 x = V.gen(i)
2051 y = V.gen(j)
2052 x0 = x[0]
2053 xbar = x[1:]
2054 y0 = y[0]
2055 ybar = y[1:]
2056 z0 = x0*y0 + (self._B*xbar).inner_product(ybar)
2057 zbar = y0*xbar + x0*ybar
2058 z = V([z0] + zbar.list())
2059 mult_table[i][j] = z
2060
2061 # The rank of this algebra is two, unless we're in a
2062 # one-dimensional ambient space (because the rank is bounded
2063 # by the ambient dimension).
2064 fdeja = super(BilinearFormEJA, self)
2065 fdeja.__init__(field, mult_table, **kwargs)
2066 self.rank.set_cache(min(n,2))
2067
2068 def inner_product(self, x, y):
2069 r"""
2070 Half of the trace inner product.
2071
2072 This is defined so that the special case of the Jordan spin
2073 algebra gets the usual inner product.
2074
2075 SETUP::
2076
2077 sage: from mjo.eja.eja_algebra import BilinearFormEJA
2078
2079 TESTS:
2080
2081 Ensure that this is one-half of the trace inner-product when
2082 the algebra isn't just the reals (when ``n`` isn't one). This
2083 is in Faraut and Koranyi, and also my "On the symmetry..."
2084 paper::
2085
2086 sage: set_random_seed()
2087 sage: n = ZZ.random_element(2,5)
2088 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2089 sage: B = M.transpose()*M
2090 sage: J = BilinearFormEJA(n, B=B)
2091 sage: x = J.random_element()
2092 sage: y = J.random_element()
2093 sage: x.inner_product(y) == (x*y).trace()/2
2094 True
2095
2096 """
2097 xvec = x.to_vector()
2098 xbar = xvec[1:]
2099 yvec = y.to_vector()
2100 ybar = yvec[1:]
2101 return x[0]*y[0] + (self._B*xbar).inner_product(ybar)
2102
2103
2104 class JordanSpinEJA(BilinearFormEJA):
2105 """
2106 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2107 with the usual inner product and jordan product ``x*y =
2108 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2109 the reals.
2110
2111 SETUP::
2112
2113 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2114
2115 EXAMPLES:
2116
2117 This multiplication table can be verified by hand::
2118
2119 sage: J = JordanSpinEJA(4)
2120 sage: e0,e1,e2,e3 = J.gens()
2121 sage: e0*e0
2122 e0
2123 sage: e0*e1
2124 e1
2125 sage: e0*e2
2126 e2
2127 sage: e0*e3
2128 e3
2129 sage: e1*e2
2130 0
2131 sage: e1*e3
2132 0
2133 sage: e2*e3
2134 0
2135
2136 We can change the generator prefix::
2137
2138 sage: JordanSpinEJA(2, prefix='B').gens()
2139 (B0, B1)
2140
2141 TESTS:
2142
2143 Ensure that we have the usual inner product on `R^n`::
2144
2145 sage: set_random_seed()
2146 sage: J = JordanSpinEJA.random_instance()
2147 sage: x,y = J.random_elements(2)
2148 sage: X = x.natural_representation()
2149 sage: Y = y.natural_representation()
2150 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
2151 True
2152
2153 """
2154 def __init__(self, n, field=AA, **kwargs):
2155 # This is a special case of the BilinearFormEJA with the identity
2156 # matrix as its bilinear form.
2157 return super(JordanSpinEJA, self).__init__(n, field, **kwargs)
2158
2159
2160 class TrivialEJA(FiniteDimensionalEuclideanJordanAlgebra):
2161 """
2162 The trivial Euclidean Jordan algebra consisting of only a zero element.
2163
2164 SETUP::
2165
2166 sage: from mjo.eja.eja_algebra import TrivialEJA
2167
2168 EXAMPLES::
2169
2170 sage: J = TrivialEJA()
2171 sage: J.dimension()
2172 0
2173 sage: J.zero()
2174 0
2175 sage: J.one()
2176 0
2177 sage: 7*J.one()*12*J.one()
2178 0
2179 sage: J.one().inner_product(J.one())
2180 0
2181 sage: J.one().norm()
2182 0
2183 sage: J.one().subalgebra_generated_by()
2184 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2185 sage: J.rank()
2186 0
2187
2188 """
2189 def __init__(self, field=AA, **kwargs):
2190 mult_table = []
2191 fdeja = super(TrivialEJA, self)
2192 # The rank is zero using my definition, namely the dimension of the
2193 # largest subalgebra generated by any element.
2194 fdeja.__init__(field, mult_table, **kwargs)
2195 self.rank.set_cache(0)