2 Representations and constructions for Euclidean Jordan algebras.
4 A Euclidean Jordan algebra is a Jordan algebra that has some
7 1. It is finite-dimensional.
8 2. Its scalar field is the real numbers.
9 3a. An inner product is defined on it, and...
10 3b. That inner product is compatible with the Jordan product
11 in the sense that `<x*y,z> = <y,x*z>` for all elements
12 `x,y,z` in the algebra.
14 Every Euclidean Jordan algebra is formally-real: for any two elements
15 `x` and `y` in the algebra, `x^{2} + y^{2} = 0` implies that `x = y =
16 0`. Conversely, every finite-dimensional formally-real Jordan algebra
17 can be made into a Euclidean Jordan algebra with an appropriate choice
20 Formally-real Jordan algebras were originally studied as a framework
21 for quantum mechanics. Today, Euclidean Jordan algebras are crucial in
22 symmetric cone optimization, since every symmetric cone arises as the
23 cone of squares in some Euclidean Jordan algebra.
25 It is known that every Euclidean Jordan algebra decomposes into an
26 orthogonal direct sum (essentially, a Cartesian product) of simple
27 algebras, and that moreover, up to Jordan-algebra isomorphism, there
28 are only five families of simple algebras. We provide constructions
29 for these simple algebras:
31 * :class:`BilinearFormEJA`
32 * :class:`RealSymmetricEJA`
33 * :class:`ComplexHermitianEJA`
34 * :class:`QuaternionHermitianEJA`
36 Missing from this list is the algebra of three-by-three octononion
37 Hermitian matrices, as there is (as of yet) no implementation of the
38 octonions in SageMath. In addition to these, we provide two other
39 example constructions,
41 * :class:`HadamardEJA`
44 The Jordan spin algebra is a bilinear form algebra where the bilinear
45 form is the identity. The Hadamard EJA is simply a Cartesian product
46 of one-dimensional spin algebras. And last but not least, the trivial
47 EJA is exactly what you think. Cartesian products of these are also
48 supported using the usual ``cartesian_product()`` function; as a
49 result, we support (up to isomorphism) all Euclidean Jordan algebras
50 that don't involve octonions.
54 sage: from mjo.eja.eja_algebra import random_eja
59 Euclidean Jordan algebra of dimension...
62 from itertools
import repeat
64 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
65 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
66 from sage
.categories
.sets_cat
import cartesian_product
67 from sage
.combinat
.free_module
import CombinatorialFreeModule
68 from sage
.matrix
.constructor
import matrix
69 from sage
.matrix
.matrix_space
import MatrixSpace
70 from sage
.misc
.cachefunc
import cached_method
71 from sage
.misc
.table
import table
72 from sage
.modules
.free_module
import FreeModule
, VectorSpace
73 from sage
.rings
.all
import (ZZ
, QQ
, AA
, QQbar
, RR
, RLF
, CLF
,
76 from mjo
.eja
.eja_element
import FiniteDimensionalEJAElement
77 from mjo
.eja
.eja_operator
import FiniteDimensionalEJAOperator
78 from mjo
.eja
.eja_utils
import _all2list
, _mat2vec
80 class FiniteDimensionalEJA(CombinatorialFreeModule
):
82 A finite-dimensional Euclidean Jordan algebra.
86 - ``basis`` -- a tuple; a tuple of basis elements in "matrix
87 form," which must be the same form as the arguments to
88 ``jordan_product`` and ``inner_product``. In reality, "matrix
89 form" can be either vectors, matrices, or a Cartesian product
90 (ordered tuple) of vectors or matrices. All of these would
91 ideally be vector spaces in sage with no special-casing
92 needed; but in reality we turn vectors into column-matrices
93 and Cartesian products `(a,b)` into column matrices
94 `(a,b)^{T}` after converting `a` and `b` themselves.
96 - ``jordan_product`` -- a function; afunction of two ``basis``
97 elements (in matrix form) that returns their jordan product,
98 also in matrix form; this will be applied to ``basis`` to
99 compute a multiplication table for the algebra.
101 - ``inner_product`` -- a function; a function of two ``basis``
102 elements (in matrix form) that returns their inner
103 product. This will be applied to ``basis`` to compute an
104 inner-product table (basically a matrix) for this algebra.
106 - ``field`` -- a subfield of the reals (default: ``AA``); the scalar
107 field for the algebra.
109 - ``orthonormalize`` -- boolean (default: ``True``); whether or
110 not to orthonormalize the basis. Doing so is expensive and
111 generally rules out using the rationals as your ``field``, but
112 is required for spectral decompositions.
116 sage: from mjo.eja.eja_algebra import random_eja
120 We should compute that an element subalgebra is associative even
121 if we circumvent the element method::
123 sage: set_random_seed()
124 sage: J = random_eja(field=QQ,orthonormalize=False)
125 sage: x = J.random_element()
126 sage: A = x.subalgebra_generated_by(orthonormalize=False)
127 sage: basis = tuple(b.superalgebra_element() for b in A.basis())
128 sage: J.subalgebra(basis, orthonormalize=False).is_associative()
132 Element
= FiniteDimensionalEJAElement
141 cartesian_product
=False,
149 if not field
.is_subring(RR
):
150 # Note: this does return true for the real algebraic
151 # field, the rationals, and any quadratic field where
152 # we've specified a real embedding.
153 raise ValueError("scalar field is not real")
156 # Check commutativity of the Jordan and inner-products.
157 # This has to be done before we build the multiplication
158 # and inner-product tables/matrices, because we take
159 # advantage of symmetry in the process.
160 if not all( jordan_product(bi
,bj
) == jordan_product(bj
,bi
)
163 raise ValueError("Jordan product is not commutative")
165 if not all( inner_product(bi
,bj
) == inner_product(bj
,bi
)
168 raise ValueError("inner-product is not commutative")
171 category
= MagmaticAlgebras(field
).FiniteDimensional()
172 category
= category
.WithBasis().Unital().Commutative()
174 if associative
is None:
175 # We should figure it out. As with check_axioms, we have to do
176 # this without the help of the _jordan_product_is_associative()
177 # method because we need to know the category before we
178 # initialize the algebra.
179 associative
= all( jordan_product(jordan_product(bi
,bj
),bk
)
181 jordan_product(bi
,jordan_product(bj
,bk
))
187 # Element subalgebras can take advantage of this.
188 category
= category
.Associative()
189 if cartesian_product
:
190 # Use join() here because otherwise we only get the
191 # "Cartesian product of..." and not the things themselves.
192 category
= category
.join([category
,
193 category
.CartesianProducts()])
195 # Call the superclass constructor so that we can use its from_vector()
196 # method to build our multiplication table.
197 CombinatorialFreeModule
.__init
__(self
,
204 # Now comes all of the hard work. We'll be constructing an
205 # ambient vector space V that our (vectorized) basis lives in,
206 # as well as a subspace W of V spanned by those (vectorized)
207 # basis elements. The W-coordinates are the coefficients that
208 # we see in things like x = 1*b1 + 2*b2.
213 degree
= len(_all2list(basis
[0]))
215 # Build an ambient space that fits our matrix basis when
216 # written out as "long vectors."
217 V
= VectorSpace(field
, degree
)
219 # The matrix that will hole the orthonormal -> unorthonormal
220 # coordinate transformation.
221 self
._deortho
_matrix
= None
224 # Save a copy of the un-orthonormalized basis for later.
225 # Convert it to ambient V (vector) coordinates while we're
226 # at it, because we'd have to do it later anyway.
227 deortho_vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
229 from mjo
.eja
.eja_utils
import gram_schmidt
230 basis
= tuple(gram_schmidt(basis
, inner_product
))
232 # Save the (possibly orthonormalized) matrix basis for
234 self
._matrix
_basis
= basis
236 # Now create the vector space for the algebra, which will have
237 # its own set of non-ambient coordinates (in terms of the
239 vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
240 W
= V
.span_of_basis( vector_basis
, check
=check_axioms
)
243 # Now "W" is the vector space of our algebra coordinates. The
244 # variables "X1", "X2",... refer to the entries of vectors in
245 # W. Thus to convert back and forth between the orthonormal
246 # coordinates and the given ones, we need to stick the original
248 U
= V
.span_of_basis( deortho_vector_basis
, check
=check_axioms
)
249 self
._deortho
_matrix
= matrix( U
.coordinate_vector(q
)
250 for q
in vector_basis
)
253 # Now we actually compute the multiplication and inner-product
254 # tables/matrices using the possibly-orthonormalized basis.
255 self
._inner
_product
_matrix
= matrix
.identity(field
, n
)
256 self
._multiplication
_table
= [ [0 for j
in range(i
+1)]
259 # Note: the Jordan and inner-products are defined in terms
260 # of the ambient basis. It's important that their arguments
261 # are in ambient coordinates as well.
264 # ortho basis w.r.t. ambient coords
268 # The jordan product returns a matrixy answer, so we
269 # have to convert it to the algebra coordinates.
270 elt
= jordan_product(q_i
, q_j
)
271 elt
= W
.coordinate_vector(V(_all2list(elt
)))
272 self
._multiplication
_table
[i
][j
] = self
.from_vector(elt
)
274 if not orthonormalize
:
275 # If we're orthonormalizing the basis with respect
276 # to an inner-product, then the inner-product
277 # matrix with respect to the resulting basis is
278 # just going to be the identity.
279 ip
= inner_product(q_i
, q_j
)
280 self
._inner
_product
_matrix
[i
,j
] = ip
281 self
._inner
_product
_matrix
[j
,i
] = ip
283 self
._inner
_product
_matrix
._cache
= {'hermitian': True}
284 self
._inner
_product
_matrix
.set_immutable()
287 if not self
._is
_jordanian
():
288 raise ValueError("Jordan identity does not hold")
289 if not self
._inner
_product
_is
_associative
():
290 raise ValueError("inner product is not associative")
293 def _coerce_map_from_base_ring(self
):
295 Disable the map from the base ring into the algebra.
297 Performing a nonsense conversion like this automatically
298 is counterpedagogical. The fallback is to try the usual
299 element constructor, which should also fail.
303 sage: from mjo.eja.eja_algebra import random_eja
307 sage: set_random_seed()
308 sage: J = random_eja()
310 Traceback (most recent call last):
312 ValueError: not an element of this algebra
318 def product_on_basis(self
, i
, j
):
320 Returns the Jordan product of the `i` and `j`th basis elements.
322 This completely defines the Jordan product on the algebra, and
323 is used direclty by our superclass machinery to implement
328 sage: from mjo.eja.eja_algebra import random_eja
332 sage: set_random_seed()
333 sage: J = random_eja()
334 sage: n = J.dimension()
337 sage: bi_bj = J.zero()*J.zero()
339 ....: i = ZZ.random_element(n)
340 ....: j = ZZ.random_element(n)
341 ....: bi = J.monomial(i)
342 ....: bj = J.monomial(j)
343 ....: bi_bj = J.product_on_basis(i,j)
348 # We only stored the lower-triangular portion of the
349 # multiplication table.
351 return self
._multiplication
_table
[i
][j
]
353 return self
._multiplication
_table
[j
][i
]
355 def inner_product(self
, x
, y
):
357 The inner product associated with this Euclidean Jordan algebra.
359 Defaults to the trace inner product, but can be overridden by
360 subclasses if they are sure that the necessary properties are
365 sage: from mjo.eja.eja_algebra import (random_eja,
367 ....: BilinearFormEJA)
371 Our inner product is "associative," which means the following for
372 a symmetric bilinear form::
374 sage: set_random_seed()
375 sage: J = random_eja()
376 sage: x,y,z = J.random_elements(3)
377 sage: (x*y).inner_product(z) == y.inner_product(x*z)
382 Ensure that this is the usual inner product for the algebras
385 sage: set_random_seed()
386 sage: J = HadamardEJA.random_instance()
387 sage: x,y = J.random_elements(2)
388 sage: actual = x.inner_product(y)
389 sage: expected = x.to_vector().inner_product(y.to_vector())
390 sage: actual == expected
393 Ensure that this is one-half of the trace inner-product in a
394 BilinearFormEJA that isn't just the reals (when ``n`` isn't
395 one). This is in Faraut and Koranyi, and also my "On the
398 sage: set_random_seed()
399 sage: J = BilinearFormEJA.random_instance()
400 sage: n = J.dimension()
401 sage: x = J.random_element()
402 sage: y = J.random_element()
403 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
407 B
= self
._inner
_product
_matrix
408 return (B
*x
.to_vector()).inner_product(y
.to_vector())
411 def is_associative(self
):
413 Return whether or not this algebra's Jordan product is associative.
417 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
421 sage: J = ComplexHermitianEJA(3, field=QQ, orthonormalize=False)
422 sage: J.is_associative()
424 sage: x = sum(J.gens())
425 sage: A = x.subalgebra_generated_by(orthonormalize=False)
426 sage: A.is_associative()
430 return "Associative" in self
.category().axioms()
432 def _is_commutative(self
):
434 Whether or not this algebra's multiplication table is commutative.
436 This method should of course always return ``True``, unless
437 this algebra was constructed with ``check_axioms=False`` and
438 passed an invalid multiplication table.
440 return all( x
*y
== y
*x
for x
in self
.gens() for y
in self
.gens() )
442 def _is_jordanian(self
):
444 Whether or not this algebra's multiplication table respects the
445 Jordan identity `(x^{2})(xy) = x(x^{2}y)`.
447 We only check one arrangement of `x` and `y`, so for a
448 ``True`` result to be truly true, you should also check
449 :meth:`_is_commutative`. This method should of course always
450 return ``True``, unless this algebra was constructed with
451 ``check_axioms=False`` and passed an invalid multiplication table.
453 return all( (self
.monomial(i
)**2)*(self
.monomial(i
)*self
.monomial(j
))
455 (self
.monomial(i
))*((self
.monomial(i
)**2)*self
.monomial(j
))
456 for i
in range(self
.dimension())
457 for j
in range(self
.dimension()) )
459 def _jordan_product_is_associative(self
):
461 Return whether or not this algebra's Jordan product is
462 associative; that is, whether or not `x*(y*z) = (x*y)*z`
465 This method should agree with :meth:`is_associative` unless
466 you lied about the value of the ``associative`` parameter
467 when you constructed the algebra.
471 sage: from mjo.eja.eja_algebra import (random_eja,
472 ....: RealSymmetricEJA,
473 ....: ComplexHermitianEJA,
474 ....: QuaternionHermitianEJA)
478 sage: J = RealSymmetricEJA(4, orthonormalize=False)
479 sage: J._jordan_product_is_associative()
481 sage: x = sum(J.gens())
482 sage: A = x.subalgebra_generated_by()
483 sage: A._jordan_product_is_associative()
488 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
489 sage: J._jordan_product_is_associative()
491 sage: x = sum(J.gens())
492 sage: A = x.subalgebra_generated_by(orthonormalize=False)
493 sage: A._jordan_product_is_associative()
498 sage: J = QuaternionHermitianEJA(2)
499 sage: J._jordan_product_is_associative()
501 sage: x = sum(J.gens())
502 sage: A = x.subalgebra_generated_by()
503 sage: A._jordan_product_is_associative()
508 The values we've presupplied to the constructors agree with
511 sage: set_random_seed()
512 sage: J = random_eja()
513 sage: J.is_associative() == J._jordan_product_is_associative()
519 # Used to check whether or not something is zero.
522 # I don't know of any examples that make this magnitude
523 # necessary because I don't know how to make an
524 # associative algebra when the element subalgebra
525 # construction is unreliable (as it is over RDF; we can't
526 # find the degree of an element because we can't compute
527 # the rank of a matrix). But even multiplication of floats
528 # is non-associative, so *some* epsilon is needed... let's
529 # just take the one from _inner_product_is_associative?
532 for i
in range(self
.dimension()):
533 for j
in range(self
.dimension()):
534 for k
in range(self
.dimension()):
538 diff
= (x
*y
)*z
- x
*(y
*z
)
540 if diff
.norm() > epsilon
:
545 def _inner_product_is_associative(self
):
547 Return whether or not this algebra's inner product `B` is
548 associative; that is, whether or not `B(xy,z) = B(x,yz)`.
550 This method should of course always return ``True``, unless
551 this algebra was constructed with ``check_axioms=False`` and
552 passed an invalid Jordan or inner-product.
556 # Used to check whether or not something is zero.
559 # This choice is sufficient to allow the construction of
560 # QuaternionHermitianEJA(2, field=RDF) with check_axioms=True.
563 for i
in range(self
.dimension()):
564 for j
in range(self
.dimension()):
565 for k
in range(self
.dimension()):
569 diff
= (x
*y
).inner_product(z
) - x
.inner_product(y
*z
)
571 if diff
.abs() > epsilon
:
576 def _element_constructor_(self
, elt
):
578 Construct an element of this algebra from its vector or matrix
581 This gets called only after the parent element _call_ method
582 fails to find a coercion for the argument.
586 sage: from mjo.eja.eja_algebra import (random_eja,
589 ....: RealSymmetricEJA)
593 The identity in `S^n` is converted to the identity in the EJA::
595 sage: J = RealSymmetricEJA(3)
596 sage: I = matrix.identity(QQ,3)
597 sage: J(I) == J.one()
600 This skew-symmetric matrix can't be represented in the EJA::
602 sage: J = RealSymmetricEJA(3)
603 sage: A = matrix(QQ,3, lambda i,j: i-j)
605 Traceback (most recent call last):
607 ValueError: not an element of this algebra
609 Tuples work as well, provided that the matrix basis for the
610 algebra consists of them::
612 sage: J1 = HadamardEJA(3)
613 sage: J2 = RealSymmetricEJA(2)
614 sage: J = cartesian_product([J1,J2])
615 sage: J( (J1.matrix_basis()[1], J2.matrix_basis()[2]) )
620 Ensure that we can convert any element back and forth
621 faithfully between its matrix and algebra representations::
623 sage: set_random_seed()
624 sage: J = random_eja()
625 sage: x = J.random_element()
626 sage: J(x.to_matrix()) == x
629 We cannot coerce elements between algebras just because their
630 matrix representations are compatible::
632 sage: J1 = HadamardEJA(3)
633 sage: J2 = JordanSpinEJA(3)
635 Traceback (most recent call last):
637 ValueError: not an element of this algebra
639 Traceback (most recent call last):
641 ValueError: not an element of this algebra
643 msg
= "not an element of this algebra"
644 if elt
in self
.base_ring():
645 # Ensure that no base ring -> algebra coercion is performed
646 # by this method. There's some stupidity in sage that would
647 # otherwise propagate to this method; for example, sage thinks
648 # that the integer 3 belongs to the space of 2-by-2 matrices.
649 raise ValueError(msg
)
652 # Try to convert a vector into a column-matrix...
654 except (AttributeError, TypeError):
655 # and ignore failure, because we weren't really expecting
656 # a vector as an argument anyway.
659 if elt
not in self
.matrix_space():
660 raise ValueError(msg
)
662 # Thanks for nothing! Matrix spaces aren't vector spaces in
663 # Sage, so we have to figure out its matrix-basis coordinates
664 # ourselves. We use the basis space's ring instead of the
665 # element's ring because the basis space might be an algebraic
666 # closure whereas the base ring of the 3-by-3 identity matrix
667 # could be QQ instead of QQbar.
669 # And, we also have to handle Cartesian product bases (when
670 # the matrix basis consists of tuples) here. The "good news"
671 # is that we're already converting everything to long vectors,
672 # and that strategy works for tuples as well.
674 # We pass check=False because the matrix basis is "guaranteed"
675 # to be linearly independent... right? Ha ha.
677 V
= VectorSpace(self
.base_ring(), len(elt
))
678 W
= V
.span_of_basis( (V(_all2list(s
)) for s
in self
.matrix_basis()),
682 coords
= W
.coordinate_vector(V(elt
))
683 except ArithmeticError: # vector is not in free module
684 raise ValueError(msg
)
686 return self
.from_vector(coords
)
690 Return a string representation of ``self``.
694 sage: from mjo.eja.eja_algebra import JordanSpinEJA
698 Ensure that it says what we think it says::
700 sage: JordanSpinEJA(2, field=AA)
701 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
702 sage: JordanSpinEJA(3, field=RDF)
703 Euclidean Jordan algebra of dimension 3 over Real Double Field
706 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
707 return fmt
.format(self
.dimension(), self
.base_ring())
711 def characteristic_polynomial_of(self
):
713 Return the algebra's "characteristic polynomial of" function,
714 which is itself a multivariate polynomial that, when evaluated
715 at the coordinates of some algebra element, returns that
716 element's characteristic polynomial.
718 The resulting polynomial has `n+1` variables, where `n` is the
719 dimension of this algebra. The first `n` variables correspond to
720 the coordinates of an algebra element: when evaluated at the
721 coordinates of an algebra element with respect to a certain
722 basis, the result is a univariate polynomial (in the one
723 remaining variable ``t``), namely the characteristic polynomial
728 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
732 The characteristic polynomial in the spin algebra is given in
733 Alizadeh, Example 11.11::
735 sage: J = JordanSpinEJA(3)
736 sage: p = J.characteristic_polynomial_of(); p
737 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
738 sage: xvec = J.one().to_vector()
742 By definition, the characteristic polynomial is a monic
743 degree-zero polynomial in a rank-zero algebra. Note that
744 Cayley-Hamilton is indeed satisfied since the polynomial
745 ``1`` evaluates to the identity element of the algebra on
748 sage: J = TrivialEJA()
749 sage: J.characteristic_polynomial_of()
756 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_(r-1).
757 a
= self
._charpoly
_coefficients
()
759 # We go to a bit of trouble here to reorder the
760 # indeterminates, so that it's easier to evaluate the
761 # characteristic polynomial at x's coordinates and get back
762 # something in terms of t, which is what we want.
763 S
= PolynomialRing(self
.base_ring(),'t')
767 S
= PolynomialRing(S
, R
.variable_names())
770 return (t
**r
+ sum( a
[k
]*(t
**k
) for k
in range(r
) ))
772 def coordinate_polynomial_ring(self
):
774 The multivariate polynomial ring in which this algebra's
775 :meth:`characteristic_polynomial_of` lives.
779 sage: from mjo.eja.eja_algebra import (HadamardEJA,
780 ....: RealSymmetricEJA)
784 sage: J = HadamardEJA(2)
785 sage: J.coordinate_polynomial_ring()
786 Multivariate Polynomial Ring in X1, X2...
787 sage: J = RealSymmetricEJA(3,field=QQ,orthonormalize=False)
788 sage: J.coordinate_polynomial_ring()
789 Multivariate Polynomial Ring in X1, X2, X3, X4, X5, X6...
792 var_names
= tuple( "X%d" % z
for z
in range(1, self
.dimension()+1) )
793 return PolynomialRing(self
.base_ring(), var_names
)
795 def inner_product(self
, x
, y
):
797 The inner product associated with this Euclidean Jordan algebra.
799 Defaults to the trace inner product, but can be overridden by
800 subclasses if they are sure that the necessary properties are
805 sage: from mjo.eja.eja_algebra import (random_eja,
807 ....: BilinearFormEJA)
811 Our inner product is "associative," which means the following for
812 a symmetric bilinear form::
814 sage: set_random_seed()
815 sage: J = random_eja()
816 sage: x,y,z = J.random_elements(3)
817 sage: (x*y).inner_product(z) == y.inner_product(x*z)
822 Ensure that this is the usual inner product for the algebras
825 sage: set_random_seed()
826 sage: J = HadamardEJA.random_instance()
827 sage: x,y = J.random_elements(2)
828 sage: actual = x.inner_product(y)
829 sage: expected = x.to_vector().inner_product(y.to_vector())
830 sage: actual == expected
833 Ensure that this is one-half of the trace inner-product in a
834 BilinearFormEJA that isn't just the reals (when ``n`` isn't
835 one). This is in Faraut and Koranyi, and also my "On the
838 sage: set_random_seed()
839 sage: J = BilinearFormEJA.random_instance()
840 sage: n = J.dimension()
841 sage: x = J.random_element()
842 sage: y = J.random_element()
843 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
846 B
= self
._inner
_product
_matrix
847 return (B
*x
.to_vector()).inner_product(y
.to_vector())
850 def is_trivial(self
):
852 Return whether or not this algebra is trivial.
854 A trivial algebra contains only the zero element.
858 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
863 sage: J = ComplexHermitianEJA(3)
869 sage: J = TrivialEJA()
874 return self
.dimension() == 0
877 def multiplication_table(self
):
879 Return a visual representation of this algebra's multiplication
880 table (on basis elements).
884 sage: from mjo.eja.eja_algebra import JordanSpinEJA
888 sage: J = JordanSpinEJA(4)
889 sage: J.multiplication_table()
890 +----++----+----+----+----+
891 | * || b0 | b1 | b2 | b3 |
892 +====++====+====+====+====+
893 | b0 || b0 | b1 | b2 | b3 |
894 +----++----+----+----+----+
895 | b1 || b1 | b0 | 0 | 0 |
896 +----++----+----+----+----+
897 | b2 || b2 | 0 | b0 | 0 |
898 +----++----+----+----+----+
899 | b3 || b3 | 0 | 0 | b0 |
900 +----++----+----+----+----+
904 # Prepend the header row.
905 M
= [["*"] + list(self
.gens())]
907 # And to each subsequent row, prepend an entry that belongs to
908 # the left-side "header column."
909 M
+= [ [self
.monomial(i
)] + [ self
.monomial(i
)*self
.monomial(j
)
913 return table(M
, header_row
=True, header_column
=True, frame
=True)
916 def matrix_basis(self
):
918 Return an (often more natural) representation of this algebras
919 basis as an ordered tuple of matrices.
921 Every finite-dimensional Euclidean Jordan Algebra is a, up to
922 Jordan isomorphism, a direct sum of five simple
923 algebras---four of which comprise Hermitian matrices. And the
924 last type of algebra can of course be thought of as `n`-by-`1`
925 column matrices (ambiguusly called column vectors) to avoid
926 special cases. As a result, matrices (and column vectors) are
927 a natural representation format for Euclidean Jordan algebra
930 But, when we construct an algebra from a basis of matrices,
931 those matrix representations are lost in favor of coordinate
932 vectors *with respect to* that basis. We could eventually
933 convert back if we tried hard enough, but having the original
934 representations handy is valuable enough that we simply store
935 them and return them from this method.
937 Why implement this for non-matrix algebras? Avoiding special
938 cases for the :class:`BilinearFormEJA` pays with simplicity in
939 its own right. But mainly, we would like to be able to assume
940 that elements of a :class:`CartesianProductEJA` can be displayed
941 nicely, without having to have special classes for direct sums
942 one of whose components was a matrix algebra.
946 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
947 ....: RealSymmetricEJA)
951 sage: J = RealSymmetricEJA(2)
953 Finite family {0: b0, 1: b1, 2: b2}
954 sage: J.matrix_basis()
956 [1 0] [ 0 0.7071067811865475?] [0 0]
957 [0 0], [0.7071067811865475? 0], [0 1]
962 sage: J = JordanSpinEJA(2)
964 Finite family {0: b0, 1: b1}
965 sage: J.matrix_basis()
971 return self
._matrix
_basis
974 def matrix_space(self
):
976 Return the matrix space in which this algebra's elements live, if
977 we think of them as matrices (including column vectors of the
980 "By default" this will be an `n`-by-`1` column-matrix space,
981 except when the algebra is trivial. There it's `n`-by-`n`
982 (where `n` is zero), to ensure that two elements of the matrix
983 space (empty matrices) can be multiplied. For algebras of
984 matrices, this returns the space in which their
985 real embeddings live.
989 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
991 ....: QuaternionHermitianEJA,
996 By default, the matrix representation is just a column-matrix
997 equivalent to the vector representation::
999 sage: J = JordanSpinEJA(3)
1000 sage: J.matrix_space()
1001 Full MatrixSpace of 3 by 1 dense matrices over Algebraic
1004 The matrix representation in the trivial algebra is
1005 zero-by-zero instead of the usual `n`-by-one::
1007 sage: J = TrivialEJA()
1008 sage: J.matrix_space()
1009 Full MatrixSpace of 0 by 0 dense matrices over Algebraic
1012 The matrix space for complex/quaternion Hermitian matrix EJA
1013 is the space in which their real-embeddings live, not the
1014 original complex/quaternion matrix space::
1016 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1017 sage: J.matrix_space()
1018 Full MatrixSpace of 4 by 4 dense matrices over Rational Field
1019 sage: J = QuaternionHermitianEJA(1,field=QQ,orthonormalize=False)
1020 sage: J.matrix_space()
1021 Full MatrixSpace of 4 by 4 dense matrices over Rational Field
1024 if self
.is_trivial():
1025 return MatrixSpace(self
.base_ring(), 0)
1027 return self
.matrix_basis()[0].parent()
1033 Return the unit element of this algebra.
1037 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1042 We can compute unit element in the Hadamard EJA::
1044 sage: J = HadamardEJA(5)
1046 b0 + b1 + b2 + b3 + b4
1048 The unit element in the Hadamard EJA is inherited in the
1049 subalgebras generated by its elements::
1051 sage: J = HadamardEJA(5)
1053 b0 + b1 + b2 + b3 + b4
1054 sage: x = sum(J.gens())
1055 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1058 sage: A.one().superalgebra_element()
1059 b0 + b1 + b2 + b3 + b4
1063 The identity element acts like the identity, regardless of
1064 whether or not we orthonormalize::
1066 sage: set_random_seed()
1067 sage: J = random_eja()
1068 sage: x = J.random_element()
1069 sage: J.one()*x == x and x*J.one() == x
1071 sage: A = x.subalgebra_generated_by()
1072 sage: y = A.random_element()
1073 sage: A.one()*y == y and y*A.one() == y
1078 sage: set_random_seed()
1079 sage: J = random_eja(field=QQ, orthonormalize=False)
1080 sage: x = J.random_element()
1081 sage: J.one()*x == x and x*J.one() == x
1083 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1084 sage: y = A.random_element()
1085 sage: A.one()*y == y and y*A.one() == y
1088 The matrix of the unit element's operator is the identity,
1089 regardless of the base field and whether or not we
1092 sage: set_random_seed()
1093 sage: J = random_eja()
1094 sage: actual = J.one().operator().matrix()
1095 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1096 sage: actual == expected
1098 sage: x = J.random_element()
1099 sage: A = x.subalgebra_generated_by()
1100 sage: actual = A.one().operator().matrix()
1101 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1102 sage: actual == expected
1107 sage: set_random_seed()
1108 sage: J = random_eja(field=QQ, orthonormalize=False)
1109 sage: actual = J.one().operator().matrix()
1110 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1111 sage: actual == expected
1113 sage: x = J.random_element()
1114 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1115 sage: actual = A.one().operator().matrix()
1116 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1117 sage: actual == expected
1120 Ensure that the cached unit element (often precomputed by
1121 hand) agrees with the computed one::
1123 sage: set_random_seed()
1124 sage: J = random_eja()
1125 sage: cached = J.one()
1126 sage: J.one.clear_cache()
1127 sage: J.one() == cached
1132 sage: set_random_seed()
1133 sage: J = random_eja(field=QQ, orthonormalize=False)
1134 sage: cached = J.one()
1135 sage: J.one.clear_cache()
1136 sage: J.one() == cached
1140 # We can brute-force compute the matrices of the operators
1141 # that correspond to the basis elements of this algebra.
1142 # If some linear combination of those basis elements is the
1143 # algebra identity, then the same linear combination of
1144 # their matrices has to be the identity matrix.
1146 # Of course, matrices aren't vectors in sage, so we have to
1147 # appeal to the "long vectors" isometry.
1148 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
1150 # Now we use basic linear algebra to find the coefficients,
1151 # of the matrices-as-vectors-linear-combination, which should
1152 # work for the original algebra basis too.
1153 A
= matrix(self
.base_ring(), oper_vecs
)
1155 # We used the isometry on the left-hand side already, but we
1156 # still need to do it for the right-hand side. Recall that we
1157 # wanted something that summed to the identity matrix.
1158 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
1160 # Now if there's an identity element in the algebra, this
1161 # should work. We solve on the left to avoid having to
1162 # transpose the matrix "A".
1163 return self
.from_vector(A
.solve_left(b
))
1166 def peirce_decomposition(self
, c
):
1168 The Peirce decomposition of this algebra relative to the
1171 In the future, this can be extended to a complete system of
1172 orthogonal idempotents.
1176 - ``c`` -- an idempotent of this algebra.
1180 A triple (J0, J5, J1) containing two subalgebras and one subspace
1183 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
1184 corresponding to the eigenvalue zero.
1186 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
1187 corresponding to the eigenvalue one-half.
1189 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
1190 corresponding to the eigenvalue one.
1192 These are the only possible eigenspaces for that operator, and this
1193 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
1194 orthogonal, and are subalgebras of this algebra with the appropriate
1199 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
1203 The canonical example comes from the symmetric matrices, which
1204 decompose into diagonal and off-diagonal parts::
1206 sage: J = RealSymmetricEJA(3)
1207 sage: C = matrix(QQ, [ [1,0,0],
1211 sage: J0,J5,J1 = J.peirce_decomposition(c)
1213 Euclidean Jordan algebra of dimension 1...
1215 Vector space of degree 6 and dimension 2...
1217 Euclidean Jordan algebra of dimension 3...
1218 sage: J0.one().to_matrix()
1222 sage: orig_df = AA.options.display_format
1223 sage: AA.options.display_format = 'radical'
1224 sage: J.from_vector(J5.basis()[0]).to_matrix()
1228 sage: J.from_vector(J5.basis()[1]).to_matrix()
1232 sage: AA.options.display_format = orig_df
1233 sage: J1.one().to_matrix()
1240 Every algebra decomposes trivially with respect to its identity
1243 sage: set_random_seed()
1244 sage: J = random_eja()
1245 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
1246 sage: J0.dimension() == 0 and J5.dimension() == 0
1248 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
1251 The decomposition is into eigenspaces, and its components are
1252 therefore necessarily orthogonal. Moreover, the identity
1253 elements in the two subalgebras are the projections onto their
1254 respective subspaces of the superalgebra's identity element::
1256 sage: set_random_seed()
1257 sage: J = random_eja()
1258 sage: x = J.random_element()
1259 sage: if not J.is_trivial():
1260 ....: while x.is_nilpotent():
1261 ....: x = J.random_element()
1262 sage: c = x.subalgebra_idempotent()
1263 sage: J0,J5,J1 = J.peirce_decomposition(c)
1265 sage: for (w,y,z) in zip(J0.basis(), J5.basis(), J1.basis()):
1266 ....: w = w.superalgebra_element()
1267 ....: y = J.from_vector(y)
1268 ....: z = z.superalgebra_element()
1269 ....: ipsum += w.inner_product(y).abs()
1270 ....: ipsum += w.inner_product(z).abs()
1271 ....: ipsum += y.inner_product(z).abs()
1274 sage: J1(c) == J1.one()
1276 sage: J0(J.one() - c) == J0.one()
1280 if not c
.is_idempotent():
1281 raise ValueError("element is not idempotent: %s" % c
)
1283 # Default these to what they should be if they turn out to be
1284 # trivial, because eigenspaces_left() won't return eigenvalues
1285 # corresponding to trivial spaces (e.g. it returns only the
1286 # eigenspace corresponding to lambda=1 if you take the
1287 # decomposition relative to the identity element).
1288 trivial
= self
.subalgebra(())
1289 J0
= trivial
# eigenvalue zero
1290 J5
= VectorSpace(self
.base_ring(), 0) # eigenvalue one-half
1291 J1
= trivial
# eigenvalue one
1293 for (eigval
, eigspace
) in c
.operator().matrix().right_eigenspaces():
1294 if eigval
== ~
(self
.base_ring()(2)):
1297 gens
= tuple( self
.from_vector(b
) for b
in eigspace
.basis() )
1298 subalg
= self
.subalgebra(gens
, check_axioms
=False)
1304 raise ValueError("unexpected eigenvalue: %s" % eigval
)
1309 def random_element(self
, thorough
=False):
1311 Return a random element of this algebra.
1313 Our algebra superclass method only returns a linear
1314 combination of at most two basis elements. We instead
1315 want the vector space "random element" method that
1316 returns a more diverse selection.
1320 - ``thorough`` -- (boolean; default False) whether or not we
1321 should generate irrational coefficients for the random
1322 element when our base ring is irrational; this slows the
1323 algebra operations to a crawl, but any truly random method
1327 # For a general base ring... maybe we can trust this to do the
1328 # right thing? Unlikely, but.
1329 V
= self
.vector_space()
1330 v
= V
.random_element()
1332 if self
.base_ring() is AA
:
1333 # The "random element" method of the algebraic reals is
1334 # stupid at the moment, and only returns integers between
1335 # -2 and 2, inclusive:
1337 # https://trac.sagemath.org/ticket/30875
1339 # Instead, we implement our own "random vector" method,
1340 # and then coerce that into the algebra. We use the vector
1341 # space degree here instead of the dimension because a
1342 # subalgebra could (for example) be spanned by only two
1343 # vectors, each with five coordinates. We need to
1344 # generate all five coordinates.
1346 v
*= QQbar
.random_element().real()
1348 v
*= QQ
.random_element()
1350 return self
.from_vector(V
.coordinate_vector(v
))
1352 def random_elements(self
, count
, thorough
=False):
1354 Return ``count`` random elements as a tuple.
1358 - ``thorough`` -- (boolean; default False) whether or not we
1359 should generate irrational coefficients for the random
1360 elements when our base ring is irrational; this slows the
1361 algebra operations to a crawl, but any truly random method
1366 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1370 sage: J = JordanSpinEJA(3)
1371 sage: x,y,z = J.random_elements(3)
1372 sage: all( [ x in J, y in J, z in J ])
1374 sage: len( J.random_elements(10) ) == 10
1378 return tuple( self
.random_element(thorough
)
1379 for idx
in range(count
) )
1383 def _charpoly_coefficients(self
):
1385 The `r` polynomial coefficients of the "characteristic polynomial
1390 sage: from mjo.eja.eja_algebra import random_eja
1394 The theory shows that these are all homogeneous polynomials of
1397 sage: set_random_seed()
1398 sage: J = random_eja()
1399 sage: all(p.is_homogeneous() for p in J._charpoly_coefficients())
1403 n
= self
.dimension()
1404 R
= self
.coordinate_polynomial_ring()
1406 F
= R
.fraction_field()
1409 # From a result in my book, these are the entries of the
1410 # basis representation of L_x.
1411 return sum( vars[k
]*self
.monomial(k
).operator().matrix()[i
,j
]
1414 L_x
= matrix(F
, n
, n
, L_x_i_j
)
1417 if self
.rank
.is_in_cache():
1419 # There's no need to pad the system with redundant
1420 # columns if we *know* they'll be redundant.
1423 # Compute an extra power in case the rank is equal to
1424 # the dimension (otherwise, we would stop at x^(r-1)).
1425 x_powers
= [ (L_x
**k
)*self
.one().to_vector()
1426 for k
in range(n
+1) ]
1427 A
= matrix
.column(F
, x_powers
[:n
])
1428 AE
= A
.extended_echelon_form()
1435 # The theory says that only the first "r" coefficients are
1436 # nonzero, and they actually live in the original polynomial
1437 # ring and not the fraction field. We negate them because in
1438 # the actual characteristic polynomial, they get moved to the
1439 # other side where x^r lives. We don't bother to trim A_rref
1440 # down to a square matrix and solve the resulting system,
1441 # because the upper-left r-by-r portion of A_rref is
1442 # guaranteed to be the identity matrix, so e.g.
1444 # A_rref.solve_right(Y)
1446 # would just be returning Y.
1447 return (-E
*b
)[:r
].change_ring(R
)
1452 Return the rank of this EJA.
1454 This is a cached method because we know the rank a priori for
1455 all of the algebras we can construct. Thus we can avoid the
1456 expensive ``_charpoly_coefficients()`` call unless we truly
1457 need to compute the whole characteristic polynomial.
1461 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1462 ....: JordanSpinEJA,
1463 ....: RealSymmetricEJA,
1464 ....: ComplexHermitianEJA,
1465 ....: QuaternionHermitianEJA,
1470 The rank of the Jordan spin algebra is always two::
1472 sage: JordanSpinEJA(2).rank()
1474 sage: JordanSpinEJA(3).rank()
1476 sage: JordanSpinEJA(4).rank()
1479 The rank of the `n`-by-`n` Hermitian real, complex, or
1480 quaternion matrices is `n`::
1482 sage: RealSymmetricEJA(4).rank()
1484 sage: ComplexHermitianEJA(3).rank()
1486 sage: QuaternionHermitianEJA(2).rank()
1491 Ensure that every EJA that we know how to construct has a
1492 positive integer rank, unless the algebra is trivial in
1493 which case its rank will be zero::
1495 sage: set_random_seed()
1496 sage: J = random_eja()
1500 sage: r > 0 or (r == 0 and J.is_trivial())
1503 Ensure that computing the rank actually works, since the ranks
1504 of all simple algebras are known and will be cached by default::
1506 sage: set_random_seed() # long time
1507 sage: J = random_eja() # long time
1508 sage: cached = J.rank() # long time
1509 sage: J.rank.clear_cache() # long time
1510 sage: J.rank() == cached # long time
1514 return len(self
._charpoly
_coefficients
())
1517 def subalgebra(self
, basis
, **kwargs
):
1519 Create a subalgebra of this algebra from the given basis.
1521 from mjo
.eja
.eja_subalgebra
import FiniteDimensionalEJASubalgebra
1522 return FiniteDimensionalEJASubalgebra(self
, basis
, **kwargs
)
1525 def vector_space(self
):
1527 Return the vector space that underlies this algebra.
1531 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1535 sage: J = RealSymmetricEJA(2)
1536 sage: J.vector_space()
1537 Vector space of dimension 3 over...
1540 return self
.zero().to_vector().parent().ambient_vector_space()
1544 class RationalBasisEJA(FiniteDimensionalEJA
):
1546 New class for algebras whose supplied basis elements have all rational entries.
1550 sage: from mjo.eja.eja_algebra import BilinearFormEJA
1554 The supplied basis is orthonormalized by default::
1556 sage: B = matrix(QQ, [[1, 0, 0], [0, 25, -32], [0, -32, 41]])
1557 sage: J = BilinearFormEJA(B)
1558 sage: J.matrix_basis()
1575 # Abuse the check_field parameter to check that the entries of
1576 # out basis (in ambient coordinates) are in the field QQ.
1577 if not all( all(b_i
in QQ
for b_i
in b
.list()) for b
in basis
):
1578 raise TypeError("basis not rational")
1580 super().__init
__(basis
,
1584 check_field
=check_field
,
1587 self
._rational
_algebra
= None
1589 # There's no point in constructing the extra algebra if this
1590 # one is already rational.
1592 # Note: the same Jordan and inner-products work here,
1593 # because they are necessarily defined with respect to
1594 # ambient coordinates and not any particular basis.
1595 self
._rational
_algebra
= FiniteDimensionalEJA(
1600 associative
=self
.is_associative(),
1601 orthonormalize
=False,
1606 def _charpoly_coefficients(self
):
1610 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1611 ....: JordanSpinEJA)
1615 The base ring of the resulting polynomial coefficients is what
1616 it should be, and not the rationals (unless the algebra was
1617 already over the rationals)::
1619 sage: J = JordanSpinEJA(3)
1620 sage: J._charpoly_coefficients()
1621 (X1^2 - X2^2 - X3^2, -2*X1)
1622 sage: a0 = J._charpoly_coefficients()[0]
1624 Algebraic Real Field
1625 sage: a0.base_ring()
1626 Algebraic Real Field
1629 if self
._rational
_algebra
is None:
1630 # There's no need to construct *another* algebra over the
1631 # rationals if this one is already over the
1632 # rationals. Likewise, if we never orthonormalized our
1633 # basis, we might as well just use the given one.
1634 return super()._charpoly
_coefficients
()
1636 # Do the computation over the rationals. The answer will be
1637 # the same, because all we've done is a change of basis.
1638 # Then, change back from QQ to our real base ring
1639 a
= ( a_i
.change_ring(self
.base_ring())
1640 for a_i
in self
._rational
_algebra
._charpoly
_coefficients
() )
1642 if self
._deortho
_matrix
is None:
1643 # This can happen if our base ring was, say, AA and we
1644 # chose not to (or didn't need to) orthonormalize. It's
1645 # still faster to do the computations over QQ even if
1646 # the numbers in the boxes stay the same.
1649 # Otherwise, convert the coordinate variables back to the
1650 # deorthonormalized ones.
1651 R
= self
.coordinate_polynomial_ring()
1652 from sage
.modules
.free_module_element
import vector
1653 X
= vector(R
, R
.gens())
1654 BX
= self
._deortho
_matrix
*X
1656 subs_dict
= { X[i]: BX[i] for i in range(len(X)) }
1657 return tuple( a_i
.subs(subs_dict
) for a_i
in a
)
1659 class ConcreteEJA(RationalBasisEJA
):
1661 A class for the Euclidean Jordan algebras that we know by name.
1663 These are the Jordan algebras whose basis, multiplication table,
1664 rank, and so on are known a priori. More to the point, they are
1665 the Euclidean Jordan algebras for which we are able to conjure up
1666 a "random instance."
1670 sage: from mjo.eja.eja_algebra import ConcreteEJA
1674 Our basis is normalized with respect to the algebra's inner
1675 product, unless we specify otherwise::
1677 sage: set_random_seed()
1678 sage: J = ConcreteEJA.random_instance()
1679 sage: all( b.norm() == 1 for b in J.gens() )
1682 Since our basis is orthonormal with respect to the algebra's inner
1683 product, and since we know that this algebra is an EJA, any
1684 left-multiplication operator's matrix will be symmetric because
1685 natural->EJA basis representation is an isometry and within the
1686 EJA the operator is self-adjoint by the Jordan axiom::
1688 sage: set_random_seed()
1689 sage: J = ConcreteEJA.random_instance()
1690 sage: x = J.random_element()
1691 sage: x.operator().is_self_adjoint()
1696 def _max_random_instance_size():
1698 Return an integer "size" that is an upper bound on the size of
1699 this algebra when it is used in a random test
1700 case. Unfortunately, the term "size" is ambiguous -- when
1701 dealing with `R^n` under either the Hadamard or Jordan spin
1702 product, the "size" refers to the dimension `n`. When dealing
1703 with a matrix algebra (real symmetric or complex/quaternion
1704 Hermitian), it refers to the size of the matrix, which is far
1705 less than the dimension of the underlying vector space.
1707 This method must be implemented in each subclass.
1709 raise NotImplementedError
1712 def random_instance(cls
, *args
, **kwargs
):
1714 Return a random instance of this type of algebra.
1716 This method should be implemented in each subclass.
1718 from sage
.misc
.prandom
import choice
1719 eja_class
= choice(cls
.__subclasses
__())
1721 # These all bubble up to the RationalBasisEJA superclass
1722 # constructor, so any (kw)args valid there are also valid
1724 return eja_class
.random_instance(*args
, **kwargs
)
1729 def dimension_over_reals():
1731 The dimension of this matrix's base ring over the reals.
1733 The reals are dimension one over themselves, obviously; that's
1734 just `\mathbb{R}^{1}`. Likewise, the complex numbers `a + bi`
1735 have dimension two. Finally, the quaternions have dimension
1736 four over the reals.
1738 This is used to determine the size of the matrix returned from
1739 :meth:`real_embed`, among other things.
1741 raise NotImplementedError
1744 def real_embed(cls
,M
):
1746 Embed the matrix ``M`` into a space of real matrices.
1748 The matrix ``M`` can have entries in any field at the moment:
1749 the real numbers, complex numbers, or quaternions. And although
1750 they are not a field, we can probably support octonions at some
1751 point, too. This function returns a real matrix that "acts like"
1752 the original with respect to matrix multiplication; i.e.
1754 real_embed(M*N) = real_embed(M)*real_embed(N)
1757 if M
.ncols() != M
.nrows():
1758 raise ValueError("the matrix 'M' must be square")
1763 def real_unembed(cls
,M
):
1765 The inverse of :meth:`real_embed`.
1767 if M
.ncols() != M
.nrows():
1768 raise ValueError("the matrix 'M' must be square")
1769 if not ZZ(M
.nrows()).mod(cls
.dimension_over_reals()).is_zero():
1770 raise ValueError("the matrix 'M' must be a real embedding")
1774 def jordan_product(X
,Y
):
1775 return (X
*Y
+ Y
*X
)/2
1778 def trace_inner_product(cls
,X
,Y
):
1780 Compute the trace inner-product of two real-embeddings.
1784 sage: from mjo.eja.eja_algebra import (RealSymmetricEJA,
1785 ....: ComplexHermitianEJA,
1786 ....: QuaternionHermitianEJA)
1790 This gives the same answer as it would if we computed the trace
1791 from the unembedded (original) matrices::
1793 sage: set_random_seed()
1794 sage: J = RealSymmetricEJA.random_instance()
1795 sage: x,y = J.random_elements(2)
1796 sage: Xe = x.to_matrix()
1797 sage: Ye = y.to_matrix()
1798 sage: X = J.real_unembed(Xe)
1799 sage: Y = J.real_unembed(Ye)
1800 sage: expected = (X*Y).trace()
1801 sage: actual = J.trace_inner_product(Xe,Ye)
1802 sage: actual == expected
1807 sage: set_random_seed()
1808 sage: J = ComplexHermitianEJA.random_instance()
1809 sage: x,y = J.random_elements(2)
1810 sage: Xe = x.to_matrix()
1811 sage: Ye = y.to_matrix()
1812 sage: X = J.real_unembed(Xe)
1813 sage: Y = J.real_unembed(Ye)
1814 sage: expected = (X*Y).trace().real()
1815 sage: actual = J.trace_inner_product(Xe,Ye)
1816 sage: actual == expected
1821 sage: set_random_seed()
1822 sage: J = QuaternionHermitianEJA.random_instance()
1823 sage: x,y = J.random_elements(2)
1824 sage: Xe = x.to_matrix()
1825 sage: Ye = y.to_matrix()
1826 sage: X = J.real_unembed(Xe)
1827 sage: Y = J.real_unembed(Ye)
1828 sage: expected = (X*Y).trace().coefficient_tuple()[0]
1829 sage: actual = J.trace_inner_product(Xe,Ye)
1830 sage: actual == expected
1834 # This does in fact compute the real part of the trace.
1835 # If we compute the trace of e.g. a complex matrix M,
1836 # then we do so by adding up its diagonal entries --
1837 # call them z_1 through z_n. The real embedding of z_1
1838 # will be a 2-by-2 REAL matrix [a, b; -b, a] whose trace
1839 # as a REAL matrix will be 2*a = 2*Re(z_1). And so forth.
1840 return (X
*Y
).trace()/cls
.dimension_over_reals()
1843 class RealMatrixEJA(MatrixEJA
):
1845 def dimension_over_reals():
1849 class RealSymmetricEJA(ConcreteEJA
, RealMatrixEJA
):
1851 The rank-n simple EJA consisting of real symmetric n-by-n
1852 matrices, the usual symmetric Jordan product, and the trace inner
1853 product. It has dimension `(n^2 + n)/2` over the reals.
1857 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1861 sage: J = RealSymmetricEJA(2)
1862 sage: b0, b1, b2 = J.gens()
1870 In theory, our "field" can be any subfield of the reals::
1872 sage: RealSymmetricEJA(2, field=RDF, check_axioms=True)
1873 Euclidean Jordan algebra of dimension 3 over Real Double Field
1874 sage: RealSymmetricEJA(2, field=RR, check_axioms=True)
1875 Euclidean Jordan algebra of dimension 3 over Real Field with
1876 53 bits of precision
1880 The dimension of this algebra is `(n^2 + n) / 2`::
1882 sage: set_random_seed()
1883 sage: n_max = RealSymmetricEJA._max_random_instance_size()
1884 sage: n = ZZ.random_element(1, n_max)
1885 sage: J = RealSymmetricEJA(n)
1886 sage: J.dimension() == (n^2 + n)/2
1889 The Jordan multiplication is what we think it is::
1891 sage: set_random_seed()
1892 sage: J = RealSymmetricEJA.random_instance()
1893 sage: x,y = J.random_elements(2)
1894 sage: actual = (x*y).to_matrix()
1895 sage: X = x.to_matrix()
1896 sage: Y = y.to_matrix()
1897 sage: expected = (X*Y + Y*X)/2
1898 sage: actual == expected
1900 sage: J(expected) == x*y
1903 We can change the generator prefix::
1905 sage: RealSymmetricEJA(3, prefix='q').gens()
1906 (q0, q1, q2, q3, q4, q5)
1908 We can construct the (trivial) algebra of rank zero::
1910 sage: RealSymmetricEJA(0)
1911 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
1915 def _denormalized_basis(cls
, n
, field
):
1917 Return a basis for the space of real symmetric n-by-n matrices.
1921 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1925 sage: set_random_seed()
1926 sage: n = ZZ.random_element(1,5)
1927 sage: B = RealSymmetricEJA._denormalized_basis(n,ZZ)
1928 sage: all( M.is_symmetric() for M in B)
1932 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
1936 for j
in range(i
+1):
1937 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
1941 Sij
= Eij
+ Eij
.transpose()
1947 def _max_random_instance_size():
1948 return 4 # Dimension 10
1951 def random_instance(cls
, **kwargs
):
1953 Return a random instance of this type of algebra.
1955 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
1956 return cls(n
, **kwargs
)
1958 def __init__(self
, n
, field
=AA
, **kwargs
):
1959 # We know this is a valid EJA, but will double-check
1960 # if the user passes check_axioms=True.
1961 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
1967 super().__init
__(self
._denormalized
_basis
(n
,field
),
1968 self
.jordan_product
,
1969 self
.trace_inner_product
,
1971 associative
=associative
,
1974 # TODO: this could be factored out somehow, but is left here
1975 # because the MatrixEJA is not presently a subclass of the
1976 # FDEJA class that defines rank() and one().
1977 self
.rank
.set_cache(n
)
1978 idV
= matrix
.identity(ZZ
, self
.dimension_over_reals()*n
)
1979 self
.one
.set_cache(self(idV
))
1983 class ComplexMatrixEJA(MatrixEJA
):
1984 # A manual dictionary-cache for the complex_extension() method,
1985 # since apparently @classmethods can't also be @cached_methods.
1986 _complex_extension
= {}
1989 def complex_extension(cls
,field
):
1991 The complex field that we embed/unembed, as an extension
1992 of the given ``field``.
1994 if field
in cls
._complex
_extension
:
1995 return cls
._complex
_extension
[field
]
1997 # Sage doesn't know how to adjoin the complex "i" (the root of
1998 # x^2 + 1) to a field in a general way. Here, we just enumerate
1999 # all of the cases that I have cared to support so far.
2001 # Sage doesn't know how to embed AA into QQbar, i.e. how
2002 # to adjoin sqrt(-1) to AA.
2004 elif not field
.is_exact():
2006 F
= field
.complex_field()
2008 # Works for QQ and... maybe some other fields.
2009 R
= PolynomialRing(field
, 'z')
2011 F
= field
.extension(z
**2 + 1, 'I', embedding
=CLF(-1).sqrt())
2013 cls
._complex
_extension
[field
] = F
2017 def dimension_over_reals():
2021 def real_embed(cls
,M
):
2023 Embed the n-by-n complex matrix ``M`` into the space of real
2024 matrices of size 2n-by-2n via the map the sends each entry `z = a +
2025 bi` to the block matrix ``[[a,b],[-b,a]]``.
2029 sage: from mjo.eja.eja_algebra import ComplexMatrixEJA
2033 sage: F = QuadraticField(-1, 'I')
2034 sage: x1 = F(4 - 2*i)
2035 sage: x2 = F(1 + 2*i)
2038 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
2039 sage: ComplexMatrixEJA.real_embed(M)
2048 Embedding is a homomorphism (isomorphism, in fact)::
2050 sage: set_random_seed()
2051 sage: n = ZZ.random_element(3)
2052 sage: F = QuadraticField(-1, 'I')
2053 sage: X = random_matrix(F, n)
2054 sage: Y = random_matrix(F, n)
2055 sage: Xe = ComplexMatrixEJA.real_embed(X)
2056 sage: Ye = ComplexMatrixEJA.real_embed(Y)
2057 sage: XYe = ComplexMatrixEJA.real_embed(X*Y)
2062 super().real_embed(M
)
2065 # We don't need any adjoined elements...
2066 field
= M
.base_ring().base_ring()
2072 blocks
.append(matrix(field
, 2, [ [ a
, b
],
2075 return matrix
.block(field
, n
, blocks
)
2079 def real_unembed(cls
,M
):
2081 The inverse of _embed_complex_matrix().
2085 sage: from mjo.eja.eja_algebra import ComplexMatrixEJA
2089 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
2090 ....: [-2, 1, -4, 3],
2091 ....: [ 9, 10, 11, 12],
2092 ....: [-10, 9, -12, 11] ])
2093 sage: ComplexMatrixEJA.real_unembed(A)
2095 [ 10*I + 9 12*I + 11]
2099 Unembedding is the inverse of embedding::
2101 sage: set_random_seed()
2102 sage: F = QuadraticField(-1, 'I')
2103 sage: M = random_matrix(F, 3)
2104 sage: Me = ComplexMatrixEJA.real_embed(M)
2105 sage: ComplexMatrixEJA.real_unembed(Me) == M
2109 super().real_unembed(M
)
2111 d
= cls
.dimension_over_reals()
2112 F
= cls
.complex_extension(M
.base_ring())
2115 # Go top-left to bottom-right (reading order), converting every
2116 # 2-by-2 block we see to a single complex element.
2118 for k
in range(n
/d
):
2119 for j
in range(n
/d
):
2120 submat
= M
[d
*k
:d
*k
+d
,d
*j
:d
*j
+d
]
2121 if submat
[0,0] != submat
[1,1]:
2122 raise ValueError('bad on-diagonal submatrix')
2123 if submat
[0,1] != -submat
[1,0]:
2124 raise ValueError('bad off-diagonal submatrix')
2125 z
= submat
[0,0] + submat
[0,1]*i
2128 return matrix(F
, n
/d
, elements
)
2131 class ComplexHermitianEJA(ConcreteEJA
, ComplexMatrixEJA
):
2133 The rank-n simple EJA consisting of complex Hermitian n-by-n
2134 matrices over the real numbers, the usual symmetric Jordan product,
2135 and the real-part-of-trace inner product. It has dimension `n^2` over
2140 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
2144 In theory, our "field" can be any subfield of the reals::
2146 sage: ComplexHermitianEJA(2, field=RDF, check_axioms=True)
2147 Euclidean Jordan algebra of dimension 4 over Real Double Field
2148 sage: ComplexHermitianEJA(2, field=RR, check_axioms=True)
2149 Euclidean Jordan algebra of dimension 4 over Real Field with
2150 53 bits of precision
2154 The dimension of this algebra is `n^2`::
2156 sage: set_random_seed()
2157 sage: n_max = ComplexHermitianEJA._max_random_instance_size()
2158 sage: n = ZZ.random_element(1, n_max)
2159 sage: J = ComplexHermitianEJA(n)
2160 sage: J.dimension() == n^2
2163 The Jordan multiplication is what we think it is::
2165 sage: set_random_seed()
2166 sage: J = ComplexHermitianEJA.random_instance()
2167 sage: x,y = J.random_elements(2)
2168 sage: actual = (x*y).to_matrix()
2169 sage: X = x.to_matrix()
2170 sage: Y = y.to_matrix()
2171 sage: expected = (X*Y + Y*X)/2
2172 sage: actual == expected
2174 sage: J(expected) == x*y
2177 We can change the generator prefix::
2179 sage: ComplexHermitianEJA(2, prefix='z').gens()
2182 We can construct the (trivial) algebra of rank zero::
2184 sage: ComplexHermitianEJA(0)
2185 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2190 def _denormalized_basis(cls
, n
, field
):
2192 Returns a basis for the space of complex Hermitian n-by-n matrices.
2194 Why do we embed these? Basically, because all of numerical linear
2195 algebra assumes that you're working with vectors consisting of `n`
2196 entries from a field and scalars from the same field. There's no way
2197 to tell SageMath that (for example) the vectors contain complex
2198 numbers, while the scalar field is real.
2202 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
2206 sage: set_random_seed()
2207 sage: n = ZZ.random_element(1,5)
2208 sage: B = ComplexHermitianEJA._denormalized_basis(n,ZZ)
2209 sage: all( M.is_symmetric() for M in B)
2213 R
= PolynomialRing(ZZ
, 'z')
2215 F
= ZZ
.extension(z
**2 + 1, 'I')
2218 # This is like the symmetric case, but we need to be careful:
2220 # * We want conjugate-symmetry, not just symmetry.
2221 # * The diagonal will (as a result) be real.
2224 Eij
= matrix
.zero(F
,n
)
2226 for j
in range(i
+1):
2230 Sij
= cls
.real_embed(Eij
)
2233 # The second one has a minus because it's conjugated.
2234 Eij
[j
,i
] = 1 # Eij = Eij + Eij.transpose()
2235 Sij_real
= cls
.real_embed(Eij
)
2237 # Eij = I*Eij - I*Eij.transpose()
2240 Sij_imag
= cls
.real_embed(Eij
)
2246 # Since we embedded the entries, we can drop back to the
2247 # desired real "field" instead of the extension "F".
2248 return tuple( s
.change_ring(field
) for s
in S
)
2251 def __init__(self
, n
, field
=AA
, **kwargs
):
2252 # We know this is a valid EJA, but will double-check
2253 # if the user passes check_axioms=True.
2254 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2260 super().__init
__(self
._denormalized
_basis
(n
,field
),
2261 self
.jordan_product
,
2262 self
.trace_inner_product
,
2264 associative
=associative
,
2266 # TODO: this could be factored out somehow, but is left here
2267 # because the MatrixEJA is not presently a subclass of the
2268 # FDEJA class that defines rank() and one().
2269 self
.rank
.set_cache(n
)
2270 idV
= matrix
.identity(ZZ
, self
.dimension_over_reals()*n
)
2271 self
.one
.set_cache(self(idV
))
2274 def _max_random_instance_size():
2275 return 3 # Dimension 9
2278 def random_instance(cls
, **kwargs
):
2280 Return a random instance of this type of algebra.
2282 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2283 return cls(n
, **kwargs
)
2285 class QuaternionMatrixEJA(MatrixEJA
):
2287 # A manual dictionary-cache for the quaternion_extension() method,
2288 # since apparently @classmethods can't also be @cached_methods.
2289 _quaternion_extension
= {}
2292 def quaternion_extension(cls
,field
):
2294 The quaternion field that we embed/unembed, as an extension
2295 of the given ``field``.
2297 if field
in cls
._quaternion
_extension
:
2298 return cls
._quaternion
_extension
[field
]
2300 Q
= QuaternionAlgebra(field
,-1,-1)
2302 cls
._quaternion
_extension
[field
] = Q
2306 def dimension_over_reals():
2310 def real_embed(cls
,M
):
2312 Embed the n-by-n quaternion matrix ``M`` into the space of real
2313 matrices of size 4n-by-4n by first sending each quaternion entry `z
2314 = a + bi + cj + dk` to the block-complex matrix ``[[a + bi,
2315 c+di],[-c + di, a-bi]]`, and then embedding those into a real
2320 sage: from mjo.eja.eja_algebra import QuaternionMatrixEJA
2324 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2325 sage: i,j,k = Q.gens()
2326 sage: x = 1 + 2*i + 3*j + 4*k
2327 sage: M = matrix(Q, 1, [[x]])
2328 sage: QuaternionMatrixEJA.real_embed(M)
2334 Embedding is a homomorphism (isomorphism, in fact)::
2336 sage: set_random_seed()
2337 sage: n = ZZ.random_element(2)
2338 sage: Q = QuaternionAlgebra(QQ,-1,-1)
2339 sage: X = random_matrix(Q, n)
2340 sage: Y = random_matrix(Q, n)
2341 sage: Xe = QuaternionMatrixEJA.real_embed(X)
2342 sage: Ye = QuaternionMatrixEJA.real_embed(Y)
2343 sage: XYe = QuaternionMatrixEJA.real_embed(X*Y)
2348 super().real_embed(M
)
2349 quaternions
= M
.base_ring()
2352 F
= QuadraticField(-1, 'I')
2357 t
= z
.coefficient_tuple()
2362 cplxM
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
2363 [-c
+ d
*i
, a
- b
*i
]])
2364 realM
= ComplexMatrixEJA
.real_embed(cplxM
)
2365 blocks
.append(realM
)
2367 # We should have real entries by now, so use the realest field
2368 # we've got for the return value.
2369 return matrix
.block(quaternions
.base_ring(), n
, blocks
)
2374 def real_unembed(cls
,M
):
2376 The inverse of _embed_quaternion_matrix().
2380 sage: from mjo.eja.eja_algebra import QuaternionMatrixEJA
2384 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
2385 ....: [-2, 1, -4, 3],
2386 ....: [-3, 4, 1, -2],
2387 ....: [-4, -3, 2, 1]])
2388 sage: QuaternionMatrixEJA.real_unembed(M)
2389 [1 + 2*i + 3*j + 4*k]
2393 Unembedding is the inverse of embedding::
2395 sage: set_random_seed()
2396 sage: Q = QuaternionAlgebra(QQ, -1, -1)
2397 sage: M = random_matrix(Q, 3)
2398 sage: Me = QuaternionMatrixEJA.real_embed(M)
2399 sage: QuaternionMatrixEJA.real_unembed(Me) == M
2403 super().real_unembed(M
)
2405 d
= cls
.dimension_over_reals()
2407 # Use the base ring of the matrix to ensure that its entries can be
2408 # multiplied by elements of the quaternion algebra.
2409 Q
= cls
.quaternion_extension(M
.base_ring())
2412 # Go top-left to bottom-right (reading order), converting every
2413 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
2416 for l
in range(n
/d
):
2417 for m
in range(n
/d
):
2418 submat
= ComplexMatrixEJA
.real_unembed(
2419 M
[d
*l
:d
*l
+d
,d
*m
:d
*m
+d
] )
2420 if submat
[0,0] != submat
[1,1].conjugate():
2421 raise ValueError('bad on-diagonal submatrix')
2422 if submat
[0,1] != -submat
[1,0].conjugate():
2423 raise ValueError('bad off-diagonal submatrix')
2424 z
= submat
[0,0].real()
2425 z
+= submat
[0,0].imag()*i
2426 z
+= submat
[0,1].real()*j
2427 z
+= submat
[0,1].imag()*k
2430 return matrix(Q
, n
/d
, elements
)
2433 class QuaternionHermitianEJA(ConcreteEJA
, QuaternionMatrixEJA
):
2435 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2436 matrices, the usual symmetric Jordan product, and the
2437 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2442 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2446 In theory, our "field" can be any subfield of the reals::
2448 sage: QuaternionHermitianEJA(2, field=RDF, check_axioms=True)
2449 Euclidean Jordan algebra of dimension 6 over Real Double Field
2450 sage: QuaternionHermitianEJA(2, field=RR, check_axioms=True)
2451 Euclidean Jordan algebra of dimension 6 over Real Field with
2452 53 bits of precision
2456 The dimension of this algebra is `2*n^2 - n`::
2458 sage: set_random_seed()
2459 sage: n_max = QuaternionHermitianEJA._max_random_instance_size()
2460 sage: n = ZZ.random_element(1, n_max)
2461 sage: J = QuaternionHermitianEJA(n)
2462 sage: J.dimension() == 2*(n^2) - n
2465 The Jordan multiplication is what we think it is::
2467 sage: set_random_seed()
2468 sage: J = QuaternionHermitianEJA.random_instance()
2469 sage: x,y = J.random_elements(2)
2470 sage: actual = (x*y).to_matrix()
2471 sage: X = x.to_matrix()
2472 sage: Y = y.to_matrix()
2473 sage: expected = (X*Y + Y*X)/2
2474 sage: actual == expected
2476 sage: J(expected) == x*y
2479 We can change the generator prefix::
2481 sage: QuaternionHermitianEJA(2, prefix='a').gens()
2482 (a0, a1, a2, a3, a4, a5)
2484 We can construct the (trivial) algebra of rank zero::
2486 sage: QuaternionHermitianEJA(0)
2487 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2491 def _denormalized_basis(cls
, n
, field
):
2493 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
2495 Why do we embed these? Basically, because all of numerical
2496 linear algebra assumes that you're working with vectors consisting
2497 of `n` entries from a field and scalars from the same field. There's
2498 no way to tell SageMath that (for example) the vectors contain
2499 complex numbers, while the scalar field is real.
2503 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2507 sage: set_random_seed()
2508 sage: n = ZZ.random_element(1,5)
2509 sage: B = QuaternionHermitianEJA._denormalized_basis(n,ZZ)
2510 sage: all( M.is_symmetric() for M in B )
2514 Q
= QuaternionAlgebra(QQ
,-1,-1)
2517 # This is like the symmetric case, but we need to be careful:
2519 # * We want conjugate-symmetry, not just symmetry.
2520 # * The diagonal will (as a result) be real.
2523 Eij
= matrix
.zero(Q
,n
)
2525 for j
in range(i
+1):
2529 Sij
= cls
.real_embed(Eij
)
2532 # The second, third, and fourth ones have a minus
2533 # because they're conjugated.
2534 # Eij = Eij + Eij.transpose()
2536 Sij_real
= cls
.real_embed(Eij
)
2538 # Eij = I*(Eij - Eij.transpose())
2541 Sij_I
= cls
.real_embed(Eij
)
2543 # Eij = J*(Eij - Eij.transpose())
2546 Sij_J
= cls
.real_embed(Eij
)
2548 # Eij = K*(Eij - Eij.transpose())
2551 Sij_K
= cls
.real_embed(Eij
)
2557 # Since we embedded the entries, we can drop back to the
2558 # desired real "field" instead of the quaternion algebra "Q".
2559 return tuple( s
.change_ring(field
) for s
in S
)
2562 def __init__(self
, n
, field
=AA
, **kwargs
):
2563 # We know this is a valid EJA, but will double-check
2564 # if the user passes check_axioms=True.
2565 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2571 super().__init
__(self
._denormalized
_basis
(n
,field
),
2572 self
.jordan_product
,
2573 self
.trace_inner_product
,
2575 associative
=associative
,
2578 # TODO: this could be factored out somehow, but is left here
2579 # because the MatrixEJA is not presently a subclass of the
2580 # FDEJA class that defines rank() and one().
2581 self
.rank
.set_cache(n
)
2582 idV
= matrix
.identity(ZZ
, self
.dimension_over_reals()*n
)
2583 self
.one
.set_cache(self(idV
))
2587 def _max_random_instance_size():
2589 The maximum rank of a random QuaternionHermitianEJA.
2591 return 2 # Dimension 6
2594 def random_instance(cls
, **kwargs
):
2596 Return a random instance of this type of algebra.
2598 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2599 return cls(n
, **kwargs
)
2602 class HadamardEJA(ConcreteEJA
):
2604 Return the Euclidean Jordan Algebra corresponding to the set
2605 `R^n` under the Hadamard product.
2607 Note: this is nothing more than the Cartesian product of ``n``
2608 copies of the spin algebra. Once Cartesian product algebras
2609 are implemented, this can go.
2613 sage: from mjo.eja.eja_algebra import HadamardEJA
2617 This multiplication table can be verified by hand::
2619 sage: J = HadamardEJA(3)
2620 sage: b0,b1,b2 = J.gens()
2636 We can change the generator prefix::
2638 sage: HadamardEJA(3, prefix='r').gens()
2642 def __init__(self
, n
, field
=AA
, **kwargs
):
2644 jordan_product
= lambda x
,y
: x
2645 inner_product
= lambda x
,y
: x
2647 def jordan_product(x
,y
):
2649 return P( xi
*yi
for (xi
,yi
) in zip(x
,y
) )
2651 def inner_product(x
,y
):
2654 # New defaults for keyword arguments. Don't orthonormalize
2655 # because our basis is already orthonormal with respect to our
2656 # inner-product. Don't check the axioms, because we know this
2657 # is a valid EJA... but do double-check if the user passes
2658 # check_axioms=True. Note: we DON'T override the "check_field"
2659 # default here, because the user can pass in a field!
2660 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2661 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2663 column_basis
= tuple( b
.column()
2664 for b
in FreeModule(field
, n
).basis() )
2665 super().__init
__(column_basis
,
2671 self
.rank
.set_cache(n
)
2674 self
.one
.set_cache( self
.zero() )
2676 self
.one
.set_cache( sum(self
.gens()) )
2679 def _max_random_instance_size():
2681 The maximum dimension of a random HadamardEJA.
2686 def random_instance(cls
, **kwargs
):
2688 Return a random instance of this type of algebra.
2690 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2691 return cls(n
, **kwargs
)
2694 class BilinearFormEJA(ConcreteEJA
):
2696 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2697 with the half-trace inner product and jordan product ``x*y =
2698 (<Bx,y>,y_bar>, x0*y_bar + y0*x_bar)`` where `B = 1 \times B22` is
2699 a symmetric positive-definite "bilinear form" matrix. Its
2700 dimension is the size of `B`, and it has rank two in dimensions
2701 larger than two. It reduces to the ``JordanSpinEJA`` when `B` is
2702 the identity matrix of order ``n``.
2704 We insist that the one-by-one upper-left identity block of `B` be
2705 passed in as well so that we can be passed a matrix of size zero
2706 to construct a trivial algebra.
2710 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
2711 ....: JordanSpinEJA)
2715 When no bilinear form is specified, the identity matrix is used,
2716 and the resulting algebra is the Jordan spin algebra::
2718 sage: B = matrix.identity(AA,3)
2719 sage: J0 = BilinearFormEJA(B)
2720 sage: J1 = JordanSpinEJA(3)
2721 sage: J0.multiplication_table() == J0.multiplication_table()
2724 An error is raised if the matrix `B` does not correspond to a
2725 positive-definite bilinear form::
2727 sage: B = matrix.random(QQ,2,3)
2728 sage: J = BilinearFormEJA(B)
2729 Traceback (most recent call last):
2731 ValueError: bilinear form is not positive-definite
2732 sage: B = matrix.zero(QQ,3)
2733 sage: J = BilinearFormEJA(B)
2734 Traceback (most recent call last):
2736 ValueError: bilinear form is not positive-definite
2740 We can create a zero-dimensional algebra::
2742 sage: B = matrix.identity(AA,0)
2743 sage: J = BilinearFormEJA(B)
2747 We can check the multiplication condition given in the Jordan, von
2748 Neumann, and Wigner paper (and also discussed on my "On the
2749 symmetry..." paper). Note that this relies heavily on the standard
2750 choice of basis, as does anything utilizing the bilinear form
2751 matrix. We opt not to orthonormalize the basis, because if we
2752 did, we would have to normalize the `s_{i}` in a similar manner::
2754 sage: set_random_seed()
2755 sage: n = ZZ.random_element(5)
2756 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2757 sage: B11 = matrix.identity(QQ,1)
2758 sage: B22 = M.transpose()*M
2759 sage: B = block_matrix(2,2,[ [B11,0 ],
2761 sage: J = BilinearFormEJA(B, orthonormalize=False)
2762 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
2763 sage: V = J.vector_space()
2764 sage: sis = [ J( V([0] + (M.inverse()*ei).list()).column() )
2765 ....: for ei in eis ]
2766 sage: actual = [ sis[i]*sis[j]
2767 ....: for i in range(n-1)
2768 ....: for j in range(n-1) ]
2769 sage: expected = [ J.one() if i == j else J.zero()
2770 ....: for i in range(n-1)
2771 ....: for j in range(n-1) ]
2772 sage: actual == expected
2776 def __init__(self
, B
, field
=AA
, **kwargs
):
2777 # The matrix "B" is supplied by the user in most cases,
2778 # so it makes sense to check whether or not its positive-
2779 # definite unless we are specifically asked not to...
2780 if ("check_axioms" not in kwargs
) or kwargs
["check_axioms"]:
2781 if not B
.is_positive_definite():
2782 raise ValueError("bilinear form is not positive-definite")
2784 # However, all of the other data for this EJA is computed
2785 # by us in manner that guarantees the axioms are
2786 # satisfied. So, again, unless we are specifically asked to
2787 # verify things, we'll skip the rest of the checks.
2788 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2790 def inner_product(x
,y
):
2791 return (y
.T
*B
*x
)[0,0]
2793 def jordan_product(x
,y
):
2799 z0
= inner_product(y
,x
)
2800 zbar
= y0
*xbar
+ x0
*ybar
2801 return P([z0
] + zbar
.list())
2804 column_basis
= tuple( b
.column()
2805 for b
in FreeModule(field
, n
).basis() )
2807 # TODO: I haven't actually checked this, but it seems legit.
2812 super().__init
__(column_basis
,
2816 associative
=associative
,
2819 # The rank of this algebra is two, unless we're in a
2820 # one-dimensional ambient space (because the rank is bounded
2821 # by the ambient dimension).
2822 self
.rank
.set_cache(min(n
,2))
2825 self
.one
.set_cache( self
.zero() )
2827 self
.one
.set_cache( self
.monomial(0) )
2830 def _max_random_instance_size():
2832 The maximum dimension of a random BilinearFormEJA.
2837 def random_instance(cls
, **kwargs
):
2839 Return a random instance of this algebra.
2841 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2843 B
= matrix
.identity(ZZ
, n
)
2844 return cls(B
, **kwargs
)
2846 B11
= matrix
.identity(ZZ
, 1)
2847 M
= matrix
.random(ZZ
, n
-1)
2848 I
= matrix
.identity(ZZ
, n
-1)
2850 while alpha
.is_zero():
2851 alpha
= ZZ
.random_element().abs()
2852 B22
= M
.transpose()*M
+ alpha
*I
2854 from sage
.matrix
.special
import block_matrix
2855 B
= block_matrix(2,2, [ [B11
, ZZ(0) ],
2858 return cls(B
, **kwargs
)
2861 class JordanSpinEJA(BilinearFormEJA
):
2863 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2864 with the usual inner product and jordan product ``x*y =
2865 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2870 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2874 This multiplication table can be verified by hand::
2876 sage: J = JordanSpinEJA(4)
2877 sage: b0,b1,b2,b3 = J.gens()
2893 We can change the generator prefix::
2895 sage: JordanSpinEJA(2, prefix='B').gens()
2900 Ensure that we have the usual inner product on `R^n`::
2902 sage: set_random_seed()
2903 sage: J = JordanSpinEJA.random_instance()
2904 sage: x,y = J.random_elements(2)
2905 sage: actual = x.inner_product(y)
2906 sage: expected = x.to_vector().inner_product(y.to_vector())
2907 sage: actual == expected
2911 def __init__(self
, n
, *args
, **kwargs
):
2912 # This is a special case of the BilinearFormEJA with the
2913 # identity matrix as its bilinear form.
2914 B
= matrix
.identity(ZZ
, n
)
2916 # Don't orthonormalize because our basis is already
2917 # orthonormal with respect to our inner-product.
2918 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2920 # But also don't pass check_field=False here, because the user
2921 # can pass in a field!
2922 super().__init
__(B
, *args
, **kwargs
)
2925 def _max_random_instance_size():
2927 The maximum dimension of a random JordanSpinEJA.
2932 def random_instance(cls
, **kwargs
):
2934 Return a random instance of this type of algebra.
2936 Needed here to override the implementation for ``BilinearFormEJA``.
2938 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2939 return cls(n
, **kwargs
)
2942 class TrivialEJA(ConcreteEJA
):
2944 The trivial Euclidean Jordan algebra consisting of only a zero element.
2948 sage: from mjo.eja.eja_algebra import TrivialEJA
2952 sage: J = TrivialEJA()
2959 sage: 7*J.one()*12*J.one()
2961 sage: J.one().inner_product(J.one())
2963 sage: J.one().norm()
2965 sage: J.one().subalgebra_generated_by()
2966 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2971 def __init__(self
, **kwargs
):
2972 jordan_product
= lambda x
,y
: x
2973 inner_product
= lambda x
,y
: 0
2976 # New defaults for keyword arguments
2977 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2978 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2980 super().__init
__(basis
,
2986 # The rank is zero using my definition, namely the dimension of the
2987 # largest subalgebra generated by any element.
2988 self
.rank
.set_cache(0)
2989 self
.one
.set_cache( self
.zero() )
2992 def random_instance(cls
, **kwargs
):
2993 # We don't take a "size" argument so the superclass method is
2994 # inappropriate for us.
2995 return cls(**kwargs
)
2998 class CartesianProductEJA(FiniteDimensionalEJA
):
3000 The external (orthogonal) direct sum of two or more Euclidean
3001 Jordan algebras. Every Euclidean Jordan algebra decomposes into an
3002 orthogonal direct sum of simple Euclidean Jordan algebras which is
3003 then isometric to a Cartesian product, so no generality is lost by
3004 providing only this construction.
3008 sage: from mjo.eja.eja_algebra import (random_eja,
3009 ....: CartesianProductEJA,
3011 ....: JordanSpinEJA,
3012 ....: RealSymmetricEJA)
3016 The Jordan product is inherited from our factors and implemented by
3017 our CombinatorialFreeModule Cartesian product superclass::
3019 sage: set_random_seed()
3020 sage: J1 = HadamardEJA(2)
3021 sage: J2 = RealSymmetricEJA(2)
3022 sage: J = cartesian_product([J1,J2])
3023 sage: x,y = J.random_elements(2)
3027 The ability to retrieve the original factors is implemented by our
3028 CombinatorialFreeModule Cartesian product superclass::
3030 sage: J1 = HadamardEJA(2, field=QQ)
3031 sage: J2 = JordanSpinEJA(3, field=QQ)
3032 sage: J = cartesian_product([J1,J2])
3033 sage: J.cartesian_factors()
3034 (Euclidean Jordan algebra of dimension 2 over Rational Field,
3035 Euclidean Jordan algebra of dimension 3 over Rational Field)
3037 You can provide more than two factors::
3039 sage: J1 = HadamardEJA(2)
3040 sage: J2 = JordanSpinEJA(3)
3041 sage: J3 = RealSymmetricEJA(3)
3042 sage: cartesian_product([J1,J2,J3])
3043 Euclidean Jordan algebra of dimension 2 over Algebraic Real
3044 Field (+) Euclidean Jordan algebra of dimension 3 over Algebraic
3045 Real Field (+) Euclidean Jordan algebra of dimension 6 over
3046 Algebraic Real Field
3048 Rank is additive on a Cartesian product::
3050 sage: J1 = HadamardEJA(1)
3051 sage: J2 = RealSymmetricEJA(2)
3052 sage: J = cartesian_product([J1,J2])
3053 sage: J1.rank.clear_cache()
3054 sage: J2.rank.clear_cache()
3055 sage: J.rank.clear_cache()
3058 sage: J.rank() == J1.rank() + J2.rank()
3061 The same rank computation works over the rationals, with whatever
3064 sage: J1 = HadamardEJA(1, field=QQ, orthonormalize=False)
3065 sage: J2 = RealSymmetricEJA(2, field=QQ, orthonormalize=False)
3066 sage: J = cartesian_product([J1,J2])
3067 sage: J1.rank.clear_cache()
3068 sage: J2.rank.clear_cache()
3069 sage: J.rank.clear_cache()
3072 sage: J.rank() == J1.rank() + J2.rank()
3075 The product algebra will be associative if and only if all of its
3076 components are associative::
3078 sage: J1 = HadamardEJA(2)
3079 sage: J1.is_associative()
3081 sage: J2 = HadamardEJA(3)
3082 sage: J2.is_associative()
3084 sage: J3 = RealSymmetricEJA(3)
3085 sage: J3.is_associative()
3087 sage: CP1 = cartesian_product([J1,J2])
3088 sage: CP1.is_associative()
3090 sage: CP2 = cartesian_product([J1,J3])
3091 sage: CP2.is_associative()
3094 Cartesian products of Cartesian products work::
3096 sage: J1 = JordanSpinEJA(1)
3097 sage: J2 = JordanSpinEJA(1)
3098 sage: J3 = JordanSpinEJA(1)
3099 sage: J = cartesian_product([J1,cartesian_product([J2,J3])])
3100 sage: J.multiplication_table()
3101 +----++----+----+----+
3102 | * || b0 | b1 | b2 |
3103 +====++====+====+====+
3104 | b0 || b0 | 0 | 0 |
3105 +----++----+----+----+
3106 | b1 || 0 | b1 | 0 |
3107 +----++----+----+----+
3108 | b2 || 0 | 0 | b2 |
3109 +----++----+----+----+
3110 sage: HadamardEJA(3).multiplication_table()
3111 +----++----+----+----+
3112 | * || b0 | b1 | b2 |
3113 +====++====+====+====+
3114 | b0 || b0 | 0 | 0 |
3115 +----++----+----+----+
3116 | b1 || 0 | b1 | 0 |
3117 +----++----+----+----+
3118 | b2 || 0 | 0 | b2 |
3119 +----++----+----+----+
3123 All factors must share the same base field::
3125 sage: J1 = HadamardEJA(2, field=QQ)
3126 sage: J2 = RealSymmetricEJA(2)
3127 sage: CartesianProductEJA((J1,J2))
3128 Traceback (most recent call last):
3130 ValueError: all factors must share the same base field
3132 The cached unit element is the same one that would be computed::
3134 sage: set_random_seed() # long time
3135 sage: J1 = random_eja() # long time
3136 sage: J2 = random_eja() # long time
3137 sage: J = cartesian_product([J1,J2]) # long time
3138 sage: actual = J.one() # long time
3139 sage: J.one.clear_cache() # long time
3140 sage: expected = J.one() # long time
3141 sage: actual == expected # long time
3145 Element
= FiniteDimensionalEJAElement
3148 def __init__(self
, factors
, **kwargs
):
3153 self
._sets
= factors
3155 field
= factors
[0].base_ring()
3156 if not all( J
.base_ring() == field
for J
in factors
):
3157 raise ValueError("all factors must share the same base field")
3159 associative
= all( f
.is_associative() for f
in factors
)
3161 MS
= self
.matrix_space()
3165 for b
in factors
[i
].matrix_basis():
3170 basis
= tuple( MS(b
) for b
in basis
)
3172 # Define jordan/inner products that operate on that matrix_basis.
3173 def jordan_product(x
,y
):
3175 (factors
[i
](x
[i
])*factors
[i
](y
[i
])).to_matrix()
3179 def inner_product(x
, y
):
3181 factors
[i
](x
[i
]).inner_product(factors
[i
](y
[i
]))
3185 # There's no need to check the field since it already came
3186 # from an EJA. Likewise the axioms are guaranteed to be
3187 # satisfied, unless the guy writing this class sucks.
3189 # If you want the basis to be orthonormalized, orthonormalize
3191 FiniteDimensionalEJA
.__init
__(self
,
3196 orthonormalize
=False,
3197 associative
=associative
,
3198 cartesian_product
=True,
3202 ones
= tuple(J
.one().to_matrix() for J
in factors
)
3203 self
.one
.set_cache(self(ones
))
3204 self
.rank
.set_cache(sum(J
.rank() for J
in factors
))
3206 def cartesian_factors(self
):
3207 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
3210 def cartesian_factor(self
, i
):
3212 Return the ``i``th factor of this algebra.
3214 return self
._sets
[i
]
3217 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
3218 from sage
.categories
.cartesian_product
import cartesian_product
3219 return cartesian_product
.symbol
.join("%s" % factor
3220 for factor
in self
._sets
)
3222 def matrix_space(self
):
3224 Return the space that our matrix basis lives in as a Cartesian
3229 sage: from mjo.eja.eja_algebra import (HadamardEJA,
3230 ....: RealSymmetricEJA)
3234 sage: J1 = HadamardEJA(1)
3235 sage: J2 = RealSymmetricEJA(2)
3236 sage: J = cartesian_product([J1,J2])
3237 sage: J.matrix_space()
3238 The Cartesian product of (Full MatrixSpace of 1 by 1 dense
3239 matrices over Algebraic Real Field, Full MatrixSpace of 2
3240 by 2 dense matrices over Algebraic Real Field)
3243 from sage
.categories
.cartesian_product
import cartesian_product
3244 return cartesian_product( [J
.matrix_space()
3245 for J
in self
.cartesian_factors()] )
3248 def cartesian_projection(self
, i
):
3252 sage: from mjo.eja.eja_algebra import (random_eja,
3253 ....: JordanSpinEJA,
3255 ....: RealSymmetricEJA,
3256 ....: ComplexHermitianEJA)
3260 The projection morphisms are Euclidean Jordan algebra
3263 sage: J1 = HadamardEJA(2)
3264 sage: J2 = RealSymmetricEJA(2)
3265 sage: J = cartesian_product([J1,J2])
3266 sage: J.cartesian_projection(0)
3267 Linear operator between finite-dimensional Euclidean Jordan
3268 algebras represented by the matrix:
3271 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3272 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3273 Algebraic Real Field
3274 Codomain: Euclidean Jordan algebra of dimension 2 over Algebraic
3276 sage: J.cartesian_projection(1)
3277 Linear operator between finite-dimensional Euclidean Jordan
3278 algebras represented by the matrix:
3282 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3283 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3284 Algebraic Real Field
3285 Codomain: Euclidean Jordan algebra of dimension 3 over Algebraic
3288 The projections work the way you'd expect on the vector
3289 representation of an element::
3291 sage: J1 = JordanSpinEJA(2)
3292 sage: J2 = ComplexHermitianEJA(2)
3293 sage: J = cartesian_product([J1,J2])
3294 sage: pi_left = J.cartesian_projection(0)
3295 sage: pi_right = J.cartesian_projection(1)
3296 sage: pi_left(J.one()).to_vector()
3298 sage: pi_right(J.one()).to_vector()
3300 sage: J.one().to_vector()
3305 The answer never changes::
3307 sage: set_random_seed()
3308 sage: J1 = random_eja()
3309 sage: J2 = random_eja()
3310 sage: J = cartesian_product([J1,J2])
3311 sage: P0 = J.cartesian_projection(0)
3312 sage: P1 = J.cartesian_projection(0)
3317 offset
= sum( self
.cartesian_factor(k
).dimension()
3319 Ji
= self
.cartesian_factor(i
)
3320 Pi
= self
._module
_morphism
(lambda j
: Ji
.monomial(j
- offset
),
3323 return FiniteDimensionalEJAOperator(self
,Ji
,Pi
.matrix())
3326 def cartesian_embedding(self
, i
):
3330 sage: from mjo.eja.eja_algebra import (random_eja,
3331 ....: JordanSpinEJA,
3333 ....: RealSymmetricEJA)
3337 The embedding morphisms are Euclidean Jordan algebra
3340 sage: J1 = HadamardEJA(2)
3341 sage: J2 = RealSymmetricEJA(2)
3342 sage: J = cartesian_product([J1,J2])
3343 sage: J.cartesian_embedding(0)
3344 Linear operator between finite-dimensional Euclidean Jordan
3345 algebras represented by the matrix:
3351 Domain: Euclidean Jordan algebra of dimension 2 over
3352 Algebraic Real Field
3353 Codomain: Euclidean Jordan algebra of dimension 2 over
3354 Algebraic Real Field (+) Euclidean Jordan algebra of
3355 dimension 3 over Algebraic Real Field
3356 sage: J.cartesian_embedding(1)
3357 Linear operator between finite-dimensional Euclidean Jordan
3358 algebras represented by the matrix:
3364 Domain: Euclidean Jordan algebra of dimension 3 over
3365 Algebraic Real Field
3366 Codomain: Euclidean Jordan algebra of dimension 2 over
3367 Algebraic Real Field (+) Euclidean Jordan algebra of
3368 dimension 3 over Algebraic Real Field
3370 The embeddings work the way you'd expect on the vector
3371 representation of an element::
3373 sage: J1 = JordanSpinEJA(3)
3374 sage: J2 = RealSymmetricEJA(2)
3375 sage: J = cartesian_product([J1,J2])
3376 sage: iota_left = J.cartesian_embedding(0)
3377 sage: iota_right = J.cartesian_embedding(1)
3378 sage: iota_left(J1.zero()) == J.zero()
3380 sage: iota_right(J2.zero()) == J.zero()
3382 sage: J1.one().to_vector()
3384 sage: iota_left(J1.one()).to_vector()
3386 sage: J2.one().to_vector()
3388 sage: iota_right(J2.one()).to_vector()
3390 sage: J.one().to_vector()
3395 The answer never changes::
3397 sage: set_random_seed()
3398 sage: J1 = random_eja()
3399 sage: J2 = random_eja()
3400 sage: J = cartesian_product([J1,J2])
3401 sage: E0 = J.cartesian_embedding(0)
3402 sage: E1 = J.cartesian_embedding(0)
3406 Composing a projection with the corresponding inclusion should
3407 produce the identity map, and mismatching them should produce
3410 sage: set_random_seed()
3411 sage: J1 = random_eja()
3412 sage: J2 = random_eja()
3413 sage: J = cartesian_product([J1,J2])
3414 sage: iota_left = J.cartesian_embedding(0)
3415 sage: iota_right = J.cartesian_embedding(1)
3416 sage: pi_left = J.cartesian_projection(0)
3417 sage: pi_right = J.cartesian_projection(1)
3418 sage: pi_left*iota_left == J1.one().operator()
3420 sage: pi_right*iota_right == J2.one().operator()
3422 sage: (pi_left*iota_right).is_zero()
3424 sage: (pi_right*iota_left).is_zero()
3428 offset
= sum( self
.cartesian_factor(k
).dimension()
3430 Ji
= self
.cartesian_factor(i
)
3431 Ei
= Ji
._module
_morphism
(lambda j
: self
.monomial(j
+ offset
),
3433 return FiniteDimensionalEJAOperator(Ji
,self
,Ei
.matrix())
3437 FiniteDimensionalEJA
.CartesianProduct
= CartesianProductEJA
3439 class RationalBasisCartesianProductEJA(CartesianProductEJA
,
3442 A separate class for products of algebras for which we know a
3447 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
3448 ....: RealSymmetricEJA)
3452 This gives us fast characteristic polynomial computations in
3453 product algebras, too::
3456 sage: J1 = JordanSpinEJA(2)
3457 sage: J2 = RealSymmetricEJA(3)
3458 sage: J = cartesian_product([J1,J2])
3459 sage: J.characteristic_polynomial_of().degree()
3465 def __init__(self
, algebras
, **kwargs
):
3466 CartesianProductEJA
.__init
__(self
, algebras
, **kwargs
)
3468 self
._rational
_algebra
= None
3469 if self
.vector_space().base_field() is not QQ
:
3470 self
._rational
_algebra
= cartesian_product([
3471 r
._rational
_algebra
for r
in algebras
3475 RationalBasisEJA
.CartesianProduct
= RationalBasisCartesianProductEJA
3477 def random_eja(*args
, **kwargs
):
3478 J1
= ConcreteEJA
.random_instance(*args
, **kwargs
)
3480 # This might make Cartesian products appear roughly as often as
3481 # any other ConcreteEJA.
3482 if ZZ
.random_element(len(ConcreteEJA
.__subclasses
__()) + 1) == 0:
3483 # Use random_eja() again so we can get more than two factors.
3484 J2
= random_eja(*args
, **kwargs
)
3485 J
= cartesian_product([J1
,J2
])