]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_algebra.py
eja: require "field" argument for matrix basis functions.
[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 sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra
9 from sage.categories.magmatic_algebras import MagmaticAlgebras
10 from sage.combinat.free_module import CombinatorialFreeModule
11 from sage.matrix.constructor import matrix
12 from sage.matrix.matrix_space import MatrixSpace
13 from sage.misc.cachefunc import cached_method
14 from sage.misc.prandom import choice
15 from sage.misc.table import table
16 from sage.modules.free_module import FreeModule, VectorSpace
17 from sage.rings.integer_ring import ZZ
18 from sage.rings.number_field.number_field import QuadraticField
19 from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
20 from sage.rings.rational_field import QQ
21 from sage.structure.element import is_Matrix
22
23 from mjo.eja.eja_element import FiniteDimensionalEuclideanJordanAlgebraElement
24 from mjo.eja.eja_utils import _mat2vec
25
26 class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
27 # This is an ugly hack needed to prevent the category framework
28 # from implementing a coercion from our base ring (e.g. the
29 # rationals) into the algebra. First of all -- such a coercion is
30 # nonsense to begin with. But more importantly, it tries to do so
31 # in the category of rings, and since our algebras aren't
32 # associative they generally won't be rings.
33 _no_generic_basering_coercion = True
34
35 def __init__(self,
36 field,
37 mult_table,
38 rank,
39 prefix='e',
40 category=None,
41 natural_basis=None):
42 """
43 SETUP::
44
45 sage: from mjo.eja.eja_algebra import random_eja
46
47 EXAMPLES:
48
49 By definition, Jordan multiplication commutes::
50
51 sage: set_random_seed()
52 sage: J = random_eja()
53 sage: x = J.random_element()
54 sage: y = J.random_element()
55 sage: x*y == y*x
56 True
57
58 """
59 self._rank = rank
60 self._natural_basis = natural_basis
61
62 if category is None:
63 category = MagmaticAlgebras(field).FiniteDimensional()
64 category = category.WithBasis().Unital()
65
66 fda = super(FiniteDimensionalEuclideanJordanAlgebra, self)
67 fda.__init__(field,
68 range(len(mult_table)),
69 prefix=prefix,
70 category=category)
71 self.print_options(bracket='')
72
73 # The multiplication table we're given is necessarily in terms
74 # of vectors, because we don't have an algebra yet for
75 # anything to be an element of. However, it's faster in the
76 # long run to have the multiplication table be in terms of
77 # algebra elements. We do this after calling the superclass
78 # constructor so that from_vector() knows what to do.
79 self._multiplication_table = [ map(lambda x: self.from_vector(x), ls)
80 for ls in mult_table ]
81
82
83 def _element_constructor_(self, elt):
84 """
85 Construct an element of this algebra from its natural
86 representation.
87
88 This gets called only after the parent element _call_ method
89 fails to find a coercion for the argument.
90
91 SETUP::
92
93 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
94 ....: RealCartesianProductEJA,
95 ....: RealSymmetricEJA)
96
97 EXAMPLES:
98
99 The identity in `S^n` is converted to the identity in the EJA::
100
101 sage: J = RealSymmetricEJA(3)
102 sage: I = matrix.identity(QQ,3)
103 sage: J(I) == J.one()
104 True
105
106 This skew-symmetric matrix can't be represented in the EJA::
107
108 sage: J = RealSymmetricEJA(3)
109 sage: A = matrix(QQ,3, lambda i,j: i-j)
110 sage: J(A)
111 Traceback (most recent call last):
112 ...
113 ArithmeticError: vector is not in free module
114
115 TESTS:
116
117 Ensure that we can convert any element of the two non-matrix
118 simple algebras (whose natural representations are their usual
119 vector representations) back and forth faithfully::
120
121 sage: set_random_seed()
122 sage: J = RealCartesianProductEJA(5)
123 sage: x = J.random_element()
124 sage: J(x.to_vector().column()) == x
125 True
126 sage: J = JordanSpinEJA(5)
127 sage: x = J.random_element()
128 sage: J(x.to_vector().column()) == x
129 True
130
131 """
132 if elt == 0:
133 # The superclass implementation of random_element()
134 # needs to be able to coerce "0" into the algebra.
135 return self.zero()
136
137 natural_basis = self.natural_basis()
138 if elt not in natural_basis[0].matrix_space():
139 raise ValueError("not a naturally-represented algebra element")
140
141 # Thanks for nothing! Matrix spaces aren't vector
142 # spaces in Sage, so we have to figure out its
143 # natural-basis coordinates ourselves.
144 V = VectorSpace(elt.base_ring(), elt.nrows()*elt.ncols())
145 W = V.span_of_basis( _mat2vec(s) for s in natural_basis )
146 coords = W.coordinate_vector(_mat2vec(elt))
147 return self.from_vector(coords)
148
149
150 def _repr_(self):
151 """
152 Return a string representation of ``self``.
153
154 SETUP::
155
156 sage: from mjo.eja.eja_algebra import JordanSpinEJA
157
158 TESTS:
159
160 Ensure that it says what we think it says::
161
162 sage: JordanSpinEJA(2, field=QQ)
163 Euclidean Jordan algebra of dimension 2 over Rational Field
164 sage: JordanSpinEJA(3, field=RDF)
165 Euclidean Jordan algebra of dimension 3 over Real Double Field
166
167 """
168 fmt = "Euclidean Jordan algebra of dimension {} over {}"
169 return fmt.format(self.dimension(), self.base_ring())
170
171 def product_on_basis(self, i, j):
172 return self._multiplication_table[i][j]
173
174 def _a_regular_element(self):
175 """
176 Guess a regular element. Needed to compute the basis for our
177 characteristic polynomial coefficients.
178
179 SETUP::
180
181 sage: from mjo.eja.eja_algebra import random_eja
182
183 TESTS:
184
185 Ensure that this hacky method succeeds for every algebra that we
186 know how to construct::
187
188 sage: set_random_seed()
189 sage: J = random_eja()
190 sage: J._a_regular_element().is_regular()
191 True
192
193 """
194 gs = self.gens()
195 z = self.sum( (i+1)*gs[i] for i in range(len(gs)) )
196 if not z.is_regular():
197 raise ValueError("don't know a regular element")
198 return z
199
200
201 @cached_method
202 def _charpoly_basis_space(self):
203 """
204 Return the vector space spanned by the basis used in our
205 characteristic polynomial coefficients. This is used not only to
206 compute those coefficients, but also any time we need to
207 evaluate the coefficients (like when we compute the trace or
208 determinant).
209 """
210 z = self._a_regular_element()
211 # Don't use the parent vector space directly here in case this
212 # happens to be a subalgebra. In that case, we would be e.g.
213 # two-dimensional but span_of_basis() would expect three
214 # coordinates.
215 V = VectorSpace(self.base_ring(), self.vector_space().dimension())
216 basis = [ (z**k).to_vector() for k in range(self.rank()) ]
217 V1 = V.span_of_basis( basis )
218 b = (V1.basis() + V1.complement().basis())
219 return V.span_of_basis(b)
220
221
222 @cached_method
223 def _charpoly_coeff(self, i):
224 """
225 Return the coefficient polynomial "a_{i}" of this algebra's
226 general characteristic polynomial.
227
228 Having this be a separate cached method lets us compute and
229 store the trace/determinant (a_{r-1} and a_{0} respectively)
230 separate from the entire characteristic polynomial.
231 """
232 (A_of_x, x, xr, detA) = self._charpoly_matrix_system()
233 R = A_of_x.base_ring()
234 if i >= self.rank():
235 # Guaranteed by theory
236 return R.zero()
237
238 # Danger: the in-place modification is done for performance
239 # reasons (reconstructing a matrix with huge polynomial
240 # entries is slow), but I don't know how cached_method works,
241 # so it's highly possible that we're modifying some global
242 # list variable by reference, here. In other words, you
243 # probably shouldn't call this method twice on the same
244 # algebra, at the same time, in two threads
245 Ai_orig = A_of_x.column(i)
246 A_of_x.set_column(i,xr)
247 numerator = A_of_x.det()
248 A_of_x.set_column(i,Ai_orig)
249
250 # We're relying on the theory here to ensure that each a_i is
251 # indeed back in R, and the added negative signs are to make
252 # the whole charpoly expression sum to zero.
253 return R(-numerator/detA)
254
255
256 @cached_method
257 def _charpoly_matrix_system(self):
258 """
259 Compute the matrix whose entries A_ij are polynomials in
260 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
261 corresponding to `x^r` and the determinent of the matrix A =
262 [A_ij]. In other words, all of the fixed (cachable) data needed
263 to compute the coefficients of the characteristic polynomial.
264 """
265 r = self.rank()
266 n = self.dimension()
267
268 # Turn my vector space into a module so that "vectors" can
269 # have multivatiate polynomial entries.
270 names = tuple('X' + str(i) for i in range(1,n+1))
271 R = PolynomialRing(self.base_ring(), names)
272
273 # Using change_ring() on the parent's vector space doesn't work
274 # here because, in a subalgebra, that vector space has a basis
275 # and change_ring() tries to bring the basis along with it. And
276 # that doesn't work unless the new ring is a PID, which it usually
277 # won't be.
278 V = FreeModule(R,n)
279
280 # Now let x = (X1,X2,...,Xn) be the vector whose entries are
281 # indeterminates...
282 x = V(names)
283
284 # And figure out the "left multiplication by x" matrix in
285 # that setting.
286 lmbx_cols = []
287 monomial_matrices = [ self.monomial(i).operator().matrix()
288 for i in range(n) ] # don't recompute these!
289 for k in range(n):
290 ek = self.monomial(k).to_vector()
291 lmbx_cols.append(
292 sum( x[i]*(monomial_matrices[i]*ek)
293 for i in range(n) ) )
294 Lx = matrix.column(R, lmbx_cols)
295
296 # Now we can compute powers of x "symbolically"
297 x_powers = [self.one().to_vector(), x]
298 for d in range(2, r+1):
299 x_powers.append( Lx*(x_powers[-1]) )
300
301 idmat = matrix.identity(R, n)
302
303 W = self._charpoly_basis_space()
304 W = W.change_ring(R.fraction_field())
305
306 # Starting with the standard coordinates x = (X1,X2,...,Xn)
307 # and then converting the entries to W-coordinates allows us
308 # to pass in the standard coordinates to the charpoly and get
309 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
310 # we have
311 #
312 # W.coordinates(x^2) eval'd at (standard z-coords)
313 # =
314 # W-coords of (z^2)
315 # =
316 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
317 #
318 # We want the middle equivalent thing in our matrix, but use
319 # the first equivalent thing instead so that we can pass in
320 # standard coordinates.
321 x_powers = [ W.coordinate_vector(xp) for xp in x_powers ]
322 l2 = [idmat.column(k-1) for k in range(r+1, n+1)]
323 A_of_x = matrix.column(R, n, (x_powers[:r] + l2))
324 return (A_of_x, x, x_powers[r], A_of_x.det())
325
326
327 @cached_method
328 def characteristic_polynomial(self):
329 """
330 Return a characteristic polynomial that works for all elements
331 of this algebra.
332
333 The resulting polynomial has `n+1` variables, where `n` is the
334 dimension of this algebra. The first `n` variables correspond to
335 the coordinates of an algebra element: when evaluated at the
336 coordinates of an algebra element with respect to a certain
337 basis, the result is a univariate polynomial (in the one
338 remaining variable ``t``), namely the characteristic polynomial
339 of that element.
340
341 SETUP::
342
343 sage: from mjo.eja.eja_algebra import JordanSpinEJA
344
345 EXAMPLES:
346
347 The characteristic polynomial in the spin algebra is given in
348 Alizadeh, Example 11.11::
349
350 sage: J = JordanSpinEJA(3)
351 sage: p = J.characteristic_polynomial(); p
352 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
353 sage: xvec = J.one().to_vector()
354 sage: p(*xvec)
355 t^2 - 2*t + 1
356
357 """
358 r = self.rank()
359 n = self.dimension()
360
361 # The list of coefficient polynomials a_1, a_2, ..., a_n.
362 a = [ self._charpoly_coeff(i) for i in range(n) ]
363
364 # We go to a bit of trouble here to reorder the
365 # indeterminates, so that it's easier to evaluate the
366 # characteristic polynomial at x's coordinates and get back
367 # something in terms of t, which is what we want.
368 R = a[0].parent()
369 S = PolynomialRing(self.base_ring(),'t')
370 t = S.gen(0)
371 S = PolynomialRing(S, R.variable_names())
372 t = S(t)
373
374 # Note: all entries past the rth should be zero. The
375 # coefficient of the highest power (x^r) is 1, but it doesn't
376 # appear in the solution vector which contains coefficients
377 # for the other powers (to make them sum to x^r).
378 if (r < n):
379 a[r] = 1 # corresponds to x^r
380 else:
381 # When the rank is equal to the dimension, trying to
382 # assign a[r] goes out-of-bounds.
383 a.append(1) # corresponds to x^r
384
385 return sum( a[k]*(t**k) for k in range(len(a)) )
386
387
388 def inner_product(self, x, y):
389 """
390 The inner product associated with this Euclidean Jordan algebra.
391
392 Defaults to the trace inner product, but can be overridden by
393 subclasses if they are sure that the necessary properties are
394 satisfied.
395
396 SETUP::
397
398 sage: from mjo.eja.eja_algebra import random_eja
399
400 EXAMPLES:
401
402 The inner product must satisfy its axiom for this algebra to truly
403 be a Euclidean Jordan Algebra::
404
405 sage: set_random_seed()
406 sage: J = random_eja()
407 sage: x = J.random_element()
408 sage: y = J.random_element()
409 sage: z = J.random_element()
410 sage: (x*y).inner_product(z) == y.inner_product(x*z)
411 True
412
413 """
414 if (not x in self) or (not y in self):
415 raise TypeError("arguments must live in this algebra")
416 return x.trace_inner_product(y)
417
418
419 def is_trivial(self):
420 """
421 Return whether or not this algebra is trivial.
422
423 A trivial algebra contains only the zero element.
424
425 SETUP::
426
427 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
428
429 EXAMPLES::
430
431 sage: J = ComplexHermitianEJA(3)
432 sage: J.is_trivial()
433 False
434 sage: A = J.zero().subalgebra_generated_by()
435 sage: A.is_trivial()
436 True
437
438 """
439 return self.dimension() == 0
440
441
442 def multiplication_table(self):
443 """
444 Return a visual representation of this algebra's multiplication
445 table (on basis elements).
446
447 SETUP::
448
449 sage: from mjo.eja.eja_algebra import JordanSpinEJA
450
451 EXAMPLES::
452
453 sage: J = JordanSpinEJA(4)
454 sage: J.multiplication_table()
455 +----++----+----+----+----+
456 | * || e0 | e1 | e2 | e3 |
457 +====++====+====+====+====+
458 | e0 || e0 | e1 | e2 | e3 |
459 +----++----+----+----+----+
460 | e1 || e1 | e0 | 0 | 0 |
461 +----++----+----+----+----+
462 | e2 || e2 | 0 | e0 | 0 |
463 +----++----+----+----+----+
464 | e3 || e3 | 0 | 0 | e0 |
465 +----++----+----+----+----+
466
467 """
468 M = list(self._multiplication_table) # copy
469 for i in range(len(M)):
470 # M had better be "square"
471 M[i] = [self.monomial(i)] + M[i]
472 M = [["*"] + list(self.gens())] + M
473 return table(M, header_row=True, header_column=True, frame=True)
474
475
476 def natural_basis(self):
477 """
478 Return a more-natural representation of this algebra's basis.
479
480 Every finite-dimensional Euclidean Jordan Algebra is a direct
481 sum of five simple algebras, four of which comprise Hermitian
482 matrices. This method returns the original "natural" basis
483 for our underlying vector space. (Typically, the natural basis
484 is used to construct the multiplication table in the first place.)
485
486 Note that this will always return a matrix. The standard basis
487 in `R^n` will be returned as `n`-by-`1` column matrices.
488
489 SETUP::
490
491 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
492 ....: RealSymmetricEJA)
493
494 EXAMPLES::
495
496 sage: J = RealSymmetricEJA(2)
497 sage: J.basis()
498 Finite family {0: e0, 1: e1, 2: e2}
499 sage: J.natural_basis()
500 (
501 [1 0] [0 1] [0 0]
502 [0 0], [1 0], [0 1]
503 )
504
505 ::
506
507 sage: J = JordanSpinEJA(2)
508 sage: J.basis()
509 Finite family {0: e0, 1: e1}
510 sage: J.natural_basis()
511 (
512 [1] [0]
513 [0], [1]
514 )
515
516 """
517 if self._natural_basis is None:
518 M = self.natural_basis_space()
519 return tuple( M(b.to_vector()) for b in self.basis() )
520 else:
521 return self._natural_basis
522
523
524 def natural_basis_space(self):
525 """
526 Return the matrix space in which this algebra's natural basis
527 elements live.
528 """
529 if self._natural_basis is None or len(self._natural_basis) == 0:
530 return MatrixSpace(self.base_ring(), self.dimension(), 1)
531 else:
532 return self._natural_basis[0].matrix_space()
533
534
535 @cached_method
536 def one(self):
537 """
538 Return the unit element of this algebra.
539
540 SETUP::
541
542 sage: from mjo.eja.eja_algebra import (RealCartesianProductEJA,
543 ....: random_eja)
544
545 EXAMPLES::
546
547 sage: J = RealCartesianProductEJA(5)
548 sage: J.one()
549 e0 + e1 + e2 + e3 + e4
550
551 TESTS:
552
553 The identity element acts like the identity::
554
555 sage: set_random_seed()
556 sage: J = random_eja()
557 sage: x = J.random_element()
558 sage: J.one()*x == x and x*J.one() == x
559 True
560
561 The matrix of the unit element's operator is the identity::
562
563 sage: set_random_seed()
564 sage: J = random_eja()
565 sage: actual = J.one().operator().matrix()
566 sage: expected = matrix.identity(J.base_ring(), J.dimension())
567 sage: actual == expected
568 True
569
570 """
571 # We can brute-force compute the matrices of the operators
572 # that correspond to the basis elements of this algebra.
573 # If some linear combination of those basis elements is the
574 # algebra identity, then the same linear combination of
575 # their matrices has to be the identity matrix.
576 #
577 # Of course, matrices aren't vectors in sage, so we have to
578 # appeal to the "long vectors" isometry.
579 oper_vecs = [ _mat2vec(g.operator().matrix()) for g in self.gens() ]
580
581 # Now we use basis linear algebra to find the coefficients,
582 # of the matrices-as-vectors-linear-combination, which should
583 # work for the original algebra basis too.
584 A = matrix.column(self.base_ring(), oper_vecs)
585
586 # We used the isometry on the left-hand side already, but we
587 # still need to do it for the right-hand side. Recall that we
588 # wanted something that summed to the identity matrix.
589 b = _mat2vec( matrix.identity(self.base_ring(), self.dimension()) )
590
591 # Now if there's an identity element in the algebra, this should work.
592 coeffs = A.solve_right(b)
593 return self.linear_combination(zip(self.gens(), coeffs))
594
595
596 def random_element(self):
597 # Temporary workaround for https://trac.sagemath.org/ticket/28327
598 if self.is_trivial():
599 return self.zero()
600 else:
601 s = super(FiniteDimensionalEuclideanJordanAlgebra, self)
602 return s.random_element()
603
604
605 def rank(self):
606 """
607 Return the rank of this EJA.
608
609 ALGORITHM:
610
611 The author knows of no algorithm to compute the rank of an EJA
612 where only the multiplication table is known. In lieu of one, we
613 require the rank to be specified when the algebra is created,
614 and simply pass along that number here.
615
616 SETUP::
617
618 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
619 ....: RealSymmetricEJA,
620 ....: ComplexHermitianEJA,
621 ....: QuaternionHermitianEJA,
622 ....: random_eja)
623
624 EXAMPLES:
625
626 The rank of the Jordan spin algebra is always two::
627
628 sage: JordanSpinEJA(2).rank()
629 2
630 sage: JordanSpinEJA(3).rank()
631 2
632 sage: JordanSpinEJA(4).rank()
633 2
634
635 The rank of the `n`-by-`n` Hermitian real, complex, or
636 quaternion matrices is `n`::
637
638 sage: RealSymmetricEJA(2).rank()
639 2
640 sage: ComplexHermitianEJA(2).rank()
641 2
642 sage: QuaternionHermitianEJA(2).rank()
643 2
644 sage: RealSymmetricEJA(5).rank()
645 5
646 sage: ComplexHermitianEJA(5).rank()
647 5
648 sage: QuaternionHermitianEJA(5).rank()
649 5
650
651 TESTS:
652
653 Ensure that every EJA that we know how to construct has a
654 positive integer rank::
655
656 sage: set_random_seed()
657 sage: r = random_eja().rank()
658 sage: r in ZZ and r > 0
659 True
660
661 """
662 return self._rank
663
664
665 def vector_space(self):
666 """
667 Return the vector space that underlies this algebra.
668
669 SETUP::
670
671 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
672
673 EXAMPLES::
674
675 sage: J = RealSymmetricEJA(2)
676 sage: J.vector_space()
677 Vector space of dimension 3 over Rational Field
678
679 """
680 return self.zero().to_vector().parent().ambient_vector_space()
681
682
683 Element = FiniteDimensionalEuclideanJordanAlgebraElement
684
685
686 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
687 """
688 Return the Euclidean Jordan Algebra corresponding to the set
689 `R^n` under the Hadamard product.
690
691 Note: this is nothing more than the Cartesian product of ``n``
692 copies of the spin algebra. Once Cartesian product algebras
693 are implemented, this can go.
694
695 SETUP::
696
697 sage: from mjo.eja.eja_algebra import RealCartesianProductEJA
698
699 EXAMPLES:
700
701 This multiplication table can be verified by hand::
702
703 sage: J = RealCartesianProductEJA(3)
704 sage: e0,e1,e2 = J.gens()
705 sage: e0*e0
706 e0
707 sage: e0*e1
708 0
709 sage: e0*e2
710 0
711 sage: e1*e1
712 e1
713 sage: e1*e2
714 0
715 sage: e2*e2
716 e2
717
718 TESTS:
719
720 We can change the generator prefix::
721
722 sage: RealCartesianProductEJA(3, prefix='r').gens()
723 (r0, r1, r2)
724
725 Our inner product satisfies the Jordan axiom::
726
727 sage: set_random_seed()
728 sage: n = ZZ.random_element(1,5)
729 sage: J = RealCartesianProductEJA(n)
730 sage: x = J.random_element()
731 sage: y = J.random_element()
732 sage: z = J.random_element()
733 sage: (x*y).inner_product(z) == y.inner_product(x*z)
734 True
735
736 """
737 def __init__(self, n, field=QQ, **kwargs):
738 V = VectorSpace(field, n)
739 mult_table = [ [ V.gen(i)*(i == j) for j in range(n) ]
740 for i in range(n) ]
741
742 fdeja = super(RealCartesianProductEJA, self)
743 return fdeja.__init__(field, mult_table, rank=n, **kwargs)
744
745 def inner_product(self, x, y):
746 return _usual_ip(x,y)
747
748
749 def random_eja():
750 """
751 Return a "random" finite-dimensional Euclidean Jordan Algebra.
752
753 ALGORITHM:
754
755 For now, we choose a random natural number ``n`` (greater than zero)
756 and then give you back one of the following:
757
758 * The cartesian product of the rational numbers ``n`` times; this is
759 ``QQ^n`` with the Hadamard product.
760
761 * The Jordan spin algebra on ``QQ^n``.
762
763 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
764 product.
765
766 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
767 in the space of ``2n``-by-``2n`` real symmetric matrices.
768
769 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
770 in the space of ``4n``-by-``4n`` real symmetric matrices.
771
772 Later this might be extended to return Cartesian products of the
773 EJAs above.
774
775 SETUP::
776
777 sage: from mjo.eja.eja_algebra import random_eja
778
779 TESTS::
780
781 sage: random_eja()
782 Euclidean Jordan algebra of dimension...
783
784 """
785
786 # The max_n component lets us choose different upper bounds on the
787 # value "n" that gets passed to the constructor. This is needed
788 # because e.g. R^{10} is reasonable to test, while the Hermitian
789 # 10-by-10 quaternion matrices are not.
790 (constructor, max_n) = choice([(RealCartesianProductEJA, 6),
791 (JordanSpinEJA, 6),
792 (RealSymmetricEJA, 5),
793 (ComplexHermitianEJA, 4),
794 (QuaternionHermitianEJA, 3)])
795 n = ZZ.random_element(1, max_n)
796 return constructor(n, field=QQ)
797
798
799
800 def _real_symmetric_basis(n, field):
801 """
802 Return a basis for the space of real symmetric n-by-n matrices.
803 """
804 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
805 # coordinates.
806 S = []
807 for i in xrange(n):
808 for j in xrange(i+1):
809 Eij = matrix(field, n, lambda k,l: k==i and l==j)
810 if i == j:
811 Sij = Eij
812 else:
813 # Beware, orthogonal but not normalized!
814 Sij = Eij + Eij.transpose()
815 S.append(Sij)
816 return tuple(S)
817
818
819 def _complex_hermitian_basis(n, field):
820 """
821 Returns a basis for the space of complex Hermitian n-by-n matrices.
822
823 SETUP::
824
825 sage: from mjo.eja.eja_algebra import _complex_hermitian_basis
826
827 TESTS::
828
829 sage: set_random_seed()
830 sage: n = ZZ.random_element(1,5)
831 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
832 True
833
834 """
835 F = QuadraticField(-1, 'I')
836 I = F.gen()
837
838 # This is like the symmetric case, but we need to be careful:
839 #
840 # * We want conjugate-symmetry, not just symmetry.
841 # * The diagonal will (as a result) be real.
842 #
843 S = []
844 for i in xrange(n):
845 for j in xrange(i+1):
846 Eij = matrix(field, n, lambda k,l: k==i and l==j)
847 if i == j:
848 Sij = _embed_complex_matrix(Eij)
849 S.append(Sij)
850 else:
851 # Beware, orthogonal but not normalized! The second one
852 # has a minus because it's conjugated.
853 Sij_real = _embed_complex_matrix(Eij + Eij.transpose())
854 S.append(Sij_real)
855 Sij_imag = _embed_complex_matrix(I*Eij - I*Eij.transpose())
856 S.append(Sij_imag)
857 return tuple(S)
858
859
860 def _quaternion_hermitian_basis(n, field):
861 """
862 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
863
864 SETUP::
865
866 sage: from mjo.eja.eja_algebra import _quaternion_hermitian_basis
867
868 TESTS::
869
870 sage: set_random_seed()
871 sage: n = ZZ.random_element(1,5)
872 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
873 True
874
875 """
876 Q = QuaternionAlgebra(QQ,-1,-1)
877 I,J,K = Q.gens()
878
879 # This is like the symmetric case, but we need to be careful:
880 #
881 # * We want conjugate-symmetry, not just symmetry.
882 # * The diagonal will (as a result) be real.
883 #
884 S = []
885 for i in xrange(n):
886 for j in xrange(i+1):
887 Eij = matrix(Q, n, lambda k,l: k==i and l==j)
888 if i == j:
889 Sij = _embed_quaternion_matrix(Eij)
890 S.append(Sij)
891 else:
892 # Beware, orthogonal but not normalized! The second,
893 # third, and fourth ones have a minus because they're
894 # conjugated.
895 Sij_real = _embed_quaternion_matrix(Eij + Eij.transpose())
896 S.append(Sij_real)
897 Sij_I = _embed_quaternion_matrix(I*Eij - I*Eij.transpose())
898 S.append(Sij_I)
899 Sij_J = _embed_quaternion_matrix(J*Eij - J*Eij.transpose())
900 S.append(Sij_J)
901 Sij_K = _embed_quaternion_matrix(K*Eij - K*Eij.transpose())
902 S.append(Sij_K)
903 return tuple(S)
904
905
906
907 def _multiplication_table_from_matrix_basis(basis):
908 """
909 At least three of the five simple Euclidean Jordan algebras have the
910 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
911 multiplication on the right is matrix multiplication. Given a basis
912 for the underlying matrix space, this function returns a
913 multiplication table (obtained by looping through the basis
914 elements) for an algebra of those matrices.
915 """
916 # In S^2, for example, we nominally have four coordinates even
917 # though the space is of dimension three only. The vector space V
918 # is supposed to hold the entire long vector, and the subspace W
919 # of V will be spanned by the vectors that arise from symmetric
920 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
921 field = basis[0].base_ring()
922 dimension = basis[0].nrows()
923
924 V = VectorSpace(field, dimension**2)
925 W = V.span_of_basis( _mat2vec(s) for s in basis )
926 n = len(basis)
927 mult_table = [[W.zero() for j in range(n)] for i in range(n)]
928 for i in range(n):
929 for j in range(n):
930 mat_entry = (basis[i]*basis[j] + basis[j]*basis[i])/2
931 mult_table[i][j] = W.coordinate_vector(_mat2vec(mat_entry))
932
933 return mult_table
934
935
936 def _embed_complex_matrix(M):
937 """
938 Embed the n-by-n complex matrix ``M`` into the space of real
939 matrices of size 2n-by-2n via the map the sends each entry `z = a +
940 bi` to the block matrix ``[[a,b],[-b,a]]``.
941
942 SETUP::
943
944 sage: from mjo.eja.eja_algebra import _embed_complex_matrix
945
946 EXAMPLES::
947
948 sage: F = QuadraticField(-1,'i')
949 sage: x1 = F(4 - 2*i)
950 sage: x2 = F(1 + 2*i)
951 sage: x3 = F(-i)
952 sage: x4 = F(6)
953 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
954 sage: _embed_complex_matrix(M)
955 [ 4 -2| 1 2]
956 [ 2 4|-2 1]
957 [-----+-----]
958 [ 0 -1| 6 0]
959 [ 1 0| 0 6]
960
961 TESTS:
962
963 Embedding is a homomorphism (isomorphism, in fact)::
964
965 sage: set_random_seed()
966 sage: n = ZZ.random_element(5)
967 sage: F = QuadraticField(-1, 'i')
968 sage: X = random_matrix(F, n)
969 sage: Y = random_matrix(F, n)
970 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
971 sage: expected = _embed_complex_matrix(X*Y)
972 sage: actual == expected
973 True
974
975 """
976 n = M.nrows()
977 if M.ncols() != n:
978 raise ValueError("the matrix 'M' must be square")
979 field = M.base_ring()
980 blocks = []
981 for z in M.list():
982 a = z.real()
983 b = z.imag()
984 blocks.append(matrix(field, 2, [[a,b],[-b,a]]))
985
986 # We can drop the imaginaries here.
987 return matrix.block(field.base_ring(), n, blocks)
988
989
990 def _unembed_complex_matrix(M):
991 """
992 The inverse of _embed_complex_matrix().
993
994 SETUP::
995
996 sage: from mjo.eja.eja_algebra import (_embed_complex_matrix,
997 ....: _unembed_complex_matrix)
998
999 EXAMPLES::
1000
1001 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1002 ....: [-2, 1, -4, 3],
1003 ....: [ 9, 10, 11, 12],
1004 ....: [-10, 9, -12, 11] ])
1005 sage: _unembed_complex_matrix(A)
1006 [ 2*i + 1 4*i + 3]
1007 [ 10*i + 9 12*i + 11]
1008
1009 TESTS:
1010
1011 Unembedding is the inverse of embedding::
1012
1013 sage: set_random_seed()
1014 sage: F = QuadraticField(-1, 'i')
1015 sage: M = random_matrix(F, 3)
1016 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1017 True
1018
1019 """
1020 n = ZZ(M.nrows())
1021 if M.ncols() != n:
1022 raise ValueError("the matrix 'M' must be square")
1023 if not n.mod(2).is_zero():
1024 raise ValueError("the matrix 'M' must be a complex embedding")
1025
1026 F = QuadraticField(-1, 'i')
1027 i = F.gen()
1028
1029 # Go top-left to bottom-right (reading order), converting every
1030 # 2-by-2 block we see to a single complex element.
1031 elements = []
1032 for k in xrange(n/2):
1033 for j in xrange(n/2):
1034 submat = M[2*k:2*k+2,2*j:2*j+2]
1035 if submat[0,0] != submat[1,1]:
1036 raise ValueError('bad on-diagonal submatrix')
1037 if submat[0,1] != -submat[1,0]:
1038 raise ValueError('bad off-diagonal submatrix')
1039 z = submat[0,0] + submat[0,1]*i
1040 elements.append(z)
1041
1042 return matrix(F, n/2, elements)
1043
1044
1045 def _embed_quaternion_matrix(M):
1046 """
1047 Embed the n-by-n quaternion matrix ``M`` into the space of real
1048 matrices of size 4n-by-4n by first sending each quaternion entry
1049 `z = a + bi + cj + dk` to the block-complex matrix
1050 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1051 a real matrix.
1052
1053 SETUP::
1054
1055 sage: from mjo.eja.eja_algebra import _embed_quaternion_matrix
1056
1057 EXAMPLES::
1058
1059 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1060 sage: i,j,k = Q.gens()
1061 sage: x = 1 + 2*i + 3*j + 4*k
1062 sage: M = matrix(Q, 1, [[x]])
1063 sage: _embed_quaternion_matrix(M)
1064 [ 1 2 3 4]
1065 [-2 1 -4 3]
1066 [-3 4 1 -2]
1067 [-4 -3 2 1]
1068
1069 Embedding is a homomorphism (isomorphism, in fact)::
1070
1071 sage: set_random_seed()
1072 sage: n = ZZ.random_element(5)
1073 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1074 sage: X = random_matrix(Q, n)
1075 sage: Y = random_matrix(Q, n)
1076 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1077 sage: expected = _embed_quaternion_matrix(X*Y)
1078 sage: actual == expected
1079 True
1080
1081 """
1082 quaternions = M.base_ring()
1083 n = M.nrows()
1084 if M.ncols() != n:
1085 raise ValueError("the matrix 'M' must be square")
1086
1087 F = QuadraticField(-1, 'i')
1088 i = F.gen()
1089
1090 blocks = []
1091 for z in M.list():
1092 t = z.coefficient_tuple()
1093 a = t[0]
1094 b = t[1]
1095 c = t[2]
1096 d = t[3]
1097 cplx_matrix = matrix(F, 2, [[ a + b*i, c + d*i],
1098 [-c + d*i, a - b*i]])
1099 blocks.append(_embed_complex_matrix(cplx_matrix))
1100
1101 # We should have real entries by now, so use the realest field
1102 # we've got for the return value.
1103 return matrix.block(quaternions.base_ring(), n, blocks)
1104
1105
1106 def _unembed_quaternion_matrix(M):
1107 """
1108 The inverse of _embed_quaternion_matrix().
1109
1110 SETUP::
1111
1112 sage: from mjo.eja.eja_algebra import (_embed_quaternion_matrix,
1113 ....: _unembed_quaternion_matrix)
1114
1115 EXAMPLES::
1116
1117 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1118 ....: [-2, 1, -4, 3],
1119 ....: [-3, 4, 1, -2],
1120 ....: [-4, -3, 2, 1]])
1121 sage: _unembed_quaternion_matrix(M)
1122 [1 + 2*i + 3*j + 4*k]
1123
1124 TESTS:
1125
1126 Unembedding is the inverse of embedding::
1127
1128 sage: set_random_seed()
1129 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1130 sage: M = random_matrix(Q, 3)
1131 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1132 True
1133
1134 """
1135 n = ZZ(M.nrows())
1136 if M.ncols() != n:
1137 raise ValueError("the matrix 'M' must be square")
1138 if not n.mod(4).is_zero():
1139 raise ValueError("the matrix 'M' must be a complex embedding")
1140
1141 Q = QuaternionAlgebra(QQ,-1,-1)
1142 i,j,k = Q.gens()
1143
1144 # Go top-left to bottom-right (reading order), converting every
1145 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1146 # quaternion block.
1147 elements = []
1148 for l in xrange(n/4):
1149 for m in xrange(n/4):
1150 submat = _unembed_complex_matrix(M[4*l:4*l+4,4*m:4*m+4])
1151 if submat[0,0] != submat[1,1].conjugate():
1152 raise ValueError('bad on-diagonal submatrix')
1153 if submat[0,1] != -submat[1,0].conjugate():
1154 raise ValueError('bad off-diagonal submatrix')
1155 z = submat[0,0].real() + submat[0,0].imag()*i
1156 z += submat[0,1].real()*j + submat[0,1].imag()*k
1157 elements.append(z)
1158
1159 return matrix(Q, n/4, elements)
1160
1161
1162 # The usual inner product on R^n.
1163 def _usual_ip(x,y):
1164 return x.to_vector().inner_product(y.to_vector())
1165
1166 # The inner product used for the real symmetric simple EJA.
1167 # We keep it as a separate function because e.g. the complex
1168 # algebra uses the same inner product, except divided by 2.
1169 def _matrix_ip(X,Y):
1170 X_mat = X.natural_representation()
1171 Y_mat = Y.natural_representation()
1172 return (X_mat*Y_mat).trace()
1173
1174
1175 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
1176 """
1177 The rank-n simple EJA consisting of real symmetric n-by-n
1178 matrices, the usual symmetric Jordan product, and the trace inner
1179 product. It has dimension `(n^2 + n)/2` over the reals.
1180
1181 SETUP::
1182
1183 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1184
1185 EXAMPLES::
1186
1187 sage: J = RealSymmetricEJA(2)
1188 sage: e0, e1, e2 = J.gens()
1189 sage: e0*e0
1190 e0
1191 sage: e1*e1
1192 e0 + e2
1193 sage: e2*e2
1194 e2
1195
1196 TESTS:
1197
1198 The dimension of this algebra is `(n^2 + n) / 2`::
1199
1200 sage: set_random_seed()
1201 sage: n = ZZ.random_element(1,5)
1202 sage: J = RealSymmetricEJA(n)
1203 sage: J.dimension() == (n^2 + n)/2
1204 True
1205
1206 The Jordan multiplication is what we think it is::
1207
1208 sage: set_random_seed()
1209 sage: n = ZZ.random_element(1,5)
1210 sage: J = RealSymmetricEJA(n)
1211 sage: x = J.random_element()
1212 sage: y = J.random_element()
1213 sage: actual = (x*y).natural_representation()
1214 sage: X = x.natural_representation()
1215 sage: Y = y.natural_representation()
1216 sage: expected = (X*Y + Y*X)/2
1217 sage: actual == expected
1218 True
1219 sage: J(expected) == x*y
1220 True
1221
1222 We can change the generator prefix::
1223
1224 sage: RealSymmetricEJA(3, prefix='q').gens()
1225 (q0, q1, q2, q3, q4, q5)
1226
1227 Our inner product satisfies the Jordan axiom::
1228
1229 sage: set_random_seed()
1230 sage: n = ZZ.random_element(1,5)
1231 sage: J = RealSymmetricEJA(n)
1232 sage: x = J.random_element()
1233 sage: y = J.random_element()
1234 sage: z = J.random_element()
1235 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1236 True
1237
1238 """
1239 def __init__(self, n, field=QQ, **kwargs):
1240 S = _real_symmetric_basis(n, field)
1241 Qs = _multiplication_table_from_matrix_basis(S)
1242
1243 fdeja = super(RealSymmetricEJA, self)
1244 return fdeja.__init__(field,
1245 Qs,
1246 rank=n,
1247 natural_basis=S,
1248 **kwargs)
1249
1250 def inner_product(self, x, y):
1251 return _matrix_ip(x,y)
1252
1253
1254 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
1255 """
1256 The rank-n simple EJA consisting of complex Hermitian n-by-n
1257 matrices over the real numbers, the usual symmetric Jordan product,
1258 and the real-part-of-trace inner product. It has dimension `n^2` over
1259 the reals.
1260
1261 SETUP::
1262
1263 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1264
1265 TESTS:
1266
1267 The dimension of this algebra is `n^2`::
1268
1269 sage: set_random_seed()
1270 sage: n = ZZ.random_element(1,5)
1271 sage: J = ComplexHermitianEJA(n)
1272 sage: J.dimension() == n^2
1273 True
1274
1275 The Jordan multiplication is what we think it is::
1276
1277 sage: set_random_seed()
1278 sage: n = ZZ.random_element(1,5)
1279 sage: J = ComplexHermitianEJA(n)
1280 sage: x = J.random_element()
1281 sage: y = J.random_element()
1282 sage: actual = (x*y).natural_representation()
1283 sage: X = x.natural_representation()
1284 sage: Y = y.natural_representation()
1285 sage: expected = (X*Y + Y*X)/2
1286 sage: actual == expected
1287 True
1288 sage: J(expected) == x*y
1289 True
1290
1291 We can change the generator prefix::
1292
1293 sage: ComplexHermitianEJA(2, prefix='z').gens()
1294 (z0, z1, z2, z3)
1295
1296 Our inner product satisfies the Jordan axiom::
1297
1298 sage: set_random_seed()
1299 sage: n = ZZ.random_element(1,5)
1300 sage: J = ComplexHermitianEJA(n)
1301 sage: x = J.random_element()
1302 sage: y = J.random_element()
1303 sage: z = J.random_element()
1304 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1305 True
1306
1307 """
1308 def __init__(self, n, field=QQ, **kwargs):
1309 S = _complex_hermitian_basis(n, field)
1310 Qs = _multiplication_table_from_matrix_basis(S)
1311
1312 fdeja = super(ComplexHermitianEJA, self)
1313 return fdeja.__init__(field,
1314 Qs,
1315 rank=n,
1316 natural_basis=S,
1317 **kwargs)
1318
1319
1320 def inner_product(self, x, y):
1321 # Since a+bi on the diagonal is represented as
1322 #
1323 # a + bi = [ a b ]
1324 # [ -b a ],
1325 #
1326 # we'll double-count the "a" entries if we take the trace of
1327 # the embedding.
1328 return _matrix_ip(x,y)/2
1329
1330
1331 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
1332 """
1333 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1334 matrices, the usual symmetric Jordan product, and the
1335 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1336 the reals.
1337
1338 SETUP::
1339
1340 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1341
1342 TESTS:
1343
1344 The dimension of this algebra is `n^2`::
1345
1346 sage: set_random_seed()
1347 sage: n = ZZ.random_element(1,5)
1348 sage: J = QuaternionHermitianEJA(n)
1349 sage: J.dimension() == 2*(n^2) - n
1350 True
1351
1352 The Jordan multiplication is what we think it is::
1353
1354 sage: set_random_seed()
1355 sage: n = ZZ.random_element(1,5)
1356 sage: J = QuaternionHermitianEJA(n)
1357 sage: x = J.random_element()
1358 sage: y = J.random_element()
1359 sage: actual = (x*y).natural_representation()
1360 sage: X = x.natural_representation()
1361 sage: Y = y.natural_representation()
1362 sage: expected = (X*Y + Y*X)/2
1363 sage: actual == expected
1364 True
1365 sage: J(expected) == x*y
1366 True
1367
1368 We can change the generator prefix::
1369
1370 sage: QuaternionHermitianEJA(2, prefix='a').gens()
1371 (a0, a1, a2, a3, a4, a5)
1372
1373 Our inner product satisfies the Jordan axiom::
1374
1375 sage: set_random_seed()
1376 sage: n = ZZ.random_element(1,5)
1377 sage: J = QuaternionHermitianEJA(n)
1378 sage: x = J.random_element()
1379 sage: y = J.random_element()
1380 sage: z = J.random_element()
1381 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1382 True
1383
1384 """
1385 def __init__(self, n, field=QQ, **kwargs):
1386 S = _quaternion_hermitian_basis(n, field)
1387 Qs = _multiplication_table_from_matrix_basis(S)
1388
1389 fdeja = super(QuaternionHermitianEJA, self)
1390 return fdeja.__init__(field,
1391 Qs,
1392 rank=n,
1393 natural_basis=S,
1394 **kwargs)
1395
1396 def inner_product(self, x, y):
1397 # Since a+bi+cj+dk on the diagonal is represented as
1398 #
1399 # a + bi +cj + dk = [ a b c d]
1400 # [ -b a -d c]
1401 # [ -c d a -b]
1402 # [ -d -c b a],
1403 #
1404 # we'll quadruple-count the "a" entries if we take the trace of
1405 # the embedding.
1406 return _matrix_ip(x,y)/4
1407
1408
1409 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
1410 """
1411 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1412 with the usual inner product and jordan product ``x*y =
1413 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1414 the reals.
1415
1416 SETUP::
1417
1418 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1419
1420 EXAMPLES:
1421
1422 This multiplication table can be verified by hand::
1423
1424 sage: J = JordanSpinEJA(4)
1425 sage: e0,e1,e2,e3 = J.gens()
1426 sage: e0*e0
1427 e0
1428 sage: e0*e1
1429 e1
1430 sage: e0*e2
1431 e2
1432 sage: e0*e3
1433 e3
1434 sage: e1*e2
1435 0
1436 sage: e1*e3
1437 0
1438 sage: e2*e3
1439 0
1440
1441 We can change the generator prefix::
1442
1443 sage: JordanSpinEJA(2, prefix='B').gens()
1444 (B0, B1)
1445
1446 Our inner product satisfies the Jordan axiom::
1447
1448 sage: set_random_seed()
1449 sage: n = ZZ.random_element(1,5)
1450 sage: J = JordanSpinEJA(n)
1451 sage: x = J.random_element()
1452 sage: y = J.random_element()
1453 sage: z = J.random_element()
1454 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1455 True
1456
1457 """
1458 def __init__(self, n, field=QQ, **kwargs):
1459 V = VectorSpace(field, n)
1460 mult_table = [[V.zero() for j in range(n)] for i in range(n)]
1461 for i in range(n):
1462 for j in range(n):
1463 x = V.gen(i)
1464 y = V.gen(j)
1465 x0 = x[0]
1466 xbar = x[1:]
1467 y0 = y[0]
1468 ybar = y[1:]
1469 # z = x*y
1470 z0 = x.inner_product(y)
1471 zbar = y0*xbar + x0*ybar
1472 z = V([z0] + zbar.list())
1473 mult_table[i][j] = z
1474
1475 # The rank of the spin algebra is two, unless we're in a
1476 # one-dimensional ambient space (because the rank is bounded by
1477 # the ambient dimension).
1478 fdeja = super(JordanSpinEJA, self)
1479 return fdeja.__init__(field, mult_table, rank=min(n,2), **kwargs)
1480
1481 def inner_product(self, x, y):
1482 return _usual_ip(x,y)