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.
10 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra
import FiniteDimensionalAlgebra
11 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_element
import FiniteDimensionalAlgebraElement
12 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
13 from sage
.categories
.finite_dimensional_algebras_with_basis
import FiniteDimensionalAlgebrasWithBasis
14 from sage
.functions
.other
import sqrt
15 from sage
.matrix
.constructor
import matrix
16 from sage
.misc
.cachefunc
import cached_method
17 from sage
.misc
.prandom
import choice
18 from sage
.modules
.free_module
import VectorSpace
19 from sage
.modules
.free_module_element
import vector
20 from sage
.rings
.integer_ring
import ZZ
21 from sage
.rings
.number_field
.number_field
import QuadraticField
22 from sage
.rings
.polynomial
.polynomial_ring_constructor
import PolynomialRing
23 from sage
.rings
.rational_field
import QQ
24 from sage
.structure
.element
import is_Matrix
25 from sage
.structure
.category_object
import normalize_names
27 from mjo
.eja
.eja_operator
import FiniteDimensionalEuclideanJordanAlgebraOperator
30 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
32 def __classcall_private__(cls
,
37 assume_associative
=False,
41 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
44 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
45 raise ValueError("input is not a multiplication table")
46 mult_table
= tuple(mult_table
)
48 cat
= FiniteDimensionalAlgebrasWithBasis(field
)
49 cat
.or_subcategory(category
)
50 if assume_associative
:
51 cat
= cat
.Associative()
53 names
= normalize_names(n
, names
)
55 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
56 return fda
.__classcall
__(cls
,
60 assume_associative
=assume_associative
,
63 natural_basis
=natural_basis
)
71 assume_associative
=False,
77 sage: from mjo.eja.eja_algebra import random_eja
81 By definition, Jordan multiplication commutes::
83 sage: set_random_seed()
84 sage: J = random_eja()
85 sage: x = J.random_element()
86 sage: y = J.random_element()
92 self
._natural
_basis
= natural_basis
93 self
._multiplication
_table
= mult_table
94 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
103 Return a string representation of ``self``.
107 sage: from mjo.eja.eja_algebra import JordanSpinEJA
111 Ensure that it says what we think it says::
113 sage: JordanSpinEJA(2, field=QQ)
114 Euclidean Jordan algebra of degree 2 over Rational Field
115 sage: JordanSpinEJA(3, field=RDF)
116 Euclidean Jordan algebra of degree 3 over Real Double Field
119 fmt
= "Euclidean Jordan algebra of degree {} over {}"
120 return fmt
.format(self
.degree(), self
.base_ring())
123 def _a_regular_element(self
):
125 Guess a regular element. Needed to compute the basis for our
126 characteristic polynomial coefficients.
130 sage: from mjo.eja.eja_algebra import random_eja
134 Ensure that this hacky method succeeds for every algebra that we
135 know how to construct::
137 sage: set_random_seed()
138 sage: J = random_eja()
139 sage: J._a_regular_element().is_regular()
144 z
= self
.sum( (i
+1)*gs
[i
] for i
in range(len(gs
)) )
145 if not z
.is_regular():
146 raise ValueError("don't know a regular element")
151 def _charpoly_basis_space(self
):
153 Return the vector space spanned by the basis used in our
154 characteristic polynomial coefficients. This is used not only to
155 compute those coefficients, but also any time we need to
156 evaluate the coefficients (like when we compute the trace or
159 z
= self
._a
_regular
_element
()
160 V
= self
.vector_space()
161 V1
= V
.span_of_basis( (z
**k
).vector() for k
in range(self
.rank()) )
162 b
= (V1
.basis() + V1
.complement().basis())
163 return V
.span_of_basis(b
)
167 def _charpoly_coeff(self
, i
):
169 Return the coefficient polynomial "a_{i}" of this algebra's
170 general characteristic polynomial.
172 Having this be a separate cached method lets us compute and
173 store the trace/determinant (a_{r-1} and a_{0} respectively)
174 separate from the entire characteristic polynomial.
176 (A_of_x
, x
, xr
, detA
) = self
._charpoly
_matrix
_system
()
177 R
= A_of_x
.base_ring()
179 # Guaranteed by theory
182 # Danger: the in-place modification is done for performance
183 # reasons (reconstructing a matrix with huge polynomial
184 # entries is slow), but I don't know how cached_method works,
185 # so it's highly possible that we're modifying some global
186 # list variable by reference, here. In other words, you
187 # probably shouldn't call this method twice on the same
188 # algebra, at the same time, in two threads
189 Ai_orig
= A_of_x
.column(i
)
190 A_of_x
.set_column(i
,xr
)
191 numerator
= A_of_x
.det()
192 A_of_x
.set_column(i
,Ai_orig
)
194 # We're relying on the theory here to ensure that each a_i is
195 # indeed back in R, and the added negative signs are to make
196 # the whole charpoly expression sum to zero.
197 return R(-numerator
/detA
)
201 def _charpoly_matrix_system(self
):
203 Compute the matrix whose entries A_ij are polynomials in
204 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
205 corresponding to `x^r` and the determinent of the matrix A =
206 [A_ij]. In other words, all of the fixed (cachable) data needed
207 to compute the coefficients of the characteristic polynomial.
212 # Construct a new algebra over a multivariate polynomial ring...
213 names
= ['X' + str(i
) for i
in range(1,n
+1)]
214 R
= PolynomialRing(self
.base_ring(), names
)
215 J
= FiniteDimensionalEuclideanJordanAlgebra(R
,
216 self
._multiplication
_table
,
219 idmat
= matrix
.identity(J
.base_ring(), n
)
221 W
= self
._charpoly
_basis
_space
()
222 W
= W
.change_ring(R
.fraction_field())
224 # Starting with the standard coordinates x = (X1,X2,...,Xn)
225 # and then converting the entries to W-coordinates allows us
226 # to pass in the standard coordinates to the charpoly and get
227 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
230 # W.coordinates(x^2) eval'd at (standard z-coords)
234 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
236 # We want the middle equivalent thing in our matrix, but use
237 # the first equivalent thing instead so that we can pass in
238 # standard coordinates.
240 l1
= [matrix
.column(W
.coordinates((x
**k
).vector())) for k
in range(r
)]
241 l2
= [idmat
.column(k
-1).column() for k
in range(r
+1, n
+1)]
242 A_of_x
= matrix
.block(R
, 1, n
, (l1
+ l2
))
243 xr
= W
.coordinates((x
**r
).vector())
244 return (A_of_x
, x
, xr
, A_of_x
.det())
248 def characteristic_polynomial(self
):
250 Return a characteristic polynomial that works for all elements
253 The resulting polynomial has `n+1` variables, where `n` is the
254 dimension of this algebra. The first `n` variables correspond to
255 the coordinates of an algebra element: when evaluated at the
256 coordinates of an algebra element with respect to a certain
257 basis, the result is a univariate polynomial (in the one
258 remaining variable ``t``), namely the characteristic polynomial
263 sage: from mjo.eja.eja_algebra import JordanSpinEJA
267 The characteristic polynomial in the spin algebra is given in
268 Alizadeh, Example 11.11::
270 sage: J = JordanSpinEJA(3)
271 sage: p = J.characteristic_polynomial(); p
272 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
273 sage: xvec = J.one().vector()
281 # The list of coefficient polynomials a_1, a_2, ..., a_n.
282 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
284 # We go to a bit of trouble here to reorder the
285 # indeterminates, so that it's easier to evaluate the
286 # characteristic polynomial at x's coordinates and get back
287 # something in terms of t, which is what we want.
289 S
= PolynomialRing(self
.base_ring(),'t')
291 S
= PolynomialRing(S
, R
.variable_names())
294 # Note: all entries past the rth should be zero. The
295 # coefficient of the highest power (x^r) is 1, but it doesn't
296 # appear in the solution vector which contains coefficients
297 # for the other powers (to make them sum to x^r).
299 a
[r
] = 1 # corresponds to x^r
301 # When the rank is equal to the dimension, trying to
302 # assign a[r] goes out-of-bounds.
303 a
.append(1) # corresponds to x^r
305 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
308 def inner_product(self
, x
, y
):
310 The inner product associated with this Euclidean Jordan algebra.
312 Defaults to the trace inner product, but can be overridden by
313 subclasses if they are sure that the necessary properties are
318 sage: from mjo.eja.eja_algebra import random_eja
322 The inner product must satisfy its axiom for this algebra to truly
323 be a Euclidean Jordan Algebra::
325 sage: set_random_seed()
326 sage: J = random_eja()
327 sage: x = J.random_element()
328 sage: y = J.random_element()
329 sage: z = J.random_element()
330 sage: (x*y).inner_product(z) == y.inner_product(x*z)
334 if (not x
in self
) or (not y
in self
):
335 raise TypeError("arguments must live in this algebra")
336 return x
.trace_inner_product(y
)
339 def natural_basis(self
):
341 Return a more-natural representation of this algebra's basis.
343 Every finite-dimensional Euclidean Jordan Algebra is a direct
344 sum of five simple algebras, four of which comprise Hermitian
345 matrices. This method returns the original "natural" basis
346 for our underlying vector space. (Typically, the natural basis
347 is used to construct the multiplication table in the first place.)
349 Note that this will always return a matrix. The standard basis
350 in `R^n` will be returned as `n`-by-`1` column matrices.
354 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
355 ....: RealSymmetricEJA)
359 sage: J = RealSymmetricEJA(2)
362 sage: J.natural_basis()
370 sage: J = JordanSpinEJA(2)
373 sage: J.natural_basis()
380 if self
._natural
_basis
is None:
381 return tuple( b
.vector().column() for b
in self
.basis() )
383 return self
._natural
_basis
388 Return the rank of this EJA.
392 The author knows of no algorithm to compute the rank of an EJA
393 where only the multiplication table is known. In lieu of one, we
394 require the rank to be specified when the algebra is created,
395 and simply pass along that number here.
399 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
400 ....: RealSymmetricEJA,
401 ....: ComplexHermitianEJA,
402 ....: QuaternionHermitianEJA,
407 The rank of the Jordan spin algebra is always two::
409 sage: JordanSpinEJA(2).rank()
411 sage: JordanSpinEJA(3).rank()
413 sage: JordanSpinEJA(4).rank()
416 The rank of the `n`-by-`n` Hermitian real, complex, or
417 quaternion matrices is `n`::
419 sage: RealSymmetricEJA(2).rank()
421 sage: ComplexHermitianEJA(2).rank()
423 sage: QuaternionHermitianEJA(2).rank()
425 sage: RealSymmetricEJA(5).rank()
427 sage: ComplexHermitianEJA(5).rank()
429 sage: QuaternionHermitianEJA(5).rank()
434 Ensure that every EJA that we know how to construct has a
435 positive integer rank::
437 sage: set_random_seed()
438 sage: r = random_eja().rank()
439 sage: r in ZZ and r > 0
446 def vector_space(self
):
448 Return the vector space that underlies this algebra.
452 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
456 sage: J = RealSymmetricEJA(2)
457 sage: J.vector_space()
458 Vector space of dimension 3 over Rational Field
461 return self
.zero().vector().parent().ambient_vector_space()
464 class Element(FiniteDimensionalAlgebraElement
):
466 An element of a Euclidean Jordan algebra.
471 Oh man, I should not be doing this. This hides the "disabled"
472 methods ``left_matrix`` and ``matrix`` from introspection;
473 in particular it removes them from tab-completion.
475 return filter(lambda s
: s
not in ['left_matrix', 'matrix'],
476 dir(self
.__class
__) )
479 def __init__(self
, A
, elt
=None):
484 sage: from mjo.eja.eja_algebra import (RealSymmetricEJA,
489 The identity in `S^n` is converted to the identity in the EJA::
491 sage: J = RealSymmetricEJA(3)
492 sage: I = matrix.identity(QQ,3)
493 sage: J(I) == J.one()
496 This skew-symmetric matrix can't be represented in the EJA::
498 sage: J = RealSymmetricEJA(3)
499 sage: A = matrix(QQ,3, lambda i,j: i-j)
501 Traceback (most recent call last):
503 ArithmeticError: vector is not in free module
507 Ensure that we can convert any element of the parent's
508 underlying vector space back into an algebra element whose
509 vector representation is what we started with::
511 sage: set_random_seed()
512 sage: J = random_eja()
513 sage: v = J.vector_space().random_element()
514 sage: J(v).vector() == v
518 # Goal: if we're given a matrix, and if it lives in our
519 # parent algebra's "natural ambient space," convert it
520 # into an algebra element.
522 # The catch is, we make a recursive call after converting
523 # the given matrix into a vector that lives in the algebra.
524 # This we need to try the parent class initializer first,
525 # to avoid recursing forever if we're given something that
526 # already fits into the algebra, but also happens to live
527 # in the parent's "natural ambient space" (this happens with
530 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, elt
)
532 natural_basis
= A
.natural_basis()
533 if elt
in natural_basis
[0].matrix_space():
534 # Thanks for nothing! Matrix spaces aren't vector
535 # spaces in Sage, so we have to figure out its
536 # natural-basis coordinates ourselves.
537 V
= VectorSpace(elt
.base_ring(), elt
.nrows()**2)
538 W
= V
.span( _mat2vec(s
) for s
in natural_basis
)
539 coords
= W
.coordinates(_mat2vec(elt
))
540 FiniteDimensionalAlgebraElement
.__init
__(self
, A
, coords
)
542 def __pow__(self
, n
):
544 Return ``self`` raised to the power ``n``.
546 Jordan algebras are always power-associative; see for
547 example Faraut and Koranyi, Proposition II.1.2 (ii).
549 We have to override this because our superclass uses row
550 vectors instead of column vectors! We, on the other hand,
551 assume column vectors everywhere.
555 sage: from mjo.eja.eja_algebra import random_eja
559 The definition of `x^2` is the unambiguous `x*x`::
561 sage: set_random_seed()
562 sage: x = random_eja().random_element()
566 A few examples of power-associativity::
568 sage: set_random_seed()
569 sage: x = random_eja().random_element()
570 sage: x*(x*x)*(x*x) == x^5
572 sage: (x*x)*(x*x*x) == x^5
575 We also know that powers operator-commute (Koecher, Chapter
578 sage: set_random_seed()
579 sage: x = random_eja().random_element()
580 sage: m = ZZ.random_element(0,10)
581 sage: n = ZZ.random_element(0,10)
582 sage: Lxm = (x^m).operator()
583 sage: Lxn = (x^n).operator()
584 sage: Lxm*Lxn == Lxn*Lxm
589 return self
.parent().one()
593 return (self
.operator()**(n
-1))(self
)
596 def apply_univariate_polynomial(self
, p
):
598 Apply the univariate polynomial ``p`` to this element.
600 A priori, SageMath won't allow us to apply a univariate
601 polynomial to an element of an EJA, because we don't know
602 that EJAs are rings (they are usually not associative). Of
603 course, we know that EJAs are power-associative, so the
604 operation is ultimately kosher. This function sidesteps
605 the CAS to get the answer we want and expect.
609 sage: from mjo.eja.eja_algebra import (RealCartesianProductEJA,
614 sage: R = PolynomialRing(QQ, 't')
616 sage: p = t^4 - t^3 + 5*t - 2
617 sage: J = RealCartesianProductEJA(5)
618 sage: J.one().apply_univariate_polynomial(p) == 3*J.one()
623 We should always get back an element of the algebra::
625 sage: set_random_seed()
626 sage: p = PolynomialRing(QQ, 't').random_element()
627 sage: J = random_eja()
628 sage: x = J.random_element()
629 sage: x.apply_univariate_polynomial(p) in J
633 if len(p
.variables()) > 1:
634 raise ValueError("not a univariate polynomial")
637 # Convert the coeficcients to the parent's base ring,
638 # because a priori they might live in an (unnecessarily)
639 # larger ring for which P.sum() would fail below.
640 cs
= [ R(c
) for c
in p
.coefficients(sparse
=False) ]
641 return P
.sum( cs
[k
]*(self
**k
) for k
in range(len(cs
)) )
644 def characteristic_polynomial(self
):
646 Return the characteristic polynomial of this element.
650 sage: from mjo.eja.eja_algebra import RealCartesianProductEJA
654 The rank of `R^3` is three, and the minimal polynomial of
655 the identity element is `(t-1)` from which it follows that
656 the characteristic polynomial should be `(t-1)^3`::
658 sage: J = RealCartesianProductEJA(3)
659 sage: J.one().characteristic_polynomial()
660 t^3 - 3*t^2 + 3*t - 1
662 Likewise, the characteristic of the zero element in the
663 rank-three algebra `R^{n}` should be `t^{3}`::
665 sage: J = RealCartesianProductEJA(3)
666 sage: J.zero().characteristic_polynomial()
671 The characteristic polynomial of an element should evaluate
672 to zero on that element::
674 sage: set_random_seed()
675 sage: x = RealCartesianProductEJA(3).random_element()
676 sage: p = x.characteristic_polynomial()
677 sage: x.apply_univariate_polynomial(p)
681 p
= self
.parent().characteristic_polynomial()
682 return p(*self
.vector())
685 def inner_product(self
, other
):
687 Return the parent algebra's inner product of myself and ``other``.
691 sage: from mjo.eja.eja_algebra import (
692 ....: ComplexHermitianEJA,
694 ....: QuaternionHermitianEJA,
695 ....: RealSymmetricEJA,
700 The inner product in the Jordan spin algebra is the usual
701 inner product on `R^n` (this example only works because the
702 basis for the Jordan algebra is the standard basis in `R^n`)::
704 sage: J = JordanSpinEJA(3)
705 sage: x = vector(QQ,[1,2,3])
706 sage: y = vector(QQ,[4,5,6])
707 sage: x.inner_product(y)
709 sage: J(x).inner_product(J(y))
712 The inner product on `S^n` is `<X,Y> = trace(X*Y)`, where
713 multiplication is the usual matrix multiplication in `S^n`,
714 so the inner product of the identity matrix with itself
717 sage: J = RealSymmetricEJA(3)
718 sage: J.one().inner_product(J.one())
721 Likewise, the inner product on `C^n` is `<X,Y> =
722 Re(trace(X*Y))`, where we must necessarily take the real
723 part because the product of Hermitian matrices may not be
726 sage: J = ComplexHermitianEJA(3)
727 sage: J.one().inner_product(J.one())
730 Ditto for the quaternions::
732 sage: J = QuaternionHermitianEJA(3)
733 sage: J.one().inner_product(J.one())
738 Ensure that we can always compute an inner product, and that
739 it gives us back a real number::
741 sage: set_random_seed()
742 sage: J = random_eja()
743 sage: x = J.random_element()
744 sage: y = J.random_element()
745 sage: x.inner_product(y) in RR
751 raise TypeError("'other' must live in the same algebra")
753 return P
.inner_product(self
, other
)
756 def operator_commutes_with(self
, other
):
758 Return whether or not this element operator-commutes
763 sage: from mjo.eja.eja_algebra import random_eja
767 The definition of a Jordan algebra says that any element
768 operator-commutes with its square::
770 sage: set_random_seed()
771 sage: x = random_eja().random_element()
772 sage: x.operator_commutes_with(x^2)
777 Test Lemma 1 from Chapter III of Koecher::
779 sage: set_random_seed()
780 sage: J = random_eja()
781 sage: u = J.random_element()
782 sage: v = J.random_element()
783 sage: lhs = u.operator_commutes_with(u*v)
784 sage: rhs = v.operator_commutes_with(u^2)
788 Test the first polarization identity from my notes, Koecher
789 Chapter III, or from Baes (2.3)::
791 sage: set_random_seed()
792 sage: J = random_eja()
793 sage: x = J.random_element()
794 sage: y = J.random_element()
795 sage: Lx = x.operator()
796 sage: Ly = y.operator()
797 sage: Lxx = (x*x).operator()
798 sage: Lxy = (x*y).operator()
799 sage: bool(2*Lx*Lxy + Ly*Lxx == 2*Lxy*Lx + Lxx*Ly)
802 Test the second polarization identity from my notes or from
805 sage: set_random_seed()
806 sage: J = random_eja()
807 sage: x = J.random_element()
808 sage: y = J.random_element()
809 sage: z = J.random_element()
810 sage: Lx = x.operator()
811 sage: Ly = y.operator()
812 sage: Lz = z.operator()
813 sage: Lzy = (z*y).operator()
814 sage: Lxy = (x*y).operator()
815 sage: Lxz = (x*z).operator()
816 sage: bool(Lx*Lzy + Lz*Lxy + Ly*Lxz == Lzy*Lx + Lxy*Lz + Lxz*Ly)
819 Test the third polarization identity from my notes or from
822 sage: set_random_seed()
823 sage: J = random_eja()
824 sage: u = J.random_element()
825 sage: y = J.random_element()
826 sage: z = J.random_element()
827 sage: Lu = u.operator()
828 sage: Ly = y.operator()
829 sage: Lz = z.operator()
830 sage: Lzy = (z*y).operator()
831 sage: Luy = (u*y).operator()
832 sage: Luz = (u*z).operator()
833 sage: Luyz = (u*(y*z)).operator()
834 sage: lhs = Lu*Lzy + Lz*Luy + Ly*Luz
835 sage: rhs = Luyz + Ly*Lu*Lz + Lz*Lu*Ly
836 sage: bool(lhs == rhs)
840 if not other
in self
.parent():
841 raise TypeError("'other' must live in the same algebra")
850 Return my determinant, the product of my eigenvalues.
854 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
859 sage: J = JordanSpinEJA(2)
860 sage: e0,e1 = J.gens()
861 sage: x = sum( J.gens() )
867 sage: J = JordanSpinEJA(3)
868 sage: e0,e1,e2 = J.gens()
869 sage: x = sum( J.gens() )
875 An element is invertible if and only if its determinant is
878 sage: set_random_seed()
879 sage: x = random_eja().random_element()
880 sage: x.is_invertible() == (x.det() != 0)
886 p
= P
._charpoly
_coeff
(0)
887 # The _charpoly_coeff function already adds the factor of
888 # -1 to ensure that _charpoly_coeff(0) is really what
889 # appears in front of t^{0} in the charpoly. However,
890 # we want (-1)^r times THAT for the determinant.
891 return ((-1)**r
)*p(*self
.vector())
896 Return the Jordan-multiplicative inverse of this element.
900 We appeal to the quadratic representation as in Koecher's
901 Theorem 12 in Chapter III, Section 5.
905 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
910 The inverse in the spin factor algebra is given in Alizadeh's
913 sage: set_random_seed()
914 sage: n = ZZ.random_element(1,10)
915 sage: J = JordanSpinEJA(n)
916 sage: x = J.random_element()
917 sage: while not x.is_invertible():
918 ....: x = J.random_element()
919 sage: x_vec = x.vector()
921 sage: x_bar = x_vec[1:]
922 sage: coeff = ~(x0^2 - x_bar.inner_product(x_bar))
923 sage: inv_vec = x_vec.parent()([x0] + (-x_bar).list())
924 sage: x_inverse = coeff*inv_vec
925 sage: x.inverse() == J(x_inverse)
930 The identity element is its own inverse::
932 sage: set_random_seed()
933 sage: J = random_eja()
934 sage: J.one().inverse() == J.one()
937 If an element has an inverse, it acts like one::
939 sage: set_random_seed()
940 sage: J = random_eja()
941 sage: x = J.random_element()
942 sage: (not x.is_invertible()) or (x.inverse()*x == J.one())
945 The inverse of the inverse is what we started with::
947 sage: set_random_seed()
948 sage: J = random_eja()
949 sage: x = J.random_element()
950 sage: (not x.is_invertible()) or (x.inverse().inverse() == x)
953 The zero element is never invertible::
955 sage: set_random_seed()
956 sage: J = random_eja().zero().inverse()
957 Traceback (most recent call last):
959 ValueError: element is not invertible
962 if not self
.is_invertible():
963 raise ValueError("element is not invertible")
965 return (~self
.quadratic_representation())(self
)
968 def is_invertible(self
):
970 Return whether or not this element is invertible.
974 The usual way to do this is to check if the determinant is
975 zero, but we need the characteristic polynomial for the
976 determinant. The minimal polynomial is a lot easier to get,
977 so we use Corollary 2 in Chapter V of Koecher to check
978 whether or not the paren't algebra's zero element is a root
979 of this element's minimal polynomial.
981 Beware that we can't use the superclass method, because it
982 relies on the algebra being associative.
986 sage: from mjo.eja.eja_algebra import random_eja
990 The identity element is always invertible::
992 sage: set_random_seed()
993 sage: J = random_eja()
994 sage: J.one().is_invertible()
997 The zero element is never invertible::
999 sage: set_random_seed()
1000 sage: J = random_eja()
1001 sage: J.zero().is_invertible()
1005 zero
= self
.parent().zero()
1006 p
= self
.minimal_polynomial()
1007 return not (p(zero
) == zero
)
1010 def is_nilpotent(self
):
1012 Return whether or not some power of this element is zero.
1014 The superclass method won't work unless we're in an
1015 associative algebra, and we aren't. However, we generate
1016 an assocoative subalgebra and we're nilpotent there if and
1017 only if we're nilpotent here (probably).
1021 sage: from mjo.eja.eja_algebra import random_eja
1025 The identity element is never nilpotent::
1027 sage: set_random_seed()
1028 sage: random_eja().one().is_nilpotent()
1031 The additive identity is always nilpotent::
1033 sage: set_random_seed()
1034 sage: random_eja().zero().is_nilpotent()
1038 # The element we're going to call "is_nilpotent()" on.
1039 # Either myself, interpreted as an element of a finite-
1040 # dimensional algebra, or an element of an associative
1044 if self
.parent().is_associative():
1045 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
1047 V
= self
.span_of_powers()
1048 assoc_subalg
= self
.subalgebra_generated_by()
1049 # Mis-design warning: the basis used for span_of_powers()
1050 # and subalgebra_generated_by() must be the same, and in
1052 elt
= assoc_subalg(V
.coordinates(self
.vector()))
1054 # Recursive call, but should work since elt lives in an
1055 # associative algebra.
1056 return elt
.is_nilpotent()
1059 def is_regular(self
):
1061 Return whether or not this is a regular element.
1065 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1069 The identity element always has degree one, but any element
1070 linearly-independent from it is regular::
1072 sage: J = JordanSpinEJA(5)
1073 sage: J.one().is_regular()
1075 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
1076 sage: for x in J.gens():
1077 ....: (J.one() + x).is_regular()
1085 return self
.degree() == self
.parent().rank()
1090 Compute the degree of this element the straightforward way
1091 according to the definition; by appending powers to a list
1092 and figuring out its dimension (that is, whether or not
1093 they're linearly dependent).
1097 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1101 sage: J = JordanSpinEJA(4)
1102 sage: J.one().degree()
1104 sage: e0,e1,e2,e3 = J.gens()
1105 sage: (e0 - e1).degree()
1108 In the spin factor algebra (of rank two), all elements that
1109 aren't multiples of the identity are regular::
1111 sage: set_random_seed()
1112 sage: n = ZZ.random_element(1,10)
1113 sage: J = JordanSpinEJA(n)
1114 sage: x = J.random_element()
1115 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
1119 return self
.span_of_powers().dimension()
1122 def left_matrix(self
):
1124 Our parent class defines ``left_matrix`` and ``matrix``
1125 methods whose names are misleading. We don't want them.
1127 raise NotImplementedError("use operator().matrix() instead")
1129 matrix
= left_matrix
1132 def minimal_polynomial(self
):
1134 Return the minimal polynomial of this element,
1135 as a function of the variable `t`.
1139 We restrict ourselves to the associative subalgebra
1140 generated by this element, and then return the minimal
1141 polynomial of this element's operator matrix (in that
1142 subalgebra). This works by Baes Proposition 2.3.16.
1146 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1151 The minimal polynomial of the identity and zero elements are
1154 sage: set_random_seed()
1155 sage: J = random_eja()
1156 sage: J.one().minimal_polynomial()
1158 sage: J.zero().minimal_polynomial()
1161 The degree of an element is (by one definition) the degree
1162 of its minimal polynomial::
1164 sage: set_random_seed()
1165 sage: x = random_eja().random_element()
1166 sage: x.degree() == x.minimal_polynomial().degree()
1169 The minimal polynomial and the characteristic polynomial coincide
1170 and are known (see Alizadeh, Example 11.11) for all elements of
1171 the spin factor algebra that aren't scalar multiples of the
1174 sage: set_random_seed()
1175 sage: n = ZZ.random_element(2,10)
1176 sage: J = JordanSpinEJA(n)
1177 sage: y = J.random_element()
1178 sage: while y == y.coefficient(0)*J.one():
1179 ....: y = J.random_element()
1180 sage: y0 = y.vector()[0]
1181 sage: y_bar = y.vector()[1:]
1182 sage: actual = y.minimal_polynomial()
1183 sage: t = PolynomialRing(J.base_ring(),'t').gen(0)
1184 sage: expected = t^2 - 2*y0*t + (y0^2 - norm(y_bar)^2)
1185 sage: bool(actual == expected)
1188 The minimal polynomial should always kill its element::
1190 sage: set_random_seed()
1191 sage: x = random_eja().random_element()
1192 sage: p = x.minimal_polynomial()
1193 sage: x.apply_univariate_polynomial(p)
1197 V
= self
.span_of_powers()
1198 assoc_subalg
= self
.subalgebra_generated_by()
1199 # Mis-design warning: the basis used for span_of_powers()
1200 # and subalgebra_generated_by() must be the same, and in
1202 elt
= assoc_subalg(V
.coordinates(self
.vector()))
1203 return elt
.operator().minimal_polynomial()
1207 def natural_representation(self
):
1209 Return a more-natural representation of this element.
1211 Every finite-dimensional Euclidean Jordan Algebra is a
1212 direct sum of five simple algebras, four of which comprise
1213 Hermitian matrices. This method returns the original
1214 "natural" representation of this element as a Hermitian
1215 matrix, if it has one. If not, you get the usual representation.
1219 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
1220 ....: QuaternionHermitianEJA)
1224 sage: J = ComplexHermitianEJA(3)
1227 sage: J.one().natural_representation()
1237 sage: J = QuaternionHermitianEJA(3)
1240 sage: J.one().natural_representation()
1241 [1 0 0 0 0 0 0 0 0 0 0 0]
1242 [0 1 0 0 0 0 0 0 0 0 0 0]
1243 [0 0 1 0 0 0 0 0 0 0 0 0]
1244 [0 0 0 1 0 0 0 0 0 0 0 0]
1245 [0 0 0 0 1 0 0 0 0 0 0 0]
1246 [0 0 0 0 0 1 0 0 0 0 0 0]
1247 [0 0 0 0 0 0 1 0 0 0 0 0]
1248 [0 0 0 0 0 0 0 1 0 0 0 0]
1249 [0 0 0 0 0 0 0 0 1 0 0 0]
1250 [0 0 0 0 0 0 0 0 0 1 0 0]
1251 [0 0 0 0 0 0 0 0 0 0 1 0]
1252 [0 0 0 0 0 0 0 0 0 0 0 1]
1255 B
= self
.parent().natural_basis()
1256 W
= B
[0].matrix_space()
1257 return W
.linear_combination(zip(self
.vector(), B
))
1262 Return the left-multiplication-by-this-element
1263 operator on the ambient algebra.
1267 sage: from mjo.eja.eja_algebra import random_eja
1271 sage: set_random_seed()
1272 sage: J = random_eja()
1273 sage: x = J.random_element()
1274 sage: y = J.random_element()
1275 sage: x.operator()(y) == x*y
1277 sage: y.operator()(x) == x*y
1282 fda_elt
= FiniteDimensionalAlgebraElement(P
, self
)
1283 return FiniteDimensionalEuclideanJordanAlgebraOperator(
1286 fda_elt
.matrix().transpose() )
1289 def quadratic_representation(self
, other
=None):
1291 Return the quadratic representation of this element.
1295 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1300 The explicit form in the spin factor algebra is given by
1301 Alizadeh's Example 11.12::
1303 sage: set_random_seed()
1304 sage: n = ZZ.random_element(1,10)
1305 sage: J = JordanSpinEJA(n)
1306 sage: x = J.random_element()
1307 sage: x_vec = x.vector()
1309 sage: x_bar = x_vec[1:]
1310 sage: A = matrix(QQ, 1, [x_vec.inner_product(x_vec)])
1311 sage: B = 2*x0*x_bar.row()
1312 sage: C = 2*x0*x_bar.column()
1313 sage: D = matrix.identity(QQ, n-1)
1314 sage: D = (x0^2 - x_bar.inner_product(x_bar))*D
1315 sage: D = D + 2*x_bar.tensor_product(x_bar)
1316 sage: Q = matrix.block(2,2,[A,B,C,D])
1317 sage: Q == x.quadratic_representation().matrix()
1320 Test all of the properties from Theorem 11.2 in Alizadeh::
1322 sage: set_random_seed()
1323 sage: J = random_eja()
1324 sage: x = J.random_element()
1325 sage: y = J.random_element()
1326 sage: Lx = x.operator()
1327 sage: Lxx = (x*x).operator()
1328 sage: Qx = x.quadratic_representation()
1329 sage: Qy = y.quadratic_representation()
1330 sage: Qxy = x.quadratic_representation(y)
1331 sage: Qex = J.one().quadratic_representation(x)
1332 sage: n = ZZ.random_element(10)
1333 sage: Qxn = (x^n).quadratic_representation()
1337 sage: 2*Qxy == (x+y).quadratic_representation() - Qx - Qy
1340 Property 2 (multiply on the right for :trac:`28272`):
1342 sage: alpha = QQ.random_element()
1343 sage: (alpha*x).quadratic_representation() == Qx*(alpha^2)
1348 sage: not x.is_invertible() or ( Qx(x.inverse()) == x )
1351 sage: not x.is_invertible() or (
1354 ....: x.inverse().quadratic_representation() )
1357 sage: Qxy(J.one()) == x*y
1362 sage: not x.is_invertible() or (
1363 ....: x.quadratic_representation(x.inverse())*Qx
1364 ....: == Qx*x.quadratic_representation(x.inverse()) )
1367 sage: not x.is_invertible() or (
1368 ....: x.quadratic_representation(x.inverse())*Qx
1370 ....: 2*x.operator()*Qex - Qx )
1373 sage: 2*x.operator()*Qex - Qx == Lxx
1378 sage: Qy(x).quadratic_representation() == Qy*Qx*Qy
1388 sage: not x.is_invertible() or (
1389 ....: Qx*x.inverse().operator() == Lx )
1394 sage: not x.operator_commutes_with(y) or (
1395 ....: Qx(y)^n == Qxn(y^n) )
1401 elif not other
in self
.parent():
1402 raise TypeError("'other' must live in the same algebra")
1405 M
= other
.operator()
1406 return ( L
*M
+ M
*L
- (self
*other
).operator() )
1409 def span_of_powers(self
):
1411 Return the vector space spanned by successive powers of
1414 # The dimension of the subalgebra can't be greater than
1415 # the big algebra, so just put everything into a list
1416 # and let span() get rid of the excess.
1418 # We do the extra ambient_vector_space() in case we're messing
1419 # with polynomials and the direct parent is a module.
1420 V
= self
.parent().vector_space()
1421 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
1424 def subalgebra_generated_by(self
):
1426 Return the associative subalgebra of the parent EJA generated
1431 sage: from mjo.eja.eja_algebra import random_eja
1435 sage: set_random_seed()
1436 sage: x = random_eja().random_element()
1437 sage: x.subalgebra_generated_by().is_associative()
1440 Squaring in the subalgebra should work the same as in
1443 sage: set_random_seed()
1444 sage: x = random_eja().random_element()
1445 sage: u = x.subalgebra_generated_by().random_element()
1446 sage: u.operator()(u) == u^2
1450 # First get the subspace spanned by the powers of myself...
1451 V
= self
.span_of_powers()
1452 F
= self
.base_ring()
1454 # Now figure out the entries of the right-multiplication
1455 # matrix for the successive basis elements b0, b1,... of
1458 for b_right
in V
.basis():
1459 eja_b_right
= self
.parent()(b_right
)
1461 # The first row of the right-multiplication matrix by
1462 # b1 is what we get if we apply that matrix to b1. The
1463 # second row of the right multiplication matrix by b1
1464 # is what we get when we apply that matrix to b2...
1466 # IMPORTANT: this assumes that all vectors are COLUMN
1467 # vectors, unlike our superclass (which uses row vectors).
1468 for b_left
in V
.basis():
1469 eja_b_left
= self
.parent()(b_left
)
1470 # Multiply in the original EJA, but then get the
1471 # coordinates from the subalgebra in terms of its
1473 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
1474 b_right_rows
.append(this_row
)
1475 b_right_matrix
= matrix(F
, b_right_rows
)
1476 mats
.append(b_right_matrix
)
1478 # It's an algebra of polynomials in one element, and EJAs
1479 # are power-associative.
1481 # TODO: choose generator names intelligently.
1483 # The rank is the highest possible degree of a minimal polynomial,
1484 # and is bounded above by the dimension. We know in this case that
1485 # there's an element whose minimal polynomial has the same degree
1486 # as the space's dimension, so that must be its rank too.
1487 return FiniteDimensionalEuclideanJordanAlgebra(
1491 assume_associative
=True,
1495 def subalgebra_idempotent(self
):
1497 Find an idempotent in the associative subalgebra I generate
1498 using Proposition 2.3.5 in Baes.
1502 sage: from mjo.eja.eja_algebra import random_eja
1506 sage: set_random_seed()
1507 sage: J = random_eja()
1508 sage: x = J.random_element()
1509 sage: while x.is_nilpotent():
1510 ....: x = J.random_element()
1511 sage: c = x.subalgebra_idempotent()
1516 if self
.is_nilpotent():
1517 raise ValueError("this only works with non-nilpotent elements!")
1519 V
= self
.span_of_powers()
1520 J
= self
.subalgebra_generated_by()
1521 # Mis-design warning: the basis used for span_of_powers()
1522 # and subalgebra_generated_by() must be the same, and in
1524 u
= J(V
.coordinates(self
.vector()))
1526 # The image of the matrix of left-u^m-multiplication
1527 # will be minimal for some natural number s...
1529 minimal_dim
= V
.dimension()
1530 for i
in xrange(1, V
.dimension()):
1531 this_dim
= (u
**i
).operator().matrix().image().dimension()
1532 if this_dim
< minimal_dim
:
1533 minimal_dim
= this_dim
1536 # Now minimal_matrix should correspond to the smallest
1537 # non-zero subspace in Baes's (or really, Koecher's)
1540 # However, we need to restrict the matrix to work on the
1541 # subspace... or do we? Can't we just solve, knowing that
1542 # A(c) = u^(s+1) should have a solution in the big space,
1545 # Beware, solve_right() means that we're using COLUMN vectors.
1546 # Our FiniteDimensionalAlgebraElement superclass uses rows.
1548 A
= u_next
.operator().matrix()
1549 c_coordinates
= A
.solve_right(u_next
.vector())
1551 # Now c_coordinates is the idempotent we want, but it's in
1552 # the coordinate system of the subalgebra.
1554 # We need the basis for J, but as elements of the parent algebra.
1556 basis
= [self
.parent(v
) for v
in V
.basis()]
1557 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
1562 Return my trace, the sum of my eigenvalues.
1566 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1567 ....: RealCartesianProductEJA,
1572 sage: J = JordanSpinEJA(3)
1573 sage: x = sum(J.gens())
1579 sage: J = RealCartesianProductEJA(5)
1580 sage: J.one().trace()
1585 The trace of an element is a real number::
1587 sage: set_random_seed()
1588 sage: J = random_eja()
1589 sage: J.random_element().trace() in J.base_ring()
1595 p
= P
._charpoly
_coeff
(r
-1)
1596 # The _charpoly_coeff function already adds the factor of
1597 # -1 to ensure that _charpoly_coeff(r-1) is really what
1598 # appears in front of t^{r-1} in the charpoly. However,
1599 # we want the negative of THAT for the trace.
1600 return -p(*self
.vector())
1603 def trace_inner_product(self
, other
):
1605 Return the trace inner product of myself and ``other``.
1609 sage: from mjo.eja.eja_algebra import random_eja
1613 The trace inner product is commutative::
1615 sage: set_random_seed()
1616 sage: J = random_eja()
1617 sage: x = J.random_element(); y = J.random_element()
1618 sage: x.trace_inner_product(y) == y.trace_inner_product(x)
1621 The trace inner product is bilinear::
1623 sage: set_random_seed()
1624 sage: J = random_eja()
1625 sage: x = J.random_element()
1626 sage: y = J.random_element()
1627 sage: z = J.random_element()
1628 sage: a = QQ.random_element();
1629 sage: actual = (a*(x+z)).trace_inner_product(y)
1630 sage: expected = ( a*x.trace_inner_product(y) +
1631 ....: a*z.trace_inner_product(y) )
1632 sage: actual == expected
1634 sage: actual = x.trace_inner_product(a*(y+z))
1635 sage: expected = ( a*x.trace_inner_product(y) +
1636 ....: a*x.trace_inner_product(z) )
1637 sage: actual == expected
1640 The trace inner product satisfies the compatibility
1641 condition in the definition of a Euclidean Jordan algebra::
1643 sage: set_random_seed()
1644 sage: J = random_eja()
1645 sage: x = J.random_element()
1646 sage: y = J.random_element()
1647 sage: z = J.random_element()
1648 sage: (x*y).trace_inner_product(z) == y.trace_inner_product(x*z)
1652 if not other
in self
.parent():
1653 raise TypeError("'other' must live in the same algebra")
1655 return (self
*other
).trace()
1658 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1660 Return the Euclidean Jordan Algebra corresponding to the set
1661 `R^n` under the Hadamard product.
1663 Note: this is nothing more than the Cartesian product of ``n``
1664 copies of the spin algebra. Once Cartesian product algebras
1665 are implemented, this can go.
1669 sage: from mjo.eja.eja_algebra import RealCartesianProductEJA
1673 This multiplication table can be verified by hand::
1675 sage: J = RealCartesianProductEJA(3)
1676 sage: e0,e1,e2 = J.gens()
1692 def __classcall_private__(cls
, n
, field
=QQ
):
1693 # The FiniteDimensionalAlgebra constructor takes a list of
1694 # matrices, the ith representing right multiplication by the ith
1695 # basis element in the vector space. So if e_1 = (1,0,0), then
1696 # right (Hadamard) multiplication of x by e_1 picks out the first
1697 # component of x; and likewise for the ith basis element e_i.
1698 Qs
= [ matrix(field
, n
, n
, lambda k
,j
: 1*(k
== j
== i
))
1699 for i
in xrange(n
) ]
1701 fdeja
= super(RealCartesianProductEJA
, cls
)
1702 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=n
)
1704 def inner_product(self
, x
, y
):
1705 return _usual_ip(x
,y
)
1710 Return a "random" finite-dimensional Euclidean Jordan Algebra.
1714 For now, we choose a random natural number ``n`` (greater than zero)
1715 and then give you back one of the following:
1717 * The cartesian product of the rational numbers ``n`` times; this is
1718 ``QQ^n`` with the Hadamard product.
1720 * The Jordan spin algebra on ``QQ^n``.
1722 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
1725 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
1726 in the space of ``2n``-by-``2n`` real symmetric matrices.
1728 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
1729 in the space of ``4n``-by-``4n`` real symmetric matrices.
1731 Later this might be extended to return Cartesian products of the
1736 sage: from mjo.eja.eja_algebra import random_eja
1741 Euclidean Jordan algebra of degree...
1745 # The max_n component lets us choose different upper bounds on the
1746 # value "n" that gets passed to the constructor. This is needed
1747 # because e.g. R^{10} is reasonable to test, while the Hermitian
1748 # 10-by-10 quaternion matrices are not.
1749 (constructor
, max_n
) = choice([(RealCartesianProductEJA
, 6),
1751 (RealSymmetricEJA
, 5),
1752 (ComplexHermitianEJA
, 4),
1753 (QuaternionHermitianEJA
, 3)])
1754 n
= ZZ
.random_element(1, max_n
)
1755 return constructor(n
, field
=QQ
)
1759 def _real_symmetric_basis(n
, field
=QQ
):
1761 Return a basis for the space of real symmetric n-by-n matrices.
1763 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1767 for j
in xrange(i
+1):
1768 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1772 # Beware, orthogonal but not normalized!
1773 Sij
= Eij
+ Eij
.transpose()
1778 def _complex_hermitian_basis(n
, field
=QQ
):
1780 Returns a basis for the space of complex Hermitian n-by-n matrices.
1784 sage: from mjo.eja.eja_algebra import _complex_hermitian_basis
1788 sage: set_random_seed()
1789 sage: n = ZZ.random_element(1,5)
1790 sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
1794 F
= QuadraticField(-1, 'I')
1797 # This is like the symmetric case, but we need to be careful:
1799 # * We want conjugate-symmetry, not just symmetry.
1800 # * The diagonal will (as a result) be real.
1804 for j
in xrange(i
+1):
1805 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1807 Sij
= _embed_complex_matrix(Eij
)
1810 # Beware, orthogonal but not normalized! The second one
1811 # has a minus because it's conjugated.
1812 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
1814 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
1819 def _quaternion_hermitian_basis(n
, field
=QQ
):
1821 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
1825 sage: from mjo.eja.eja_algebra import _quaternion_hermitian_basis
1829 sage: set_random_seed()
1830 sage: n = ZZ.random_element(1,5)
1831 sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
1835 Q
= QuaternionAlgebra(QQ
,-1,-1)
1838 # This is like the symmetric case, but we need to be careful:
1840 # * We want conjugate-symmetry, not just symmetry.
1841 # * The diagonal will (as a result) be real.
1845 for j
in xrange(i
+1):
1846 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
1848 Sij
= _embed_quaternion_matrix(Eij
)
1851 # Beware, orthogonal but not normalized! The second,
1852 # third, and fourth ones have a minus because they're
1854 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1856 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1858 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1860 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1866 return vector(m
.base_ring(), m
.list())
1869 return matrix(v
.base_ring(), sqrt(v
.degree()), v
.list())
1871 def _multiplication_table_from_matrix_basis(basis
):
1873 At least three of the five simple Euclidean Jordan algebras have the
1874 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1875 multiplication on the right is matrix multiplication. Given a basis
1876 for the underlying matrix space, this function returns a
1877 multiplication table (obtained by looping through the basis
1878 elements) for an algebra of those matrices. A reordered copy
1879 of the basis is also returned to work around the fact that
1880 the ``span()`` in this function will change the order of the basis
1881 from what we think it is, to... something else.
1883 # In S^2, for example, we nominally have four coordinates even
1884 # though the space is of dimension three only. The vector space V
1885 # is supposed to hold the entire long vector, and the subspace W
1886 # of V will be spanned by the vectors that arise from symmetric
1887 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1888 field
= basis
[0].base_ring()
1889 dimension
= basis
[0].nrows()
1891 V
= VectorSpace(field
, dimension
**2)
1892 W
= V
.span( _mat2vec(s
) for s
in basis
)
1894 # Taking the span above reorders our basis (thanks, jerk!) so we
1895 # need to put our "matrix basis" in the same order as the
1896 # (reordered) vector basis.
1897 S
= tuple( _vec2mat(b
) for b
in W
.basis() )
1901 # Brute force the multiplication-by-s matrix by looping
1902 # through all elements of the basis and doing the computation
1903 # to find out what the corresponding row should be. BEWARE:
1904 # these multiplication tables won't be symmetric! It therefore
1905 # becomes REALLY IMPORTANT that the underlying algebra
1906 # constructor uses ROW vectors and not COLUMN vectors. That's
1907 # why we're computing rows here and not columns.
1910 this_row
= _mat2vec((s
*t
+ t
*s
)/2)
1911 Q_rows
.append(W
.coordinates(this_row
))
1912 Q
= matrix(field
, W
.dimension(), Q_rows
)
1918 def _embed_complex_matrix(M
):
1920 Embed the n-by-n complex matrix ``M`` into the space of real
1921 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1922 bi` to the block matrix ``[[a,b],[-b,a]]``.
1926 sage: from mjo.eja.eja_algebra import _embed_complex_matrix
1930 sage: F = QuadraticField(-1,'i')
1931 sage: x1 = F(4 - 2*i)
1932 sage: x2 = F(1 + 2*i)
1935 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1936 sage: _embed_complex_matrix(M)
1945 Embedding is a homomorphism (isomorphism, in fact)::
1947 sage: set_random_seed()
1948 sage: n = ZZ.random_element(5)
1949 sage: F = QuadraticField(-1, 'i')
1950 sage: X = random_matrix(F, n)
1951 sage: Y = random_matrix(F, n)
1952 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1953 sage: expected = _embed_complex_matrix(X*Y)
1954 sage: actual == expected
1960 raise ValueError("the matrix 'M' must be square")
1961 field
= M
.base_ring()
1966 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1968 # We can drop the imaginaries here.
1969 return matrix
.block(field
.base_ring(), n
, blocks
)
1972 def _unembed_complex_matrix(M
):
1974 The inverse of _embed_complex_matrix().
1978 sage: from mjo.eja.eja_algebra import (_embed_complex_matrix,
1979 ....: _unembed_complex_matrix)
1983 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1984 ....: [-2, 1, -4, 3],
1985 ....: [ 9, 10, 11, 12],
1986 ....: [-10, 9, -12, 11] ])
1987 sage: _unembed_complex_matrix(A)
1989 [ 10*i + 9 12*i + 11]
1993 Unembedding is the inverse of embedding::
1995 sage: set_random_seed()
1996 sage: F = QuadraticField(-1, 'i')
1997 sage: M = random_matrix(F, 3)
1998 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
2004 raise ValueError("the matrix 'M' must be square")
2005 if not n
.mod(2).is_zero():
2006 raise ValueError("the matrix 'M' must be a complex embedding")
2008 F
= QuadraticField(-1, 'i')
2011 # Go top-left to bottom-right (reading order), converting every
2012 # 2-by-2 block we see to a single complex element.
2014 for k
in xrange(n
/2):
2015 for j
in xrange(n
/2):
2016 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
2017 if submat
[0,0] != submat
[1,1]:
2018 raise ValueError('bad on-diagonal submatrix')
2019 if submat
[0,1] != -submat
[1,0]:
2020 raise ValueError('bad off-diagonal submatrix')
2021 z
= submat
[0,0] + submat
[0,1]*i
2024 return matrix(F
, n
/2, elements
)
2027 def _embed_quaternion_matrix(M
):
2029 Embed the n-by-n quaternion matrix ``M`` into the space of real
2030 matrices of size 4n-by-4n by first sending each quaternion entry
2031 `z = a + bi + cj + dk` to the block-complex matrix
2032 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
2037 sage: from mjo.eja.eja_algebra import _embed_quaternion_matrix
2041 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2042 sage: i,j,k = Q.gens()
2043 sage: x = 1 + 2*i + 3*j + 4*k
2044 sage: M = matrix(Q, 1, [[x]])
2045 sage: _embed_quaternion_matrix(M)
2051 Embedding is a homomorphism (isomorphism, in fact)::
2053 sage: set_random_seed()
2054 sage: n = ZZ.random_element(5)
2055 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2056 sage: X = random_matrix(Q, n)
2057 sage: Y = random_matrix(Q, n)
2058 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
2059 sage: expected = _embed_quaternion_matrix(X*Y)
2060 sage: actual == expected
2064 quaternions
= M
.base_ring()
2067 raise ValueError("the matrix 'M' must be square")
2069 F
= QuadraticField(-1, 'i')
2074 t
= z
.coefficient_tuple()
2079 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
2080 [-c
+ d
*i
, a
- b
*i
]])
2081 blocks
.append(_embed_complex_matrix(cplx_matrix
))
2083 # We should have real entries by now, so use the realest field
2084 # we've got for the return value.
2085 return matrix
.block(quaternions
.base_ring(), n
, blocks
)
2088 def _unembed_quaternion_matrix(M
):
2090 The inverse of _embed_quaternion_matrix().
2094 sage: from mjo.eja.eja_algebra import (_embed_quaternion_matrix,
2095 ....: _unembed_quaternion_matrix)
2099 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
2100 ....: [-2, 1, -4, 3],
2101 ....: [-3, 4, 1, -2],
2102 ....: [-4, -3, 2, 1]])
2103 sage: _unembed_quaternion_matrix(M)
2104 [1 + 2*i + 3*j + 4*k]
2108 Unembedding is the inverse of embedding::
2110 sage: set_random_seed()
2111 sage: Q = QuaternionAlgebra(QQ, -1, -1)
2112 sage: M = random_matrix(Q, 3)
2113 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
2119 raise ValueError("the matrix 'M' must be square")
2120 if not n
.mod(4).is_zero():
2121 raise ValueError("the matrix 'M' must be a complex embedding")
2123 Q
= QuaternionAlgebra(QQ
,-1,-1)
2126 # Go top-left to bottom-right (reading order), converting every
2127 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
2130 for l
in xrange(n
/4):
2131 for m
in xrange(n
/4):
2132 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
2133 if submat
[0,0] != submat
[1,1].conjugate():
2134 raise ValueError('bad on-diagonal submatrix')
2135 if submat
[0,1] != -submat
[1,0].conjugate():
2136 raise ValueError('bad off-diagonal submatrix')
2137 z
= submat
[0,0].real() + submat
[0,0].imag()*i
2138 z
+= submat
[0,1].real()*j
+ submat
[0,1].imag()*k
2141 return matrix(Q
, n
/4, elements
)
2144 # The usual inner product on R^n.
2146 return x
.vector().inner_product(y
.vector())
2148 # The inner product used for the real symmetric simple EJA.
2149 # We keep it as a separate function because e.g. the complex
2150 # algebra uses the same inner product, except divided by 2.
2151 def _matrix_ip(X
,Y
):
2152 X_mat
= X
.natural_representation()
2153 Y_mat
= Y
.natural_representation()
2154 return (X_mat
*Y_mat
).trace()
2157 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2159 The rank-n simple EJA consisting of real symmetric n-by-n
2160 matrices, the usual symmetric Jordan product, and the trace inner
2161 product. It has dimension `(n^2 + n)/2` over the reals.
2165 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
2169 sage: J = RealSymmetricEJA(2)
2170 sage: e0, e1, e2 = J.gens()
2180 The degree of this algebra is `(n^2 + n) / 2`::
2182 sage: set_random_seed()
2183 sage: n = ZZ.random_element(1,5)
2184 sage: J = RealSymmetricEJA(n)
2185 sage: J.degree() == (n^2 + n)/2
2188 The Jordan multiplication is what we think it is::
2190 sage: set_random_seed()
2191 sage: n = ZZ.random_element(1,5)
2192 sage: J = RealSymmetricEJA(n)
2193 sage: x = J.random_element()
2194 sage: y = J.random_element()
2195 sage: actual = (x*y).natural_representation()
2196 sage: X = x.natural_representation()
2197 sage: Y = y.natural_representation()
2198 sage: expected = (X*Y + Y*X)/2
2199 sage: actual == expected
2201 sage: J(expected) == x*y
2206 def __classcall_private__(cls
, n
, field
=QQ
):
2207 S
= _real_symmetric_basis(n
, field
=field
)
2208 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2210 fdeja
= super(RealSymmetricEJA
, cls
)
2211 return fdeja
.__classcall
_private
__(cls
,
2217 def inner_product(self
, x
, y
):
2218 return _matrix_ip(x
,y
)
2221 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2223 The rank-n simple EJA consisting of complex Hermitian n-by-n
2224 matrices over the real numbers, the usual symmetric Jordan product,
2225 and the real-part-of-trace inner product. It has dimension `n^2` over
2230 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
2234 The degree of this algebra is `n^2`::
2236 sage: set_random_seed()
2237 sage: n = ZZ.random_element(1,5)
2238 sage: J = ComplexHermitianEJA(n)
2239 sage: J.degree() == n^2
2242 The Jordan multiplication is what we think it is::
2244 sage: set_random_seed()
2245 sage: n = ZZ.random_element(1,5)
2246 sage: J = ComplexHermitianEJA(n)
2247 sage: x = J.random_element()
2248 sage: y = J.random_element()
2249 sage: actual = (x*y).natural_representation()
2250 sage: X = x.natural_representation()
2251 sage: Y = y.natural_representation()
2252 sage: expected = (X*Y + Y*X)/2
2253 sage: actual == expected
2255 sage: J(expected) == x*y
2260 def __classcall_private__(cls
, n
, field
=QQ
):
2261 S
= _complex_hermitian_basis(n
)
2262 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2264 fdeja
= super(ComplexHermitianEJA
, cls
)
2265 return fdeja
.__classcall
_private
__(cls
,
2271 def inner_product(self
, x
, y
):
2272 # Since a+bi on the diagonal is represented as
2277 # we'll double-count the "a" entries if we take the trace of
2279 return _matrix_ip(x
,y
)/2
2282 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2284 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2285 matrices, the usual symmetric Jordan product, and the
2286 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2291 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2295 The degree of this algebra is `n^2`::
2297 sage: set_random_seed()
2298 sage: n = ZZ.random_element(1,5)
2299 sage: J = QuaternionHermitianEJA(n)
2300 sage: J.degree() == 2*(n^2) - n
2303 The Jordan multiplication is what we think it is::
2305 sage: set_random_seed()
2306 sage: n = ZZ.random_element(1,5)
2307 sage: J = QuaternionHermitianEJA(n)
2308 sage: x = J.random_element()
2309 sage: y = J.random_element()
2310 sage: actual = (x*y).natural_representation()
2311 sage: X = x.natural_representation()
2312 sage: Y = y.natural_representation()
2313 sage: expected = (X*Y + Y*X)/2
2314 sage: actual == expected
2316 sage: J(expected) == x*y
2321 def __classcall_private__(cls
, n
, field
=QQ
):
2322 S
= _quaternion_hermitian_basis(n
)
2323 (Qs
, T
) = _multiplication_table_from_matrix_basis(S
)
2325 fdeja
= super(QuaternionHermitianEJA
, cls
)
2326 return fdeja
.__classcall
_private
__(cls
,
2332 def inner_product(self
, x
, y
):
2333 # Since a+bi+cj+dk on the diagonal is represented as
2335 # a + bi +cj + dk = [ a b c d]
2340 # we'll quadruple-count the "a" entries if we take the trace of
2342 return _matrix_ip(x
,y
)/4
2345 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
2347 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2348 with the usual inner product and jordan product ``x*y =
2349 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2354 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2358 This multiplication table can be verified by hand::
2360 sage: J = JordanSpinEJA(4)
2361 sage: e0,e1,e2,e3 = J.gens()
2379 def __classcall_private__(cls
, n
, field
=QQ
):
2381 id_matrix
= matrix
.identity(field
, n
)
2383 ei
= id_matrix
.column(i
)
2384 Qi
= matrix
.zero(field
, n
)
2386 Qi
.set_column(0, ei
)
2387 Qi
+= matrix
.diagonal(n
, [ei
[0]]*n
)
2388 # The addition of the diagonal matrix adds an extra ei[0] in the
2389 # upper-left corner of the matrix.
2390 Qi
[0,0] = Qi
[0,0] * ~
field(2)
2393 # The rank of the spin algebra is two, unless we're in a
2394 # one-dimensional ambient space (because the rank is bounded by
2395 # the ambient dimension).
2396 fdeja
= super(JordanSpinEJA
, cls
)
2397 return fdeja
.__classcall
_private
__(cls
, field
, Qs
, rank
=min(n
,2))
2399 def inner_product(self
, x
, y
):
2400 return _usual_ip(x
,y
)