]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/euclidean_jordan_algebra.py
eja: add minimal_polynomial() for operators.
[sage.d.git] / mjo / eja / euclidean_jordan_algebra.py
1 """
2 Euclidean Jordan Algebras. These are formally-real Jordan Algebras;
3 specifically those where u^2 + v^2 = 0 implies that u = v = 0. They
4 are used in optimization, and have some additional nice methods beyond
5 what can be supported in a general Jordan Algebra.
6 """
7
8 from sage.categories.finite_dimensional_algebras_with_basis import FiniteDimensionalAlgebrasWithBasis
9 from sage.categories.map import Map
10 from sage.structure.element import is_Matrix
11 from sage.structure.category_object import normalize_names
12
13 from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra import FiniteDimensionalAlgebra
14 from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement
15
16
17 class FiniteDimensionalEuclideanJordanAlgebraOperator(Map):
18 def __init__(self, domain_eja, codomain_eja, mat):
19 if not (
20 isinstance(domain_eja, FiniteDimensionalEuclideanJordanAlgebra) and
21 isinstance(codomain_eja, FiniteDimensionalEuclideanJordanAlgebra) ):
22 raise ValueError('(co)domains must be finite-dimensional Euclidean '
23 'Jordan algebras')
24
25 F = domain_eja.base_ring()
26 if not (F == codomain_eja.base_ring()):
27 raise ValueError("domain and codomain must have the same base ring")
28
29 # We need to supply something here to avoid getting the
30 # default Homset of the parent FiniteDimensionalAlgebra class,
31 # which messes up e.g. equality testing. We use FreeModules(F)
32 # instead of VectorSpaces(F) because our characteristic polynomial
33 # algorithm will need to F to be a polynomial ring at some point.
34 # When F is a field, FreeModules(F) returns VectorSpaces(F) anyway.
35 parent = Hom(domain_eja, codomain_eja, FreeModules(F))
36
37 # The Map initializer will set our parent to a homset, which
38 # is explicitly NOT what we want, because these ain't algebra
39 # homomorphisms.
40 super(FiniteDimensionalEuclideanJordanAlgebraOperator,self).__init__(parent)
41
42 # Keep a matrix around to do all of the real work. It would
43 # be nice if we could use a VectorSpaceMorphism instead, but
44 # those use row vectors that we don't want to accidentally
45 # expose to our users.
46 self._matrix = mat
47
48
49 def _call_(self, x):
50 """
51 Allow this operator to be called only on elements of an EJA.
52
53 EXAMPLES::
54
55 sage: J = JordanSpinEJA(3)
56 sage: x = J.linear_combination(zip(range(len(J.gens())), J.gens()))
57 sage: id = identity_matrix(J.base_ring(), J.dimension())
58 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
59 sage: f(x) == x
60 True
61
62 """
63 return self.codomain()(self.matrix()*x.vector())
64
65
66 def _add_(self, other):
67 """
68 Add the ``other`` EJA operator to this one.
69
70 EXAMPLES:
71
72 When we add two EJA operators, we get another one back::
73
74 sage: J = RealSymmetricEJA(2)
75 sage: id = identity_matrix(J.base_ring(), J.dimension())
76 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
77 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
78 sage: f + g
79 Linear operator between finite-dimensional Euclidean Jordan
80 algebras represented by the matrix:
81 [2 0 0]
82 [0 2 0]
83 [0 0 2]
84 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
85 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
86
87 If you try to add two identical vector space operators but on
88 different EJAs, that should blow up::
89
90 sage: J1 = RealSymmetricEJA(2)
91 sage: J2 = JordanSpinEJA(3)
92 sage: id = identity_matrix(QQ, 3)
93 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J1,J1,id)
94 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J2,J2,id)
95 sage: f + g
96 Traceback (most recent call last):
97 ...
98 TypeError: unsupported operand parent(s) for +: ...
99
100 """
101 return FiniteDimensionalEuclideanJordanAlgebraOperator(
102 self.domain(),
103 self.codomain(),
104 self.matrix() + other.matrix())
105
106
107 def _composition_(self, other, homset):
108 """
109 Compose two EJA operators to get another one (and NOT a formal
110 composite object) back.
111
112 EXAMPLES::
113
114 sage: J1 = JordanSpinEJA(3)
115 sage: J2 = RealCartesianProductEJA(2)
116 sage: J3 = RealSymmetricEJA(1)
117 sage: mat1 = matrix(QQ, [[1,2,3],
118 ....: [4,5,6]])
119 sage: mat2 = matrix(QQ, [[7,8]])
120 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J1,
121 ....: J2,
122 ....: mat1)
123 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J2,
124 ....: J3,
125 ....: mat2)
126 sage: f*g
127 Linear operator between finite-dimensional Euclidean Jordan
128 algebras represented by the matrix:
129 [39 54 69]
130 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
131 Codomain: Euclidean Jordan algebra of degree 1 over Rational Field
132
133 """
134 return FiniteDimensionalEuclideanJordanAlgebraOperator(
135 other.domain(),
136 self.codomain(),
137 self.matrix()*other.matrix())
138
139
140 def __eq__(self, other):
141 if self.domain() != other.domain():
142 return False
143 if self.codomain() != other.codomain():
144 return False
145 if self.matrix() != other.matrix():
146 return False
147 return True
148
149 def __invert__(self):
150 """
151 Invert this EJA operator.
152
153 EXAMPLES::
154
155 sage: J = RealSymmetricEJA(2)
156 sage: id = identity_matrix(J.base_ring(), J.dimension())
157 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
158 sage: ~f
159 Linear operator between finite-dimensional Euclidean Jordan
160 algebras represented by the matrix:
161 [1 0 0]
162 [0 1 0]
163 [0 0 1]
164 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
165 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
166
167 """
168 return FiniteDimensionalEuclideanJordanAlgebraOperator(
169 self.codomain(),
170 self.domain(),
171 ~self.matrix())
172
173
174 def __mul__(self, other):
175 """
176 Compose two EJA operators, or scale myself by an element of the
177 ambient vector space.
178
179 We need to override the real ``__mul__`` function to prevent the
180 coercion framework from throwing an error when it fails to convert
181 a base ring element into a morphism.
182
183 EXAMPLES:
184
185 We can scale an operator on a rational algebra by a rational number::
186
187 sage: J = RealSymmetricEJA(2)
188 sage: e0,e1,e2 = J.gens()
189 sage: x = 2*e0 + 4*e1 + 16*e2
190 sage: x.operator()
191 Linear operator between finite-dimensional Euclidean Jordan algebras
192 represented by the matrix:
193 [ 2 4 0]
194 [ 2 9 2]
195 [ 0 4 16]
196 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
197 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
198 sage: x.operator()*(1/2)
199 Linear operator between finite-dimensional Euclidean Jordan algebras
200 represented by the matrix:
201 [ 1 2 0]
202 [ 1 9/2 1]
203 [ 0 2 8]
204 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
205 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
206
207 """
208 if other in self.codomain().base_ring():
209 return FiniteDimensionalEuclideanJordanAlgebraOperator(
210 self.domain(),
211 self.codomain(),
212 self.matrix()*other)
213
214 # This should eventually delegate to _composition_ after performing
215 # some sanity checks for us.
216 mor = super(FiniteDimensionalEuclideanJordanAlgebraOperator,self)
217 return mor.__mul__(other)
218
219
220 def _neg_(self):
221 """
222 Negate this EJA operator.
223
224 EXAMPLES::
225
226 sage: J = RealSymmetricEJA(2)
227 sage: id = identity_matrix(J.base_ring(), J.dimension())
228 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
229 sage: -f
230 Linear operator between finite-dimensional Euclidean Jordan
231 algebras represented by the matrix:
232 [-1 0 0]
233 [ 0 -1 0]
234 [ 0 0 -1]
235 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
236 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
237
238 """
239 return FiniteDimensionalEuclideanJordanAlgebraOperator(
240 self.domain(),
241 self.codomain(),
242 -self.matrix())
243
244
245 def __pow__(self, n):
246 """
247 Raise this EJA operator to the power ``n``.
248
249 TESTS:
250
251 Ensure that we get back another EJA operator that can be added,
252 subtracted, et cetera::
253
254 sage: J = RealSymmetricEJA(2)
255 sage: id = identity_matrix(J.base_ring(), J.dimension())
256 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
257 sage: f^0 + f^1 + f^2
258 Linear operator between finite-dimensional Euclidean Jordan
259 algebras represented by the matrix:
260 [3 0 0]
261 [0 3 0]
262 [0 0 3]
263 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
264 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
265
266 """
267 if (n == 1):
268 return self
269 elif (n == 0):
270 # Raising a vector space morphism to the zero power gives
271 # you back a special IdentityMorphism that is useless to us.
272 rows = self.codomain().dimension()
273 cols = self.domain().dimension()
274 mat = matrix.identity(self.base_ring(), rows, cols)
275 else:
276 mat = self.matrix()**n
277
278 return FiniteDimensionalEuclideanJordanAlgebraOperator(
279 self.domain(),
280 self.codomain(),
281 mat)
282
283
284 def _repr_(self):
285 r"""
286
287 A text representation of this linear operator on a Euclidean
288 Jordan Algebra.
289
290 EXAMPLES::
291
292 sage: J = JordanSpinEJA(2)
293 sage: id = identity_matrix(J.base_ring(), J.dimension())
294 sage: FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
295 Linear operator between finite-dimensional Euclidean Jordan
296 algebras represented by the matrix:
297 [1 0]
298 [0 1]
299 Domain: Euclidean Jordan algebra of degree 2 over Rational Field
300 Codomain: Euclidean Jordan algebra of degree 2 over Rational Field
301
302 """
303 msg = ("Linear operator between finite-dimensional Euclidean Jordan "
304 "algebras represented by the matrix:\n",
305 "{!r}\n",
306 "Domain: {}\n",
307 "Codomain: {}")
308 return ''.join(msg).format(self.matrix(),
309 self.domain(),
310 self.codomain())
311
312
313 def _sub_(self, other):
314 """
315 Subtract ``other`` from this EJA operator.
316
317 EXAMPLES::
318
319 sage: J = RealSymmetricEJA(2)
320 sage: id = identity_matrix(J.base_ring(),J.dimension())
321 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
322 sage: f - (f*2)
323 Linear operator between finite-dimensional Euclidean Jordan
324 algebras represented by the matrix:
325 [-1 0 0]
326 [ 0 -1 0]
327 [ 0 0 -1]
328 Domain: Euclidean Jordan algebra of degree 3 over Rational Field
329 Codomain: Euclidean Jordan algebra of degree 3 over Rational Field
330
331 """
332 return (self + (-other))
333
334
335 def matrix(self):
336 """
337 Return the matrix representation of this operator with respect
338 to the default bases of its (co)domain.
339
340 EXAMPLES::
341
342 sage: J = RealSymmetricEJA(2)
343 sage: mat = matrix(J.base_ring(), J.dimension(), range(9))
344 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,mat)
345 sage: f.matrix()
346 [0 1 2]
347 [3 4 5]
348 [6 7 8]
349
350 """
351 return self._matrix
352
353
354 def minimal_polynomial(self):
355 """
356 Return the minimal polynomial of this linear operator,
357 in the variable ``t``.
358
359 EXAMPLES::
360
361 sage: J = RealSymmetricEJA(3)
362 sage: J.one().operator().minimal_polynomial()
363 t - 1
364
365 """
366 # The matrix method returns a polynomial in 'x' but want one in 't'.
367 return self.matrix().minimal_polynomial().change_variable_name('t')
368
369
370 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra):
371 @staticmethod
372 def __classcall_private__(cls,
373 field,
374 mult_table,
375 names='e',
376 assume_associative=False,
377 category=None,
378 rank=None,
379 natural_basis=None):
380 n = len(mult_table)
381 mult_table = [b.base_extend(field) for b in mult_table]
382 for b in mult_table:
383 b.set_immutable()
384 if not (is_Matrix(b) and b.dimensions() == (n, n)):
385 raise ValueError("input is not a multiplication table")
386 mult_table = tuple(mult_table)
387
388 cat = FiniteDimensionalAlgebrasWithBasis(field)
389 cat.or_subcategory(category)
390 if assume_associative:
391 cat = cat.Associative()
392
393 names = normalize_names(n, names)
394
395 fda = super(FiniteDimensionalEuclideanJordanAlgebra, cls)
396 return fda.__classcall__(cls,
397 field,
398 mult_table,
399 assume_associative=assume_associative,
400 names=names,
401 category=cat,
402 rank=rank,
403 natural_basis=natural_basis)
404
405
406 def __init__(self,
407 field,
408 mult_table,
409 names='e',
410 assume_associative=False,
411 category=None,
412 rank=None,
413 natural_basis=None):
414 """
415 EXAMPLES:
416
417 By definition, Jordan multiplication commutes::
418
419 sage: set_random_seed()
420 sage: J = random_eja()
421 sage: x = J.random_element()
422 sage: y = J.random_element()
423 sage: x*y == y*x
424 True
425
426 """
427 self._rank = rank
428 self._natural_basis = natural_basis
429 self._multiplication_table = mult_table
430 fda = super(FiniteDimensionalEuclideanJordanAlgebra, self)
431 fda.__init__(field,
432 mult_table,
433 names=names,
434 category=category)
435
436
437 def _repr_(self):
438 """
439 Return a string representation of ``self``.
440 """
441 fmt = "Euclidean Jordan algebra of degree {} over {}"
442 return fmt.format(self.degree(), self.base_ring())
443
444
445 def _a_regular_element(self):
446 """
447 Guess a regular element. Needed to compute the basis for our
448 characteristic polynomial coefficients.
449 """
450 gs = self.gens()
451 z = self.sum( (i+1)*gs[i] for i in range(len(gs)) )
452 if not z.is_regular():
453 raise ValueError("don't know a regular element")
454 return z
455
456
457 @cached_method
458 def _charpoly_basis_space(self):
459 """
460 Return the vector space spanned by the basis used in our
461 characteristic polynomial coefficients. This is used not only to
462 compute those coefficients, but also any time we need to
463 evaluate the coefficients (like when we compute the trace or
464 determinant).
465 """
466 z = self._a_regular_element()
467 V = self.vector_space()
468 V1 = V.span_of_basis( (z**k).vector() for k in range(self.rank()) )
469 b = (V1.basis() + V1.complement().basis())
470 return V.span_of_basis(b)
471
472
473 @cached_method
474 def _charpoly_coeff(self, i):
475 """
476 Return the coefficient polynomial "a_{i}" of this algebra's
477 general characteristic polynomial.
478
479 Having this be a separate cached method lets us compute and
480 store the trace/determinant (a_{r-1} and a_{0} respectively)
481 separate from the entire characteristic polynomial.
482 """
483 (A_of_x, x, xr, detA) = self._charpoly_matrix_system()
484 R = A_of_x.base_ring()
485 if i >= self.rank():
486 # Guaranteed by theory
487 return R.zero()
488
489 # Danger: the in-place modification is done for performance
490 # reasons (reconstructing a matrix with huge polynomial
491 # entries is slow), but I don't know how cached_method works,
492 # so it's highly possible that we're modifying some global
493 # list variable by reference, here. In other words, you
494 # probably shouldn't call this method twice on the same
495 # algebra, at the same time, in two threads
496 Ai_orig = A_of_x.column(i)
497 A_of_x.set_column(i,xr)
498 numerator = A_of_x.det()
499 A_of_x.set_column(i,Ai_orig)
500
501 # We're relying on the theory here to ensure that each a_i is
502 # indeed back in R, and the added negative signs are to make
503 # the whole charpoly expression sum to zero.
504 return R(-numerator/detA)
505
506
507 @cached_method
508 def _charpoly_matrix_system(self):
509 """
510 Compute the matrix whose entries A_ij are polynomials in
511 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
512 corresponding to `x^r` and the determinent of the matrix A =
513 [A_ij]. In other words, all of the fixed (cachable) data needed
514 to compute the coefficients of the characteristic polynomial.
515 """
516 r = self.rank()
517 n = self.dimension()
518
519 # Construct a new algebra over a multivariate polynomial ring...
520 names = ['X' + str(i) for i in range(1,n+1)]
521 R = PolynomialRing(self.base_ring(), names)
522 J = FiniteDimensionalEuclideanJordanAlgebra(R,
523 self._multiplication_table,
524 rank=r)
525
526 idmat = identity_matrix(J.base_ring(), n)
527
528 W = self._charpoly_basis_space()
529 W = W.change_ring(R.fraction_field())
530
531 # Starting with the standard coordinates x = (X1,X2,...,Xn)
532 # and then converting the entries to W-coordinates allows us
533 # to pass in the standard coordinates to the charpoly and get
534 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
535 # we have
536 #
537 # W.coordinates(x^2) eval'd at (standard z-coords)
538 # =
539 # W-coords of (z^2)
540 # =
541 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
542 #
543 # We want the middle equivalent thing in our matrix, but use
544 # the first equivalent thing instead so that we can pass in
545 # standard coordinates.
546 x = J(vector(R, R.gens()))
547 l1 = [column_matrix(W.coordinates((x**k).vector())) for k in range(r)]
548 l2 = [idmat.column(k-1).column() for k in range(r+1, n+1)]
549 A_of_x = block_matrix(R, 1, n, (l1 + l2))
550 xr = W.coordinates((x**r).vector())
551 return (A_of_x, x, xr, A_of_x.det())
552
553
554 @cached_method
555 def characteristic_polynomial(self):
556 """
557
558 .. WARNING::
559
560 This implementation doesn't guarantee that the polynomial
561 denominator in the coefficients is not identically zero, so
562 theoretically it could crash. The way that this is handled
563 in e.g. Faraut and Koranyi is to use a basis that guarantees
564 the denominator is non-zero. But, doing so requires knowledge
565 of at least one regular element, and we don't even know how
566 to do that. The trade-off is that, if we use the standard basis,
567 the resulting polynomial will accept the "usual" coordinates. In
568 other words, we don't have to do a change of basis before e.g.
569 computing the trace or determinant.
570
571 EXAMPLES:
572
573 The characteristic polynomial in the spin algebra is given in
574 Alizadeh, Example 11.11::
575
576 sage: J = JordanSpinEJA(3)
577 sage: p = J.characteristic_polynomial(); p
578 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
579 sage: xvec = J.one().vector()
580 sage: p(*xvec)
581 t^2 - 2*t + 1
582
583 """
584 r = self.rank()
585 n = self.dimension()
586
587 # The list of coefficient polynomials a_1, a_2, ..., a_n.
588 a = [ self._charpoly_coeff(i) for i in range(n) ]
589
590 # We go to a bit of trouble here to reorder the
591 # indeterminates, so that it's easier to evaluate the
592 # characteristic polynomial at x's coordinates and get back
593 # something in terms of t, which is what we want.
594 R = a[0].parent()
595 S = PolynomialRing(self.base_ring(),'t')
596 t = S.gen(0)
597 S = PolynomialRing(S, R.variable_names())
598 t = S(t)
599
600 # Note: all entries past the rth should be zero. The
601 # coefficient of the highest power (x^r) is 1, but it doesn't
602 # appear in the solution vector which contains coefficients
603 # for the other powers (to make them sum to x^r).
604 if (r < n):
605 a[r] = 1 # corresponds to x^r
606 else:
607 # When the rank is equal to the dimension, trying to
608 # assign a[r] goes out-of-bounds.
609 a.append(1) # corresponds to x^r
610
611 return sum( a[k]*(t**k) for k in range(len(a)) )
612
613
614 def inner_product(self, x, y):
615 """
616 The inner product associated with this Euclidean Jordan algebra.
617
618 Defaults to the trace inner product, but can be overridden by
619 subclasses if they are sure that the necessary properties are
620 satisfied.
621
622 EXAMPLES:
623
624 The inner product must satisfy its axiom for this algebra to truly
625 be a Euclidean Jordan Algebra::
626
627 sage: set_random_seed()
628 sage: J = random_eja()
629 sage: x = J.random_element()
630 sage: y = J.random_element()
631 sage: z = J.random_element()
632 sage: (x*y).inner_product(z) == y.inner_product(x*z)
633 True
634
635 """
636 if (not x in self) or (not y in self):
637 raise TypeError("arguments must live in this algebra")
638 return x.trace_inner_product(y)
639
640
641 def natural_basis(self):
642 """
643 Return a more-natural representation of this algebra's basis.
644
645 Every finite-dimensional Euclidean Jordan Algebra is a direct
646 sum of five simple algebras, four of which comprise Hermitian
647 matrices. This method returns the original "natural" basis
648 for our underlying vector space. (Typically, the natural basis
649 is used to construct the multiplication table in the first place.)
650
651 Note that this will always return a matrix. The standard basis
652 in `R^n` will be returned as `n`-by-`1` column matrices.
653
654 EXAMPLES::
655
656 sage: J = RealSymmetricEJA(2)
657 sage: J.basis()
658 Family (e0, e1, e2)
659 sage: J.natural_basis()
660 (
661 [1 0] [0 1] [0 0]
662 [0 0], [1 0], [0 1]
663 )
664
665 ::
666
667 sage: J = JordanSpinEJA(2)
668 sage: J.basis()
669 Family (e0, e1)
670 sage: J.natural_basis()
671 (
672 [1] [0]
673 [0], [1]
674 )
675
676 """
677 if self._natural_basis is None:
678 return tuple( b.vector().column() for b in self.basis() )
679 else:
680 return self._natural_basis
681
682
683 def rank(self):
684 """
685 Return the rank of this EJA.
686 """
687 if self._rank is None:
688 raise ValueError("no rank specified at genesis")
689 else:
690 return self._rank
691
692 def vector_space(self):
693 """
694 Return the vector space that underlies this algebra.
695
696 EXAMPLES::
697
698 sage: J = RealSymmetricEJA(2)
699 sage: J.vector_space()
700 Vector space of dimension 3 over Rational Field
701
702 """
703 return self.zero().vector().parent().ambient_vector_space()
704
705
706 class Element(FiniteDimensionalAlgebraElement):
707 """
708 An element of a Euclidean Jordan algebra.
709 """
710
711 def __dir__(self):
712 """
713 Oh man, I should not be doing this. This hides the "disabled"
714 methods ``left_matrix`` and ``matrix`` from introspection;
715 in particular it removes them from tab-completion.
716 """
717 return filter(lambda s: s not in ['left_matrix', 'matrix'],
718 dir(self.__class__) )
719
720
721 def __init__(self, A, elt=None):
722 """
723 EXAMPLES:
724
725 The identity in `S^n` is converted to the identity in the EJA::
726
727 sage: J = RealSymmetricEJA(3)
728 sage: I = identity_matrix(QQ,3)
729 sage: J(I) == J.one()
730 True
731
732 This skew-symmetric matrix can't be represented in the EJA::
733
734 sage: J = RealSymmetricEJA(3)
735 sage: A = matrix(QQ,3, lambda i,j: i-j)
736 sage: J(A)
737 Traceback (most recent call last):
738 ...
739 ArithmeticError: vector is not in free module
740
741 """
742 # Goal: if we're given a matrix, and if it lives in our
743 # parent algebra's "natural ambient space," convert it
744 # into an algebra element.
745 #
746 # The catch is, we make a recursive call after converting
747 # the given matrix into a vector that lives in the algebra.
748 # This we need to try the parent class initializer first,
749 # to avoid recursing forever if we're given something that
750 # already fits into the algebra, but also happens to live
751 # in the parent's "natural ambient space" (this happens with
752 # vectors in R^n).
753 try:
754 FiniteDimensionalAlgebraElement.__init__(self, A, elt)
755 except ValueError:
756 natural_basis = A.natural_basis()
757 if elt in natural_basis[0].matrix_space():
758 # Thanks for nothing! Matrix spaces aren't vector
759 # spaces in Sage, so we have to figure out its
760 # natural-basis coordinates ourselves.
761 V = VectorSpace(elt.base_ring(), elt.nrows()**2)
762 W = V.span( _mat2vec(s) for s in natural_basis )
763 coords = W.coordinates(_mat2vec(elt))
764 FiniteDimensionalAlgebraElement.__init__(self, A, coords)
765
766 def __pow__(self, n):
767 """
768 Return ``self`` raised to the power ``n``.
769
770 Jordan algebras are always power-associative; see for
771 example Faraut and Koranyi, Proposition II.1.2 (ii).
772
773 .. WARNING:
774
775 We have to override this because our superclass uses row vectors
776 instead of column vectors! We, on the other hand, assume column
777 vectors everywhere.
778
779 EXAMPLES::
780
781 sage: set_random_seed()
782 sage: x = random_eja().random_element()
783 sage: x.operator()(x) == (x^2)
784 True
785
786 A few examples of power-associativity::
787
788 sage: set_random_seed()
789 sage: x = random_eja().random_element()
790 sage: x*(x*x)*(x*x) == x^5
791 True
792 sage: (x*x)*(x*x*x) == x^5
793 True
794
795 We also know that powers operator-commute (Koecher, Chapter
796 III, Corollary 1)::
797
798 sage: set_random_seed()
799 sage: x = random_eja().random_element()
800 sage: m = ZZ.random_element(0,10)
801 sage: n = ZZ.random_element(0,10)
802 sage: Lxm = (x^m).operator()
803 sage: Lxn = (x^n).operator()
804 sage: Lxm*Lxn == Lxn*Lxm
805 True
806
807 """
808 if n == 0:
809 return self.parent().one()
810 elif n == 1:
811 return self
812 else:
813 return (self.operator()**(n-1))(self)
814
815
816 def apply_univariate_polynomial(self, p):
817 """
818 Apply the univariate polynomial ``p`` to this element.
819
820 A priori, SageMath won't allow us to apply a univariate
821 polynomial to an element of an EJA, because we don't know
822 that EJAs are rings (they are usually not associative). Of
823 course, we know that EJAs are power-associative, so the
824 operation is ultimately kosher. This function sidesteps
825 the CAS to get the answer we want and expect.
826
827 EXAMPLES::
828
829 sage: R = PolynomialRing(QQ, 't')
830 sage: t = R.gen(0)
831 sage: p = t^4 - t^3 + 5*t - 2
832 sage: J = RealCartesianProductEJA(5)
833 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
834 True
835
836 TESTS:
837
838 We should always get back an element of the algebra::
839
840 sage: set_random_seed()
841 sage: p = PolynomialRing(QQ, 't').random_element()
842 sage: J = random_eja()
843 sage: x = J.random_element()
844 sage: x.apply_univariate_polynomial(p) in J
845 True
846
847 """
848 if len(p.variables()) > 1:
849 raise ValueError("not a univariate polynomial")
850 P = self.parent()
851 R = P.base_ring()
852 # Convert the coeficcients to the parent's base ring,
853 # because a priori they might live in an (unnecessarily)
854 # larger ring for which P.sum() would fail below.
855 cs = [ R(c) for c in p.coefficients(sparse=False) ]
856 return P.sum( cs[k]*(self**k) for k in range(len(cs)) )
857
858
859 def characteristic_polynomial(self):
860 """
861 Return the characteristic polynomial of this element.
862
863 EXAMPLES:
864
865 The rank of `R^3` is three, and the minimal polynomial of
866 the identity element is `(t-1)` from which it follows that
867 the characteristic polynomial should be `(t-1)^3`::
868
869 sage: J = RealCartesianProductEJA(3)
870 sage: J.one().characteristic_polynomial()
871 t^3 - 3*t^2 + 3*t - 1
872
873 Likewise, the characteristic of the zero element in the
874 rank-three algebra `R^{n}` should be `t^{3}`::
875
876 sage: J = RealCartesianProductEJA(3)
877 sage: J.zero().characteristic_polynomial()
878 t^3
879
880 The characteristic polynomial of an element should evaluate
881 to zero on that element::
882
883 sage: set_random_seed()
884 sage: x = RealCartesianProductEJA(3).random_element()
885 sage: p = x.characteristic_polynomial()
886 sage: x.apply_univariate_polynomial(p)
887 0
888
889 """
890 p = self.parent().characteristic_polynomial()
891 return p(*self.vector())
892
893
894 def inner_product(self, other):
895 """
896 Return the parent algebra's inner product of myself and ``other``.
897
898 EXAMPLES:
899
900 The inner product in the Jordan spin algebra is the usual
901 inner product on `R^n` (this example only works because the
902 basis for the Jordan algebra is the standard basis in `R^n`)::
903
904 sage: J = JordanSpinEJA(3)
905 sage: x = vector(QQ,[1,2,3])
906 sage: y = vector(QQ,[4,5,6])
907 sage: x.inner_product(y)
908 32
909 sage: J(x).inner_product(J(y))
910 32
911
912 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
913 multiplication is the usual matrix multiplication in `S^n`,
914 so the inner product of the identity matrix with itself
915 should be the `n`::
916
917 sage: J = RealSymmetricEJA(3)
918 sage: J.one().inner_product(J.one())
919 3
920
921 Likewise, the inner product on `C^n` is `<X,Y> =
922 Re(trace(X*Y))`, where we must necessarily take the real
923 part because the product of Hermitian matrices may not be
924 Hermitian::
925
926 sage: J = ComplexHermitianEJA(3)
927 sage: J.one().inner_product(J.one())
928 3
929
930 Ditto for the quaternions::
931
932 sage: J = QuaternionHermitianEJA(3)
933 sage: J.one().inner_product(J.one())
934 3
935
936 TESTS:
937
938 Ensure that we can always compute an inner product, and that
939 it gives us back a real number::
940
941 sage: set_random_seed()
942 sage: J = random_eja()
943 sage: x = J.random_element()
944 sage: y = J.random_element()
945 sage: x.inner_product(y) in RR
946 True
947
948 """
949 P = self.parent()
950 if not other in P:
951 raise TypeError("'other' must live in the same algebra")
952
953 return P.inner_product(self, other)
954
955
956 def operator_commutes_with(self, other):
957 """
958 Return whether or not this element operator-commutes
959 with ``other``.
960
961 EXAMPLES:
962
963 The definition of a Jordan algebra says that any element
964 operator-commutes with its square::
965
966 sage: set_random_seed()
967 sage: x = random_eja().random_element()
968 sage: x.operator_commutes_with(x^2)
969 True
970
971 TESTS:
972
973 Test Lemma 1 from Chapter III of Koecher::
974
975 sage: set_random_seed()
976 sage: J = random_eja()
977 sage: u = J.random_element()
978 sage: v = J.random_element()
979 sage: lhs = u.operator_commutes_with(u*v)
980 sage: rhs = v.operator_commutes_with(u^2)
981 sage: lhs == rhs
982 True
983
984 Test the first polarization identity from my notes, Koecher Chapter
985 III, or from Baes (2.3)::
986
987 sage: set_random_seed()
988 sage: J = random_eja()
989 sage: x = J.random_element()
990 sage: y = J.random_element()
991 sage: Lx = x.operator()
992 sage: Ly = y.operator()
993 sage: Lxx = (x*x).operator()
994 sage: Lxy = (x*y).operator()
995 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
996 True
997
998 Test the second polarization identity from my notes or from
999 Baes (2.4)::
1000
1001 sage: set_random_seed()
1002 sage: J = random_eja()
1003 sage: x = J.random_element()
1004 sage: y = J.random_element()
1005 sage: z = J.random_element()
1006 sage: Lx = x.operator()
1007 sage: Ly = y.operator()
1008 sage: Lz = z.operator()
1009 sage: Lzy = (z*y).operator()
1010 sage: Lxy = (x*y).operator()
1011 sage: Lxz = (x*z).operator()
1012 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
1013 True
1014
1015 Test the third polarization identity from my notes or from
1016 Baes (2.5)::
1017
1018 sage: set_random_seed()
1019 sage: J = random_eja()
1020 sage: u = J.random_element()
1021 sage: y = J.random_element()
1022 sage: z = J.random_element()
1023 sage: Lu = u.operator()
1024 sage: Ly = y.operator()
1025 sage: Lz = z.operator()
1026 sage: Lzy = (z*y).operator()
1027 sage: Luy = (u*y).operator()
1028 sage: Luz = (u*z).operator()
1029 sage: Luyz = (u*(y*z)).operator()
1030 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
1031 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
1032 sage: bool(lhs == rhs)
1033 True
1034
1035 """
1036 if not other in self.parent():
1037 raise TypeError("'other' must live in the same algebra")
1038
1039 A = self.operator()
1040 B = other.operator()
1041 return (A*B == B*A)
1042
1043
1044 def det(self):
1045 """
1046 Return my determinant, the product of my eigenvalues.
1047
1048 EXAMPLES::
1049
1050 sage: J = JordanSpinEJA(2)
1051 sage: e0,e1 = J.gens()
1052 sage: x = sum( J.gens() )
1053 sage: x.det()
1054 0
1055
1056 ::
1057
1058 sage: J = JordanSpinEJA(3)
1059 sage: e0,e1,e2 = J.gens()
1060 sage: x = sum( J.gens() )
1061 sage: x.det()
1062 -1
1063
1064 TESTS:
1065
1066 An element is invertible if and only if its determinant is
1067 non-zero::
1068
1069 sage: set_random_seed()
1070 sage: x = random_eja().random_element()
1071 sage: x.is_invertible() == (x.det() != 0)
1072 True
1073
1074 """
1075 P = self.parent()
1076 r = P.rank()
1077 p = P._charpoly_coeff(0)
1078 # The _charpoly_coeff function already adds the factor of
1079 # -1 to ensure that _charpoly_coeff(0) is really what
1080 # appears in front of t^{0} in the charpoly. However,
1081 # we want (-1)^r times THAT for the determinant.
1082 return ((-1)**r)*p(*self.vector())
1083
1084
1085 def inverse(self):
1086 """
1087 Return the Jordan-multiplicative inverse of this element.
1088
1089 ALGORITHM:
1090
1091 We appeal to the quadratic representation as in Koecher's
1092 Theorem 12 in Chapter III, Section 5.
1093
1094 EXAMPLES:
1095
1096 The inverse in the spin factor algebra is given in Alizadeh's
1097 Example 11.11::
1098
1099 sage: set_random_seed()
1100 sage: n = ZZ.random_element(1,10)
1101 sage: J = JordanSpinEJA(n)
1102 sage: x = J.random_element()
1103 sage: while not x.is_invertible():
1104 ....: x = J.random_element()
1105 sage: x_vec = x.vector()
1106 sage: x0 = x_vec[0]
1107 sage: x_bar = x_vec[1:]
1108 sage: coeff = ~(x0^2 - x_bar.inner_product(x_bar))
1109 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
1110 sage: x_inverse = coeff*inv_vec
1111 sage: x.inverse() == J(x_inverse)
1112 True
1113
1114 TESTS:
1115
1116 The identity element is its own inverse::
1117
1118 sage: set_random_seed()
1119 sage: J = random_eja()
1120 sage: J.one().inverse() == J.one()
1121 True
1122
1123 If an element has an inverse, it acts like one::
1124
1125 sage: set_random_seed()
1126 sage: J = random_eja()
1127 sage: x = J.random_element()
1128 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
1129 True
1130
1131 The inverse of the inverse is what we started with::
1132
1133 sage: set_random_seed()
1134 sage: J = random_eja()
1135 sage: x = J.random_element()
1136 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
1137 True
1138
1139 The zero element is never invertible::
1140
1141 sage: set_random_seed()
1142 sage: J = random_eja().zero().inverse()
1143 Traceback (most recent call last):
1144 ...
1145 ValueError: element is not invertible
1146
1147 """
1148 if not self.is_invertible():
1149 raise ValueError("element is not invertible")
1150
1151 return (~self.quadratic_representation())(self)
1152
1153
1154 def is_invertible(self):
1155 """
1156 Return whether or not this element is invertible.
1157
1158 We can't use the superclass method because it relies on
1159 the algebra being associative.
1160
1161 ALGORITHM:
1162
1163 The usual way to do this is to check if the determinant is
1164 zero, but we need the characteristic polynomial for the
1165 determinant. The minimal polynomial is a lot easier to get,
1166 so we use Corollary 2 in Chapter V of Koecher to check
1167 whether or not the paren't algebra's zero element is a root
1168 of this element's minimal polynomial.
1169
1170 TESTS:
1171
1172 The identity element is always invertible::
1173
1174 sage: set_random_seed()
1175 sage: J = random_eja()
1176 sage: J.one().is_invertible()
1177 True
1178
1179 The zero element is never invertible::
1180
1181 sage: set_random_seed()
1182 sage: J = random_eja()
1183 sage: J.zero().is_invertible()
1184 False
1185
1186 """
1187 zero = self.parent().zero()
1188 p = self.minimal_polynomial()
1189 return not (p(zero) == zero)
1190
1191
1192 def is_nilpotent(self):
1193 """
1194 Return whether or not some power of this element is zero.
1195
1196 The superclass method won't work unless we're in an
1197 associative algebra, and we aren't. However, we generate
1198 an assocoative subalgebra and we're nilpotent there if and
1199 only if we're nilpotent here (probably).
1200
1201 TESTS:
1202
1203 The identity element is never nilpotent::
1204
1205 sage: set_random_seed()
1206 sage: random_eja().one().is_nilpotent()
1207 False
1208
1209 The additive identity is always nilpotent::
1210
1211 sage: set_random_seed()
1212 sage: random_eja().zero().is_nilpotent()
1213 True
1214
1215 """
1216 # The element we're going to call "is_nilpotent()" on.
1217 # Either myself, interpreted as an element of a finite-
1218 # dimensional algebra, or an element of an associative
1219 # subalgebra.
1220 elt = None
1221
1222 if self.parent().is_associative():
1223 elt = FiniteDimensionalAlgebraElement(self.parent(), self)
1224 else:
1225 V = self.span_of_powers()
1226 assoc_subalg = self.subalgebra_generated_by()
1227 # Mis-design warning: the basis used for span_of_powers()
1228 # and subalgebra_generated_by() must be the same, and in
1229 # the same order!
1230 elt = assoc_subalg(V.coordinates(self.vector()))
1231
1232 # Recursive call, but should work since elt lives in an
1233 # associative algebra.
1234 return elt.is_nilpotent()
1235
1236
1237 def is_regular(self):
1238 """
1239 Return whether or not this is a regular element.
1240
1241 EXAMPLES:
1242
1243 The identity element always has degree one, but any element
1244 linearly-independent from it is regular::
1245
1246 sage: J = JordanSpinEJA(5)
1247 sage: J.one().is_regular()
1248 False
1249 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
1250 sage: for x in J.gens():
1251 ....: (J.one() + x).is_regular()
1252 False
1253 True
1254 True
1255 True
1256 True
1257
1258 """
1259 return self.degree() == self.parent().rank()
1260
1261
1262 def degree(self):
1263 """
1264 Compute the degree of this element the straightforward way
1265 according to the definition; by appending powers to a list
1266 and figuring out its dimension (that is, whether or not
1267 they're linearly dependent).
1268
1269 EXAMPLES::
1270
1271 sage: J = JordanSpinEJA(4)
1272 sage: J.one().degree()
1273 1
1274 sage: e0,e1,e2,e3 = J.gens()
1275 sage: (e0 - e1).degree()
1276 2
1277
1278 In the spin factor algebra (of rank two), all elements that
1279 aren't multiples of the identity are regular::
1280
1281 sage: set_random_seed()
1282 sage: n = ZZ.random_element(1,10)
1283 sage: J = JordanSpinEJA(n)
1284 sage: x = J.random_element()
1285 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
1286 True
1287
1288 """
1289 return self.span_of_powers().dimension()
1290
1291
1292 def left_matrix(self):
1293 """
1294 Our parent class defines ``left_matrix`` and ``matrix``
1295 methods whose names are misleading. We don't want them.
1296 """
1297 raise NotImplementedError("use operator().matrix() instead")
1298
1299 matrix = left_matrix
1300
1301
1302 def minimal_polynomial(self):
1303 """
1304 Return the minimal polynomial of this element,
1305 as a function of the variable `t`.
1306
1307 ALGORITHM:
1308
1309 We restrict ourselves to the associative subalgebra
1310 generated by this element, and then return the minimal
1311 polynomial of this element's operator matrix (in that
1312 subalgebra). This works by Baes Proposition 2.3.16.
1313
1314 TESTS:
1315
1316 The minimal polynomial of the identity and zero elements are
1317 always the same::
1318
1319 sage: set_random_seed()
1320 sage: J = random_eja()
1321 sage: J.one().minimal_polynomial()
1322 t - 1
1323 sage: J.zero().minimal_polynomial()
1324 t
1325
1326 The degree of an element is (by one definition) the degree
1327 of its minimal polynomial::
1328
1329 sage: set_random_seed()
1330 sage: x = random_eja().random_element()
1331 sage: x.degree() == x.minimal_polynomial().degree()
1332 True
1333
1334 The minimal polynomial and the characteristic polynomial coincide
1335 and are known (see Alizadeh, Example 11.11) for all elements of
1336 the spin factor algebra that aren't scalar multiples of the
1337 identity::
1338
1339 sage: set_random_seed()
1340 sage: n = ZZ.random_element(2,10)
1341 sage: J = JordanSpinEJA(n)
1342 sage: y = J.random_element()
1343 sage: while y == y.coefficient(0)*J.one():
1344 ....: y = J.random_element()
1345 sage: y0 = y.vector()[0]
1346 sage: y_bar = y.vector()[1:]
1347 sage: actual = y.minimal_polynomial()
1348 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
1349 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
1350 sage: bool(actual == expected)
1351 True
1352
1353 The minimal polynomial should always kill its element::
1354
1355 sage: set_random_seed()
1356 sage: x = random_eja().random_element()
1357 sage: p = x.minimal_polynomial()
1358 sage: x.apply_univariate_polynomial(p)
1359 0
1360
1361 """
1362 V = self.span_of_powers()
1363 assoc_subalg = self.subalgebra_generated_by()
1364 # Mis-design warning: the basis used for span_of_powers()
1365 # and subalgebra_generated_by() must be the same, and in
1366 # the same order!
1367 elt = assoc_subalg(V.coordinates(self.vector()))
1368 return elt.operator().minimal_polynomial()
1369
1370
1371
1372 def natural_representation(self):
1373 """
1374 Return a more-natural representation of this element.
1375
1376 Every finite-dimensional Euclidean Jordan Algebra is a
1377 direct sum of five simple algebras, four of which comprise
1378 Hermitian matrices. This method returns the original
1379 "natural" representation of this element as a Hermitian
1380 matrix, if it has one. If not, you get the usual representation.
1381
1382 EXAMPLES::
1383
1384 sage: J = ComplexHermitianEJA(3)
1385 sage: J.one()
1386 e0 + e5 + e8
1387 sage: J.one().natural_representation()
1388 [1 0 0 0 0 0]
1389 [0 1 0 0 0 0]
1390 [0 0 1 0 0 0]
1391 [0 0 0 1 0 0]
1392 [0 0 0 0 1 0]
1393 [0 0 0 0 0 1]
1394
1395 ::
1396
1397 sage: J = QuaternionHermitianEJA(3)
1398 sage: J.one()
1399 e0 + e9 + e14
1400 sage: J.one().natural_representation()
1401 [1 0 0 0 0 0 0 0 0 0 0 0]
1402 [0 1 0 0 0 0 0 0 0 0 0 0]
1403 [0 0 1 0 0 0 0 0 0 0 0 0]
1404 [0 0 0 1 0 0 0 0 0 0 0 0]
1405 [0 0 0 0 1 0 0 0 0 0 0 0]
1406 [0 0 0 0 0 1 0 0 0 0 0 0]
1407 [0 0 0 0 0 0 1 0 0 0 0 0]
1408 [0 0 0 0 0 0 0 1 0 0 0 0]
1409 [0 0 0 0 0 0 0 0 1 0 0 0]
1410 [0 0 0 0 0 0 0 0 0 1 0 0]
1411 [0 0 0 0 0 0 0 0 0 0 1 0]
1412 [0 0 0 0 0 0 0 0 0 0 0 1]
1413
1414 """
1415 B = self.parent().natural_basis()
1416 W = B[0].matrix_space()
1417 return W.linear_combination(zip(self.vector(), B))
1418
1419
1420 def operator(self):
1421 """
1422 Return the left-multiplication-by-this-element
1423 operator on the ambient algebra.
1424
1425 TESTS::
1426
1427 sage: set_random_seed()
1428 sage: J = random_eja()
1429 sage: x = J.random_element()
1430 sage: y = J.random_element()
1431 sage: x.operator()(y) == x*y
1432 True
1433 sage: y.operator()(x) == x*y
1434 True
1435
1436 """
1437 P = self.parent()
1438 fda_elt = FiniteDimensionalAlgebraElement(P, self)
1439 return FiniteDimensionalEuclideanJordanAlgebraOperator(
1440 P,
1441 P,
1442 fda_elt.matrix().transpose() )
1443
1444
1445 def quadratic_representation(self, other=None):
1446 """
1447 Return the quadratic representation of this element.
1448
1449 EXAMPLES:
1450
1451 The explicit form in the spin factor algebra is given by
1452 Alizadeh's Example 11.12::
1453
1454 sage: set_random_seed()
1455 sage: n = ZZ.random_element(1,10)
1456 sage: J = JordanSpinEJA(n)
1457 sage: x = J.random_element()
1458 sage: x_vec = x.vector()
1459 sage: x0 = x_vec[0]
1460 sage: x_bar = x_vec[1:]
1461 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1462 sage: B = 2*x0*x_bar.row()
1463 sage: C = 2*x0*x_bar.column()
1464 sage: D = identity_matrix(QQ, n-1)
1465 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1466 sage: D = D + 2*x_bar.tensor_product(x_bar)
1467 sage: Q = block_matrix(2,2,[A,B,C,D])
1468 sage: Q == x.quadratic_representation().matrix()
1469 True
1470
1471 Test all of the properties from Theorem 11.2 in Alizadeh::
1472
1473 sage: set_random_seed()
1474 sage: J = random_eja()
1475 sage: x = J.random_element()
1476 sage: y = J.random_element()
1477 sage: Lx = x.operator()
1478 sage: Lxx = (x*x).operator()
1479 sage: Qx = x.quadratic_representation()
1480 sage: Qy = y.quadratic_representation()
1481 sage: Qxy = x.quadratic_representation(y)
1482 sage: Qex = J.one().quadratic_representation(x)
1483 sage: n = ZZ.random_element(10)
1484 sage: Qxn = (x^n).quadratic_representation()
1485
1486 Property 1:
1487
1488 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1489 True
1490
1491 Property 2 (multiply on the right for :trac:`28272`):
1492
1493 sage: alpha = QQ.random_element()
1494 sage: (alpha*x).quadratic_representation() == Qx*(alpha^2)
1495 True
1496
1497 Property 3:
1498
1499 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
1500 True
1501
1502 sage: not x.is_invertible() or (
1503 ....: ~Qx
1504 ....: ==
1505 ....: x.inverse().quadratic_representation() )
1506 True
1507
1508 sage: Qxy(J.one()) == x*y
1509 True
1510
1511 Property 4:
1512
1513 sage: not x.is_invertible() or (
1514 ....: x.quadratic_representation(x.inverse())*Qx
1515 ....: == Qx*x.quadratic_representation(x.inverse()) )
1516 True
1517
1518 sage: not x.is_invertible() or (
1519 ....: x.quadratic_representation(x.inverse())*Qx
1520 ....: ==
1521 ....: 2*x.operator()*Qex - Qx )
1522 True
1523
1524 sage: 2*x.operator()*Qex - Qx == Lxx
1525 True
1526
1527 Property 5:
1528
1529 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
1530 True
1531
1532 Property 6:
1533
1534 sage: Qxn == (Qx)^n
1535 True
1536
1537 Property 7:
1538
1539 sage: not x.is_invertible() or (
1540 ....: Qx*x.inverse().operator() == Lx )
1541 True
1542
1543 Property 8:
1544
1545 sage: not x.operator_commutes_with(y) or (
1546 ....: Qx(y)^n == Qxn(y^n) )
1547 True
1548
1549 """
1550 if other is None:
1551 other=self
1552 elif not other in self.parent():
1553 raise TypeError("'other' must live in the same algebra")
1554
1555 L = self.operator()
1556 M = other.operator()
1557 return ( L*M + M*L - (self*other).operator() )
1558
1559
1560 def span_of_powers(self):
1561 """
1562 Return the vector space spanned by successive powers of
1563 this element.
1564 """
1565 # The dimension of the subalgebra can't be greater than
1566 # the big algebra, so just put everything into a list
1567 # and let span() get rid of the excess.
1568 #
1569 # We do the extra ambient_vector_space() in case we're messing
1570 # with polynomials and the direct parent is a module.
1571 V = self.parent().vector_space()
1572 return V.span( (self**d).vector() for d in xrange(V.dimension()) )
1573
1574
1575 def subalgebra_generated_by(self):
1576 """
1577 Return the associative subalgebra of the parent EJA generated
1578 by this element.
1579
1580 TESTS::
1581
1582 sage: set_random_seed()
1583 sage: x = random_eja().random_element()
1584 sage: x.subalgebra_generated_by().is_associative()
1585 True
1586
1587 Squaring in the subalgebra should work the same as in
1588 the superalgebra::
1589
1590 sage: set_random_seed()
1591 sage: x = random_eja().random_element()
1592 sage: u = x.subalgebra_generated_by().random_element()
1593 sage: u.operator()(u) == u^2
1594 True
1595
1596 """
1597 # First get the subspace spanned by the powers of myself...
1598 V = self.span_of_powers()
1599 F = self.base_ring()
1600
1601 # Now figure out the entries of the right-multiplication
1602 # matrix for the successive basis elements b0, b1,... of
1603 # that subspace.
1604 mats = []
1605 for b_right in V.basis():
1606 eja_b_right = self.parent()(b_right)
1607 b_right_rows = []
1608 # The first row of the right-multiplication matrix by
1609 # b1 is what we get if we apply that matrix to b1. The
1610 # second row of the right multiplication matrix by b1
1611 # is what we get when we apply that matrix to b2...
1612 #
1613 # IMPORTANT: this assumes that all vectors are COLUMN
1614 # vectors, unlike our superclass (which uses row vectors).
1615 for b_left in V.basis():
1616 eja_b_left = self.parent()(b_left)
1617 # Multiply in the original EJA, but then get the
1618 # coordinates from the subalgebra in terms of its
1619 # basis.
1620 this_row = V.coordinates((eja_b_left*eja_b_right).vector())
1621 b_right_rows.append(this_row)
1622 b_right_matrix = matrix(F, b_right_rows)
1623 mats.append(b_right_matrix)
1624
1625 # It's an algebra of polynomials in one element, and EJAs
1626 # are power-associative.
1627 #
1628 # TODO: choose generator names intelligently.
1629 return FiniteDimensionalEuclideanJordanAlgebra(F, mats, assume_associative=True, names='f')
1630
1631
1632 def subalgebra_idempotent(self):
1633 """
1634 Find an idempotent in the associative subalgebra I generate
1635 using Proposition 2.3.5 in Baes.
1636
1637 TESTS::
1638
1639 sage: set_random_seed()
1640 sage: J = random_eja()
1641 sage: x = J.random_element()
1642 sage: while x.is_nilpotent():
1643 ....: x = J.random_element()
1644 sage: c = x.subalgebra_idempotent()
1645 sage: c^2 == c
1646 True
1647
1648 """
1649 if self.is_nilpotent():
1650 raise ValueError("this only works with non-nilpotent elements!")
1651
1652 V = self.span_of_powers()
1653 J = self.subalgebra_generated_by()
1654 # Mis-design warning: the basis used for span_of_powers()
1655 # and subalgebra_generated_by() must be the same, and in
1656 # the same order!
1657 u = J(V.coordinates(self.vector()))
1658
1659 # The image of the matrix of left-u^m-multiplication
1660 # will be minimal for some natural number s...
1661 s = 0
1662 minimal_dim = V.dimension()
1663 for i in xrange(1, V.dimension()):
1664 this_dim = (u**i).operator().matrix().image().dimension()
1665 if this_dim < minimal_dim:
1666 minimal_dim = this_dim
1667 s = i
1668
1669 # Now minimal_matrix should correspond to the smallest
1670 # non-zero subspace in Baes's (or really, Koecher's)
1671 # proposition.
1672 #
1673 # However, we need to restrict the matrix to work on the
1674 # subspace... or do we? Can't we just solve, knowing that
1675 # A(c) = u^(s+1) should have a solution in the big space,
1676 # too?
1677 #
1678 # Beware, solve_right() means that we're using COLUMN vectors.
1679 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1680 u_next = u**(s+1)
1681 A = u_next.operator().matrix()
1682 c_coordinates = A.solve_right(u_next.vector())
1683
1684 # Now c_coordinates is the idempotent we want, but it's in
1685 # the coordinate system of the subalgebra.
1686 #
1687 # We need the basis for J, but as elements of the parent algebra.
1688 #
1689 basis = [self.parent(v) for v in V.basis()]
1690 return self.parent().linear_combination(zip(c_coordinates, basis))
1691
1692
1693 def trace(self):
1694 """
1695 Return my trace, the sum of my eigenvalues.
1696
1697 EXAMPLES::
1698
1699 sage: J = JordanSpinEJA(3)
1700 sage: x = sum(J.gens())
1701 sage: x.trace()
1702 2
1703
1704 ::
1705
1706 sage: J = RealCartesianProductEJA(5)
1707 sage: J.one().trace()
1708 5
1709
1710 TESTS:
1711
1712 The trace of an element is a real number::
1713
1714 sage: set_random_seed()
1715 sage: J = random_eja()
1716 sage: J.random_element().trace() in J.base_ring()
1717 True
1718
1719 """
1720 P = self.parent()
1721 r = P.rank()
1722 p = P._charpoly_coeff(r-1)
1723 # The _charpoly_coeff function already adds the factor of
1724 # -1 to ensure that _charpoly_coeff(r-1) is really what
1725 # appears in front of t^{r-1} in the charpoly. However,
1726 # we want the negative of THAT for the trace.
1727 return -p(*self.vector())
1728
1729
1730 def trace_inner_product(self, other):
1731 """
1732 Return the trace inner product of myself and ``other``.
1733
1734 TESTS:
1735
1736 The trace inner product is commutative::
1737
1738 sage: set_random_seed()
1739 sage: J = random_eja()
1740 sage: x = J.random_element(); y = J.random_element()
1741 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1742 True
1743
1744 The trace inner product is bilinear::
1745
1746 sage: set_random_seed()
1747 sage: J = random_eja()
1748 sage: x = J.random_element()
1749 sage: y = J.random_element()
1750 sage: z = J.random_element()
1751 sage: a = QQ.random_element();
1752 sage: actual = (a*(x+z)).trace_inner_product(y)
1753 sage: expected = ( a*x.trace_inner_product(y) +
1754 ....: a*z.trace_inner_product(y) )
1755 sage: actual == expected
1756 True
1757 sage: actual = x.trace_inner_product(a*(y+z))
1758 sage: expected = ( a*x.trace_inner_product(y) +
1759 ....: a*x.trace_inner_product(z) )
1760 sage: actual == expected
1761 True
1762
1763 The trace inner product satisfies the compatibility
1764 condition in the definition of a Euclidean Jordan algebra::
1765
1766 sage: set_random_seed()
1767 sage: J = random_eja()
1768 sage: x = J.random_element()
1769 sage: y = J.random_element()
1770 sage: z = J.random_element()
1771 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1772 True
1773
1774 """
1775 if not other in self.parent():
1776 raise TypeError("'other' must live in the same algebra")
1777
1778 return (self*other).trace()
1779
1780
1781 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
1782 """
1783 Return the Euclidean Jordan Algebra corresponding to the set
1784 `R^n` under the Hadamard product.
1785
1786 Note: this is nothing more than the Cartesian product of ``n``
1787 copies of the spin algebra. Once Cartesian product algebras
1788 are implemented, this can go.
1789
1790 EXAMPLES:
1791
1792 This multiplication table can be verified by hand::
1793
1794 sage: J = RealCartesianProductEJA(3)
1795 sage: e0,e1,e2 = J.gens()
1796 sage: e0*e0
1797 e0
1798 sage: e0*e1
1799 0
1800 sage: e0*e2
1801 0
1802 sage: e1*e1
1803 e1
1804 sage: e1*e2
1805 0
1806 sage: e2*e2
1807 e2
1808
1809 """
1810 @staticmethod
1811 def __classcall_private__(cls, n, field=QQ):
1812 # The FiniteDimensionalAlgebra constructor takes a list of
1813 # matrices, the ith representing right multiplication by the ith
1814 # basis element in the vector space. So if e_1 = (1,0,0), then
1815 # right (Hadamard) multiplication of x by e_1 picks out the first
1816 # component of x; and likewise for the ith basis element e_i.
1817 Qs = [ matrix(field, n, n, lambda k,j: 1*(k == j == i))
1818 for i in xrange(n) ]
1819
1820 fdeja = super(RealCartesianProductEJA, cls)
1821 return fdeja.__classcall_private__(cls, field, Qs, rank=n)
1822
1823 def inner_product(self, x, y):
1824 return _usual_ip(x,y)
1825
1826
1827 def random_eja():
1828 """
1829 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1830
1831 ALGORITHM:
1832
1833 For now, we choose a random natural number ``n`` (greater than zero)
1834 and then give you back one of the following:
1835
1836 * The cartesian product of the rational numbers ``n`` times; this is
1837 ``QQ^n`` with the Hadamard product.
1838
1839 * The Jordan spin algebra on ``QQ^n``.
1840
1841 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1842 product.
1843
1844 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1845 in the space of ``2n``-by-``2n`` real symmetric matrices.
1846
1847 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1848 in the space of ``4n``-by-``4n`` real symmetric matrices.
1849
1850 Later this might be extended to return Cartesian products of the
1851 EJAs above.
1852
1853 TESTS::
1854
1855 sage: random_eja()
1856 Euclidean Jordan algebra of degree...
1857
1858 """
1859
1860 # The max_n component lets us choose different upper bounds on the
1861 # value "n" that gets passed to the constructor. This is needed
1862 # because e.g. R^{10} is reasonable to test, while the Hermitian
1863 # 10-by-10 quaternion matrices are not.
1864 (constructor, max_n) = choice([(RealCartesianProductEJA, 6),
1865 (JordanSpinEJA, 6),
1866 (RealSymmetricEJA, 5),
1867 (ComplexHermitianEJA, 4),
1868 (QuaternionHermitianEJA, 3)])
1869 n = ZZ.random_element(1, max_n)
1870 return constructor(n, field=QQ)
1871
1872
1873
1874 def _real_symmetric_basis(n, field=QQ):
1875 """
1876 Return a basis for the space of real symmetric n-by-n matrices.
1877 """
1878 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1879 # coordinates.
1880 S = []
1881 for i in xrange(n):
1882 for j in xrange(i+1):
1883 Eij = matrix(field, n, lambda k,l: k==i and l==j)
1884 if i == j:
1885 Sij = Eij
1886 else:
1887 # Beware, orthogonal but not normalized!
1888 Sij = Eij + Eij.transpose()
1889 S.append(Sij)
1890 return tuple(S)
1891
1892
1893 def _complex_hermitian_basis(n, field=QQ):
1894 """
1895 Returns a basis for the space of complex Hermitian n-by-n matrices.
1896
1897 TESTS::
1898
1899 sage: set_random_seed()
1900 sage: n = ZZ.random_element(1,5)
1901 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1902 True
1903
1904 """
1905 F = QuadraticField(-1, 'I')
1906 I = F.gen()
1907
1908 # This is like the symmetric case, but we need to be careful:
1909 #
1910 # * We want conjugate-symmetry, not just symmetry.
1911 # * The diagonal will (as a result) be real.
1912 #
1913 S = []
1914 for i in xrange(n):
1915 for j in xrange(i+1):
1916 Eij = matrix(field, n, lambda k,l: k==i and l==j)
1917 if i == j:
1918 Sij = _embed_complex_matrix(Eij)
1919 S.append(Sij)
1920 else:
1921 # Beware, orthogonal but not normalized! The second one
1922 # has a minus because it's conjugated.
1923 Sij_real = _embed_complex_matrix(Eij + Eij.transpose())
1924 S.append(Sij_real)
1925 Sij_imag = _embed_complex_matrix(I*Eij - I*Eij.transpose())
1926 S.append(Sij_imag)
1927 return tuple(S)
1928
1929
1930 def _quaternion_hermitian_basis(n, field=QQ):
1931 """
1932 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1933
1934 TESTS::
1935
1936 sage: set_random_seed()
1937 sage: n = ZZ.random_element(1,5)
1938 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1939 True
1940
1941 """
1942 Q = QuaternionAlgebra(QQ,-1,-1)
1943 I,J,K = Q.gens()
1944
1945 # This is like the symmetric case, but we need to be careful:
1946 #
1947 # * We want conjugate-symmetry, not just symmetry.
1948 # * The diagonal will (as a result) be real.
1949 #
1950 S = []
1951 for i in xrange(n):
1952 for j in xrange(i+1):
1953 Eij = matrix(Q, n, lambda k,l: k==i and l==j)
1954 if i == j:
1955 Sij = _embed_quaternion_matrix(Eij)
1956 S.append(Sij)
1957 else:
1958 # Beware, orthogonal but not normalized! The second,
1959 # third, and fourth ones have a minus because they're
1960 # conjugated.
1961 Sij_real = _embed_quaternion_matrix(Eij + Eij.transpose())
1962 S.append(Sij_real)
1963 Sij_I = _embed_quaternion_matrix(I*Eij - I*Eij.transpose())
1964 S.append(Sij_I)
1965 Sij_J = _embed_quaternion_matrix(J*Eij - J*Eij.transpose())
1966 S.append(Sij_J)
1967 Sij_K = _embed_quaternion_matrix(K*Eij - K*Eij.transpose())
1968 S.append(Sij_K)
1969 return tuple(S)
1970
1971
1972 def _mat2vec(m):
1973 return vector(m.base_ring(), m.list())
1974
1975 def _vec2mat(v):
1976 return matrix(v.base_ring(), sqrt(v.degree()), v.list())
1977
1978 def _multiplication_table_from_matrix_basis(basis):
1979 """
1980 At least three of the five simple Euclidean Jordan algebras have the
1981 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1982 multiplication on the right is matrix multiplication. Given a basis
1983 for the underlying matrix space, this function returns a
1984 multiplication table (obtained by looping through the basis
1985 elements) for an algebra of those matrices. A reordered copy
1986 of the basis is also returned to work around the fact that
1987 the ``span()`` in this function will change the order of the basis
1988 from what we think it is, to... something else.
1989 """
1990 # In S^2, for example, we nominally have four coordinates even
1991 # though the space is of dimension three only. The vector space V
1992 # is supposed to hold the entire long vector, and the subspace W
1993 # of V will be spanned by the vectors that arise from symmetric
1994 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1995 field = basis[0].base_ring()
1996 dimension = basis[0].nrows()
1997
1998 V = VectorSpace(field, dimension**2)
1999 W = V.span( _mat2vec(s) for s in basis )
2000
2001 # Taking the span above reorders our basis (thanks, jerk!) so we
2002 # need to put our "matrix basis" in the same order as the
2003 # (reordered) vector basis.
2004 S = tuple( _vec2mat(b) for b in W.basis() )
2005
2006 Qs = []
2007 for s in S:
2008 # Brute force the multiplication-by-s matrix by looping
2009 # through all elements of the basis and doing the computation
2010 # to find out what the corresponding row should be. BEWARE:
2011 # these multiplication tables won't be symmetric! It therefore
2012 # becomes REALLY IMPORTANT that the underlying algebra
2013 # constructor uses ROW vectors and not COLUMN vectors. That's
2014 # why we're computing rows here and not columns.
2015 Q_rows = []
2016 for t in S:
2017 this_row = _mat2vec((s*t + t*s)/2)
2018 Q_rows.append(W.coordinates(this_row))
2019 Q = matrix(field, W.dimension(), Q_rows)
2020 Qs.append(Q)
2021
2022 return (Qs, S)
2023
2024
2025 def _embed_complex_matrix(M):
2026 """
2027 Embed the n-by-n complex matrix ``M`` into the space of real
2028 matrices of size 2n-by-2n via the map the sends each entry `z = a +
2029 bi` to the block matrix ``[[a,b],[-b,a]]``.
2030
2031 EXAMPLES::
2032
2033 sage: F = QuadraticField(-1,'i')
2034 sage: x1 = F(4 - 2*i)
2035 sage: x2 = F(1 + 2*i)
2036 sage: x3 = F(-i)
2037 sage: x4 = F(6)
2038 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
2039 sage: _embed_complex_matrix(M)
2040 [ 4 -2| 1 2]
2041 [ 2 4|-2 1]
2042 [-----+-----]
2043 [ 0 -1| 6 0]
2044 [ 1 0| 0 6]
2045
2046 TESTS:
2047
2048 Embedding is a homomorphism (isomorphism, in fact)::
2049
2050 sage: set_random_seed()
2051 sage: n = ZZ.random_element(5)
2052 sage: F = QuadraticField(-1, 'i')
2053 sage: X = random_matrix(F, n)
2054 sage: Y = random_matrix(F, n)
2055 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
2056 sage: expected = _embed_complex_matrix(X*Y)
2057 sage: actual == expected
2058 True
2059
2060 """
2061 n = M.nrows()
2062 if M.ncols() != n:
2063 raise ValueError("the matrix 'M' must be square")
2064 field = M.base_ring()
2065 blocks = []
2066 for z in M.list():
2067 a = z.real()
2068 b = z.imag()
2069 blocks.append(matrix(field, 2, [[a,b],[-b,a]]))
2070
2071 # We can drop the imaginaries here.
2072 return block_matrix(field.base_ring(), n, blocks)
2073
2074
2075 def _unembed_complex_matrix(M):
2076 """
2077 The inverse of _embed_complex_matrix().
2078
2079 EXAMPLES::
2080
2081 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
2082 ....: [-2, 1, -4, 3],
2083 ....: [ 9, 10, 11, 12],
2084 ....: [-10, 9, -12, 11] ])
2085 sage: _unembed_complex_matrix(A)
2086 [ 2*i + 1 4*i + 3]
2087 [ 10*i + 9 12*i + 11]
2088
2089 TESTS:
2090
2091 Unembedding is the inverse of embedding::
2092
2093 sage: set_random_seed()
2094 sage: F = QuadraticField(-1, 'i')
2095 sage: M = random_matrix(F, 3)
2096 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
2097 True
2098
2099 """
2100 n = ZZ(M.nrows())
2101 if M.ncols() != n:
2102 raise ValueError("the matrix 'M' must be square")
2103 if not n.mod(2).is_zero():
2104 raise ValueError("the matrix 'M' must be a complex embedding")
2105
2106 F = QuadraticField(-1, 'i')
2107 i = F.gen()
2108
2109 # Go top-left to bottom-right (reading order), converting every
2110 # 2-by-2 block we see to a single complex element.
2111 elements = []
2112 for k in xrange(n/2):
2113 for j in xrange(n/2):
2114 submat = M[2*k:2*k+2,2*j:2*j+2]
2115 if submat[0,0] != submat[1,1]:
2116 raise ValueError('bad on-diagonal submatrix')
2117 if submat[0,1] != -submat[1,0]:
2118 raise ValueError('bad off-diagonal submatrix')
2119 z = submat[0,0] + submat[0,1]*i
2120 elements.append(z)
2121
2122 return matrix(F, n/2, elements)
2123
2124
2125 def _embed_quaternion_matrix(M):
2126 """
2127 Embed the n-by-n quaternion matrix ``M`` into the space of real
2128 matrices of size 4n-by-4n by first sending each quaternion entry
2129 `z = a + bi + cj + dk` to the block-complex matrix
2130 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
2131 a real matrix.
2132
2133 EXAMPLES::
2134
2135 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2136 sage: i,j,k = Q.gens()
2137 sage: x = 1 + 2*i + 3*j + 4*k
2138 sage: M = matrix(Q, 1, [[x]])
2139 sage: _embed_quaternion_matrix(M)
2140 [ 1 2 3 4]
2141 [-2 1 -4 3]
2142 [-3 4 1 -2]
2143 [-4 -3 2 1]
2144
2145 Embedding is a homomorphism (isomorphism, in fact)::
2146
2147 sage: set_random_seed()
2148 sage: n = ZZ.random_element(5)
2149 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2150 sage: X = random_matrix(Q, n)
2151 sage: Y = random_matrix(Q, n)
2152 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
2153 sage: expected = _embed_quaternion_matrix(X*Y)
2154 sage: actual == expected
2155 True
2156
2157 """
2158 quaternions = M.base_ring()
2159 n = M.nrows()
2160 if M.ncols() != n:
2161 raise ValueError("the matrix 'M' must be square")
2162
2163 F = QuadraticField(-1, 'i')
2164 i = F.gen()
2165
2166 blocks = []
2167 for z in M.list():
2168 t = z.coefficient_tuple()
2169 a = t[0]
2170 b = t[1]
2171 c = t[2]
2172 d = t[3]
2173 cplx_matrix = matrix(F, 2, [[ a + b*i, c + d*i],
2174 [-c + d*i, a - b*i]])
2175 blocks.append(_embed_complex_matrix(cplx_matrix))
2176
2177 # We should have real entries by now, so use the realest field
2178 # we've got for the return value.
2179 return block_matrix(quaternions.base_ring(), n, blocks)
2180
2181
2182 def _unembed_quaternion_matrix(M):
2183 """
2184 The inverse of _embed_quaternion_matrix().
2185
2186 EXAMPLES::
2187
2188 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
2189 ....: [-2, 1, -4, 3],
2190 ....: [-3, 4, 1, -2],
2191 ....: [-4, -3, 2, 1]])
2192 sage: _unembed_quaternion_matrix(M)
2193 [1 + 2*i + 3*j + 4*k]
2194
2195 TESTS:
2196
2197 Unembedding is the inverse of embedding::
2198
2199 sage: set_random_seed()
2200 sage: Q = QuaternionAlgebra(QQ, -1, -1)
2201 sage: M = random_matrix(Q, 3)
2202 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
2203 True
2204
2205 """
2206 n = ZZ(M.nrows())
2207 if M.ncols() != n:
2208 raise ValueError("the matrix 'M' must be square")
2209 if not n.mod(4).is_zero():
2210 raise ValueError("the matrix 'M' must be a complex embedding")
2211
2212 Q = QuaternionAlgebra(QQ,-1,-1)
2213 i,j,k = Q.gens()
2214
2215 # Go top-left to bottom-right (reading order), converting every
2216 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
2217 # quaternion block.
2218 elements = []
2219 for l in xrange(n/4):
2220 for m in xrange(n/4):
2221 submat = _unembed_complex_matrix(M[4*l:4*l+4,4*m:4*m+4])
2222 if submat[0,0] != submat[1,1].conjugate():
2223 raise ValueError('bad on-diagonal submatrix')
2224 if submat[0,1] != -submat[1,0].conjugate():
2225 raise ValueError('bad off-diagonal submatrix')
2226 z = submat[0,0].real() + submat[0,0].imag()*i
2227 z += submat[0,1].real()*j + submat[0,1].imag()*k
2228 elements.append(z)
2229
2230 return matrix(Q, n/4, elements)
2231
2232
2233 # The usual inner product on R^n.
2234 def _usual_ip(x,y):
2235 return x.vector().inner_product(y.vector())
2236
2237 # The inner product used for the real symmetric simple EJA.
2238 # We keep it as a separate function because e.g. the complex
2239 # algebra uses the same inner product, except divided by 2.
2240 def _matrix_ip(X,Y):
2241 X_mat = X.natural_representation()
2242 Y_mat = Y.natural_representation()
2243 return (X_mat*Y_mat).trace()
2244
2245
2246 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
2247 """
2248 The rank-n simple EJA consisting of real symmetric n-by-n
2249 matrices, the usual symmetric Jordan product, and the trace inner
2250 product. It has dimension `(n^2 + n)/2` over the reals.
2251
2252 EXAMPLES::
2253
2254 sage: J = RealSymmetricEJA(2)
2255 sage: e0, e1, e2 = J.gens()
2256 sage: e0*e0
2257 e0
2258 sage: e1*e1
2259 e0 + e2
2260 sage: e2*e2
2261 e2
2262
2263 TESTS:
2264
2265 The degree of this algebra is `(n^2 + n) / 2`::
2266
2267 sage: set_random_seed()
2268 sage: n = ZZ.random_element(1,5)
2269 sage: J = RealSymmetricEJA(n)
2270 sage: J.degree() == (n^2 + n)/2
2271 True
2272
2273 The Jordan multiplication is what we think it is::
2274
2275 sage: set_random_seed()
2276 sage: n = ZZ.random_element(1,5)
2277 sage: J = RealSymmetricEJA(n)
2278 sage: x = J.random_element()
2279 sage: y = J.random_element()
2280 sage: actual = (x*y).natural_representation()
2281 sage: X = x.natural_representation()
2282 sage: Y = y.natural_representation()
2283 sage: expected = (X*Y + Y*X)/2
2284 sage: actual == expected
2285 True
2286 sage: J(expected) == x*y
2287 True
2288
2289 """
2290 @staticmethod
2291 def __classcall_private__(cls, n, field=QQ):
2292 S = _real_symmetric_basis(n, field=field)
2293 (Qs, T) = _multiplication_table_from_matrix_basis(S)
2294
2295 fdeja = super(RealSymmetricEJA, cls)
2296 return fdeja.__classcall_private__(cls,
2297 field,
2298 Qs,
2299 rank=n,
2300 natural_basis=T)
2301
2302 def inner_product(self, x, y):
2303 return _matrix_ip(x,y)
2304
2305
2306 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
2307 """
2308 The rank-n simple EJA consisting of complex Hermitian n-by-n
2309 matrices over the real numbers, the usual symmetric Jordan product,
2310 and the real-part-of-trace inner product. It has dimension `n^2` over
2311 the reals.
2312
2313 TESTS:
2314
2315 The degree of this algebra is `n^2`::
2316
2317 sage: set_random_seed()
2318 sage: n = ZZ.random_element(1,5)
2319 sage: J = ComplexHermitianEJA(n)
2320 sage: J.degree() == n^2
2321 True
2322
2323 The Jordan multiplication is what we think it is::
2324
2325 sage: set_random_seed()
2326 sage: n = ZZ.random_element(1,5)
2327 sage: J = ComplexHermitianEJA(n)
2328 sage: x = J.random_element()
2329 sage: y = J.random_element()
2330 sage: actual = (x*y).natural_representation()
2331 sage: X = x.natural_representation()
2332 sage: Y = y.natural_representation()
2333 sage: expected = (X*Y + Y*X)/2
2334 sage: actual == expected
2335 True
2336 sage: J(expected) == x*y
2337 True
2338
2339 """
2340 @staticmethod
2341 def __classcall_private__(cls, n, field=QQ):
2342 S = _complex_hermitian_basis(n)
2343 (Qs, T) = _multiplication_table_from_matrix_basis(S)
2344
2345 fdeja = super(ComplexHermitianEJA, cls)
2346 return fdeja.__classcall_private__(cls,
2347 field,
2348 Qs,
2349 rank=n,
2350 natural_basis=T)
2351
2352 def inner_product(self, x, y):
2353 # Since a+bi on the diagonal is represented as
2354 #
2355 # a + bi = [ a b ]
2356 # [ -b a ],
2357 #
2358 # we'll double-count the "a" entries if we take the trace of
2359 # the embedding.
2360 return _matrix_ip(x,y)/2
2361
2362
2363 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
2364 """
2365 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2366 matrices, the usual symmetric Jordan product, and the
2367 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2368 the reals.
2369
2370 TESTS:
2371
2372 The degree of this algebra is `n^2`::
2373
2374 sage: set_random_seed()
2375 sage: n = ZZ.random_element(1,5)
2376 sage: J = QuaternionHermitianEJA(n)
2377 sage: J.degree() == 2*(n^2) - n
2378 True
2379
2380 The Jordan multiplication is what we think it is::
2381
2382 sage: set_random_seed()
2383 sage: n = ZZ.random_element(1,5)
2384 sage: J = QuaternionHermitianEJA(n)
2385 sage: x = J.random_element()
2386 sage: y = J.random_element()
2387 sage: actual = (x*y).natural_representation()
2388 sage: X = x.natural_representation()
2389 sage: Y = y.natural_representation()
2390 sage: expected = (X*Y + Y*X)/2
2391 sage: actual == expected
2392 True
2393 sage: J(expected) == x*y
2394 True
2395
2396 """
2397 @staticmethod
2398 def __classcall_private__(cls, n, field=QQ):
2399 S = _quaternion_hermitian_basis(n)
2400 (Qs, T) = _multiplication_table_from_matrix_basis(S)
2401
2402 fdeja = super(QuaternionHermitianEJA, cls)
2403 return fdeja.__classcall_private__(cls,
2404 field,
2405 Qs,
2406 rank=n,
2407 natural_basis=T)
2408
2409 def inner_product(self, x, y):
2410 # Since a+bi+cj+dk on the diagonal is represented as
2411 #
2412 # a + bi +cj + dk = [ a b c d]
2413 # [ -b a -d c]
2414 # [ -c d a -b]
2415 # [ -d -c b a],
2416 #
2417 # we'll quadruple-count the "a" entries if we take the trace of
2418 # the embedding.
2419 return _matrix_ip(x,y)/4
2420
2421
2422 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
2423 """
2424 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2425 with the usual inner product and jordan product ``x*y =
2426 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2427 the reals.
2428
2429 EXAMPLES:
2430
2431 This multiplication table can be verified by hand::
2432
2433 sage: J = JordanSpinEJA(4)
2434 sage: e0,e1,e2,e3 = J.gens()
2435 sage: e0*e0
2436 e0
2437 sage: e0*e1
2438 e1
2439 sage: e0*e2
2440 e2
2441 sage: e0*e3
2442 e3
2443 sage: e1*e2
2444 0
2445 sage: e1*e3
2446 0
2447 sage: e2*e3
2448 0
2449
2450 """
2451 @staticmethod
2452 def __classcall_private__(cls, n, field=QQ):
2453 Qs = []
2454 id_matrix = identity_matrix(field, n)
2455 for i in xrange(n):
2456 ei = id_matrix.column(i)
2457 Qi = zero_matrix(field, n)
2458 Qi.set_row(0, ei)
2459 Qi.set_column(0, ei)
2460 Qi += diagonal_matrix(n, [ei[0]]*n)
2461 # The addition of the diagonal matrix adds an extra ei[0] in the
2462 # upper-left corner of the matrix.
2463 Qi[0,0] = Qi[0,0] * ~field(2)
2464 Qs.append(Qi)
2465
2466 # The rank of the spin algebra is two, unless we're in a
2467 # one-dimensional ambient space (because the rank is bounded by
2468 # the ambient dimension).
2469 fdeja = super(JordanSpinEJA, cls)
2470 return fdeja.__classcall_private__(cls, field, Qs, rank=min(n,2))
2471
2472 def inner_product(self, x, y):
2473 return _usual_ip(x,y)