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.
8 from itertools
import repeat
10 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
11 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
12 from sage
.combinat
.free_module
import CombinatorialFreeModule
13 from sage
.matrix
.constructor
import matrix
14 from sage
.matrix
.matrix_space
import MatrixSpace
15 from sage
.misc
.cachefunc
import cached_method
16 from sage
.misc
.lazy_import
import lazy_import
17 from sage
.misc
.prandom
import choice
18 from sage
.misc
.table
import table
19 from sage
.modules
.free_module
import FreeModule
, VectorSpace
20 from sage
.rings
.all
import (ZZ
, QQ
, AA
, QQbar
, RR
, RLF
, CLF
,
23 from mjo
.eja
.eja_element
import FiniteDimensionalEuclideanJordanAlgebraElement
24 lazy_import('mjo.eja.eja_subalgebra',
25 'FiniteDimensionalEuclideanJordanSubalgebra')
26 from mjo
.eja
.eja_utils
import _mat2vec
28 class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule
):
30 def _coerce_map_from_base_ring(self
):
32 Disable the map from the base ring into the algebra.
34 Performing a nonsense conversion like this automatically
35 is counterpedagogical. The fallback is to try the usual
36 element constructor, which should also fail.
40 sage: from mjo.eja.eja_algebra import random_eja
44 sage: set_random_seed()
45 sage: J = random_eja()
47 Traceback (most recent call last):
49 ValueError: not a naturally-represented algebra element
64 sage: from mjo.eja.eja_algebra import (JordanSpinEJA, random_eja)
68 By definition, Jordan multiplication commutes::
70 sage: set_random_seed()
71 sage: J = random_eja()
72 sage: x,y = J.random_elements(2)
78 The ``field`` we're given must be real::
80 sage: JordanSpinEJA(2,QQbar)
81 Traceback (most recent call last):
83 ValueError: field is not real
87 if not field
.is_subring(RR
):
88 # Note: this does return true for the real algebraic
89 # field, and any quadratic field where we've specified
91 raise ValueError('field is not real')
93 self
._natural
_basis
= natural_basis
96 category
= MagmaticAlgebras(field
).FiniteDimensional()
97 category
= category
.WithBasis().Unital()
99 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
101 range(len(mult_table
)),
104 self
.print_options(bracket
='')
106 # The multiplication table we're given is necessarily in terms
107 # of vectors, because we don't have an algebra yet for
108 # anything to be an element of. However, it's faster in the
109 # long run to have the multiplication table be in terms of
110 # algebra elements. We do this after calling the superclass
111 # constructor so that from_vector() knows what to do.
112 self
._multiplication
_table
= [
113 list(map(lambda x
: self
.from_vector(x
), ls
))
118 def _element_constructor_(self
, elt
):
120 Construct an element of this algebra from its natural
123 This gets called only after the parent element _call_ method
124 fails to find a coercion for the argument.
128 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
130 ....: RealSymmetricEJA)
134 The identity in `S^n` is converted to the identity in the EJA::
136 sage: J = RealSymmetricEJA(3)
137 sage: I = matrix.identity(QQ,3)
138 sage: J(I) == J.one()
141 This skew-symmetric matrix can't be represented in the EJA::
143 sage: J = RealSymmetricEJA(3)
144 sage: A = matrix(QQ,3, lambda i,j: i-j)
146 Traceback (most recent call last):
148 ArithmeticError: vector is not in free module
152 Ensure that we can convert any element of the two non-matrix
153 simple algebras (whose natural representations are their usual
154 vector representations) back and forth faithfully::
156 sage: set_random_seed()
157 sage: J = HadamardEJA.random_instance()
158 sage: x = J.random_element()
159 sage: J(x.to_vector().column()) == x
161 sage: J = JordanSpinEJA.random_instance()
162 sage: x = J.random_element()
163 sage: J(x.to_vector().column()) == x
167 msg
= "not a naturally-represented algebra element"
169 # The superclass implementation of random_element()
170 # needs to be able to coerce "0" into the algebra.
172 elif elt
in self
.base_ring():
173 # Ensure that no base ring -> algebra coercion is performed
174 # by this method. There's some stupidity in sage that would
175 # otherwise propagate to this method; for example, sage thinks
176 # that the integer 3 belongs to the space of 2-by-2 matrices.
177 raise ValueError(msg
)
179 natural_basis
= self
.natural_basis()
180 basis_space
= natural_basis
[0].matrix_space()
181 if elt
not in basis_space
:
182 raise ValueError(msg
)
184 # Thanks for nothing! Matrix spaces aren't vector spaces in
185 # Sage, so we have to figure out its natural-basis coordinates
186 # ourselves. We use the basis space's ring instead of the
187 # element's ring because the basis space might be an algebraic
188 # closure whereas the base ring of the 3-by-3 identity matrix
189 # could be QQ instead of QQbar.
190 V
= VectorSpace(basis_space
.base_ring(), elt
.nrows()*elt
.ncols())
191 W
= V
.span_of_basis( _mat2vec(s
) for s
in natural_basis
)
192 coords
= W
.coordinate_vector(_mat2vec(elt
))
193 return self
.from_vector(coords
)
196 def _max_test_case_size():
198 Return an integer "size" that is an upper bound on the size of
199 this algebra when it is used in a random test
200 case. Unfortunately, the term "size" is quite vague -- when
201 dealing with `R^n` under either the Hadamard or Jordan spin
202 product, the "size" refers to the dimension `n`. When dealing
203 with a matrix algebra (real symmetric or complex/quaternion
204 Hermitian), it refers to the size of the matrix, which is
205 far less than the dimension of the underlying vector space.
207 We default to five in this class, which is safe in `R^n`. The
208 matrix algebra subclasses (or any class where the "size" is
209 interpreted to be far less than the dimension) should override
210 with a smaller number.
216 Return a string representation of ``self``.
220 sage: from mjo.eja.eja_algebra import JordanSpinEJA
224 Ensure that it says what we think it says::
226 sage: JordanSpinEJA(2, field=AA)
227 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
228 sage: JordanSpinEJA(3, field=RDF)
229 Euclidean Jordan algebra of dimension 3 over Real Double Field
232 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
233 return fmt
.format(self
.dimension(), self
.base_ring())
235 def product_on_basis(self
, i
, j
):
236 return self
._multiplication
_table
[i
][j
]
239 def characteristic_polynomial_of(self
):
241 Return the algebra's "characteristic polynomial of" function,
242 which is itself a multivariate polynomial that, when evaluated
243 at the coordinates of some algebra element, returns that
244 element's characteristic polynomial.
246 The resulting polynomial has `n+1` variables, where `n` is the
247 dimension of this algebra. The first `n` variables correspond to
248 the coordinates of an algebra element: when evaluated at the
249 coordinates of an algebra element with respect to a certain
250 basis, the result is a univariate polynomial (in the one
251 remaining variable ``t``), namely the characteristic polynomial
256 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
260 The characteristic polynomial in the spin algebra is given in
261 Alizadeh, Example 11.11::
263 sage: J = JordanSpinEJA(3)
264 sage: p = J.characteristic_polynomial_of(); p
265 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
266 sage: xvec = J.one().to_vector()
270 By definition, the characteristic polynomial is a monic
271 degree-zero polynomial in a rank-zero algebra. Note that
272 Cayley-Hamilton is indeed satisfied since the polynomial
273 ``1`` evaluates to the identity element of the algebra on
276 sage: J = TrivialEJA()
277 sage: J.characteristic_polynomial_of()
284 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_(r-1).
285 a
= self
._charpoly
_coefficients
()
287 # We go to a bit of trouble here to reorder the
288 # indeterminates, so that it's easier to evaluate the
289 # characteristic polynomial at x's coordinates and get back
290 # something in terms of t, which is what we want.
291 S
= PolynomialRing(self
.base_ring(),'t')
295 S
= PolynomialRing(S
, R
.variable_names())
298 return (t
**r
+ sum( a
[k
]*(t
**k
) for k
in range(r
) ))
301 def inner_product(self
, x
, y
):
303 The inner product associated with this Euclidean Jordan algebra.
305 Defaults to the trace inner product, but can be overridden by
306 subclasses if they are sure that the necessary properties are
311 sage: from mjo.eja.eja_algebra import random_eja
315 Our inner product is "associative," which means the following for
316 a symmetric bilinear form::
318 sage: set_random_seed()
319 sage: J = random_eja()
320 sage: x,y,z = J.random_elements(3)
321 sage: (x*y).inner_product(z) == y.inner_product(x*z)
325 X
= x
.natural_representation()
326 Y
= y
.natural_representation()
327 return self
.natural_inner_product(X
,Y
)
330 def is_trivial(self
):
332 Return whether or not this algebra is trivial.
334 A trivial algebra contains only the zero element.
338 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
343 sage: J = ComplexHermitianEJA(3)
349 sage: J = TrivialEJA()
354 return self
.dimension() == 0
357 def multiplication_table(self
):
359 Return a visual representation of this algebra's multiplication
360 table (on basis elements).
364 sage: from mjo.eja.eja_algebra import JordanSpinEJA
368 sage: J = JordanSpinEJA(4)
369 sage: J.multiplication_table()
370 +----++----+----+----+----+
371 | * || e0 | e1 | e2 | e3 |
372 +====++====+====+====+====+
373 | e0 || e0 | e1 | e2 | e3 |
374 +----++----+----+----+----+
375 | e1 || e1 | e0 | 0 | 0 |
376 +----++----+----+----+----+
377 | e2 || e2 | 0 | e0 | 0 |
378 +----++----+----+----+----+
379 | e3 || e3 | 0 | 0 | e0 |
380 +----++----+----+----+----+
383 M
= list(self
._multiplication
_table
) # copy
384 for i
in range(len(M
)):
385 # M had better be "square"
386 M
[i
] = [self
.monomial(i
)] + M
[i
]
387 M
= [["*"] + list(self
.gens())] + M
388 return table(M
, header_row
=True, header_column
=True, frame
=True)
391 def natural_basis(self
):
393 Return a more-natural representation of this algebra's basis.
395 Every finite-dimensional Euclidean Jordan Algebra is a direct
396 sum of five simple algebras, four of which comprise Hermitian
397 matrices. This method returns the original "natural" basis
398 for our underlying vector space. (Typically, the natural basis
399 is used to construct the multiplication table in the first place.)
401 Note that this will always return a matrix. The standard basis
402 in `R^n` will be returned as `n`-by-`1` column matrices.
406 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
407 ....: RealSymmetricEJA)
411 sage: J = RealSymmetricEJA(2)
413 Finite family {0: e0, 1: e1, 2: e2}
414 sage: J.natural_basis()
416 [1 0] [ 0 0.7071067811865475?] [0 0]
417 [0 0], [0.7071067811865475? 0], [0 1]
422 sage: J = JordanSpinEJA(2)
424 Finite family {0: e0, 1: e1}
425 sage: J.natural_basis()
432 if self
._natural
_basis
is None:
433 M
= self
.natural_basis_space()
434 return tuple( M(b
.to_vector()) for b
in self
.basis() )
436 return self
._natural
_basis
439 def natural_basis_space(self
):
441 Return the matrix space in which this algebra's natural basis
444 Generally this will be an `n`-by-`1` column-vector space,
445 except when the algebra is trivial. There it's `n`-by-`n`
446 (where `n` is zero), to ensure that two elements of the
447 natural basis space (empty matrices) can be multiplied.
449 if self
.is_trivial():
450 return MatrixSpace(self
.base_ring(), 0)
451 elif self
._natural
_basis
is None or len(self
._natural
_basis
) == 0:
452 return MatrixSpace(self
.base_ring(), self
.dimension(), 1)
454 return self
._natural
_basis
[0].matrix_space()
458 def natural_inner_product(X
,Y
):
460 Compute the inner product of two naturally-represented elements.
462 For example in the real symmetric matrix EJA, this will compute
463 the trace inner-product of two n-by-n symmetric matrices. The
464 default should work for the real cartesian product EJA, the
465 Jordan spin EJA, and the real symmetric matrices. The others
466 will have to be overridden.
468 return (X
.conjugate_transpose()*Y
).trace()
474 Return the unit element of this algebra.
478 sage: from mjo.eja.eja_algebra import (HadamardEJA,
483 sage: J = HadamardEJA(5)
485 e0 + e1 + e2 + e3 + e4
489 The identity element acts like the identity::
491 sage: set_random_seed()
492 sage: J = random_eja()
493 sage: x = J.random_element()
494 sage: J.one()*x == x and x*J.one() == x
497 The matrix of the unit element's operator is the identity::
499 sage: set_random_seed()
500 sage: J = random_eja()
501 sage: actual = J.one().operator().matrix()
502 sage: expected = matrix.identity(J.base_ring(), J.dimension())
503 sage: actual == expected
507 # We can brute-force compute the matrices of the operators
508 # that correspond to the basis elements of this algebra.
509 # If some linear combination of those basis elements is the
510 # algebra identity, then the same linear combination of
511 # their matrices has to be the identity matrix.
513 # Of course, matrices aren't vectors in sage, so we have to
514 # appeal to the "long vectors" isometry.
515 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
517 # Now we use basis linear algebra to find the coefficients,
518 # of the matrices-as-vectors-linear-combination, which should
519 # work for the original algebra basis too.
520 A
= matrix
.column(self
.base_ring(), oper_vecs
)
522 # We used the isometry on the left-hand side already, but we
523 # still need to do it for the right-hand side. Recall that we
524 # wanted something that summed to the identity matrix.
525 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
527 # Now if there's an identity element in the algebra, this should work.
528 coeffs
= A
.solve_right(b
)
529 return self
.linear_combination(zip(self
.gens(), coeffs
))
532 def peirce_decomposition(self
, c
):
534 The Peirce decomposition of this algebra relative to the
537 In the future, this can be extended to a complete system of
538 orthogonal idempotents.
542 - ``c`` -- an idempotent of this algebra.
546 A triple (J0, J5, J1) containing two subalgebras and one subspace
549 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
550 corresponding to the eigenvalue zero.
552 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
553 corresponding to the eigenvalue one-half.
555 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
556 corresponding to the eigenvalue one.
558 These are the only possible eigenspaces for that operator, and this
559 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
560 orthogonal, and are subalgebras of this algebra with the appropriate
565 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
569 The canonical example comes from the symmetric matrices, which
570 decompose into diagonal and off-diagonal parts::
572 sage: J = RealSymmetricEJA(3)
573 sage: C = matrix(QQ, [ [1,0,0],
577 sage: J0,J5,J1 = J.peirce_decomposition(c)
579 Euclidean Jordan algebra of dimension 1...
581 Vector space of degree 6 and dimension 2...
583 Euclidean Jordan algebra of dimension 3...
584 sage: J0.one().natural_representation()
588 sage: orig_df = AA.options.display_format
589 sage: AA.options.display_format = 'radical'
590 sage: J.from_vector(J5.basis()[0]).natural_representation()
594 sage: J.from_vector(J5.basis()[1]).natural_representation()
598 sage: AA.options.display_format = orig_df
599 sage: J1.one().natural_representation()
606 Every algebra decomposes trivially with respect to its identity
609 sage: set_random_seed()
610 sage: J = random_eja()
611 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
612 sage: J0.dimension() == 0 and J5.dimension() == 0
614 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
617 The decomposition is into eigenspaces, and its components are
618 therefore necessarily orthogonal. Moreover, the identity
619 elements in the two subalgebras are the projections onto their
620 respective subspaces of the superalgebra's identity element::
622 sage: set_random_seed()
623 sage: J = random_eja()
624 sage: x = J.random_element()
625 sage: if not J.is_trivial():
626 ....: while x.is_nilpotent():
627 ....: x = J.random_element()
628 sage: c = x.subalgebra_idempotent()
629 sage: J0,J5,J1 = J.peirce_decomposition(c)
631 sage: for (w,y,z) in zip(J0.basis(), J5.basis(), J1.basis()):
632 ....: w = w.superalgebra_element()
633 ....: y = J.from_vector(y)
634 ....: z = z.superalgebra_element()
635 ....: ipsum += w.inner_product(y).abs()
636 ....: ipsum += w.inner_product(z).abs()
637 ....: ipsum += y.inner_product(z).abs()
640 sage: J1(c) == J1.one()
642 sage: J0(J.one() - c) == J0.one()
646 if not c
.is_idempotent():
647 raise ValueError("element is not idempotent: %s" % c
)
649 # Default these to what they should be if they turn out to be
650 # trivial, because eigenspaces_left() won't return eigenvalues
651 # corresponding to trivial spaces (e.g. it returns only the
652 # eigenspace corresponding to lambda=1 if you take the
653 # decomposition relative to the identity element).
654 trivial
= FiniteDimensionalEuclideanJordanSubalgebra(self
, ())
655 J0
= trivial
# eigenvalue zero
656 J5
= VectorSpace(self
.base_ring(), 0) # eigenvalue one-half
657 J1
= trivial
# eigenvalue one
659 for (eigval
, eigspace
) in c
.operator().matrix().right_eigenspaces():
660 if eigval
== ~
(self
.base_ring()(2)):
663 gens
= tuple( self
.from_vector(b
) for b
in eigspace
.basis() )
664 subalg
= FiniteDimensionalEuclideanJordanSubalgebra(self
, gens
)
670 raise ValueError("unexpected eigenvalue: %s" % eigval
)
675 def random_element(self
, thorough
=False):
677 Return a random element of this algebra.
679 Our algebra superclass method only returns a linear
680 combination of at most two basis elements. We instead
681 want the vector space "random element" method that
682 returns a more diverse selection.
686 - ``thorough`` -- (boolean; default False) whether or not we
687 should generate irrational coefficients for the random
688 element when our base ring is irrational; this slows the
689 algebra operations to a crawl, but any truly random method
693 # For a general base ring... maybe we can trust this to do the
694 # right thing? Unlikely, but.
695 V
= self
.vector_space()
696 v
= V
.random_element()
698 if self
.base_ring() is AA
:
699 # The "random element" method of the algebraic reals is
700 # stupid at the moment, and only returns integers between
701 # -2 and 2, inclusive. Instead, we implement our own
702 # "random vector" method, and then coerce that into the
703 # algebra. We use the vector space degree here instead of
704 # the dimension because a subalgebra could (for example) be
705 # spanned by only two vectors, each with five coordinates.
706 # We need to generate all five coordinates.
708 v
*= QQbar
.random_element().real()
710 v
*= QQ
.random_element()
712 return self
.from_vector(V
.coordinate_vector(v
))
714 def random_elements(self
, count
, thorough
=False):
716 Return ``count`` random elements as a tuple.
720 - ``thorough`` -- (boolean; default False) whether or not we
721 should generate irrational coefficients for the random
722 elements when our base ring is irrational; this slows the
723 algebra operations to a crawl, but any truly random method
728 sage: from mjo.eja.eja_algebra import JordanSpinEJA
732 sage: J = JordanSpinEJA(3)
733 sage: x,y,z = J.random_elements(3)
734 sage: all( [ x in J, y in J, z in J ])
736 sage: len( J.random_elements(10) ) == 10
740 return tuple( self
.random_element(thorough
)
741 for idx
in range(count
) )
744 def random_instance(cls
, field
=AA
, **kwargs
):
746 Return a random instance of this type of algebra.
748 Beware, this will crash for "most instances" because the
749 constructor below looks wrong.
751 if cls
is TrivialEJA
:
752 # The TrivialEJA class doesn't take an "n" argument because
756 n
= ZZ
.random_element(cls
._max
_test
_case
_size
() + 1)
757 return cls(n
, field
, **kwargs
)
760 def _charpoly_coefficients(self
):
762 The `r` polynomial coefficients of the "characteristic polynomial
766 var_names
= [ "X" + str(z
) for z
in range(1,n
+1) ]
767 R
= PolynomialRing(self
.base_ring(), var_names
)
769 F
= R
.fraction_field()
772 # From a result in my book, these are the entries of the
773 # basis representation of L_x.
774 return sum( vars[k
]*self
.monomial(k
).operator().matrix()[i
,j
]
777 L_x
= matrix(F
, n
, n
, L_x_i_j
)
780 if self
.rank
.is_in_cache():
782 # There's no need to pad the system with redundant
783 # columns if we *know* they'll be redundant.
786 # Compute an extra power in case the rank is equal to
787 # the dimension (otherwise, we would stop at x^(r-1)).
788 x_powers
= [ (L_x
**k
)*self
.one().to_vector()
789 for k
in range(n
+1) ]
790 A
= matrix
.column(F
, x_powers
[:n
])
791 AE
= A
.extended_echelon_form()
798 # The theory says that only the first "r" coefficients are
799 # nonzero, and they actually live in the original polynomial
800 # ring and not the fraction field. We negate them because
801 # in the actual characteristic polynomial, they get moved
802 # to the other side where x^r lives.
803 return -A_rref
.solve_right(E
*b
).change_ring(R
)[:r
]
808 Return the rank of this EJA.
810 This is a cached method because we know the rank a priori for
811 all of the algebras we can construct. Thus we can avoid the
812 expensive ``_charpoly_coefficients()`` call unless we truly
813 need to compute the whole characteristic polynomial.
817 sage: from mjo.eja.eja_algebra import (HadamardEJA,
819 ....: RealSymmetricEJA,
820 ....: ComplexHermitianEJA,
821 ....: QuaternionHermitianEJA,
826 The rank of the Jordan spin algebra is always two::
828 sage: JordanSpinEJA(2).rank()
830 sage: JordanSpinEJA(3).rank()
832 sage: JordanSpinEJA(4).rank()
835 The rank of the `n`-by-`n` Hermitian real, complex, or
836 quaternion matrices is `n`::
838 sage: RealSymmetricEJA(4).rank()
840 sage: ComplexHermitianEJA(3).rank()
842 sage: QuaternionHermitianEJA(2).rank()
847 Ensure that every EJA that we know how to construct has a
848 positive integer rank, unless the algebra is trivial in
849 which case its rank will be zero::
851 sage: set_random_seed()
852 sage: J = random_eja()
856 sage: r > 0 or (r == 0 and J.is_trivial())
859 Ensure that computing the rank actually works, since the ranks
860 of all simple algebras are known and will be cached by default::
862 sage: J = HadamardEJA(4)
863 sage: J.rank.clear_cache()
869 sage: J = JordanSpinEJA(4)
870 sage: J.rank.clear_cache()
876 sage: J = RealSymmetricEJA(3)
877 sage: J.rank.clear_cache()
883 sage: J = ComplexHermitianEJA(2)
884 sage: J.rank.clear_cache()
890 sage: J = QuaternionHermitianEJA(2)
891 sage: J.rank.clear_cache()
895 return len(self
._charpoly
_coefficients
())
898 def vector_space(self
):
900 Return the vector space that underlies this algebra.
904 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
908 sage: J = RealSymmetricEJA(2)
909 sage: J.vector_space()
910 Vector space of dimension 3 over...
913 return self
.zero().to_vector().parent().ambient_vector_space()
916 Element
= FiniteDimensionalEuclideanJordanAlgebraElement
919 class HadamardEJA(FiniteDimensionalEuclideanJordanAlgebra
):
921 Return the Euclidean Jordan Algebra corresponding to the set
922 `R^n` under the Hadamard product.
924 Note: this is nothing more than the Cartesian product of ``n``
925 copies of the spin algebra. Once Cartesian product algebras
926 are implemented, this can go.
930 sage: from mjo.eja.eja_algebra import HadamardEJA
934 This multiplication table can be verified by hand::
936 sage: J = HadamardEJA(3)
937 sage: e0,e1,e2 = J.gens()
953 We can change the generator prefix::
955 sage: HadamardEJA(3, prefix='r').gens()
959 def __init__(self
, n
, field
=AA
, **kwargs
):
960 V
= VectorSpace(field
, n
)
961 mult_table
= [ [ V
.gen(i
)*(i
== j
) for j
in range(n
) ]
964 fdeja
= super(HadamardEJA
, self
)
965 fdeja
.__init
__(field
, mult_table
, **kwargs
)
966 self
.rank
.set_cache(n
)
968 def inner_product(self
, x
, y
):
970 Faster to reimplement than to use natural representations.
974 sage: from mjo.eja.eja_algebra import HadamardEJA
978 Ensure that this is the usual inner product for the algebras
981 sage: set_random_seed()
982 sage: J = HadamardEJA.random_instance()
983 sage: x,y = J.random_elements(2)
984 sage: X = x.natural_representation()
985 sage: Y = y.natural_representation()
986 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
990 return x
.to_vector().inner_product(y
.to_vector())
993 def random_eja(field
=AA
):
995 Return a "random" finite-dimensional Euclidean Jordan Algebra.
999 sage: from mjo.eja.eja_algebra import random_eja
1004 Euclidean Jordan algebra of dimension...
1007 classname
= choice([TrivialEJA
,
1011 ComplexHermitianEJA
,
1012 QuaternionHermitianEJA
])
1013 return classname
.random_instance(field
=field
)
1018 class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra
):
1020 def _max_test_case_size():
1021 # Play it safe, since this will be squared and the underlying
1022 # field can have dimension 4 (quaternions) too.
1025 def __init__(self
, field
, basis
, normalize_basis
=True, **kwargs
):
1027 Compared to the superclass constructor, we take a basis instead of
1028 a multiplication table because the latter can be computed in terms
1029 of the former when the product is known (like it is here).
1031 # Used in this class's fast _charpoly_coefficients() override.
1032 self
._basis
_normalizers
= None
1034 # We're going to loop through this a few times, so now's a good
1035 # time to ensure that it isn't a generator expression.
1036 basis
= tuple(basis
)
1038 if len(basis
) > 1 and normalize_basis
:
1039 # We'll need sqrt(2) to normalize the basis, and this
1040 # winds up in the multiplication table, so the whole
1041 # algebra needs to be over the field extension.
1042 R
= PolynomialRing(field
, 'z')
1045 if p
.is_irreducible():
1046 field
= field
.extension(p
, 'sqrt2', embedding
=RLF(2).sqrt())
1047 basis
= tuple( s
.change_ring(field
) for s
in basis
)
1048 self
._basis
_normalizers
= tuple(
1049 ~
(self
.natural_inner_product(s
,s
).sqrt()) for s
in basis
)
1050 basis
= tuple(s
*c
for (s
,c
) in zip(basis
,self
._basis
_normalizers
))
1052 Qs
= self
.multiplication_table_from_matrix_basis(basis
)
1054 fdeja
= super(MatrixEuclideanJordanAlgebra
, self
)
1055 fdeja
.__init
__(field
, Qs
, natural_basis
=basis
, **kwargs
)
1060 def _charpoly_coefficients(self
):
1062 Override the parent method with something that tries to compute
1063 over a faster (non-extension) field.
1065 if self
._basis
_normalizers
is None:
1066 # We didn't normalize, so assume that the basis we started
1067 # with had entries in a nice field.
1068 return super(MatrixEuclideanJordanAlgebra
, self
)._charpoly
_coefficients
()
1070 basis
= ( (b
/n
) for (b
,n
) in zip(self
.natural_basis(),
1071 self
._basis
_normalizers
) )
1073 # Do this over the rationals and convert back at the end.
1074 # Only works because we know the entries of the basis are
1076 J
= MatrixEuclideanJordanAlgebra(QQ
,
1078 normalize_basis
=False)
1079 a
= J
._charpoly
_coefficients
()
1081 # Unfortunately, changing the basis does change the
1082 # coefficients of the characteristic polynomial, but since
1083 # these are really the coefficients of the "characteristic
1084 # polynomial of" function, everything is still nice and
1085 # unevaluated. It's therefore "obvious" how scaling the
1086 # basis affects the coordinate variables X1, X2, et
1087 # cetera. Scaling the first basis vector up by "n" adds a
1088 # factor of 1/n into every "X1" term, for example. So here
1089 # we simply undo the basis_normalizer scaling that we
1090 # performed earlier.
1092 # The a[0] access here is safe because trivial algebras
1093 # won't have any basis normalizers and therefore won't
1094 # make it to this "else" branch.
1095 XS
= a
[0].parent().gens()
1096 subs_dict
= { XS
[i
]: self
._basis
_normalizers
[i
]*XS
[i
]
1097 for i
in range(len(XS
)) }
1098 return tuple( a_i
.subs(subs_dict
) for a_i
in a
)
1102 def multiplication_table_from_matrix_basis(basis
):
1104 At least three of the five simple Euclidean Jordan algebras have the
1105 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1106 multiplication on the right is matrix multiplication. Given a basis
1107 for the underlying matrix space, this function returns a
1108 multiplication table (obtained by looping through the basis
1109 elements) for an algebra of those matrices.
1111 # In S^2, for example, we nominally have four coordinates even
1112 # though the space is of dimension three only. The vector space V
1113 # is supposed to hold the entire long vector, and the subspace W
1114 # of V will be spanned by the vectors that arise from symmetric
1115 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1119 field
= basis
[0].base_ring()
1120 dimension
= basis
[0].nrows()
1122 V
= VectorSpace(field
, dimension
**2)
1123 W
= V
.span_of_basis( _mat2vec(s
) for s
in basis
)
1125 mult_table
= [[W
.zero() for j
in range(n
)] for i
in range(n
)]
1128 mat_entry
= (basis
[i
]*basis
[j
] + basis
[j
]*basis
[i
])/2
1129 mult_table
[i
][j
] = W
.coordinate_vector(_mat2vec(mat_entry
))
1137 Embed the matrix ``M`` into a space of real matrices.
1139 The matrix ``M`` can have entries in any field at the moment:
1140 the real numbers, complex numbers, or quaternions. And although
1141 they are not a field, we can probably support octonions at some
1142 point, too. This function returns a real matrix that "acts like"
1143 the original with respect to matrix multiplication; i.e.
1145 real_embed(M*N) = real_embed(M)*real_embed(N)
1148 raise NotImplementedError
1152 def real_unembed(M
):
1154 The inverse of :meth:`real_embed`.
1156 raise NotImplementedError
1160 def natural_inner_product(cls
,X
,Y
):
1161 Xu
= cls
.real_unembed(X
)
1162 Yu
= cls
.real_unembed(Y
)
1163 tr
= (Xu
*Yu
).trace()
1166 # It's real already.
1169 # Otherwise, try the thing that works for complex numbers; and
1170 # if that doesn't work, the thing that works for quaternions.
1172 return tr
.vector()[0] # real part, imag part is index 1
1173 except AttributeError:
1174 # A quaternions doesn't have a vector() method, but does
1175 # have coefficient_tuple() method that returns the
1176 # coefficients of 1, i, j, and k -- in that order.
1177 return tr
.coefficient_tuple()[0]
1180 class RealMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra
):
1184 The identity function, for embedding real matrices into real
1190 def real_unembed(M
):
1192 The identity function, for unembedding real matrices from real
1198 class RealSymmetricEJA(RealMatrixEuclideanJordanAlgebra
):
1200 The rank-n simple EJA consisting of real symmetric n-by-n
1201 matrices, the usual symmetric Jordan product, and the trace inner
1202 product. It has dimension `(n^2 + n)/2` over the reals.
1206 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1210 sage: J = RealSymmetricEJA(2)
1211 sage: e0, e1, e2 = J.gens()
1219 In theory, our "field" can be any subfield of the reals::
1221 sage: RealSymmetricEJA(2, RDF)
1222 Euclidean Jordan algebra of dimension 3 over Real Double Field
1223 sage: RealSymmetricEJA(2, RR)
1224 Euclidean Jordan algebra of dimension 3 over Real Field with
1225 53 bits of precision
1229 The dimension of this algebra is `(n^2 + n) / 2`::
1231 sage: set_random_seed()
1232 sage: n_max = RealSymmetricEJA._max_test_case_size()
1233 sage: n = ZZ.random_element(1, n_max)
1234 sage: J = RealSymmetricEJA(n)
1235 sage: J.dimension() == (n^2 + n)/2
1238 The Jordan multiplication is what we think it is::
1240 sage: set_random_seed()
1241 sage: J = RealSymmetricEJA.random_instance()
1242 sage: x,y = J.random_elements(2)
1243 sage: actual = (x*y).natural_representation()
1244 sage: X = x.natural_representation()
1245 sage: Y = y.natural_representation()
1246 sage: expected = (X*Y + Y*X)/2
1247 sage: actual == expected
1249 sage: J(expected) == x*y
1252 We can change the generator prefix::
1254 sage: RealSymmetricEJA(3, prefix='q').gens()
1255 (q0, q1, q2, q3, q4, q5)
1257 Our natural basis is normalized with respect to the natural inner
1258 product unless we specify otherwise::
1260 sage: set_random_seed()
1261 sage: J = RealSymmetricEJA.random_instance()
1262 sage: all( b.norm() == 1 for b in J.gens() )
1265 Since our natural basis is normalized with respect to the natural
1266 inner product, and since we know that this algebra is an EJA, any
1267 left-multiplication operator's matrix will be symmetric because
1268 natural->EJA basis representation is an isometry and within the EJA
1269 the operator is self-adjoint by the Jordan axiom::
1271 sage: set_random_seed()
1272 sage: x = RealSymmetricEJA.random_instance().random_element()
1273 sage: x.operator().matrix().is_symmetric()
1276 We can construct the (trivial) algebra of rank zero::
1278 sage: RealSymmetricEJA(0)
1279 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
1283 def _denormalized_basis(cls
, n
, field
):
1285 Return a basis for the space of real symmetric n-by-n matrices.
1289 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1293 sage: set_random_seed()
1294 sage: n = ZZ.random_element(1,5)
1295 sage: B = RealSymmetricEJA._denormalized_basis(n,QQ)
1296 sage: all( M.is_symmetric() for M in B)
1300 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1304 for j
in range(i
+1):
1305 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1309 Sij
= Eij
+ Eij
.transpose()
1315 def _max_test_case_size():
1316 return 4 # Dimension 10
1319 def __init__(self
, n
, field
=AA
, **kwargs
):
1320 basis
= self
._denormalized
_basis
(n
, field
)
1321 super(RealSymmetricEJA
, self
).__init
__(field
, basis
, **kwargs
)
1322 self
.rank
.set_cache(n
)
1325 class ComplexMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra
):
1329 Embed the n-by-n complex matrix ``M`` into the space of real
1330 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1331 bi` to the block matrix ``[[a,b],[-b,a]]``.
1335 sage: from mjo.eja.eja_algebra import \
1336 ....: ComplexMatrixEuclideanJordanAlgebra
1340 sage: F = QuadraticField(-1, 'I')
1341 sage: x1 = F(4 - 2*i)
1342 sage: x2 = F(1 + 2*i)
1345 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1346 sage: ComplexMatrixEuclideanJordanAlgebra.real_embed(M)
1355 Embedding is a homomorphism (isomorphism, in fact)::
1357 sage: set_random_seed()
1358 sage: n_max = ComplexMatrixEuclideanJordanAlgebra._max_test_case_size()
1359 sage: n = ZZ.random_element(n_max)
1360 sage: F = QuadraticField(-1, 'I')
1361 sage: X = random_matrix(F, n)
1362 sage: Y = random_matrix(F, n)
1363 sage: Xe = ComplexMatrixEuclideanJordanAlgebra.real_embed(X)
1364 sage: Ye = ComplexMatrixEuclideanJordanAlgebra.real_embed(Y)
1365 sage: XYe = ComplexMatrixEuclideanJordanAlgebra.real_embed(X*Y)
1372 raise ValueError("the matrix 'M' must be square")
1374 # We don't need any adjoined elements...
1375 field
= M
.base_ring().base_ring()
1379 a
= z
.list()[0] # real part, I guess
1380 b
= z
.list()[1] # imag part, I guess
1381 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1383 return matrix
.block(field
, n
, blocks
)
1387 def real_unembed(M
):
1389 The inverse of _embed_complex_matrix().
1393 sage: from mjo.eja.eja_algebra import \
1394 ....: ComplexMatrixEuclideanJordanAlgebra
1398 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1399 ....: [-2, 1, -4, 3],
1400 ....: [ 9, 10, 11, 12],
1401 ....: [-10, 9, -12, 11] ])
1402 sage: ComplexMatrixEuclideanJordanAlgebra.real_unembed(A)
1404 [ 10*I + 9 12*I + 11]
1408 Unembedding is the inverse of embedding::
1410 sage: set_random_seed()
1411 sage: F = QuadraticField(-1, 'I')
1412 sage: M = random_matrix(F, 3)
1413 sage: Me = ComplexMatrixEuclideanJordanAlgebra.real_embed(M)
1414 sage: ComplexMatrixEuclideanJordanAlgebra.real_unembed(Me) == M
1420 raise ValueError("the matrix 'M' must be square")
1421 if not n
.mod(2).is_zero():
1422 raise ValueError("the matrix 'M' must be a complex embedding")
1424 # If "M" was normalized, its base ring might have roots
1425 # adjoined and they can stick around after unembedding.
1426 field
= M
.base_ring()
1427 R
= PolynomialRing(field
, 'z')
1430 # Sage doesn't know how to embed AA into QQbar, i.e. how
1431 # to adjoin sqrt(-1) to AA.
1434 F
= field
.extension(z
**2 + 1, 'I', embedding
=CLF(-1).sqrt())
1437 # Go top-left to bottom-right (reading order), converting every
1438 # 2-by-2 block we see to a single complex element.
1440 for k
in range(n
/2):
1441 for j
in range(n
/2):
1442 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1443 if submat
[0,0] != submat
[1,1]:
1444 raise ValueError('bad on-diagonal submatrix')
1445 if submat
[0,1] != -submat
[1,0]:
1446 raise ValueError('bad off-diagonal submatrix')
1447 z
= submat
[0,0] + submat
[0,1]*i
1450 return matrix(F
, n
/2, elements
)
1454 def natural_inner_product(cls
,X
,Y
):
1456 Compute a natural inner product in this algebra directly from
1461 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1465 This gives the same answer as the slow, default method implemented
1466 in :class:`MatrixEuclideanJordanAlgebra`::
1468 sage: set_random_seed()
1469 sage: J = ComplexHermitianEJA.random_instance()
1470 sage: x,y = J.random_elements(2)
1471 sage: Xe = x.natural_representation()
1472 sage: Ye = y.natural_representation()
1473 sage: X = ComplexHermitianEJA.real_unembed(Xe)
1474 sage: Y = ComplexHermitianEJA.real_unembed(Ye)
1475 sage: expected = (X*Y).trace().real()
1476 sage: actual = ComplexHermitianEJA.natural_inner_product(Xe,Ye)
1477 sage: actual == expected
1481 return RealMatrixEuclideanJordanAlgebra
.natural_inner_product(X
,Y
)/2
1484 class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra
):
1486 The rank-n simple EJA consisting of complex Hermitian n-by-n
1487 matrices over the real numbers, the usual symmetric Jordan product,
1488 and the real-part-of-trace inner product. It has dimension `n^2` over
1493 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1497 In theory, our "field" can be any subfield of the reals::
1499 sage: ComplexHermitianEJA(2, RDF)
1500 Euclidean Jordan algebra of dimension 4 over Real Double Field
1501 sage: ComplexHermitianEJA(2, RR)
1502 Euclidean Jordan algebra of dimension 4 over Real Field with
1503 53 bits of precision
1507 The dimension of this algebra is `n^2`::
1509 sage: set_random_seed()
1510 sage: n_max = ComplexHermitianEJA._max_test_case_size()
1511 sage: n = ZZ.random_element(1, n_max)
1512 sage: J = ComplexHermitianEJA(n)
1513 sage: J.dimension() == n^2
1516 The Jordan multiplication is what we think it is::
1518 sage: set_random_seed()
1519 sage: J = ComplexHermitianEJA.random_instance()
1520 sage: x,y = J.random_elements(2)
1521 sage: actual = (x*y).natural_representation()
1522 sage: X = x.natural_representation()
1523 sage: Y = y.natural_representation()
1524 sage: expected = (X*Y + Y*X)/2
1525 sage: actual == expected
1527 sage: J(expected) == x*y
1530 We can change the generator prefix::
1532 sage: ComplexHermitianEJA(2, prefix='z').gens()
1535 Our natural basis is normalized with respect to the natural inner
1536 product unless we specify otherwise::
1538 sage: set_random_seed()
1539 sage: J = ComplexHermitianEJA.random_instance()
1540 sage: all( b.norm() == 1 for b in J.gens() )
1543 Since our natural basis is normalized with respect to the natural
1544 inner product, and since we know that this algebra is an EJA, any
1545 left-multiplication operator's matrix will be symmetric because
1546 natural->EJA basis representation is an isometry and within the EJA
1547 the operator is self-adjoint by the Jordan axiom::
1549 sage: set_random_seed()
1550 sage: x = ComplexHermitianEJA.random_instance().random_element()
1551 sage: x.operator().matrix().is_symmetric()
1554 We can construct the (trivial) algebra of rank zero::
1556 sage: ComplexHermitianEJA(0)
1557 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
1562 def _denormalized_basis(cls
, n
, field
):
1564 Returns a basis for the space of complex Hermitian n-by-n matrices.
1566 Why do we embed these? Basically, because all of numerical linear
1567 algebra assumes that you're working with vectors consisting of `n`
1568 entries from a field and scalars from the same field. There's no way
1569 to tell SageMath that (for example) the vectors contain complex
1570 numbers, while the scalar field is real.
1574 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1578 sage: set_random_seed()
1579 sage: n = ZZ.random_element(1,5)
1580 sage: field = QuadraticField(2, 'sqrt2')
1581 sage: B = ComplexHermitianEJA._denormalized_basis(n, field)
1582 sage: all( M.is_symmetric() for M in B)
1586 R
= PolynomialRing(field
, 'z')
1588 F
= field
.extension(z
**2 + 1, 'I')
1591 # This is like the symmetric case, but we need to be careful:
1593 # * We want conjugate-symmetry, not just symmetry.
1594 # * The diagonal will (as a result) be real.
1598 for j
in range(i
+1):
1599 Eij
= matrix(F
, n
, lambda k
,l
: k
==i
and l
==j
)
1601 Sij
= cls
.real_embed(Eij
)
1604 # The second one has a minus because it's conjugated.
1605 Sij_real
= cls
.real_embed(Eij
+ Eij
.transpose())
1607 Sij_imag
= cls
.real_embed(I
*Eij
- I
*Eij
.transpose())
1610 # Since we embedded these, we can drop back to the "field" that we
1611 # started with instead of the complex extension "F".
1612 return ( s
.change_ring(field
) for s
in S
)
1615 def __init__(self
, n
, field
=AA
, **kwargs
):
1616 basis
= self
._denormalized
_basis
(n
,field
)
1617 super(ComplexHermitianEJA
,self
).__init
__(field
, basis
, **kwargs
)
1618 self
.rank
.set_cache(n
)
1621 class QuaternionMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra
):
1625 Embed the n-by-n quaternion matrix ``M`` into the space of real
1626 matrices of size 4n-by-4n by first sending each quaternion entry `z
1627 = a + bi + cj + dk` to the block-complex matrix ``[[a + bi,
1628 c+di],[-c + di, a-bi]]`, and then embedding those into a real
1633 sage: from mjo.eja.eja_algebra import \
1634 ....: QuaternionMatrixEuclideanJordanAlgebra
1638 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1639 sage: i,j,k = Q.gens()
1640 sage: x = 1 + 2*i + 3*j + 4*k
1641 sage: M = matrix(Q, 1, [[x]])
1642 sage: QuaternionMatrixEuclideanJordanAlgebra.real_embed(M)
1648 Embedding is a homomorphism (isomorphism, in fact)::
1650 sage: set_random_seed()
1651 sage: n_max = QuaternionMatrixEuclideanJordanAlgebra._max_test_case_size()
1652 sage: n = ZZ.random_element(n_max)
1653 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1654 sage: X = random_matrix(Q, n)
1655 sage: Y = random_matrix(Q, n)
1656 sage: Xe = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X)
1657 sage: Ye = QuaternionMatrixEuclideanJordanAlgebra.real_embed(Y)
1658 sage: XYe = QuaternionMatrixEuclideanJordanAlgebra.real_embed(X*Y)
1663 quaternions
= M
.base_ring()
1666 raise ValueError("the matrix 'M' must be square")
1668 F
= QuadraticField(-1, 'I')
1673 t
= z
.coefficient_tuple()
1678 cplxM
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1679 [-c
+ d
*i
, a
- b
*i
]])
1680 realM
= ComplexMatrixEuclideanJordanAlgebra
.real_embed(cplxM
)
1681 blocks
.append(realM
)
1683 # We should have real entries by now, so use the realest field
1684 # we've got for the return value.
1685 return matrix
.block(quaternions
.base_ring(), n
, blocks
)
1690 def real_unembed(M
):
1692 The inverse of _embed_quaternion_matrix().
1696 sage: from mjo.eja.eja_algebra import \
1697 ....: QuaternionMatrixEuclideanJordanAlgebra
1701 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1702 ....: [-2, 1, -4, 3],
1703 ....: [-3, 4, 1, -2],
1704 ....: [-4, -3, 2, 1]])
1705 sage: QuaternionMatrixEuclideanJordanAlgebra.real_unembed(M)
1706 [1 + 2*i + 3*j + 4*k]
1710 Unembedding is the inverse of embedding::
1712 sage: set_random_seed()
1713 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1714 sage: M = random_matrix(Q, 3)
1715 sage: Me = QuaternionMatrixEuclideanJordanAlgebra.real_embed(M)
1716 sage: QuaternionMatrixEuclideanJordanAlgebra.real_unembed(Me) == M
1722 raise ValueError("the matrix 'M' must be square")
1723 if not n
.mod(4).is_zero():
1724 raise ValueError("the matrix 'M' must be a quaternion embedding")
1726 # Use the base ring of the matrix to ensure that its entries can be
1727 # multiplied by elements of the quaternion algebra.
1728 field
= M
.base_ring()
1729 Q
= QuaternionAlgebra(field
,-1,-1)
1732 # Go top-left to bottom-right (reading order), converting every
1733 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1736 for l
in range(n
/4):
1737 for m
in range(n
/4):
1738 submat
= ComplexMatrixEuclideanJordanAlgebra
.real_unembed(
1739 M
[4*l
:4*l
+4,4*m
:4*m
+4] )
1740 if submat
[0,0] != submat
[1,1].conjugate():
1741 raise ValueError('bad on-diagonal submatrix')
1742 if submat
[0,1] != -submat
[1,0].conjugate():
1743 raise ValueError('bad off-diagonal submatrix')
1744 z
= submat
[0,0].real()
1745 z
+= submat
[0,0].imag()*i
1746 z
+= submat
[0,1].real()*j
1747 z
+= submat
[0,1].imag()*k
1750 return matrix(Q
, n
/4, elements
)
1754 def natural_inner_product(cls
,X
,Y
):
1756 Compute a natural inner product in this algebra directly from
1761 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1765 This gives the same answer as the slow, default method implemented
1766 in :class:`MatrixEuclideanJordanAlgebra`::
1768 sage: set_random_seed()
1769 sage: J = QuaternionHermitianEJA.random_instance()
1770 sage: x,y = J.random_elements(2)
1771 sage: Xe = x.natural_representation()
1772 sage: Ye = y.natural_representation()
1773 sage: X = QuaternionHermitianEJA.real_unembed(Xe)
1774 sage: Y = QuaternionHermitianEJA.real_unembed(Ye)
1775 sage: expected = (X*Y).trace().coefficient_tuple()[0]
1776 sage: actual = QuaternionHermitianEJA.natural_inner_product(Xe,Ye)
1777 sage: actual == expected
1781 return RealMatrixEuclideanJordanAlgebra
.natural_inner_product(X
,Y
)/4
1784 class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra
):
1786 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1787 matrices, the usual symmetric Jordan product, and the
1788 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1793 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1797 In theory, our "field" can be any subfield of the reals::
1799 sage: QuaternionHermitianEJA(2, RDF)
1800 Euclidean Jordan algebra of dimension 6 over Real Double Field
1801 sage: QuaternionHermitianEJA(2, RR)
1802 Euclidean Jordan algebra of dimension 6 over Real Field with
1803 53 bits of precision
1807 The dimension of this algebra is `2*n^2 - n`::
1809 sage: set_random_seed()
1810 sage: n_max = QuaternionHermitianEJA._max_test_case_size()
1811 sage: n = ZZ.random_element(1, n_max)
1812 sage: J = QuaternionHermitianEJA(n)
1813 sage: J.dimension() == 2*(n^2) - n
1816 The Jordan multiplication is what we think it is::
1818 sage: set_random_seed()
1819 sage: J = QuaternionHermitianEJA.random_instance()
1820 sage: x,y = J.random_elements(2)
1821 sage: actual = (x*y).natural_representation()
1822 sage: X = x.natural_representation()
1823 sage: Y = y.natural_representation()
1824 sage: expected = (X*Y + Y*X)/2
1825 sage: actual == expected
1827 sage: J(expected) == x*y
1830 We can change the generator prefix::
1832 sage: QuaternionHermitianEJA(2, prefix='a').gens()
1833 (a0, a1, a2, a3, a4, a5)
1835 Our natural basis is normalized with respect to the natural inner
1836 product unless we specify otherwise::
1838 sage: set_random_seed()
1839 sage: J = QuaternionHermitianEJA.random_instance()
1840 sage: all( b.norm() == 1 for b in J.gens() )
1843 Since our natural basis is normalized with respect to the natural
1844 inner product, and since we know that this algebra is an EJA, any
1845 left-multiplication operator's matrix will be symmetric because
1846 natural->EJA basis representation is an isometry and within the EJA
1847 the operator is self-adjoint by the Jordan axiom::
1849 sage: set_random_seed()
1850 sage: x = QuaternionHermitianEJA.random_instance().random_element()
1851 sage: x.operator().matrix().is_symmetric()
1854 We can construct the (trivial) algebra of rank zero::
1856 sage: QuaternionHermitianEJA(0)
1857 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
1861 def _denormalized_basis(cls
, n
, field
):
1863 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1865 Why do we embed these? Basically, because all of numerical
1866 linear algebra assumes that you're working with vectors consisting
1867 of `n` entries from a field and scalars from the same field. There's
1868 no way to tell SageMath that (for example) the vectors contain
1869 complex numbers, while the scalar field is real.
1873 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1877 sage: set_random_seed()
1878 sage: n = ZZ.random_element(1,5)
1879 sage: B = QuaternionHermitianEJA._denormalized_basis(n,QQ)
1880 sage: all( M.is_symmetric() for M in B )
1884 Q
= QuaternionAlgebra(QQ
,-1,-1)
1887 # This is like the symmetric case, but we need to be careful:
1889 # * We want conjugate-symmetry, not just symmetry.
1890 # * The diagonal will (as a result) be real.
1894 for j
in range(i
+1):
1895 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1897 Sij
= cls
.real_embed(Eij
)
1900 # The second, third, and fourth ones have a minus
1901 # because they're conjugated.
1902 Sij_real
= cls
.real_embed(Eij
+ Eij
.transpose())
1904 Sij_I
= cls
.real_embed(I
*Eij
- I
*Eij
.transpose())
1906 Sij_J
= cls
.real_embed(J
*Eij
- J
*Eij
.transpose())
1908 Sij_K
= cls
.real_embed(K
*Eij
- K
*Eij
.transpose())
1911 # Since we embedded these, we can drop back to the "field" that we
1912 # started with instead of the quaternion algebra "Q".
1913 return ( s
.change_ring(field
) for s
in S
)
1916 def __init__(self
, n
, field
=AA
, **kwargs
):
1917 basis
= self
._denormalized
_basis
(n
,field
)
1918 super(QuaternionHermitianEJA
,self
).__init
__(field
, basis
, **kwargs
)
1919 self
.rank
.set_cache(n
)
1922 class BilinearFormEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1924 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1925 with the half-trace inner product and jordan product ``x*y =
1926 (x0*y0 + <B*x_bar,y_bar>, x0*y_bar + y0*x_bar)`` where ``B`` is a
1927 symmetric positive-definite "bilinear form" matrix. It has
1928 dimension `n` over the reals, and reduces to the ``JordanSpinEJA``
1929 when ``B`` is the identity matrix of order ``n-1``.
1933 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1934 ....: JordanSpinEJA)
1938 When no bilinear form is specified, the identity matrix is used,
1939 and the resulting algebra is the Jordan spin algebra::
1941 sage: J0 = BilinearFormEJA(3)
1942 sage: J1 = JordanSpinEJA(3)
1943 sage: J0.multiplication_table() == J0.multiplication_table()
1948 We can create a zero-dimensional algebra::
1950 sage: J = BilinearFormEJA(0)
1954 We can check the multiplication condition given in the Jordan, von
1955 Neumann, and Wigner paper (and also discussed on my "On the
1956 symmetry..." paper). Note that this relies heavily on the standard
1957 choice of basis, as does anything utilizing the bilinear form matrix::
1959 sage: set_random_seed()
1960 sage: n = ZZ.random_element(5)
1961 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
1962 sage: B = M.transpose()*M
1963 sage: J = BilinearFormEJA(n, B=B)
1964 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
1965 sage: V = J.vector_space()
1966 sage: sis = [ J.from_vector(V([0] + (M.inverse()*ei).list()))
1967 ....: for ei in eis ]
1968 sage: actual = [ sis[i]*sis[j]
1969 ....: for i in range(n-1)
1970 ....: for j in range(n-1) ]
1971 sage: expected = [ J.one() if i == j else J.zero()
1972 ....: for i in range(n-1)
1973 ....: for j in range(n-1) ]
1974 sage: actual == expected
1977 def __init__(self
, n
, field
=AA
, B
=None, **kwargs
):
1979 self
._B
= matrix
.identity(field
, max(0,n
-1))
1983 V
= VectorSpace(field
, n
)
1984 mult_table
= [[V
.zero() for j
in range(n
)] for i
in range(n
)]
1993 z0
= x0
*y0
+ (self
._B
*xbar
).inner_product(ybar
)
1994 zbar
= y0
*xbar
+ x0
*ybar
1995 z
= V([z0
] + zbar
.list())
1996 mult_table
[i
][j
] = z
1998 # The rank of this algebra is two, unless we're in a
1999 # one-dimensional ambient space (because the rank is bounded
2000 # by the ambient dimension).
2001 fdeja
= super(BilinearFormEJA
, self
)
2002 fdeja
.__init
__(field
, mult_table
, **kwargs
)
2003 self
.rank
.set_cache(min(n
,2))
2005 def inner_product(self
, x
, y
):
2007 Half of the trace inner product.
2009 This is defined so that the special case of the Jordan spin
2010 algebra gets the usual inner product.
2014 sage: from mjo.eja.eja_algebra import BilinearFormEJA
2018 Ensure that this is one-half of the trace inner-product when
2019 the algebra isn't just the reals (when ``n`` isn't one). This
2020 is in Faraut and Koranyi, and also my "On the symmetry..."
2023 sage: set_random_seed()
2024 sage: n = ZZ.random_element(2,5)
2025 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2026 sage: B = M.transpose()*M
2027 sage: J = BilinearFormEJA(n, B=B)
2028 sage: x = J.random_element()
2029 sage: y = J.random_element()
2030 sage: x.inner_product(y) == (x*y).trace()/2
2034 xvec
= x
.to_vector()
2036 yvec
= y
.to_vector()
2038 return x
[0]*y
[0] + (self
._B
*xbar
).inner_product(ybar
)
2041 class JordanSpinEJA(BilinearFormEJA
):
2043 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2044 with the usual inner product and jordan product ``x*y =
2045 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2050 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2054 This multiplication table can be verified by hand::
2056 sage: J = JordanSpinEJA(4)
2057 sage: e0,e1,e2,e3 = J.gens()
2073 We can change the generator prefix::
2075 sage: JordanSpinEJA(2, prefix='B').gens()
2080 Ensure that we have the usual inner product on `R^n`::
2082 sage: set_random_seed()
2083 sage: J = JordanSpinEJA.random_instance()
2084 sage: x,y = J.random_elements(2)
2085 sage: X = x.natural_representation()
2086 sage: Y = y.natural_representation()
2087 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
2091 def __init__(self
, n
, field
=AA
, **kwargs
):
2092 # This is a special case of the BilinearFormEJA with the identity
2093 # matrix as its bilinear form.
2094 return super(JordanSpinEJA
, self
).__init
__(n
, field
, **kwargs
)
2097 class TrivialEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2099 The trivial Euclidean Jordan algebra consisting of only a zero element.
2103 sage: from mjo.eja.eja_algebra import TrivialEJA
2107 sage: J = TrivialEJA()
2114 sage: 7*J.one()*12*J.one()
2116 sage: J.one().inner_product(J.one())
2118 sage: J.one().norm()
2120 sage: J.one().subalgebra_generated_by()
2121 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2126 def __init__(self
, field
=AA
, **kwargs
):
2128 fdeja
= super(TrivialEJA
, self
)
2129 # The rank is zero using my definition, namely the dimension of the
2130 # largest subalgebra generated by any element.
2131 fdeja
.__init
__(field
, mult_table
, **kwargs
)
2132 self
.rank
.set_cache(0)