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`
35 * :class:`OctonionHermitianEJA`
37 In addition to these, we provide two other example constructions,
39 * :class:`JordanSpinEJA`
40 * :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. The Albert EJA is simply a special
47 case of the :class:`OctonionHermitianEJA` where the matrices are
48 three-by-three and the resulting space has dimension 27. And
49 last/least, the trivial EJA is exactly what you think it is; it could
50 also be obtained by constructing a dimension-zero instance of any of
51 the other algebras. Cartesian products of these are also supported
52 using the usual ``cartesian_product()`` function; as a result, we
53 support (up to isomorphism) all Euclidean Jordan algebras.
57 sage: from mjo.eja.eja_algebra import random_eja
62 Euclidean Jordan algebra of dimension...
65 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
66 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
67 from sage
.categories
.sets_cat
import cartesian_product
68 from sage
.combinat
.free_module
import CombinatorialFreeModule
69 from sage
.matrix
.constructor
import matrix
70 from sage
.matrix
.matrix_space
import MatrixSpace
71 from sage
.misc
.cachefunc
import cached_method
72 from sage
.misc
.table
import table
73 from sage
.modules
.free_module
import FreeModule
, VectorSpace
74 from sage
.rings
.all
import (ZZ
, QQ
, AA
, QQbar
, RR
, RLF
, CLF
,
77 from mjo
.eja
.eja_element
import FiniteDimensionalEJAElement
78 from mjo
.eja
.eja_operator
import FiniteDimensionalEJAOperator
79 from mjo
.eja
.eja_utils
import _all2list
, _mat2vec
81 class FiniteDimensionalEJA(CombinatorialFreeModule
):
83 A finite-dimensional Euclidean Jordan algebra.
87 - ``basis`` -- a tuple; a tuple of basis elements in "matrix
88 form," which must be the same form as the arguments to
89 ``jordan_product`` and ``inner_product``. In reality, "matrix
90 form" can be either vectors, matrices, or a Cartesian product
91 (ordered tuple) of vectors or matrices. All of these would
92 ideally be vector spaces in sage with no special-casing
93 needed; but in reality we turn vectors into column-matrices
94 and Cartesian products `(a,b)` into column matrices
95 `(a,b)^{T}` after converting `a` and `b` themselves.
97 - ``jordan_product`` -- a function; afunction of two ``basis``
98 elements (in matrix form) that returns their jordan product,
99 also in matrix form; this will be applied to ``basis`` to
100 compute a multiplication table for the algebra.
102 - ``inner_product`` -- a function; a function of two ``basis``
103 elements (in matrix form) that returns their inner
104 product. This will be applied to ``basis`` to compute an
105 inner-product table (basically a matrix) for this algebra.
107 - ``field`` -- a subfield of the reals (default: ``AA``); the scalar
108 field for the algebra.
110 - ``orthonormalize`` -- boolean (default: ``True``); whether or
111 not to orthonormalize the basis. Doing so is expensive and
112 generally rules out using the rationals as your ``field``, but
113 is required for spectral decompositions.
117 sage: from mjo.eja.eja_algebra import random_eja
121 We should compute that an element subalgebra is associative even
122 if we circumvent the element method::
124 sage: set_random_seed()
125 sage: J = random_eja(field=QQ,orthonormalize=False)
126 sage: x = J.random_element()
127 sage: A = x.subalgebra_generated_by(orthonormalize=False)
128 sage: basis = tuple(b.superalgebra_element() for b in A.basis())
129 sage: J.subalgebra(basis, orthonormalize=False).is_associative()
133 Element
= FiniteDimensionalEJAElement
142 cartesian_product
=False,
150 if not field
.is_subring(RR
):
151 # Note: this does return true for the real algebraic
152 # field, the rationals, and any quadratic field where
153 # we've specified a real embedding.
154 raise ValueError("scalar field is not real")
157 # Check commutativity of the Jordan and inner-products.
158 # This has to be done before we build the multiplication
159 # and inner-product tables/matrices, because we take
160 # advantage of symmetry in the process.
161 if not all( jordan_product(bi
,bj
) == jordan_product(bj
,bi
)
164 raise ValueError("Jordan product is not commutative")
166 if not all( inner_product(bi
,bj
) == inner_product(bj
,bi
)
169 raise ValueError("inner-product is not commutative")
172 category
= MagmaticAlgebras(field
).FiniteDimensional()
173 category
= category
.WithBasis().Unital().Commutative()
176 # All zero- and one-dimensional algebras are just the real
177 # numbers with (some positive multiples of) the usual
178 # multiplication as its Jordan and inner-product.
180 if associative
is None:
181 # We should figure it out. As with check_axioms, we have to do
182 # this without the help of the _jordan_product_is_associative()
183 # method because we need to know the category before we
184 # initialize the algebra.
185 associative
= all( jordan_product(jordan_product(bi
,bj
),bk
)
187 jordan_product(bi
,jordan_product(bj
,bk
))
193 # Element subalgebras can take advantage of this.
194 category
= category
.Associative()
195 if cartesian_product
:
196 # Use join() here because otherwise we only get the
197 # "Cartesian product of..." and not the things themselves.
198 category
= category
.join([category
,
199 category
.CartesianProducts()])
201 # Call the superclass constructor so that we can use its from_vector()
202 # method to build our multiplication table.
203 CombinatorialFreeModule
.__init
__(self
,
210 # Now comes all of the hard work. We'll be constructing an
211 # ambient vector space V that our (vectorized) basis lives in,
212 # as well as a subspace W of V spanned by those (vectorized)
213 # basis elements. The W-coordinates are the coefficients that
214 # we see in things like x = 1*b1 + 2*b2.
219 degree
= len(_all2list(basis
[0]))
221 # Build an ambient space that fits our matrix basis when
222 # written out as "long vectors."
223 V
= VectorSpace(field
, degree
)
225 # The matrix that will hole the orthonormal -> unorthonormal
226 # coordinate transformation.
227 self
._deortho
_matrix
= None
230 # Save a copy of the un-orthonormalized basis for later.
231 # Convert it to ambient V (vector) coordinates while we're
232 # at it, because we'd have to do it later anyway.
233 deortho_vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
235 from mjo
.eja
.eja_utils
import gram_schmidt
236 basis
= tuple(gram_schmidt(basis
, inner_product
))
238 # Save the (possibly orthonormalized) matrix basis for
240 self
._matrix
_basis
= basis
242 # Now create the vector space for the algebra, which will have
243 # its own set of non-ambient coordinates (in terms of the
245 vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
246 W
= V
.span_of_basis( vector_basis
, check
=check_axioms
)
249 # Now "W" is the vector space of our algebra coordinates. The
250 # variables "X1", "X2",... refer to the entries of vectors in
251 # W. Thus to convert back and forth between the orthonormal
252 # coordinates and the given ones, we need to stick the original
254 U
= V
.span_of_basis( deortho_vector_basis
, check
=check_axioms
)
255 self
._deortho
_matrix
= matrix( U
.coordinate_vector(q
)
256 for q
in vector_basis
)
259 # Now we actually compute the multiplication and inner-product
260 # tables/matrices using the possibly-orthonormalized basis.
261 self
._inner
_product
_matrix
= matrix
.identity(field
, n
)
262 self
._multiplication
_table
= [ [0 for j
in range(i
+1)]
265 # Note: the Jordan and inner-products are defined in terms
266 # of the ambient basis. It's important that their arguments
267 # are in ambient coordinates as well.
270 # ortho basis w.r.t. ambient coords
274 # The jordan product returns a matrixy answer, so we
275 # have to convert it to the algebra coordinates.
276 elt
= jordan_product(q_i
, q_j
)
277 elt
= W
.coordinate_vector(V(_all2list(elt
)))
278 self
._multiplication
_table
[i
][j
] = self
.from_vector(elt
)
280 if not orthonormalize
:
281 # If we're orthonormalizing the basis with respect
282 # to an inner-product, then the inner-product
283 # matrix with respect to the resulting basis is
284 # just going to be the identity.
285 ip
= inner_product(q_i
, q_j
)
286 self
._inner
_product
_matrix
[i
,j
] = ip
287 self
._inner
_product
_matrix
[j
,i
] = ip
289 self
._inner
_product
_matrix
._cache
= {'hermitian': True}
290 self
._inner
_product
_matrix
.set_immutable()
293 if not self
._is
_jordanian
():
294 raise ValueError("Jordan identity does not hold")
295 if not self
._inner
_product
_is
_associative
():
296 raise ValueError("inner product is not associative")
299 def _coerce_map_from_base_ring(self
):
301 Disable the map from the base ring into the algebra.
303 Performing a nonsense conversion like this automatically
304 is counterpedagogical. The fallback is to try the usual
305 element constructor, which should also fail.
309 sage: from mjo.eja.eja_algebra import random_eja
313 sage: set_random_seed()
314 sage: J = random_eja()
316 Traceback (most recent call last):
318 ValueError: not an element of this algebra
324 def product_on_basis(self
, i
, j
):
326 Returns the Jordan product of the `i` and `j`th basis elements.
328 This completely defines the Jordan product on the algebra, and
329 is used direclty by our superclass machinery to implement
334 sage: from mjo.eja.eja_algebra import random_eja
338 sage: set_random_seed()
339 sage: J = random_eja()
340 sage: n = J.dimension()
343 sage: bi_bj = J.zero()*J.zero()
345 ....: i = ZZ.random_element(n)
346 ....: j = ZZ.random_element(n)
347 ....: bi = J.monomial(i)
348 ....: bj = J.monomial(j)
349 ....: bi_bj = J.product_on_basis(i,j)
354 # We only stored the lower-triangular portion of the
355 # multiplication table.
357 return self
._multiplication
_table
[i
][j
]
359 return self
._multiplication
_table
[j
][i
]
361 def inner_product(self
, x
, y
):
363 The inner product associated with this Euclidean Jordan algebra.
365 Defaults to the trace inner product, but can be overridden by
366 subclasses if they are sure that the necessary properties are
371 sage: from mjo.eja.eja_algebra import (random_eja,
373 ....: BilinearFormEJA)
377 Our inner product is "associative," which means the following for
378 a symmetric bilinear form::
380 sage: set_random_seed()
381 sage: J = random_eja()
382 sage: x,y,z = J.random_elements(3)
383 sage: (x*y).inner_product(z) == y.inner_product(x*z)
388 Ensure that this is the usual inner product for the algebras
391 sage: set_random_seed()
392 sage: J = HadamardEJA.random_instance()
393 sage: x,y = J.random_elements(2)
394 sage: actual = x.inner_product(y)
395 sage: expected = x.to_vector().inner_product(y.to_vector())
396 sage: actual == expected
399 Ensure that this is one-half of the trace inner-product in a
400 BilinearFormEJA that isn't just the reals (when ``n`` isn't
401 one). This is in Faraut and Koranyi, and also my "On the
404 sage: set_random_seed()
405 sage: J = BilinearFormEJA.random_instance()
406 sage: n = J.dimension()
407 sage: x = J.random_element()
408 sage: y = J.random_element()
409 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
413 B
= self
._inner
_product
_matrix
414 return (B
*x
.to_vector()).inner_product(y
.to_vector())
417 def is_associative(self
):
419 Return whether or not this algebra's Jordan product is associative.
423 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
427 sage: J = ComplexHermitianEJA(3, field=QQ, orthonormalize=False)
428 sage: J.is_associative()
430 sage: x = sum(J.gens())
431 sage: A = x.subalgebra_generated_by(orthonormalize=False)
432 sage: A.is_associative()
436 return "Associative" in self
.category().axioms()
438 def _is_commutative(self
):
440 Whether or not this algebra's multiplication table is commutative.
442 This method should of course always return ``True``, unless
443 this algebra was constructed with ``check_axioms=False`` and
444 passed an invalid multiplication table.
446 return all( x
*y
== y
*x
for x
in self
.gens() for y
in self
.gens() )
448 def _is_jordanian(self
):
450 Whether or not this algebra's multiplication table respects the
451 Jordan identity `(x^{2})(xy) = x(x^{2}y)`.
453 We only check one arrangement of `x` and `y`, so for a
454 ``True`` result to be truly true, you should also check
455 :meth:`_is_commutative`. This method should of course always
456 return ``True``, unless this algebra was constructed with
457 ``check_axioms=False`` and passed an invalid multiplication table.
459 return all( (self
.monomial(i
)**2)*(self
.monomial(i
)*self
.monomial(j
))
461 (self
.monomial(i
))*((self
.monomial(i
)**2)*self
.monomial(j
))
462 for i
in range(self
.dimension())
463 for j
in range(self
.dimension()) )
465 def _jordan_product_is_associative(self
):
467 Return whether or not this algebra's Jordan product is
468 associative; that is, whether or not `x*(y*z) = (x*y)*z`
471 This method should agree with :meth:`is_associative` unless
472 you lied about the value of the ``associative`` parameter
473 when you constructed the algebra.
477 sage: from mjo.eja.eja_algebra import (random_eja,
478 ....: RealSymmetricEJA,
479 ....: ComplexHermitianEJA,
480 ....: QuaternionHermitianEJA)
484 sage: J = RealSymmetricEJA(4, orthonormalize=False)
485 sage: J._jordan_product_is_associative()
487 sage: x = sum(J.gens())
488 sage: A = x.subalgebra_generated_by()
489 sage: A._jordan_product_is_associative()
494 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
495 sage: J._jordan_product_is_associative()
497 sage: x = sum(J.gens())
498 sage: A = x.subalgebra_generated_by(orthonormalize=False)
499 sage: A._jordan_product_is_associative()
504 sage: J = QuaternionHermitianEJA(2)
505 sage: J._jordan_product_is_associative()
507 sage: x = sum(J.gens())
508 sage: A = x.subalgebra_generated_by()
509 sage: A._jordan_product_is_associative()
514 The values we've presupplied to the constructors agree with
517 sage: set_random_seed()
518 sage: J = random_eja()
519 sage: J.is_associative() == J._jordan_product_is_associative()
525 # Used to check whether or not something is zero.
528 # I don't know of any examples that make this magnitude
529 # necessary because I don't know how to make an
530 # associative algebra when the element subalgebra
531 # construction is unreliable (as it is over RDF; we can't
532 # find the degree of an element because we can't compute
533 # the rank of a matrix). But even multiplication of floats
534 # is non-associative, so *some* epsilon is needed... let's
535 # just take the one from _inner_product_is_associative?
538 for i
in range(self
.dimension()):
539 for j
in range(self
.dimension()):
540 for k
in range(self
.dimension()):
544 diff
= (x
*y
)*z
- x
*(y
*z
)
546 if diff
.norm() > epsilon
:
551 def _inner_product_is_associative(self
):
553 Return whether or not this algebra's inner product `B` is
554 associative; that is, whether or not `B(xy,z) = B(x,yz)`.
556 This method should of course always return ``True``, unless
557 this algebra was constructed with ``check_axioms=False`` and
558 passed an invalid Jordan or inner-product.
562 # Used to check whether or not something is zero.
565 # This choice is sufficient to allow the construction of
566 # QuaternionHermitianEJA(2, field=RDF) with check_axioms=True.
569 for i
in range(self
.dimension()):
570 for j
in range(self
.dimension()):
571 for k
in range(self
.dimension()):
575 diff
= (x
*y
).inner_product(z
) - x
.inner_product(y
*z
)
577 if diff
.abs() > epsilon
:
582 def _element_constructor_(self
, elt
):
584 Construct an element of this algebra from its vector or matrix
587 This gets called only after the parent element _call_ method
588 fails to find a coercion for the argument.
592 sage: from mjo.eja.eja_algebra import (random_eja,
595 ....: RealSymmetricEJA)
599 The identity in `S^n` is converted to the identity in the EJA::
601 sage: J = RealSymmetricEJA(3)
602 sage: I = matrix.identity(QQ,3)
603 sage: J(I) == J.one()
606 This skew-symmetric matrix can't be represented in the EJA::
608 sage: J = RealSymmetricEJA(3)
609 sage: A = matrix(QQ,3, lambda i,j: i-j)
611 Traceback (most recent call last):
613 ValueError: not an element of this algebra
615 Tuples work as well, provided that the matrix basis for the
616 algebra consists of them::
618 sage: J1 = HadamardEJA(3)
619 sage: J2 = RealSymmetricEJA(2)
620 sage: J = cartesian_product([J1,J2])
621 sage: J( (J1.matrix_basis()[1], J2.matrix_basis()[2]) )
626 Ensure that we can convert any element back and forth
627 faithfully between its matrix and algebra representations::
629 sage: set_random_seed()
630 sage: J = random_eja()
631 sage: x = J.random_element()
632 sage: J(x.to_matrix()) == x
635 We cannot coerce elements between algebras just because their
636 matrix representations are compatible::
638 sage: J1 = HadamardEJA(3)
639 sage: J2 = JordanSpinEJA(3)
641 Traceback (most recent call last):
643 ValueError: not an element of this algebra
645 Traceback (most recent call last):
647 ValueError: not an element of this algebra
649 msg
= "not an element of this algebra"
650 if elt
in self
.base_ring():
651 # Ensure that no base ring -> algebra coercion is performed
652 # by this method. There's some stupidity in sage that would
653 # otherwise propagate to this method; for example, sage thinks
654 # that the integer 3 belongs to the space of 2-by-2 matrices.
655 raise ValueError(msg
)
658 # Try to convert a vector into a column-matrix...
660 except (AttributeError, TypeError):
661 # and ignore failure, because we weren't really expecting
662 # a vector as an argument anyway.
665 if elt
not in self
.matrix_space():
666 raise ValueError(msg
)
668 # Thanks for nothing! Matrix spaces aren't vector spaces in
669 # Sage, so we have to figure out its matrix-basis coordinates
670 # ourselves. We use the basis space's ring instead of the
671 # element's ring because the basis space might be an algebraic
672 # closure whereas the base ring of the 3-by-3 identity matrix
673 # could be QQ instead of QQbar.
675 # And, we also have to handle Cartesian product bases (when
676 # the matrix basis consists of tuples) here. The "good news"
677 # is that we're already converting everything to long vectors,
678 # and that strategy works for tuples as well.
680 # We pass check=False because the matrix basis is "guaranteed"
681 # to be linearly independent... right? Ha ha.
683 V
= VectorSpace(self
.base_ring(), len(elt
))
684 W
= V
.span_of_basis( (V(_all2list(s
)) for s
in self
.matrix_basis()),
688 coords
= W
.coordinate_vector(V(elt
))
689 except ArithmeticError: # vector is not in free module
690 raise ValueError(msg
)
692 return self
.from_vector(coords
)
696 Return a string representation of ``self``.
700 sage: from mjo.eja.eja_algebra import JordanSpinEJA
704 Ensure that it says what we think it says::
706 sage: JordanSpinEJA(2, field=AA)
707 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
708 sage: JordanSpinEJA(3, field=RDF)
709 Euclidean Jordan algebra of dimension 3 over Real Double Field
712 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
713 return fmt
.format(self
.dimension(), self
.base_ring())
717 def characteristic_polynomial_of(self
):
719 Return the algebra's "characteristic polynomial of" function,
720 which is itself a multivariate polynomial that, when evaluated
721 at the coordinates of some algebra element, returns that
722 element's characteristic polynomial.
724 The resulting polynomial has `n+1` variables, where `n` is the
725 dimension of this algebra. The first `n` variables correspond to
726 the coordinates of an algebra element: when evaluated at the
727 coordinates of an algebra element with respect to a certain
728 basis, the result is a univariate polynomial (in the one
729 remaining variable ``t``), namely the characteristic polynomial
734 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
738 The characteristic polynomial in the spin algebra is given in
739 Alizadeh, Example 11.11::
741 sage: J = JordanSpinEJA(3)
742 sage: p = J.characteristic_polynomial_of(); p
743 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
744 sage: xvec = J.one().to_vector()
748 By definition, the characteristic polynomial is a monic
749 degree-zero polynomial in a rank-zero algebra. Note that
750 Cayley-Hamilton is indeed satisfied since the polynomial
751 ``1`` evaluates to the identity element of the algebra on
754 sage: J = TrivialEJA()
755 sage: J.characteristic_polynomial_of()
762 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_(r-1).
763 a
= self
._charpoly
_coefficients
()
765 # We go to a bit of trouble here to reorder the
766 # indeterminates, so that it's easier to evaluate the
767 # characteristic polynomial at x's coordinates and get back
768 # something in terms of t, which is what we want.
769 S
= PolynomialRing(self
.base_ring(),'t')
773 S
= PolynomialRing(S
, R
.variable_names())
776 return (t
**r
+ sum( a
[k
]*(t
**k
) for k
in range(r
) ))
778 def coordinate_polynomial_ring(self
):
780 The multivariate polynomial ring in which this algebra's
781 :meth:`characteristic_polynomial_of` lives.
785 sage: from mjo.eja.eja_algebra import (HadamardEJA,
786 ....: RealSymmetricEJA)
790 sage: J = HadamardEJA(2)
791 sage: J.coordinate_polynomial_ring()
792 Multivariate Polynomial Ring in X1, X2...
793 sage: J = RealSymmetricEJA(3,field=QQ,orthonormalize=False)
794 sage: J.coordinate_polynomial_ring()
795 Multivariate Polynomial Ring in X1, X2, X3, X4, X5, X6...
798 var_names
= tuple( "X%d" % z
for z
in range(1, self
.dimension()+1) )
799 return PolynomialRing(self
.base_ring(), var_names
)
801 def inner_product(self
, x
, y
):
803 The inner product associated with this Euclidean Jordan algebra.
805 Defaults to the trace inner product, but can be overridden by
806 subclasses if they are sure that the necessary properties are
811 sage: from mjo.eja.eja_algebra import (random_eja,
813 ....: BilinearFormEJA)
817 Our inner product is "associative," which means the following for
818 a symmetric bilinear form::
820 sage: set_random_seed()
821 sage: J = random_eja()
822 sage: x,y,z = J.random_elements(3)
823 sage: (x*y).inner_product(z) == y.inner_product(x*z)
828 Ensure that this is the usual inner product for the algebras
831 sage: set_random_seed()
832 sage: J = HadamardEJA.random_instance()
833 sage: x,y = J.random_elements(2)
834 sage: actual = x.inner_product(y)
835 sage: expected = x.to_vector().inner_product(y.to_vector())
836 sage: actual == expected
839 Ensure that this is one-half of the trace inner-product in a
840 BilinearFormEJA that isn't just the reals (when ``n`` isn't
841 one). This is in Faraut and Koranyi, and also my "On the
844 sage: set_random_seed()
845 sage: J = BilinearFormEJA.random_instance()
846 sage: n = J.dimension()
847 sage: x = J.random_element()
848 sage: y = J.random_element()
849 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
852 B
= self
._inner
_product
_matrix
853 return (B
*x
.to_vector()).inner_product(y
.to_vector())
856 def is_trivial(self
):
858 Return whether or not this algebra is trivial.
860 A trivial algebra contains only the zero element.
864 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
869 sage: J = ComplexHermitianEJA(3)
875 sage: J = TrivialEJA()
880 return self
.dimension() == 0
883 def multiplication_table(self
):
885 Return a visual representation of this algebra's multiplication
886 table (on basis elements).
890 sage: from mjo.eja.eja_algebra import JordanSpinEJA
894 sage: J = JordanSpinEJA(4)
895 sage: J.multiplication_table()
896 +----++----+----+----+----+
897 | * || b0 | b1 | b2 | b3 |
898 +====++====+====+====+====+
899 | b0 || b0 | b1 | b2 | b3 |
900 +----++----+----+----+----+
901 | b1 || b1 | b0 | 0 | 0 |
902 +----++----+----+----+----+
903 | b2 || b2 | 0 | b0 | 0 |
904 +----++----+----+----+----+
905 | b3 || b3 | 0 | 0 | b0 |
906 +----++----+----+----+----+
910 # Prepend the header row.
911 M
= [["*"] + list(self
.gens())]
913 # And to each subsequent row, prepend an entry that belongs to
914 # the left-side "header column."
915 M
+= [ [self
.monomial(i
)] + [ self
.monomial(i
)*self
.monomial(j
)
919 return table(M
, header_row
=True, header_column
=True, frame
=True)
922 def matrix_basis(self
):
924 Return an (often more natural) representation of this algebras
925 basis as an ordered tuple of matrices.
927 Every finite-dimensional Euclidean Jordan Algebra is a, up to
928 Jordan isomorphism, a direct sum of five simple
929 algebras---four of which comprise Hermitian matrices. And the
930 last type of algebra can of course be thought of as `n`-by-`1`
931 column matrices (ambiguusly called column vectors) to avoid
932 special cases. As a result, matrices (and column vectors) are
933 a natural representation format for Euclidean Jordan algebra
936 But, when we construct an algebra from a basis of matrices,
937 those matrix representations are lost in favor of coordinate
938 vectors *with respect to* that basis. We could eventually
939 convert back if we tried hard enough, but having the original
940 representations handy is valuable enough that we simply store
941 them and return them from this method.
943 Why implement this for non-matrix algebras? Avoiding special
944 cases for the :class:`BilinearFormEJA` pays with simplicity in
945 its own right. But mainly, we would like to be able to assume
946 that elements of a :class:`CartesianProductEJA` can be displayed
947 nicely, without having to have special classes for direct sums
948 one of whose components was a matrix algebra.
952 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
953 ....: RealSymmetricEJA)
957 sage: J = RealSymmetricEJA(2)
959 Finite family {0: b0, 1: b1, 2: b2}
960 sage: J.matrix_basis()
962 [1 0] [ 0 0.7071067811865475?] [0 0]
963 [0 0], [0.7071067811865475? 0], [0 1]
968 sage: J = JordanSpinEJA(2)
970 Finite family {0: b0, 1: b1}
971 sage: J.matrix_basis()
977 return self
._matrix
_basis
980 def matrix_space(self
):
982 Return the matrix space in which this algebra's elements live, if
983 we think of them as matrices (including column vectors of the
986 "By default" this will be an `n`-by-`1` column-matrix space,
987 except when the algebra is trivial. There it's `n`-by-`n`
988 (where `n` is zero), to ensure that two elements of the matrix
989 space (empty matrices) can be multiplied. For algebras of
990 matrices, this returns the space in which their
991 real embeddings live.
995 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
997 ....: QuaternionHermitianEJA,
1002 By default, the matrix representation is just a column-matrix
1003 equivalent to the vector representation::
1005 sage: J = JordanSpinEJA(3)
1006 sage: J.matrix_space()
1007 Full MatrixSpace of 3 by 1 dense matrices over Algebraic
1010 The matrix representation in the trivial algebra is
1011 zero-by-zero instead of the usual `n`-by-one::
1013 sage: J = TrivialEJA()
1014 sage: J.matrix_space()
1015 Full MatrixSpace of 0 by 0 dense matrices over Algebraic
1018 The matrix space for complex/quaternion Hermitian matrix EJA
1019 is the space in which their real-embeddings live, not the
1020 original complex/quaternion matrix space::
1022 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1023 sage: J.matrix_space()
1024 Module of 2 by 2 matrices with entries in Algebraic Field over
1025 the scalar ring Rational Field
1026 sage: J = QuaternionHermitianEJA(1,field=QQ,orthonormalize=False)
1027 sage: J.matrix_space()
1028 Module of 1 by 1 matrices with entries in Quaternion
1029 Algebra (-1, -1) with base ring Rational Field over
1030 the scalar ring Rational Field
1033 if self
.is_trivial():
1034 return MatrixSpace(self
.base_ring(), 0)
1036 return self
.matrix_basis()[0].parent()
1042 Return the unit element of this algebra.
1046 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1051 We can compute unit element in the Hadamard EJA::
1053 sage: J = HadamardEJA(5)
1055 b0 + b1 + b2 + b3 + b4
1057 The unit element in the Hadamard EJA is inherited in the
1058 subalgebras generated by its elements::
1060 sage: J = HadamardEJA(5)
1062 b0 + b1 + b2 + b3 + b4
1063 sage: x = sum(J.gens())
1064 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1067 sage: A.one().superalgebra_element()
1068 b0 + b1 + b2 + b3 + b4
1072 The identity element acts like the identity, regardless of
1073 whether or not we orthonormalize::
1075 sage: set_random_seed()
1076 sage: J = random_eja()
1077 sage: x = J.random_element()
1078 sage: J.one()*x == x and x*J.one() == x
1080 sage: A = x.subalgebra_generated_by()
1081 sage: y = A.random_element()
1082 sage: A.one()*y == y and y*A.one() == y
1087 sage: set_random_seed()
1088 sage: J = random_eja(field=QQ, orthonormalize=False)
1089 sage: x = J.random_element()
1090 sage: J.one()*x == x and x*J.one() == x
1092 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1093 sage: y = A.random_element()
1094 sage: A.one()*y == y and y*A.one() == y
1097 The matrix of the unit element's operator is the identity,
1098 regardless of the base field and whether or not we
1101 sage: set_random_seed()
1102 sage: J = random_eja()
1103 sage: actual = J.one().operator().matrix()
1104 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1105 sage: actual == expected
1107 sage: x = J.random_element()
1108 sage: A = x.subalgebra_generated_by()
1109 sage: actual = A.one().operator().matrix()
1110 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1111 sage: actual == expected
1116 sage: set_random_seed()
1117 sage: J = random_eja(field=QQ, orthonormalize=False)
1118 sage: actual = J.one().operator().matrix()
1119 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1120 sage: actual == expected
1122 sage: x = J.random_element()
1123 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1124 sage: actual = A.one().operator().matrix()
1125 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1126 sage: actual == expected
1129 Ensure that the cached unit element (often precomputed by
1130 hand) agrees with the computed one::
1132 sage: set_random_seed()
1133 sage: J = random_eja()
1134 sage: cached = J.one()
1135 sage: J.one.clear_cache()
1136 sage: J.one() == cached
1141 sage: set_random_seed()
1142 sage: J = random_eja(field=QQ, orthonormalize=False)
1143 sage: cached = J.one()
1144 sage: J.one.clear_cache()
1145 sage: J.one() == cached
1149 # We can brute-force compute the matrices of the operators
1150 # that correspond to the basis elements of this algebra.
1151 # If some linear combination of those basis elements is the
1152 # algebra identity, then the same linear combination of
1153 # their matrices has to be the identity matrix.
1155 # Of course, matrices aren't vectors in sage, so we have to
1156 # appeal to the "long vectors" isometry.
1157 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
1159 # Now we use basic linear algebra to find the coefficients,
1160 # of the matrices-as-vectors-linear-combination, which should
1161 # work for the original algebra basis too.
1162 A
= matrix(self
.base_ring(), oper_vecs
)
1164 # We used the isometry on the left-hand side already, but we
1165 # still need to do it for the right-hand side. Recall that we
1166 # wanted something that summed to the identity matrix.
1167 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
1169 # Now if there's an identity element in the algebra, this
1170 # should work. We solve on the left to avoid having to
1171 # transpose the matrix "A".
1172 return self
.from_vector(A
.solve_left(b
))
1175 def peirce_decomposition(self
, c
):
1177 The Peirce decomposition of this algebra relative to the
1180 In the future, this can be extended to a complete system of
1181 orthogonal idempotents.
1185 - ``c`` -- an idempotent of this algebra.
1189 A triple (J0, J5, J1) containing two subalgebras and one subspace
1192 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
1193 corresponding to the eigenvalue zero.
1195 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
1196 corresponding to the eigenvalue one-half.
1198 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
1199 corresponding to the eigenvalue one.
1201 These are the only possible eigenspaces for that operator, and this
1202 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
1203 orthogonal, and are subalgebras of this algebra with the appropriate
1208 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
1212 The canonical example comes from the symmetric matrices, which
1213 decompose into diagonal and off-diagonal parts::
1215 sage: J = RealSymmetricEJA(3)
1216 sage: C = matrix(QQ, [ [1,0,0],
1220 sage: J0,J5,J1 = J.peirce_decomposition(c)
1222 Euclidean Jordan algebra of dimension 1...
1224 Vector space of degree 6 and dimension 2...
1226 Euclidean Jordan algebra of dimension 3...
1227 sage: J0.one().to_matrix()
1231 sage: orig_df = AA.options.display_format
1232 sage: AA.options.display_format = 'radical'
1233 sage: J.from_vector(J5.basis()[0]).to_matrix()
1237 sage: J.from_vector(J5.basis()[1]).to_matrix()
1241 sage: AA.options.display_format = orig_df
1242 sage: J1.one().to_matrix()
1249 Every algebra decomposes trivially with respect to its identity
1252 sage: set_random_seed()
1253 sage: J = random_eja()
1254 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
1255 sage: J0.dimension() == 0 and J5.dimension() == 0
1257 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
1260 The decomposition is into eigenspaces, and its components are
1261 therefore necessarily orthogonal. Moreover, the identity
1262 elements in the two subalgebras are the projections onto their
1263 respective subspaces of the superalgebra's identity element::
1265 sage: set_random_seed()
1266 sage: J = random_eja()
1267 sage: x = J.random_element()
1268 sage: if not J.is_trivial():
1269 ....: while x.is_nilpotent():
1270 ....: x = J.random_element()
1271 sage: c = x.subalgebra_idempotent()
1272 sage: J0,J5,J1 = J.peirce_decomposition(c)
1274 sage: for (w,y,z) in zip(J0.basis(), J5.basis(), J1.basis()):
1275 ....: w = w.superalgebra_element()
1276 ....: y = J.from_vector(y)
1277 ....: z = z.superalgebra_element()
1278 ....: ipsum += w.inner_product(y).abs()
1279 ....: ipsum += w.inner_product(z).abs()
1280 ....: ipsum += y.inner_product(z).abs()
1283 sage: J1(c) == J1.one()
1285 sage: J0(J.one() - c) == J0.one()
1289 if not c
.is_idempotent():
1290 raise ValueError("element is not idempotent: %s" % c
)
1292 # Default these to what they should be if they turn out to be
1293 # trivial, because eigenspaces_left() won't return eigenvalues
1294 # corresponding to trivial spaces (e.g. it returns only the
1295 # eigenspace corresponding to lambda=1 if you take the
1296 # decomposition relative to the identity element).
1297 trivial
= self
.subalgebra(())
1298 J0
= trivial
# eigenvalue zero
1299 J5
= VectorSpace(self
.base_ring(), 0) # eigenvalue one-half
1300 J1
= trivial
# eigenvalue one
1302 for (eigval
, eigspace
) in c
.operator().matrix().right_eigenspaces():
1303 if eigval
== ~
(self
.base_ring()(2)):
1306 gens
= tuple( self
.from_vector(b
) for b
in eigspace
.basis() )
1307 subalg
= self
.subalgebra(gens
, check_axioms
=False)
1313 raise ValueError("unexpected eigenvalue: %s" % eigval
)
1318 def random_element(self
, thorough
=False):
1320 Return a random element of this algebra.
1322 Our algebra superclass method only returns a linear
1323 combination of at most two basis elements. We instead
1324 want the vector space "random element" method that
1325 returns a more diverse selection.
1329 - ``thorough`` -- (boolean; default False) whether or not we
1330 should generate irrational coefficients for the random
1331 element when our base ring is irrational; this slows the
1332 algebra operations to a crawl, but any truly random method
1336 # For a general base ring... maybe we can trust this to do the
1337 # right thing? Unlikely, but.
1338 V
= self
.vector_space()
1339 v
= V
.random_element()
1341 if self
.base_ring() is AA
:
1342 # The "random element" method of the algebraic reals is
1343 # stupid at the moment, and only returns integers between
1344 # -2 and 2, inclusive:
1346 # https://trac.sagemath.org/ticket/30875
1348 # Instead, we implement our own "random vector" method,
1349 # and then coerce that into the algebra. We use the vector
1350 # space degree here instead of the dimension because a
1351 # subalgebra could (for example) be spanned by only two
1352 # vectors, each with five coordinates. We need to
1353 # generate all five coordinates.
1355 v
*= QQbar
.random_element().real()
1357 v
*= QQ
.random_element()
1359 return self
.from_vector(V
.coordinate_vector(v
))
1361 def random_elements(self
, count
, thorough
=False):
1363 Return ``count`` random elements as a tuple.
1367 - ``thorough`` -- (boolean; default False) whether or not we
1368 should generate irrational coefficients for the random
1369 elements when our base ring is irrational; this slows the
1370 algebra operations to a crawl, but any truly random method
1375 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1379 sage: J = JordanSpinEJA(3)
1380 sage: x,y,z = J.random_elements(3)
1381 sage: all( [ x in J, y in J, z in J ])
1383 sage: len( J.random_elements(10) ) == 10
1387 return tuple( self
.random_element(thorough
)
1388 for idx
in range(count
) )
1392 def _charpoly_coefficients(self
):
1394 The `r` polynomial coefficients of the "characteristic polynomial
1399 sage: from mjo.eja.eja_algebra import random_eja
1403 The theory shows that these are all homogeneous polynomials of
1406 sage: set_random_seed()
1407 sage: J = random_eja()
1408 sage: all(p.is_homogeneous() for p in J._charpoly_coefficients())
1412 n
= self
.dimension()
1413 R
= self
.coordinate_polynomial_ring()
1415 F
= R
.fraction_field()
1418 # From a result in my book, these are the entries of the
1419 # basis representation of L_x.
1420 return sum( vars[k
]*self
.monomial(k
).operator().matrix()[i
,j
]
1423 L_x
= matrix(F
, n
, n
, L_x_i_j
)
1426 if self
.rank
.is_in_cache():
1428 # There's no need to pad the system with redundant
1429 # columns if we *know* they'll be redundant.
1432 # Compute an extra power in case the rank is equal to
1433 # the dimension (otherwise, we would stop at x^(r-1)).
1434 x_powers
= [ (L_x
**k
)*self
.one().to_vector()
1435 for k
in range(n
+1) ]
1436 A
= matrix
.column(F
, x_powers
[:n
])
1437 AE
= A
.extended_echelon_form()
1444 # The theory says that only the first "r" coefficients are
1445 # nonzero, and they actually live in the original polynomial
1446 # ring and not the fraction field. We negate them because in
1447 # the actual characteristic polynomial, they get moved to the
1448 # other side where x^r lives. We don't bother to trim A_rref
1449 # down to a square matrix and solve the resulting system,
1450 # because the upper-left r-by-r portion of A_rref is
1451 # guaranteed to be the identity matrix, so e.g.
1453 # A_rref.solve_right(Y)
1455 # would just be returning Y.
1456 return (-E
*b
)[:r
].change_ring(R
)
1461 Return the rank of this EJA.
1463 This is a cached method because we know the rank a priori for
1464 all of the algebras we can construct. Thus we can avoid the
1465 expensive ``_charpoly_coefficients()`` call unless we truly
1466 need to compute the whole characteristic polynomial.
1470 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1471 ....: JordanSpinEJA,
1472 ....: RealSymmetricEJA,
1473 ....: ComplexHermitianEJA,
1474 ....: QuaternionHermitianEJA,
1479 The rank of the Jordan spin algebra is always two::
1481 sage: JordanSpinEJA(2).rank()
1483 sage: JordanSpinEJA(3).rank()
1485 sage: JordanSpinEJA(4).rank()
1488 The rank of the `n`-by-`n` Hermitian real, complex, or
1489 quaternion matrices is `n`::
1491 sage: RealSymmetricEJA(4).rank()
1493 sage: ComplexHermitianEJA(3).rank()
1495 sage: QuaternionHermitianEJA(2).rank()
1500 Ensure that every EJA that we know how to construct has a
1501 positive integer rank, unless the algebra is trivial in
1502 which case its rank will be zero::
1504 sage: set_random_seed()
1505 sage: J = random_eja()
1509 sage: r > 0 or (r == 0 and J.is_trivial())
1512 Ensure that computing the rank actually works, since the ranks
1513 of all simple algebras are known and will be cached by default::
1515 sage: set_random_seed() # long time
1516 sage: J = random_eja() # long time
1517 sage: cached = J.rank() # long time
1518 sage: J.rank.clear_cache() # long time
1519 sage: J.rank() == cached # long time
1523 return len(self
._charpoly
_coefficients
())
1526 def subalgebra(self
, basis
, **kwargs
):
1528 Create a subalgebra of this algebra from the given basis.
1530 from mjo
.eja
.eja_subalgebra
import FiniteDimensionalEJASubalgebra
1531 return FiniteDimensionalEJASubalgebra(self
, basis
, **kwargs
)
1534 def vector_space(self
):
1536 Return the vector space that underlies this algebra.
1540 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1544 sage: J = RealSymmetricEJA(2)
1545 sage: J.vector_space()
1546 Vector space of dimension 3 over...
1549 return self
.zero().to_vector().parent().ambient_vector_space()
1553 class RationalBasisEJA(FiniteDimensionalEJA
):
1555 Algebras whose supplied basis elements have all rational entries.
1559 sage: from mjo.eja.eja_algebra import BilinearFormEJA
1563 The supplied basis is orthonormalized by default::
1565 sage: B = matrix(QQ, [[1, 0, 0], [0, 25, -32], [0, -32, 41]])
1566 sage: J = BilinearFormEJA(B)
1567 sage: J.matrix_basis()
1584 # Abuse the check_field parameter to check that the entries of
1585 # out basis (in ambient coordinates) are in the field QQ.
1586 # Use _all2list to get the vector coordinates of octonion
1587 # entries and not the octonions themselves (which are not
1589 if not all( all(b_i
in QQ
for b_i
in _all2list(b
))
1591 raise TypeError("basis not rational")
1593 super().__init
__(basis
,
1597 check_field
=check_field
,
1600 self
._rational
_algebra
= None
1602 # There's no point in constructing the extra algebra if this
1603 # one is already rational.
1605 # Note: the same Jordan and inner-products work here,
1606 # because they are necessarily defined with respect to
1607 # ambient coordinates and not any particular basis.
1608 self
._rational
_algebra
= FiniteDimensionalEJA(
1613 associative
=self
.is_associative(),
1614 orthonormalize
=False,
1619 def _charpoly_coefficients(self
):
1623 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1624 ....: JordanSpinEJA)
1628 The base ring of the resulting polynomial coefficients is what
1629 it should be, and not the rationals (unless the algebra was
1630 already over the rationals)::
1632 sage: J = JordanSpinEJA(3)
1633 sage: J._charpoly_coefficients()
1634 (X1^2 - X2^2 - X3^2, -2*X1)
1635 sage: a0 = J._charpoly_coefficients()[0]
1637 Algebraic Real Field
1638 sage: a0.base_ring()
1639 Algebraic Real Field
1642 if self
._rational
_algebra
is None:
1643 # There's no need to construct *another* algebra over the
1644 # rationals if this one is already over the
1645 # rationals. Likewise, if we never orthonormalized our
1646 # basis, we might as well just use the given one.
1647 return super()._charpoly
_coefficients
()
1649 # Do the computation over the rationals. The answer will be
1650 # the same, because all we've done is a change of basis.
1651 # Then, change back from QQ to our real base ring
1652 a
= ( a_i
.change_ring(self
.base_ring())
1653 for a_i
in self
._rational
_algebra
._charpoly
_coefficients
() )
1655 if self
._deortho
_matrix
is None:
1656 # This can happen if our base ring was, say, AA and we
1657 # chose not to (or didn't need to) orthonormalize. It's
1658 # still faster to do the computations over QQ even if
1659 # the numbers in the boxes stay the same.
1662 # Otherwise, convert the coordinate variables back to the
1663 # deorthonormalized ones.
1664 R
= self
.coordinate_polynomial_ring()
1665 from sage
.modules
.free_module_element
import vector
1666 X
= vector(R
, R
.gens())
1667 BX
= self
._deortho
_matrix
*X
1669 subs_dict
= { X[i]: BX[i] for i in range(len(X)) }
1670 return tuple( a_i
.subs(subs_dict
) for a_i
in a
)
1672 class ConcreteEJA(FiniteDimensionalEJA
):
1674 A class for the Euclidean Jordan algebras that we know by name.
1676 These are the Jordan algebras whose basis, multiplication table,
1677 rank, and so on are known a priori. More to the point, they are
1678 the Euclidean Jordan algebras for which we are able to conjure up
1679 a "random instance."
1683 sage: from mjo.eja.eja_algebra import ConcreteEJA
1687 Our basis is normalized with respect to the algebra's inner
1688 product, unless we specify otherwise::
1690 sage: set_random_seed()
1691 sage: J = ConcreteEJA.random_instance()
1692 sage: all( b.norm() == 1 for b in J.gens() )
1695 Since our basis is orthonormal with respect to the algebra's inner
1696 product, and since we know that this algebra is an EJA, any
1697 left-multiplication operator's matrix will be symmetric because
1698 natural->EJA basis representation is an isometry and within the
1699 EJA the operator is self-adjoint by the Jordan axiom::
1701 sage: set_random_seed()
1702 sage: J = ConcreteEJA.random_instance()
1703 sage: x = J.random_element()
1704 sage: x.operator().is_self_adjoint()
1709 def _max_random_instance_size():
1711 Return an integer "size" that is an upper bound on the size of
1712 this algebra when it is used in a random test
1713 case. Unfortunately, the term "size" is ambiguous -- when
1714 dealing with `R^n` under either the Hadamard or Jordan spin
1715 product, the "size" refers to the dimension `n`. When dealing
1716 with a matrix algebra (real symmetric or complex/quaternion
1717 Hermitian), it refers to the size of the matrix, which is far
1718 less than the dimension of the underlying vector space.
1720 This method must be implemented in each subclass.
1722 raise NotImplementedError
1725 def random_instance(cls
, *args
, **kwargs
):
1727 Return a random instance of this type of algebra.
1729 This method should be implemented in each subclass.
1731 from sage
.misc
.prandom
import choice
1732 eja_class
= choice(cls
.__subclasses
__())
1734 # These all bubble up to the RationalBasisEJA superclass
1735 # constructor, so any (kw)args valid there are also valid
1737 return eja_class
.random_instance(*args
, **kwargs
)
1742 def _denormalized_basis(A
):
1744 Returns a basis for the space of complex Hermitian n-by-n matrices.
1746 Why do we embed these? Basically, because all of numerical linear
1747 algebra assumes that you're working with vectors consisting of `n`
1748 entries from a field and scalars from the same field. There's no way
1749 to tell SageMath that (for example) the vectors contain complex
1750 numbers, while the scalar field is real.
1754 sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
1755 ....: QuaternionMatrixAlgebra,
1756 ....: OctonionMatrixAlgebra)
1757 sage: from mjo.eja.eja_algebra import MatrixEJA
1761 sage: set_random_seed()
1762 sage: n = ZZ.random_element(1,5)
1763 sage: A = MatrixSpace(QQ, n)
1764 sage: B = MatrixEJA._denormalized_basis(A)
1765 sage: all( M.is_hermitian() for M in B)
1770 sage: set_random_seed()
1771 sage: n = ZZ.random_element(1,5)
1772 sage: A = ComplexMatrixAlgebra(n, scalars=QQ)
1773 sage: B = MatrixEJA._denormalized_basis(A)
1774 sage: all( M.is_hermitian() for M in B)
1779 sage: set_random_seed()
1780 sage: n = ZZ.random_element(1,5)
1781 sage: A = QuaternionMatrixAlgebra(n, scalars=QQ)
1782 sage: B = MatrixEJA._denormalized_basis(A)
1783 sage: all( M.is_hermitian() for M in B )
1788 sage: set_random_seed()
1789 sage: n = ZZ.random_element(1,5)
1790 sage: A = OctonionMatrixAlgebra(n, scalars=QQ)
1791 sage: B = MatrixEJA._denormalized_basis(A)
1792 sage: all( M.is_hermitian() for M in B )
1796 # These work for real MatrixSpace, whose monomials only have
1797 # two coordinates (because the last one would always be "1").
1798 es
= A
.base_ring().gens()
1799 gen
= lambda A
,m
: A
.monomial(m
[:2])
1801 if hasattr(A
, 'entry_algebra_gens'):
1802 # We've got a MatrixAlgebra, and its monomials will have
1803 # three coordinates.
1804 es
= A
.entry_algebra_gens()
1805 gen
= lambda A
,m
: A
.monomial(m
)
1808 for i
in range(A
.nrows()):
1809 for j
in range(i
+1):
1811 E_ii
= gen(A
, (i
,j
,es
[0]))
1815 E_ij
= gen(A
, (i
,j
,e
))
1816 E_ij
+= E_ij
.conjugate_transpose()
1819 return tuple( basis
)
1822 def jordan_product(X
,Y
):
1823 return (X
*Y
+ Y
*X
)/2
1826 def trace_inner_product(X
,Y
):
1828 A trace inner-product for matrices that aren't embedded in the
1829 reals. It takes MATRICES as arguments, not EJA elements.
1833 sage: from mjo.eja.eja_algebra import (RealSymmetricEJA,
1834 ....: ComplexHermitianEJA,
1835 ....: QuaternionHermitianEJA,
1836 ....: OctonionHermitianEJA)
1840 sage: J = RealSymmetricEJA(2,field=QQ,orthonormalize=False)
1841 sage: I = J.one().to_matrix()
1842 sage: J.trace_inner_product(I, -I)
1847 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1848 sage: I = J.one().to_matrix()
1849 sage: J.trace_inner_product(I, -I)
1854 sage: J = QuaternionHermitianEJA(2,field=QQ,orthonormalize=False)
1855 sage: I = J.one().to_matrix()
1856 sage: J.trace_inner_product(I, -I)
1861 sage: J = OctonionHermitianEJA(2,field=QQ,orthonormalize=False)
1862 sage: I = J.one().to_matrix()
1863 sage: J.trace_inner_product(I, -I)
1868 if hasattr(tr
, 'coefficient'):
1869 # Works for octonions, and has to come first because they
1870 # also have a "real()" method that doesn't return an
1871 # element of the scalar ring.
1872 return tr
.coefficient(0)
1873 elif hasattr(tr
, 'coefficient_tuple'):
1874 # Works for quaternions.
1875 return tr
.coefficient_tuple()[0]
1877 # Works for real and complex numbers.
1882 class RealSymmetricEJA(RationalBasisEJA
, ConcreteEJA
, MatrixEJA
):
1884 The rank-n simple EJA consisting of real symmetric n-by-n
1885 matrices, the usual symmetric Jordan product, and the trace inner
1886 product. It has dimension `(n^2 + n)/2` over the reals.
1890 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1894 sage: J = RealSymmetricEJA(2)
1895 sage: b0, b1, b2 = J.gens()
1903 In theory, our "field" can be any subfield of the reals::
1905 sage: RealSymmetricEJA(2, field=RDF, check_axioms=True)
1906 Euclidean Jordan algebra of dimension 3 over Real Double Field
1907 sage: RealSymmetricEJA(2, field=RR, check_axioms=True)
1908 Euclidean Jordan algebra of dimension 3 over Real Field with
1909 53 bits of precision
1913 The dimension of this algebra is `(n^2 + n) / 2`::
1915 sage: set_random_seed()
1916 sage: n_max = RealSymmetricEJA._max_random_instance_size()
1917 sage: n = ZZ.random_element(1, n_max)
1918 sage: J = RealSymmetricEJA(n)
1919 sage: J.dimension() == (n^2 + n)/2
1922 The Jordan multiplication is what we think it is::
1924 sage: set_random_seed()
1925 sage: J = RealSymmetricEJA.random_instance()
1926 sage: x,y = J.random_elements(2)
1927 sage: actual = (x*y).to_matrix()
1928 sage: X = x.to_matrix()
1929 sage: Y = y.to_matrix()
1930 sage: expected = (X*Y + Y*X)/2
1931 sage: actual == expected
1933 sage: J(expected) == x*y
1936 We can change the generator prefix::
1938 sage: RealSymmetricEJA(3, prefix='q').gens()
1939 (q0, q1, q2, q3, q4, q5)
1941 We can construct the (trivial) algebra of rank zero::
1943 sage: RealSymmetricEJA(0)
1944 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
1948 def _max_random_instance_size():
1949 return 4 # Dimension 10
1952 def random_instance(cls
, **kwargs
):
1954 Return a random instance of this type of algebra.
1956 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
1957 return cls(n
, **kwargs
)
1959 def __init__(self
, n
, field
=AA
, **kwargs
):
1960 # We know this is a valid EJA, but will double-check
1961 # if the user passes check_axioms=True.
1962 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
1964 A
= MatrixSpace(field
, n
)
1965 super().__init
__(self
._denormalized
_basis
(A
),
1966 self
.jordan_product
,
1967 self
.trace_inner_product
,
1971 # TODO: this could be factored out somehow, but is left here
1972 # because the MatrixEJA is not presently a subclass of the
1973 # FDEJA class that defines rank() and one().
1974 self
.rank
.set_cache(n
)
1975 self
.one
.set_cache(self(A
.one()))
1979 class ComplexHermitianEJA(RationalBasisEJA
, ConcreteEJA
, MatrixEJA
):
1981 The rank-n simple EJA consisting of complex Hermitian n-by-n
1982 matrices over the real numbers, the usual symmetric Jordan product,
1983 and the real-part-of-trace inner product. It has dimension `n^2` over
1988 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1992 In theory, our "field" can be any subfield of the reals::
1994 sage: ComplexHermitianEJA(2, field=RDF, check_axioms=True)
1995 Euclidean Jordan algebra of dimension 4 over Real Double Field
1996 sage: ComplexHermitianEJA(2, field=RR, check_axioms=True)
1997 Euclidean Jordan algebra of dimension 4 over Real Field with
1998 53 bits of precision
2002 The dimension of this algebra is `n^2`::
2004 sage: set_random_seed()
2005 sage: n_max = ComplexHermitianEJA._max_random_instance_size()
2006 sage: n = ZZ.random_element(1, n_max)
2007 sage: J = ComplexHermitianEJA(n)
2008 sage: J.dimension() == n^2
2011 The Jordan multiplication is what we think it is::
2013 sage: set_random_seed()
2014 sage: J = ComplexHermitianEJA.random_instance()
2015 sage: x,y = J.random_elements(2)
2016 sage: actual = (x*y).to_matrix()
2017 sage: X = x.to_matrix()
2018 sage: Y = y.to_matrix()
2019 sage: expected = (X*Y + Y*X)/2
2020 sage: actual == expected
2022 sage: J(expected) == x*y
2025 We can change the generator prefix::
2027 sage: ComplexHermitianEJA(2, prefix='z').gens()
2030 We can construct the (trivial) algebra of rank zero::
2032 sage: ComplexHermitianEJA(0)
2033 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2036 def __init__(self
, n
, field
=AA
, **kwargs
):
2037 # We know this is a valid EJA, but will double-check
2038 # if the user passes check_axioms=True.
2039 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2041 from mjo
.hurwitz
import ComplexMatrixAlgebra
2042 A
= ComplexMatrixAlgebra(n
, scalars
=field
)
2043 super().__init
__(self
._denormalized
_basis
(A
),
2044 self
.jordan_product
,
2045 self
.trace_inner_product
,
2049 # TODO: this could be factored out somehow, but is left here
2050 # because the MatrixEJA is not presently a subclass of the
2051 # FDEJA class that defines rank() and one().
2052 self
.rank
.set_cache(n
)
2053 self
.one
.set_cache(self(A
.one()))
2056 def _max_random_instance_size():
2057 return 3 # Dimension 9
2060 def random_instance(cls
, **kwargs
):
2062 Return a random instance of this type of algebra.
2064 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2065 return cls(n
, **kwargs
)
2068 class QuaternionHermitianEJA(RationalBasisEJA
, ConcreteEJA
, MatrixEJA
):
2070 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2071 matrices, the usual symmetric Jordan product, and the
2072 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2077 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2081 In theory, our "field" can be any subfield of the reals::
2083 sage: QuaternionHermitianEJA(2, field=RDF, check_axioms=True)
2084 Euclidean Jordan algebra of dimension 6 over Real Double Field
2085 sage: QuaternionHermitianEJA(2, field=RR, check_axioms=True)
2086 Euclidean Jordan algebra of dimension 6 over Real Field with
2087 53 bits of precision
2091 The dimension of this algebra is `2*n^2 - n`::
2093 sage: set_random_seed()
2094 sage: n_max = QuaternionHermitianEJA._max_random_instance_size()
2095 sage: n = ZZ.random_element(1, n_max)
2096 sage: J = QuaternionHermitianEJA(n)
2097 sage: J.dimension() == 2*(n^2) - n
2100 The Jordan multiplication is what we think it is::
2102 sage: set_random_seed()
2103 sage: J = QuaternionHermitianEJA.random_instance()
2104 sage: x,y = J.random_elements(2)
2105 sage: actual = (x*y).to_matrix()
2106 sage: X = x.to_matrix()
2107 sage: Y = y.to_matrix()
2108 sage: expected = (X*Y + Y*X)/2
2109 sage: actual == expected
2111 sage: J(expected) == x*y
2114 We can change the generator prefix::
2116 sage: QuaternionHermitianEJA(2, prefix='a').gens()
2117 (a0, a1, a2, a3, a4, a5)
2119 We can construct the (trivial) algebra of rank zero::
2121 sage: QuaternionHermitianEJA(0)
2122 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2125 def __init__(self
, n
, field
=AA
, **kwargs
):
2126 # We know this is a valid EJA, but will double-check
2127 # if the user passes check_axioms=True.
2128 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2130 from mjo
.hurwitz
import QuaternionMatrixAlgebra
2131 A
= QuaternionMatrixAlgebra(n
, scalars
=field
)
2132 super().__init
__(self
._denormalized
_basis
(A
),
2133 self
.jordan_product
,
2134 self
.trace_inner_product
,
2138 # TODO: this could be factored out somehow, but is left here
2139 # because the MatrixEJA is not presently a subclass of the
2140 # FDEJA class that defines rank() and one().
2141 self
.rank
.set_cache(n
)
2142 self
.one
.set_cache(self(A
.one()))
2146 def _max_random_instance_size():
2148 The maximum rank of a random QuaternionHermitianEJA.
2150 return 2 # Dimension 6
2153 def random_instance(cls
, **kwargs
):
2155 Return a random instance of this type of algebra.
2157 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2158 return cls(n
, **kwargs
)
2160 class OctonionHermitianEJA(RationalBasisEJA
, ConcreteEJA
, MatrixEJA
):
2164 sage: from mjo.eja.eja_algebra import (FiniteDimensionalEJA,
2165 ....: OctonionHermitianEJA)
2166 sage: from mjo.hurwitz import Octonions, OctonionMatrixAlgebra
2170 The 3-by-3 algebra satisfies the axioms of an EJA::
2172 sage: OctonionHermitianEJA(3, # long time
2173 ....: field=QQ, # long time
2174 ....: orthonormalize=False, # long time
2175 ....: check_axioms=True) # long time
2176 Euclidean Jordan algebra of dimension 27 over Rational Field
2178 After a change-of-basis, the 2-by-2 algebra has the same
2179 multiplication table as the ten-dimensional Jordan spin algebra::
2181 sage: A = OctonionMatrixAlgebra(2,Octonions(QQ),QQ)
2182 sage: b = OctonionHermitianEJA._denormalized_basis(A)
2183 sage: basis = (b[0] + b[9],) + b[1:9] + (b[0] - b[9],)
2184 sage: jp = OctonionHermitianEJA.jordan_product
2185 sage: ip = OctonionHermitianEJA.trace_inner_product
2186 sage: J = FiniteDimensionalEJA(basis,
2190 ....: orthonormalize=False)
2191 sage: J.multiplication_table()
2192 +----++----+----+----+----+----+----+----+----+----+----+
2193 | * || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2194 +====++====+====+====+====+====+====+====+====+====+====+
2195 | b0 || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2196 +----++----+----+----+----+----+----+----+----+----+----+
2197 | b1 || b1 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2198 +----++----+----+----+----+----+----+----+----+----+----+
2199 | b2 || b2 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2200 +----++----+----+----+----+----+----+----+----+----+----+
2201 | b3 || b3 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 |
2202 +----++----+----+----+----+----+----+----+----+----+----+
2203 | b4 || b4 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 |
2204 +----++----+----+----+----+----+----+----+----+----+----+
2205 | b5 || b5 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 |
2206 +----++----+----+----+----+----+----+----+----+----+----+
2207 | b6 || b6 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 |
2208 +----++----+----+----+----+----+----+----+----+----+----+
2209 | b7 || b7 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 |
2210 +----++----+----+----+----+----+----+----+----+----+----+
2211 | b8 || b8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 |
2212 +----++----+----+----+----+----+----+----+----+----+----+
2213 | b9 || b9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 |
2214 +----++----+----+----+----+----+----+----+----+----+----+
2218 We can actually construct the 27-dimensional Albert algebra,
2219 and we get the right unit element if we recompute it::
2221 sage: J = OctonionHermitianEJA(3, # long time
2222 ....: field=QQ, # long time
2223 ....: orthonormalize=False) # long time
2224 sage: J.one.clear_cache() # long time
2225 sage: J.one() # long time
2227 sage: J.one().to_matrix() # long time
2236 The 2-by-2 algebra is isomorphic to the ten-dimensional Jordan
2237 spin algebra, but just to be sure, we recompute its rank::
2239 sage: J = OctonionHermitianEJA(2, # long time
2240 ....: field=QQ, # long time
2241 ....: orthonormalize=False) # long time
2242 sage: J.rank.clear_cache() # long time
2243 sage: J.rank() # long time
2248 def _max_random_instance_size():
2250 The maximum rank of a random QuaternionHermitianEJA.
2252 return 1 # Dimension 1
2255 def random_instance(cls
, **kwargs
):
2257 Return a random instance of this type of algebra.
2259 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2260 return cls(n
, **kwargs
)
2262 def __init__(self
, n
, field
=AA
, **kwargs
):
2264 # Otherwise we don't get an EJA.
2265 raise ValueError("n cannot exceed 3")
2267 # We know this is a valid EJA, but will double-check
2268 # if the user passes check_axioms=True.
2269 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2271 from mjo
.hurwitz
import OctonionMatrixAlgebra
2272 A
= OctonionMatrixAlgebra(n
, scalars
=field
)
2273 super().__init
__(self
._denormalized
_basis
(A
),
2274 self
.jordan_product
,
2275 self
.trace_inner_product
,
2279 # TODO: this could be factored out somehow, but is left here
2280 # because the MatrixEJA is not presently a subclass of the
2281 # FDEJA class that defines rank() and one().
2282 self
.rank
.set_cache(n
)
2283 self
.one
.set_cache(self(A
.one()))
2286 class AlbertEJA(OctonionHermitianEJA
):
2288 The Albert algebra is the algebra of three-by-three Hermitian
2289 matrices whose entries are octonions.
2293 sage: from mjo.eja.eja_algebra import AlbertEJA
2297 sage: AlbertEJA(field=QQ, orthonormalize=False)
2298 Euclidean Jordan algebra of dimension 27 over Rational Field
2299 sage: AlbertEJA() # long time
2300 Euclidean Jordan algebra of dimension 27 over Algebraic Real Field
2303 def __init__(self
, *args
, **kwargs
):
2304 super().__init
__(3, *args
, **kwargs
)
2307 class HadamardEJA(RationalBasisEJA
, ConcreteEJA
):
2309 Return the Euclidean Jordan algebra on `R^n` with the Hadamard
2310 (pointwise real-number multiplication) Jordan product and the
2311 usual inner-product.
2313 This is nothing more than the Cartesian product of ``n`` copies of
2314 the one-dimensional Jordan spin algebra, and is the most common
2315 example of a non-simple Euclidean Jordan algebra.
2319 sage: from mjo.eja.eja_algebra import HadamardEJA
2323 This multiplication table can be verified by hand::
2325 sage: J = HadamardEJA(3)
2326 sage: b0,b1,b2 = J.gens()
2342 We can change the generator prefix::
2344 sage: HadamardEJA(3, prefix='r').gens()
2347 def __init__(self
, n
, field
=AA
, **kwargs
):
2349 jordan_product
= lambda x
,y
: x
2350 inner_product
= lambda x
,y
: x
2352 def jordan_product(x
,y
):
2354 return P( xi
*yi
for (xi
,yi
) in zip(x
,y
) )
2356 def inner_product(x
,y
):
2359 # New defaults for keyword arguments. Don't orthonormalize
2360 # because our basis is already orthonormal with respect to our
2361 # inner-product. Don't check the axioms, because we know this
2362 # is a valid EJA... but do double-check if the user passes
2363 # check_axioms=True. Note: we DON'T override the "check_field"
2364 # default here, because the user can pass in a field!
2365 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2366 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2368 column_basis
= tuple( b
.column()
2369 for b
in FreeModule(field
, n
).basis() )
2370 super().__init
__(column_basis
,
2376 self
.rank
.set_cache(n
)
2379 self
.one
.set_cache( self
.zero() )
2381 self
.one
.set_cache( sum(self
.gens()) )
2384 def _max_random_instance_size():
2386 The maximum dimension of a random HadamardEJA.
2391 def random_instance(cls
, **kwargs
):
2393 Return a random instance of this type of algebra.
2395 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2396 return cls(n
, **kwargs
)
2399 class BilinearFormEJA(RationalBasisEJA
, ConcreteEJA
):
2401 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2402 with the half-trace inner product and jordan product ``x*y =
2403 (<Bx,y>,y_bar>, x0*y_bar + y0*x_bar)`` where `B = 1 \times B22` is
2404 a symmetric positive-definite "bilinear form" matrix. Its
2405 dimension is the size of `B`, and it has rank two in dimensions
2406 larger than two. It reduces to the ``JordanSpinEJA`` when `B` is
2407 the identity matrix of order ``n``.
2409 We insist that the one-by-one upper-left identity block of `B` be
2410 passed in as well so that we can be passed a matrix of size zero
2411 to construct a trivial algebra.
2415 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
2416 ....: JordanSpinEJA)
2420 When no bilinear form is specified, the identity matrix is used,
2421 and the resulting algebra is the Jordan spin algebra::
2423 sage: B = matrix.identity(AA,3)
2424 sage: J0 = BilinearFormEJA(B)
2425 sage: J1 = JordanSpinEJA(3)
2426 sage: J0.multiplication_table() == J0.multiplication_table()
2429 An error is raised if the matrix `B` does not correspond to a
2430 positive-definite bilinear form::
2432 sage: B = matrix.random(QQ,2,3)
2433 sage: J = BilinearFormEJA(B)
2434 Traceback (most recent call last):
2436 ValueError: bilinear form is not positive-definite
2437 sage: B = matrix.zero(QQ,3)
2438 sage: J = BilinearFormEJA(B)
2439 Traceback (most recent call last):
2441 ValueError: bilinear form is not positive-definite
2445 We can create a zero-dimensional algebra::
2447 sage: B = matrix.identity(AA,0)
2448 sage: J = BilinearFormEJA(B)
2452 We can check the multiplication condition given in the Jordan, von
2453 Neumann, and Wigner paper (and also discussed on my "On the
2454 symmetry..." paper). Note that this relies heavily on the standard
2455 choice of basis, as does anything utilizing the bilinear form
2456 matrix. We opt not to orthonormalize the basis, because if we
2457 did, we would have to normalize the `s_{i}` in a similar manner::
2459 sage: set_random_seed()
2460 sage: n = ZZ.random_element(5)
2461 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2462 sage: B11 = matrix.identity(QQ,1)
2463 sage: B22 = M.transpose()*M
2464 sage: B = block_matrix(2,2,[ [B11,0 ],
2466 sage: J = BilinearFormEJA(B, orthonormalize=False)
2467 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
2468 sage: V = J.vector_space()
2469 sage: sis = [ J( V([0] + (M.inverse()*ei).list()).column() )
2470 ....: for ei in eis ]
2471 sage: actual = [ sis[i]*sis[j]
2472 ....: for i in range(n-1)
2473 ....: for j in range(n-1) ]
2474 sage: expected = [ J.one() if i == j else J.zero()
2475 ....: for i in range(n-1)
2476 ....: for j in range(n-1) ]
2477 sage: actual == expected
2481 def __init__(self
, B
, field
=AA
, **kwargs
):
2482 # The matrix "B" is supplied by the user in most cases,
2483 # so it makes sense to check whether or not its positive-
2484 # definite unless we are specifically asked not to...
2485 if ("check_axioms" not in kwargs
) or kwargs
["check_axioms"]:
2486 if not B
.is_positive_definite():
2487 raise ValueError("bilinear form is not positive-definite")
2489 # However, all of the other data for this EJA is computed
2490 # by us in manner that guarantees the axioms are
2491 # satisfied. So, again, unless we are specifically asked to
2492 # verify things, we'll skip the rest of the checks.
2493 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2495 def inner_product(x
,y
):
2496 return (y
.T
*B
*x
)[0,0]
2498 def jordan_product(x
,y
):
2504 z0
= inner_product(y
,x
)
2505 zbar
= y0
*xbar
+ x0
*ybar
2506 return P([z0
] + zbar
.list())
2509 column_basis
= tuple( b
.column()
2510 for b
in FreeModule(field
, n
).basis() )
2512 # TODO: I haven't actually checked this, but it seems legit.
2517 super().__init
__(column_basis
,
2521 associative
=associative
,
2524 # The rank of this algebra is two, unless we're in a
2525 # one-dimensional ambient space (because the rank is bounded
2526 # by the ambient dimension).
2527 self
.rank
.set_cache(min(n
,2))
2530 self
.one
.set_cache( self
.zero() )
2532 self
.one
.set_cache( self
.monomial(0) )
2535 def _max_random_instance_size():
2537 The maximum dimension of a random BilinearFormEJA.
2542 def random_instance(cls
, **kwargs
):
2544 Return a random instance of this algebra.
2546 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2548 B
= matrix
.identity(ZZ
, n
)
2549 return cls(B
, **kwargs
)
2551 B11
= matrix
.identity(ZZ
, 1)
2552 M
= matrix
.random(ZZ
, n
-1)
2553 I
= matrix
.identity(ZZ
, n
-1)
2555 while alpha
.is_zero():
2556 alpha
= ZZ
.random_element().abs()
2557 B22
= M
.transpose()*M
+ alpha
*I
2559 from sage
.matrix
.special
import block_matrix
2560 B
= block_matrix(2,2, [ [B11
, ZZ(0) ],
2563 return cls(B
, **kwargs
)
2566 class JordanSpinEJA(BilinearFormEJA
):
2568 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2569 with the usual inner product and jordan product ``x*y =
2570 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2575 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2579 This multiplication table can be verified by hand::
2581 sage: J = JordanSpinEJA(4)
2582 sage: b0,b1,b2,b3 = J.gens()
2598 We can change the generator prefix::
2600 sage: JordanSpinEJA(2, prefix='B').gens()
2605 Ensure that we have the usual inner product on `R^n`::
2607 sage: set_random_seed()
2608 sage: J = JordanSpinEJA.random_instance()
2609 sage: x,y = J.random_elements(2)
2610 sage: actual = x.inner_product(y)
2611 sage: expected = x.to_vector().inner_product(y.to_vector())
2612 sage: actual == expected
2616 def __init__(self
, n
, *args
, **kwargs
):
2617 # This is a special case of the BilinearFormEJA with the
2618 # identity matrix as its bilinear form.
2619 B
= matrix
.identity(ZZ
, n
)
2621 # Don't orthonormalize because our basis is already
2622 # orthonormal with respect to our inner-product.
2623 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2625 # But also don't pass check_field=False here, because the user
2626 # can pass in a field!
2627 super().__init
__(B
, *args
, **kwargs
)
2630 def _max_random_instance_size():
2632 The maximum dimension of a random JordanSpinEJA.
2637 def random_instance(cls
, **kwargs
):
2639 Return a random instance of this type of algebra.
2641 Needed here to override the implementation for ``BilinearFormEJA``.
2643 n
= ZZ
.random_element(cls
._max
_random
_instance
_size
() + 1)
2644 return cls(n
, **kwargs
)
2647 class TrivialEJA(RationalBasisEJA
, ConcreteEJA
):
2649 The trivial Euclidean Jordan algebra consisting of only a zero element.
2653 sage: from mjo.eja.eja_algebra import TrivialEJA
2657 sage: J = TrivialEJA()
2664 sage: 7*J.one()*12*J.one()
2666 sage: J.one().inner_product(J.one())
2668 sage: J.one().norm()
2670 sage: J.one().subalgebra_generated_by()
2671 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2676 def __init__(self
, **kwargs
):
2677 jordan_product
= lambda x
,y
: x
2678 inner_product
= lambda x
,y
: 0
2681 # New defaults for keyword arguments
2682 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2683 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2685 super().__init
__(basis
,
2691 # The rank is zero using my definition, namely the dimension of the
2692 # largest subalgebra generated by any element.
2693 self
.rank
.set_cache(0)
2694 self
.one
.set_cache( self
.zero() )
2697 def random_instance(cls
, **kwargs
):
2698 # We don't take a "size" argument so the superclass method is
2699 # inappropriate for us.
2700 return cls(**kwargs
)
2703 class CartesianProductEJA(FiniteDimensionalEJA
):
2705 The external (orthogonal) direct sum of two or more Euclidean
2706 Jordan algebras. Every Euclidean Jordan algebra decomposes into an
2707 orthogonal direct sum of simple Euclidean Jordan algebras which is
2708 then isometric to a Cartesian product, so no generality is lost by
2709 providing only this construction.
2713 sage: from mjo.eja.eja_algebra import (random_eja,
2714 ....: CartesianProductEJA,
2716 ....: JordanSpinEJA,
2717 ....: RealSymmetricEJA)
2721 The Jordan product is inherited from our factors and implemented by
2722 our CombinatorialFreeModule Cartesian product superclass::
2724 sage: set_random_seed()
2725 sage: J1 = HadamardEJA(2)
2726 sage: J2 = RealSymmetricEJA(2)
2727 sage: J = cartesian_product([J1,J2])
2728 sage: x,y = J.random_elements(2)
2732 The ability to retrieve the original factors is implemented by our
2733 CombinatorialFreeModule Cartesian product superclass::
2735 sage: J1 = HadamardEJA(2, field=QQ)
2736 sage: J2 = JordanSpinEJA(3, field=QQ)
2737 sage: J = cartesian_product([J1,J2])
2738 sage: J.cartesian_factors()
2739 (Euclidean Jordan algebra of dimension 2 over Rational Field,
2740 Euclidean Jordan algebra of dimension 3 over Rational Field)
2742 You can provide more than two factors::
2744 sage: J1 = HadamardEJA(2)
2745 sage: J2 = JordanSpinEJA(3)
2746 sage: J3 = RealSymmetricEJA(3)
2747 sage: cartesian_product([J1,J2,J3])
2748 Euclidean Jordan algebra of dimension 2 over Algebraic Real
2749 Field (+) Euclidean Jordan algebra of dimension 3 over Algebraic
2750 Real Field (+) Euclidean Jordan algebra of dimension 6 over
2751 Algebraic Real Field
2753 Rank is additive on a Cartesian product::
2755 sage: J1 = HadamardEJA(1)
2756 sage: J2 = RealSymmetricEJA(2)
2757 sage: J = cartesian_product([J1,J2])
2758 sage: J1.rank.clear_cache()
2759 sage: J2.rank.clear_cache()
2760 sage: J.rank.clear_cache()
2763 sage: J.rank() == J1.rank() + J2.rank()
2766 The same rank computation works over the rationals, with whatever
2769 sage: J1 = HadamardEJA(1, field=QQ, orthonormalize=False)
2770 sage: J2 = RealSymmetricEJA(2, field=QQ, orthonormalize=False)
2771 sage: J = cartesian_product([J1,J2])
2772 sage: J1.rank.clear_cache()
2773 sage: J2.rank.clear_cache()
2774 sage: J.rank.clear_cache()
2777 sage: J.rank() == J1.rank() + J2.rank()
2780 The product algebra will be associative if and only if all of its
2781 components are associative::
2783 sage: J1 = HadamardEJA(2)
2784 sage: J1.is_associative()
2786 sage: J2 = HadamardEJA(3)
2787 sage: J2.is_associative()
2789 sage: J3 = RealSymmetricEJA(3)
2790 sage: J3.is_associative()
2792 sage: CP1 = cartesian_product([J1,J2])
2793 sage: CP1.is_associative()
2795 sage: CP2 = cartesian_product([J1,J3])
2796 sage: CP2.is_associative()
2799 Cartesian products of Cartesian products work::
2801 sage: J1 = JordanSpinEJA(1)
2802 sage: J2 = JordanSpinEJA(1)
2803 sage: J3 = JordanSpinEJA(1)
2804 sage: J = cartesian_product([J1,cartesian_product([J2,J3])])
2805 sage: J.multiplication_table()
2806 +----++----+----+----+
2807 | * || b0 | b1 | b2 |
2808 +====++====+====+====+
2809 | b0 || b0 | 0 | 0 |
2810 +----++----+----+----+
2811 | b1 || 0 | b1 | 0 |
2812 +----++----+----+----+
2813 | b2 || 0 | 0 | b2 |
2814 +----++----+----+----+
2815 sage: HadamardEJA(3).multiplication_table()
2816 +----++----+----+----+
2817 | * || b0 | b1 | b2 |
2818 +====++====+====+====+
2819 | b0 || b0 | 0 | 0 |
2820 +----++----+----+----+
2821 | b1 || 0 | b1 | 0 |
2822 +----++----+----+----+
2823 | b2 || 0 | 0 | b2 |
2824 +----++----+----+----+
2828 All factors must share the same base field::
2830 sage: J1 = HadamardEJA(2, field=QQ)
2831 sage: J2 = RealSymmetricEJA(2)
2832 sage: CartesianProductEJA((J1,J2))
2833 Traceback (most recent call last):
2835 ValueError: all factors must share the same base field
2837 The cached unit element is the same one that would be computed::
2839 sage: set_random_seed() # long time
2840 sage: J1 = random_eja() # long time
2841 sage: J2 = random_eja() # long time
2842 sage: J = cartesian_product([J1,J2]) # long time
2843 sage: actual = J.one() # long time
2844 sage: J.one.clear_cache() # long time
2845 sage: expected = J.one() # long time
2846 sage: actual == expected # long time
2850 Element
= FiniteDimensionalEJAElement
2853 def __init__(self
, factors
, **kwargs
):
2858 self
._sets
= factors
2860 field
= factors
[0].base_ring()
2861 if not all( J
.base_ring() == field
for J
in factors
):
2862 raise ValueError("all factors must share the same base field")
2864 associative
= all( f
.is_associative() for f
in factors
)
2866 MS
= self
.matrix_space()
2870 for b
in factors
[i
].matrix_basis():
2875 basis
= tuple( MS(b
) for b
in basis
)
2877 # Define jordan/inner products that operate on that matrix_basis.
2878 def jordan_product(x
,y
):
2880 (factors
[i
](x
[i
])*factors
[i
](y
[i
])).to_matrix()
2884 def inner_product(x
, y
):
2886 factors
[i
](x
[i
]).inner_product(factors
[i
](y
[i
]))
2890 # There's no need to check the field since it already came
2891 # from an EJA. Likewise the axioms are guaranteed to be
2892 # satisfied, unless the guy writing this class sucks.
2894 # If you want the basis to be orthonormalized, orthonormalize
2896 FiniteDimensionalEJA
.__init
__(self
,
2901 orthonormalize
=False,
2902 associative
=associative
,
2903 cartesian_product
=True,
2907 ones
= tuple(J
.one().to_matrix() for J
in factors
)
2908 self
.one
.set_cache(self(ones
))
2909 self
.rank
.set_cache(sum(J
.rank() for J
in factors
))
2911 def cartesian_factors(self
):
2912 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
2915 def cartesian_factor(self
, i
):
2917 Return the ``i``th factor of this algebra.
2919 return self
._sets
[i
]
2922 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
2923 from sage
.categories
.cartesian_product
import cartesian_product
2924 return cartesian_product
.symbol
.join("%s" % factor
2925 for factor
in self
._sets
)
2927 def matrix_space(self
):
2929 Return the space that our matrix basis lives in as a Cartesian
2932 We don't simply use the ``cartesian_product()`` functor here
2933 because it acts differently on SageMath MatrixSpaces and our
2934 custom MatrixAlgebras, which are CombinatorialFreeModules. We
2935 always want the result to be represented (and indexed) as
2940 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
2942 ....: OctonionHermitianEJA,
2943 ....: RealSymmetricEJA)
2947 sage: J1 = HadamardEJA(1)
2948 sage: J2 = RealSymmetricEJA(2)
2949 sage: J = cartesian_product([J1,J2])
2950 sage: J.matrix_space()
2951 The Cartesian product of (Full MatrixSpace of 1 by 1 dense
2952 matrices over Algebraic Real Field, Full MatrixSpace of 2
2953 by 2 dense matrices over Algebraic Real Field)
2957 sage: J1 = ComplexHermitianEJA(1)
2958 sage: J2 = ComplexHermitianEJA(1)
2959 sage: J = cartesian_product([J1,J2])
2960 sage: J.one().to_matrix()[0]
2964 sage: J.one().to_matrix()[1]
2971 sage: J1 = OctonionHermitianEJA(1)
2972 sage: J2 = OctonionHermitianEJA(1)
2973 sage: J = cartesian_product([J1,J2])
2974 sage: J.one().to_matrix()[0]
2978 sage: J.one().to_matrix()[1]
2984 scalars
= self
.cartesian_factor(0).base_ring()
2986 # This category isn't perfect, but is good enough for what we
2988 cat
= MagmaticAlgebras(scalars
).FiniteDimensional().WithBasis()
2989 cat
= cat
.Unital().CartesianProducts()
2990 factors
= tuple( J
.matrix_space() for J
in self
.cartesian_factors() )
2992 from sage
.sets
.cartesian_product
import CartesianProduct
2993 return CartesianProduct(factors
, cat
)
2997 def cartesian_projection(self
, i
):
3001 sage: from mjo.eja.eja_algebra import (random_eja,
3002 ....: JordanSpinEJA,
3004 ....: RealSymmetricEJA,
3005 ....: ComplexHermitianEJA)
3009 The projection morphisms are Euclidean Jordan algebra
3012 sage: J1 = HadamardEJA(2)
3013 sage: J2 = RealSymmetricEJA(2)
3014 sage: J = cartesian_product([J1,J2])
3015 sage: J.cartesian_projection(0)
3016 Linear operator between finite-dimensional Euclidean Jordan
3017 algebras represented by the matrix:
3020 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3021 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3022 Algebraic Real Field
3023 Codomain: Euclidean Jordan algebra of dimension 2 over Algebraic
3025 sage: J.cartesian_projection(1)
3026 Linear operator between finite-dimensional Euclidean Jordan
3027 algebras represented by the matrix:
3031 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3032 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3033 Algebraic Real Field
3034 Codomain: Euclidean Jordan algebra of dimension 3 over Algebraic
3037 The projections work the way you'd expect on the vector
3038 representation of an element::
3040 sage: J1 = JordanSpinEJA(2)
3041 sage: J2 = ComplexHermitianEJA(2)
3042 sage: J = cartesian_product([J1,J2])
3043 sage: pi_left = J.cartesian_projection(0)
3044 sage: pi_right = J.cartesian_projection(1)
3045 sage: pi_left(J.one()).to_vector()
3047 sage: pi_right(J.one()).to_vector()
3049 sage: J.one().to_vector()
3054 The answer never changes::
3056 sage: set_random_seed()
3057 sage: J1 = random_eja()
3058 sage: J2 = random_eja()
3059 sage: J = cartesian_product([J1,J2])
3060 sage: P0 = J.cartesian_projection(0)
3061 sage: P1 = J.cartesian_projection(0)
3066 offset
= sum( self
.cartesian_factor(k
).dimension()
3068 Ji
= self
.cartesian_factor(i
)
3069 Pi
= self
._module
_morphism
(lambda j
: Ji
.monomial(j
- offset
),
3072 return FiniteDimensionalEJAOperator(self
,Ji
,Pi
.matrix())
3075 def cartesian_embedding(self
, i
):
3079 sage: from mjo.eja.eja_algebra import (random_eja,
3080 ....: JordanSpinEJA,
3082 ....: RealSymmetricEJA)
3086 The embedding morphisms are Euclidean Jordan algebra
3089 sage: J1 = HadamardEJA(2)
3090 sage: J2 = RealSymmetricEJA(2)
3091 sage: J = cartesian_product([J1,J2])
3092 sage: J.cartesian_embedding(0)
3093 Linear operator between finite-dimensional Euclidean Jordan
3094 algebras represented by the matrix:
3100 Domain: Euclidean Jordan algebra of dimension 2 over
3101 Algebraic Real Field
3102 Codomain: Euclidean Jordan algebra of dimension 2 over
3103 Algebraic Real Field (+) Euclidean Jordan algebra of
3104 dimension 3 over Algebraic Real Field
3105 sage: J.cartesian_embedding(1)
3106 Linear operator between finite-dimensional Euclidean Jordan
3107 algebras represented by the matrix:
3113 Domain: Euclidean Jordan algebra of dimension 3 over
3114 Algebraic Real Field
3115 Codomain: Euclidean Jordan algebra of dimension 2 over
3116 Algebraic Real Field (+) Euclidean Jordan algebra of
3117 dimension 3 over Algebraic Real Field
3119 The embeddings work the way you'd expect on the vector
3120 representation of an element::
3122 sage: J1 = JordanSpinEJA(3)
3123 sage: J2 = RealSymmetricEJA(2)
3124 sage: J = cartesian_product([J1,J2])
3125 sage: iota_left = J.cartesian_embedding(0)
3126 sage: iota_right = J.cartesian_embedding(1)
3127 sage: iota_left(J1.zero()) == J.zero()
3129 sage: iota_right(J2.zero()) == J.zero()
3131 sage: J1.one().to_vector()
3133 sage: iota_left(J1.one()).to_vector()
3135 sage: J2.one().to_vector()
3137 sage: iota_right(J2.one()).to_vector()
3139 sage: J.one().to_vector()
3144 The answer never changes::
3146 sage: set_random_seed()
3147 sage: J1 = random_eja()
3148 sage: J2 = random_eja()
3149 sage: J = cartesian_product([J1,J2])
3150 sage: E0 = J.cartesian_embedding(0)
3151 sage: E1 = J.cartesian_embedding(0)
3155 Composing a projection with the corresponding inclusion should
3156 produce the identity map, and mismatching them should produce
3159 sage: set_random_seed()
3160 sage: J1 = random_eja()
3161 sage: J2 = random_eja()
3162 sage: J = cartesian_product([J1,J2])
3163 sage: iota_left = J.cartesian_embedding(0)
3164 sage: iota_right = J.cartesian_embedding(1)
3165 sage: pi_left = J.cartesian_projection(0)
3166 sage: pi_right = J.cartesian_projection(1)
3167 sage: pi_left*iota_left == J1.one().operator()
3169 sage: pi_right*iota_right == J2.one().operator()
3171 sage: (pi_left*iota_right).is_zero()
3173 sage: (pi_right*iota_left).is_zero()
3177 offset
= sum( self
.cartesian_factor(k
).dimension()
3179 Ji
= self
.cartesian_factor(i
)
3180 Ei
= Ji
._module
_morphism
(lambda j
: self
.monomial(j
+ offset
),
3182 return FiniteDimensionalEJAOperator(Ji
,self
,Ei
.matrix())
3186 FiniteDimensionalEJA
.CartesianProduct
= CartesianProductEJA
3188 class RationalBasisCartesianProductEJA(CartesianProductEJA
,
3191 A separate class for products of algebras for which we know a
3196 sage: from mjo.eja.eja_algebra import (HadamardEJA,
3197 ....: JordanSpinEJA,
3198 ....: OctonionHermitianEJA,
3199 ....: RealSymmetricEJA)
3203 This gives us fast characteristic polynomial computations in
3204 product algebras, too::
3207 sage: J1 = JordanSpinEJA(2)
3208 sage: J2 = RealSymmetricEJA(3)
3209 sage: J = cartesian_product([J1,J2])
3210 sage: J.characteristic_polynomial_of().degree()
3217 The ``cartesian_product()`` function only uses the first factor to
3218 decide where the result will live; thus we have to be careful to
3219 check that all factors do indeed have a `_rational_algebra` member
3220 before we try to access it::
3222 sage: J1 = OctonionHermitianEJA(1) # no rational basis
3223 sage: J2 = HadamardEJA(2)
3224 sage: cartesian_product([J1,J2])
3225 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
3226 (+) Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
3227 sage: cartesian_product([J2,J1])
3228 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
3229 (+) Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
3232 def __init__(self
, algebras
, **kwargs
):
3233 CartesianProductEJA
.__init
__(self
, algebras
, **kwargs
)
3235 self
._rational
_algebra
= None
3236 if self
.vector_space().base_field() is not QQ
:
3237 if all( hasattr(r
, "_rational_algebra") for r
in algebras
):
3238 self
._rational
_algebra
= cartesian_product([
3239 r
._rational
_algebra
for r
in algebras
3243 RationalBasisEJA
.CartesianProduct
= RationalBasisCartesianProductEJA
3245 def random_eja(*args
, **kwargs
):
3246 J1
= ConcreteEJA
.random_instance(*args
, **kwargs
)
3248 # This might make Cartesian products appear roughly as often as
3249 # any other ConcreteEJA.
3250 if ZZ
.random_element(len(ConcreteEJA
.__subclasses
__()) + 1) == 0:
3251 # Use random_eja() again so we can get more than two factors.
3252 J2
= random_eja(*args
, **kwargs
)
3253 J
= cartesian_product([J1
,J2
])