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.
55 At a minimum, the following are required to construct a Euclidean
58 * A basis of matrices, column vectors, or MatrixAlgebra elements
59 * A Jordan product defined on the basis
60 * Its inner product defined on the basis
62 The real numbers form a Euclidean Jordan algebra when both the Jordan
63 and inner products are the usual multiplication. We use this as our
64 example, and demonstrate a few ways to construct an EJA.
66 First, we can use one-by-one SageMath matrices with algebraic real
67 entries to represent real numbers. We define the Jordan and inner
68 products to be essentially real-number multiplication, with the only
69 difference being that the Jordan product again returns a one-by-one
70 matrix, whereas the inner product must return a scalar. Our basis for
71 the one-by-one matrices is of course the set consisting of a single
72 matrix with its sole entry non-zero::
74 sage: from mjo.eja.eja_algebra import FiniteDimensionalEJA
75 sage: jp = lambda X,Y: X*Y
76 sage: ip = lambda X,Y: X[0,0]*Y[0,0]
77 sage: b1 = matrix(AA, [[1]])
78 sage: J1 = FiniteDimensionalEJA((b1,), jp, ip)
80 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
82 In fact, any positive scalar multiple of that inner-product would work::
84 sage: ip2 = lambda X,Y: 16*ip(X,Y)
85 sage: J2 = FiniteDimensionalEJA((b1,), jp, ip2)
87 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
89 But beware that your basis will be orthonormalized _with respect to the
90 given inner-product_ unless you pass ``orthonormalize=False`` to the
91 constructor. For example::
93 sage: J3 = FiniteDimensionalEJA((b1,), jp, ip2, orthonormalize=False)
95 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
97 To see the difference, you can take the first and only basis element
98 of the resulting algebra, and ask for it to be converted back into
101 sage: J1.basis()[0].to_matrix()
103 sage: J2.basis()[0].to_matrix()
105 sage: J3.basis()[0].to_matrix()
108 Since square roots are used in that process, the default scalar field
109 that we use is the field of algebraic real numbers, ``AA``. You can
110 also Use rational numbers, but only if you either pass
111 ``orthonormalize=False`` or know that orthonormalizing your basis
112 won't stray beyond the rational numbers. The example above would
113 have worked only because ``sqrt(16) == 4`` is rational.
115 Another option for your basis is to use elemebts of a
116 :class:`MatrixAlgebra`::
118 sage: from mjo.matrix_algebra import MatrixAlgebra
119 sage: A = MatrixAlgebra(1,AA,AA)
120 sage: J4 = FiniteDimensionalEJA(A.gens(), jp, ip)
122 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
123 sage: J4.basis()[0].to_matrix()
128 An easier way to view the entire EJA basis in its original (but
129 perhaps orthonormalized) matrix form is to use the ``matrix_basis``
132 sage: J4.matrix_basis()
137 In particular, a :class:`MatrixAlgebra` is needed to work around the
138 fact that matrices in SageMath must have entries in the same
139 (commutative and associative) ring as its scalars. There are many
140 Euclidean Jordan algebras whose elements are matrices that violate
141 those assumptions. The complex, quaternion, and octonion Hermitian
142 matrices all have entries in a ring (the complex numbers, quaternions,
143 or octonions...) that differs from the algebra's scalar ring (the real
144 numbers). Quaternions are also non-commutative; the octonions are
145 neither commutative nor associative.
149 sage: from mjo.eja.eja_algebra import random_eja
154 Euclidean Jordan algebra of dimension...
157 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
158 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
159 from sage
.categories
.sets_cat
import cartesian_product
160 from sage
.combinat
.free_module
import CombinatorialFreeModule
161 from sage
.matrix
.constructor
import matrix
162 from sage
.matrix
.matrix_space
import MatrixSpace
163 from sage
.misc
.cachefunc
import cached_method
164 from sage
.misc
.table
import table
165 from sage
.modules
.free_module
import FreeModule
, VectorSpace
166 from sage
.rings
.all
import (ZZ
, QQ
, AA
, QQbar
, RR
, RLF
, CLF
,
169 from mjo
.eja
.eja_element
import FiniteDimensionalEJAElement
170 from mjo
.eja
.eja_operator
import FiniteDimensionalEJAOperator
171 from mjo
.eja
.eja_utils
import _all2list
, _mat2vec
173 def EuclideanJordanAlgebras(field
):
175 The category of Euclidean Jordan algebras over ``field``, which
176 must be a subfield of the real numbers. For now this is just a
177 convenient wrapper around all of the other category axioms that
180 category
= MagmaticAlgebras(field
).FiniteDimensional()
181 category
= category
.WithBasis().Unital().Commutative()
184 class FiniteDimensionalEJA(CombinatorialFreeModule
):
186 A finite-dimensional Euclidean Jordan algebra.
190 - ``basis`` -- a tuple; a tuple of basis elements in "matrix
191 form," which must be the same form as the arguments to
192 ``jordan_product`` and ``inner_product``. In reality, "matrix
193 form" can be either vectors, matrices, or a Cartesian product
194 (ordered tuple) of vectors or matrices. All of these would
195 ideally be vector spaces in sage with no special-casing
196 needed; but in reality we turn vectors into column-matrices
197 and Cartesian products `(a,b)` into column matrices
198 `(a,b)^{T}` after converting `a` and `b` themselves.
200 - ``jordan_product`` -- a function; afunction of two ``basis``
201 elements (in matrix form) that returns their jordan product,
202 also in matrix form; this will be applied to ``basis`` to
203 compute a multiplication table for the algebra.
205 - ``inner_product`` -- a function; a function of two ``basis``
206 elements (in matrix form) that returns their inner
207 product. This will be applied to ``basis`` to compute an
208 inner-product table (basically a matrix) for this algebra.
210 - ``matrix_space`` -- the space that your matrix basis lives in,
211 or ``None`` (the default). So long as your basis does not have
212 length zero you can omit this. But in trivial algebras, it is
215 - ``field`` -- a subfield of the reals (default: ``AA``); the scalar
216 field for the algebra.
218 - ``orthonormalize`` -- boolean (default: ``True``); whether or
219 not to orthonormalize the basis. Doing so is expensive and
220 generally rules out using the rationals as your ``field``, but
221 is required for spectral decompositions.
225 sage: from mjo.eja.eja_algebra import random_eja
229 We should compute that an element subalgebra is associative even
230 if we circumvent the element method::
232 sage: set_random_seed()
233 sage: J = random_eja(field=QQ,orthonormalize=False)
234 sage: x = J.random_element()
235 sage: A = x.subalgebra_generated_by(orthonormalize=False)
236 sage: basis = tuple(b.superalgebra_element() for b in A.basis())
237 sage: J.subalgebra(basis, orthonormalize=False).is_associative()
240 Element
= FiniteDimensionalEJAElement
243 def _check_input_field(field
):
244 if not field
.is_subring(RR
):
245 # Note: this does return true for the real algebraic
246 # field, the rationals, and any quadratic field where
247 # we've specified a real embedding.
248 raise ValueError("scalar field is not real")
251 def _check_input_axioms(basis
, jordan_product
, inner_product
):
252 if not all( jordan_product(bi
,bj
) == jordan_product(bj
,bi
)
255 raise ValueError("Jordan product is not commutative")
257 if not all( inner_product(bi
,bj
) == inner_product(bj
,bi
)
260 raise ValueError("inner-product is not commutative")
277 self
._check
_input
_field
(field
)
280 # Check commutativity of the Jordan and inner-products.
281 # This has to be done before we build the multiplication
282 # and inner-product tables/matrices, because we take
283 # advantage of symmetry in the process.
284 self
._check
_input
_axioms
(basis
, jordan_product
, inner_product
)
287 # All zero- and one-dimensional algebras are just the real
288 # numbers with (some positive multiples of) the usual
289 # multiplication as its Jordan and inner-product.
291 if associative
is None:
292 # We should figure it out. As with check_axioms, we have to do
293 # this without the help of the _jordan_product_is_associative()
294 # method because we need to know the category before we
295 # initialize the algebra.
296 associative
= all( jordan_product(jordan_product(bi
,bj
),bk
)
298 jordan_product(bi
,jordan_product(bj
,bk
))
303 category
= EuclideanJordanAlgebras(field
)
306 # Element subalgebras can take advantage of this.
307 category
= category
.Associative()
309 # Call the superclass constructor so that we can use its from_vector()
310 # method to build our multiplication table.
311 CombinatorialFreeModule
.__init
__(self
,
318 # Now comes all of the hard work. We'll be constructing an
319 # ambient vector space V that our (vectorized) basis lives in,
320 # as well as a subspace W of V spanned by those (vectorized)
321 # basis elements. The W-coordinates are the coefficients that
322 # we see in things like x = 1*b1 + 2*b2.
326 degree
= len(_all2list(basis
[0]))
328 # Build an ambient space that fits our matrix basis when
329 # written out as "long vectors."
330 V
= VectorSpace(field
, degree
)
332 # The matrix that will hold the orthonormal -> unorthonormal
333 # coordinate transformation. Default to an identity matrix of
334 # the appropriate size to avoid special cases for None
336 self
._deortho
_matrix
= matrix
.identity(field
,n
)
339 # Save a copy of the un-orthonormalized basis for later.
340 # Convert it to ambient V (vector) coordinates while we're
341 # at it, because we'd have to do it later anyway.
342 deortho_vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
344 from mjo
.eja
.eja_utils
import gram_schmidt
345 basis
= tuple(gram_schmidt(basis
, inner_product
))
347 # Save the (possibly orthonormalized) matrix basis for
348 # later, as well as the space that its elements live in.
349 # In most cases we can deduce the matrix space, but when
350 # n == 0 (that is, there are no basis elements) we cannot.
351 self
._matrix
_basis
= basis
352 if matrix_space
is None:
353 self
._matrix
_space
= self
._matrix
_basis
[0].parent()
355 self
._matrix
_space
= matrix_space
357 # Now create the vector space for the algebra, which will have
358 # its own set of non-ambient coordinates (in terms of the
360 vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
362 # Save the span of our matrix basis (when written out as long
363 # vectors) because otherwise we'll have to reconstruct it
364 # every time we want to coerce a matrix into the algebra.
365 self
._matrix
_span
= V
.span_of_basis( vector_basis
, check
=check_axioms
)
368 # Now "self._matrix_span" is the vector space of our
369 # algebra coordinates. The variables "X1", "X2",... refer
370 # to the entries of vectors in self._matrix_span. Thus to
371 # convert back and forth between the orthonormal
372 # coordinates and the given ones, we need to stick the
373 # original basis in self._matrix_span.
374 U
= V
.span_of_basis( deortho_vector_basis
, check
=check_axioms
)
375 self
._deortho
_matrix
= matrix
.column( U
.coordinate_vector(q
)
376 for q
in vector_basis
)
379 # Now we actually compute the multiplication and inner-product
380 # tables/matrices using the possibly-orthonormalized basis.
381 self
._inner
_product
_matrix
= matrix
.identity(field
, n
)
383 self
._multiplication
_table
= [ [zed
for j
in range(i
+1)]
386 # Note: the Jordan and inner-products are defined in terms
387 # of the ambient basis. It's important that their arguments
388 # are in ambient coordinates as well.
391 # ortho basis w.r.t. ambient coords
395 # The jordan product returns a matrixy answer, so we
396 # have to convert it to the algebra coordinates.
397 elt
= jordan_product(q_i
, q_j
)
398 elt
= self
._matrix
_span
.coordinate_vector(V(_all2list(elt
)))
399 self
._multiplication
_table
[i
][j
] = self
.from_vector(elt
)
401 if not orthonormalize
:
402 # If we're orthonormalizing the basis with respect
403 # to an inner-product, then the inner-product
404 # matrix with respect to the resulting basis is
405 # just going to be the identity.
406 ip
= inner_product(q_i
, q_j
)
407 self
._inner
_product
_matrix
[i
,j
] = ip
408 self
._inner
_product
_matrix
[j
,i
] = ip
410 self
._inner
_product
_matrix
._cache
= {'hermitian': True}
411 self
._inner
_product
_matrix
.set_immutable()
414 if not self
._is
_jordanian
():
415 raise ValueError("Jordan identity does not hold")
416 if not self
._inner
_product
_is
_associative
():
417 raise ValueError("inner product is not associative")
420 def _coerce_map_from_base_ring(self
):
422 Disable the map from the base ring into the algebra.
424 Performing a nonsense conversion like this automatically
425 is counterpedagogical. The fallback is to try the usual
426 element constructor, which should also fail.
430 sage: from mjo.eja.eja_algebra import random_eja
434 sage: set_random_seed()
435 sage: J = random_eja()
437 Traceback (most recent call last):
439 ValueError: not an element of this algebra
445 def product_on_basis(self
, i
, j
):
447 Returns the Jordan product of the `i` and `j`th basis elements.
449 This completely defines the Jordan product on the algebra, and
450 is used direclty by our superclass machinery to implement
455 sage: from mjo.eja.eja_algebra import random_eja
459 sage: set_random_seed()
460 sage: J = random_eja()
461 sage: n = J.dimension()
464 sage: bi_bj = J.zero()*J.zero()
466 ....: i = ZZ.random_element(n)
467 ....: j = ZZ.random_element(n)
468 ....: bi = J.monomial(i)
469 ....: bj = J.monomial(j)
470 ....: bi_bj = J.product_on_basis(i,j)
475 # We only stored the lower-triangular portion of the
476 # multiplication table.
478 return self
._multiplication
_table
[i
][j
]
480 return self
._multiplication
_table
[j
][i
]
482 def inner_product(self
, x
, y
):
484 The inner product associated with this Euclidean Jordan algebra.
486 Defaults to the trace inner product, but can be overridden by
487 subclasses if they are sure that the necessary properties are
492 sage: from mjo.eja.eja_algebra import (random_eja,
494 ....: BilinearFormEJA)
498 Our inner product is "associative," which means the following for
499 a symmetric bilinear form::
501 sage: set_random_seed()
502 sage: J = random_eja()
503 sage: x,y,z = J.random_elements(3)
504 sage: (x*y).inner_product(z) == y.inner_product(x*z)
509 Ensure that this is the usual inner product for the algebras
512 sage: set_random_seed()
513 sage: J = HadamardEJA.random_instance()
514 sage: x,y = J.random_elements(2)
515 sage: actual = x.inner_product(y)
516 sage: expected = x.to_vector().inner_product(y.to_vector())
517 sage: actual == expected
520 Ensure that this is one-half of the trace inner-product in a
521 BilinearFormEJA that isn't just the reals (when ``n`` isn't
522 one). This is in Faraut and Koranyi, and also my "On the
525 sage: set_random_seed()
526 sage: J = BilinearFormEJA.random_instance()
527 sage: n = J.dimension()
528 sage: x = J.random_element()
529 sage: y = J.random_element()
530 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
534 B
= self
._inner
_product
_matrix
535 return (B
*x
.to_vector()).inner_product(y
.to_vector())
538 def is_associative(self
):
540 Return whether or not this algebra's Jordan product is associative.
544 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
548 sage: J = ComplexHermitianEJA(3, field=QQ, orthonormalize=False)
549 sage: J.is_associative()
551 sage: x = sum(J.gens())
552 sage: A = x.subalgebra_generated_by(orthonormalize=False)
553 sage: A.is_associative()
557 return "Associative" in self
.category().axioms()
559 def _is_commutative(self
):
561 Whether or not this algebra's multiplication table is commutative.
563 This method should of course always return ``True``, unless
564 this algebra was constructed with ``check_axioms=False`` and
565 passed an invalid multiplication table.
567 return all( x
*y
== y
*x
for x
in self
.gens() for y
in self
.gens() )
569 def _is_jordanian(self
):
571 Whether or not this algebra's multiplication table respects the
572 Jordan identity `(x^{2})(xy) = x(x^{2}y)`.
574 We only check one arrangement of `x` and `y`, so for a
575 ``True`` result to be truly true, you should also check
576 :meth:`_is_commutative`. This method should of course always
577 return ``True``, unless this algebra was constructed with
578 ``check_axioms=False`` and passed an invalid multiplication table.
580 return all( (self
.monomial(i
)**2)*(self
.monomial(i
)*self
.monomial(j
))
582 (self
.monomial(i
))*((self
.monomial(i
)**2)*self
.monomial(j
))
583 for i
in range(self
.dimension())
584 for j
in range(self
.dimension()) )
586 def _jordan_product_is_associative(self
):
588 Return whether or not this algebra's Jordan product is
589 associative; that is, whether or not `x*(y*z) = (x*y)*z`
592 This method should agree with :meth:`is_associative` unless
593 you lied about the value of the ``associative`` parameter
594 when you constructed the algebra.
598 sage: from mjo.eja.eja_algebra import (random_eja,
599 ....: RealSymmetricEJA,
600 ....: ComplexHermitianEJA,
601 ....: QuaternionHermitianEJA)
605 sage: J = RealSymmetricEJA(4, orthonormalize=False)
606 sage: J._jordan_product_is_associative()
608 sage: x = sum(J.gens())
609 sage: A = x.subalgebra_generated_by()
610 sage: A._jordan_product_is_associative()
615 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
616 sage: J._jordan_product_is_associative()
618 sage: x = sum(J.gens())
619 sage: A = x.subalgebra_generated_by(orthonormalize=False)
620 sage: A._jordan_product_is_associative()
625 sage: J = QuaternionHermitianEJA(2)
626 sage: J._jordan_product_is_associative()
628 sage: x = sum(J.gens())
629 sage: A = x.subalgebra_generated_by()
630 sage: A._jordan_product_is_associative()
635 The values we've presupplied to the constructors agree with
638 sage: set_random_seed()
639 sage: J = random_eja()
640 sage: J.is_associative() == J._jordan_product_is_associative()
646 # Used to check whether or not something is zero.
649 # I don't know of any examples that make this magnitude
650 # necessary because I don't know how to make an
651 # associative algebra when the element subalgebra
652 # construction is unreliable (as it is over RDF; we can't
653 # find the degree of an element because we can't compute
654 # the rank of a matrix). But even multiplication of floats
655 # is non-associative, so *some* epsilon is needed... let's
656 # just take the one from _inner_product_is_associative?
659 for i
in range(self
.dimension()):
660 for j
in range(self
.dimension()):
661 for k
in range(self
.dimension()):
665 diff
= (x
*y
)*z
- x
*(y
*z
)
667 if diff
.norm() > epsilon
:
672 def _inner_product_is_associative(self
):
674 Return whether or not this algebra's inner product `B` is
675 associative; that is, whether or not `B(xy,z) = B(x,yz)`.
677 This method should of course always return ``True``, unless
678 this algebra was constructed with ``check_axioms=False`` and
679 passed an invalid Jordan or inner-product.
683 # Used to check whether or not something is zero.
686 # This choice is sufficient to allow the construction of
687 # QuaternionHermitianEJA(2, field=RDF) with check_axioms=True.
690 for i
in range(self
.dimension()):
691 for j
in range(self
.dimension()):
692 for k
in range(self
.dimension()):
696 diff
= (x
*y
).inner_product(z
) - x
.inner_product(y
*z
)
698 if diff
.abs() > epsilon
:
703 def _element_constructor_(self
, elt
):
705 Construct an element of this algebra or a subalgebra from its
706 EJA element, vector, or matrix representation.
708 This gets called only after the parent element _call_ method
709 fails to find a coercion for the argument.
713 sage: from mjo.eja.eja_algebra import (random_eja,
716 ....: RealSymmetricEJA)
720 The identity in `S^n` is converted to the identity in the EJA::
722 sage: J = RealSymmetricEJA(3)
723 sage: I = matrix.identity(QQ,3)
724 sage: J(I) == J.one()
727 This skew-symmetric matrix can't be represented in the EJA::
729 sage: J = RealSymmetricEJA(3)
730 sage: A = matrix(QQ,3, lambda i,j: i-j)
732 Traceback (most recent call last):
734 ValueError: not an element of this algebra
736 Tuples work as well, provided that the matrix basis for the
737 algebra consists of them::
739 sage: J1 = HadamardEJA(3)
740 sage: J2 = RealSymmetricEJA(2)
741 sage: J = cartesian_product([J1,J2])
742 sage: J( (J1.matrix_basis()[1], J2.matrix_basis()[2]) )
745 Subalgebra elements are embedded into the superalgebra::
747 sage: J = JordanSpinEJA(3)
750 sage: x = sum(J.gens())
751 sage: A = x.subalgebra_generated_by()
757 Ensure that we can convert any element back and forth
758 faithfully between its matrix and algebra representations::
760 sage: set_random_seed()
761 sage: J = random_eja()
762 sage: x = J.random_element()
763 sage: J(x.to_matrix()) == x
766 We cannot coerce elements between algebras just because their
767 matrix representations are compatible::
769 sage: J1 = HadamardEJA(3)
770 sage: J2 = JordanSpinEJA(3)
772 Traceback (most recent call last):
774 ValueError: not an element of this algebra
776 Traceback (most recent call last):
778 ValueError: not an element of this algebra
781 msg
= "not an element of this algebra"
782 if elt
in self
.base_ring():
783 # Ensure that no base ring -> algebra coercion is performed
784 # by this method. There's some stupidity in sage that would
785 # otherwise propagate to this method; for example, sage thinks
786 # that the integer 3 belongs to the space of 2-by-2 matrices.
787 raise ValueError(msg
)
789 if hasattr(elt
, 'superalgebra_element'):
790 # Handle subalgebra elements
791 if elt
.parent().superalgebra() == self
:
792 return elt
.superalgebra_element()
794 if hasattr(elt
, 'sparse_vector'):
795 # Convert a vector into a column-matrix. We check for
796 # "sparse_vector" and not "column" because matrices also
797 # have a "column" method.
800 if elt
not in self
.matrix_space():
801 raise ValueError(msg
)
803 # Thanks for nothing! Matrix spaces aren't vector spaces in
804 # Sage, so we have to figure out its matrix-basis coordinates
805 # ourselves. We use the basis space's ring instead of the
806 # element's ring because the basis space might be an algebraic
807 # closure whereas the base ring of the 3-by-3 identity matrix
808 # could be QQ instead of QQbar.
810 # And, we also have to handle Cartesian product bases (when
811 # the matrix basis consists of tuples) here. The "good news"
812 # is that we're already converting everything to long vectors,
813 # and that strategy works for tuples as well.
815 elt
= self
._matrix
_span
.ambient_vector_space()(_all2list(elt
))
818 coords
= self
._matrix
_span
.coordinate_vector(elt
)
819 except ArithmeticError: # vector is not in free module
820 raise ValueError(msg
)
822 return self
.from_vector(coords
)
826 Return a string representation of ``self``.
830 sage: from mjo.eja.eja_algebra import JordanSpinEJA
834 Ensure that it says what we think it says::
836 sage: JordanSpinEJA(2, field=AA)
837 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
838 sage: JordanSpinEJA(3, field=RDF)
839 Euclidean Jordan algebra of dimension 3 over Real Double Field
842 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
843 return fmt
.format(self
.dimension(), self
.base_ring())
847 def characteristic_polynomial_of(self
):
849 Return the algebra's "characteristic polynomial of" function,
850 which is itself a multivariate polynomial that, when evaluated
851 at the coordinates of some algebra element, returns that
852 element's characteristic polynomial.
854 The resulting polynomial has `n+1` variables, where `n` is the
855 dimension of this algebra. The first `n` variables correspond to
856 the coordinates of an algebra element: when evaluated at the
857 coordinates of an algebra element with respect to a certain
858 basis, the result is a univariate polynomial (in the one
859 remaining variable ``t``), namely the characteristic polynomial
864 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
868 The characteristic polynomial in the spin algebra is given in
869 Alizadeh, Example 11.11::
871 sage: J = JordanSpinEJA(3)
872 sage: p = J.characteristic_polynomial_of(); p
873 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
874 sage: xvec = J.one().to_vector()
878 By definition, the characteristic polynomial is a monic
879 degree-zero polynomial in a rank-zero algebra. Note that
880 Cayley-Hamilton is indeed satisfied since the polynomial
881 ``1`` evaluates to the identity element of the algebra on
884 sage: J = TrivialEJA()
885 sage: J.characteristic_polynomial_of()
892 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_(r-1).
893 a
= self
._charpoly
_coefficients
()
895 # We go to a bit of trouble here to reorder the
896 # indeterminates, so that it's easier to evaluate the
897 # characteristic polynomial at x's coordinates and get back
898 # something in terms of t, which is what we want.
899 S
= PolynomialRing(self
.base_ring(),'t')
903 S
= PolynomialRing(S
, R
.variable_names())
906 return (t
**r
+ sum( a
[k
]*(t
**k
) for k
in range(r
) ))
908 def coordinate_polynomial_ring(self
):
910 The multivariate polynomial ring in which this algebra's
911 :meth:`characteristic_polynomial_of` lives.
915 sage: from mjo.eja.eja_algebra import (HadamardEJA,
916 ....: RealSymmetricEJA)
920 sage: J = HadamardEJA(2)
921 sage: J.coordinate_polynomial_ring()
922 Multivariate Polynomial Ring in X1, X2...
923 sage: J = RealSymmetricEJA(3,field=QQ,orthonormalize=False)
924 sage: J.coordinate_polynomial_ring()
925 Multivariate Polynomial Ring in X1, X2, X3, X4, X5, X6...
928 var_names
= tuple( "X%d" % z
for z
in range(1, self
.dimension()+1) )
929 return PolynomialRing(self
.base_ring(), var_names
)
931 def inner_product(self
, x
, y
):
933 The inner product associated with this Euclidean Jordan algebra.
935 Defaults to the trace inner product, but can be overridden by
936 subclasses if they are sure that the necessary properties are
941 sage: from mjo.eja.eja_algebra import (random_eja,
943 ....: BilinearFormEJA)
947 Our inner product is "associative," which means the following for
948 a symmetric bilinear form::
950 sage: set_random_seed()
951 sage: J = random_eja()
952 sage: x,y,z = J.random_elements(3)
953 sage: (x*y).inner_product(z) == y.inner_product(x*z)
958 Ensure that this is the usual inner product for the algebras
961 sage: set_random_seed()
962 sage: J = HadamardEJA.random_instance()
963 sage: x,y = J.random_elements(2)
964 sage: actual = x.inner_product(y)
965 sage: expected = x.to_vector().inner_product(y.to_vector())
966 sage: actual == expected
969 Ensure that this is one-half of the trace inner-product in a
970 BilinearFormEJA that isn't just the reals (when ``n`` isn't
971 one). This is in Faraut and Koranyi, and also my "On the
974 sage: set_random_seed()
975 sage: J = BilinearFormEJA.random_instance()
976 sage: n = J.dimension()
977 sage: x = J.random_element()
978 sage: y = J.random_element()
979 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
982 B
= self
._inner
_product
_matrix
983 return (B
*x
.to_vector()).inner_product(y
.to_vector())
986 def is_trivial(self
):
988 Return whether or not this algebra is trivial.
990 A trivial algebra contains only the zero element.
994 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
999 sage: J = ComplexHermitianEJA(3)
1000 sage: J.is_trivial()
1005 sage: J = TrivialEJA()
1006 sage: J.is_trivial()
1010 return self
.dimension() == 0
1013 def multiplication_table(self
):
1015 Return a visual representation of this algebra's multiplication
1016 table (on basis elements).
1020 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1024 sage: J = JordanSpinEJA(4)
1025 sage: J.multiplication_table()
1026 +----++----+----+----+----+
1027 | * || b0 | b1 | b2 | b3 |
1028 +====++====+====+====+====+
1029 | b0 || b0 | b1 | b2 | b3 |
1030 +----++----+----+----+----+
1031 | b1 || b1 | b0 | 0 | 0 |
1032 +----++----+----+----+----+
1033 | b2 || b2 | 0 | b0 | 0 |
1034 +----++----+----+----+----+
1035 | b3 || b3 | 0 | 0 | b0 |
1036 +----++----+----+----+----+
1039 n
= self
.dimension()
1040 # Prepend the header row.
1041 M
= [["*"] + list(self
.gens())]
1043 # And to each subsequent row, prepend an entry that belongs to
1044 # the left-side "header column."
1045 M
+= [ [self
.monomial(i
)] + [ self
.monomial(i
)*self
.monomial(j
)
1049 return table(M
, header_row
=True, header_column
=True, frame
=True)
1052 def matrix_basis(self
):
1054 Return an (often more natural) representation of this algebras
1055 basis as an ordered tuple of matrices.
1057 Every finite-dimensional Euclidean Jordan Algebra is a, up to
1058 Jordan isomorphism, a direct sum of five simple
1059 algebras---four of which comprise Hermitian matrices. And the
1060 last type of algebra can of course be thought of as `n`-by-`1`
1061 column matrices (ambiguusly called column vectors) to avoid
1062 special cases. As a result, matrices (and column vectors) are
1063 a natural representation format for Euclidean Jordan algebra
1066 But, when we construct an algebra from a basis of matrices,
1067 those matrix representations are lost in favor of coordinate
1068 vectors *with respect to* that basis. We could eventually
1069 convert back if we tried hard enough, but having the original
1070 representations handy is valuable enough that we simply store
1071 them and return them from this method.
1073 Why implement this for non-matrix algebras? Avoiding special
1074 cases for the :class:`BilinearFormEJA` pays with simplicity in
1075 its own right. But mainly, we would like to be able to assume
1076 that elements of a :class:`CartesianProductEJA` can be displayed
1077 nicely, without having to have special classes for direct sums
1078 one of whose components was a matrix algebra.
1082 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1083 ....: RealSymmetricEJA)
1087 sage: J = RealSymmetricEJA(2)
1089 Finite family {0: b0, 1: b1, 2: b2}
1090 sage: J.matrix_basis()
1092 [1 0] [ 0 0.7071067811865475?] [0 0]
1093 [0 0], [0.7071067811865475? 0], [0 1]
1098 sage: J = JordanSpinEJA(2)
1100 Finite family {0: b0, 1: b1}
1101 sage: J.matrix_basis()
1107 return self
._matrix
_basis
1110 def matrix_space(self
):
1112 Return the matrix space in which this algebra's elements live, if
1113 we think of them as matrices (including column vectors of the
1116 "By default" this will be an `n`-by-`1` column-matrix space,
1117 except when the algebra is trivial. There it's `n`-by-`n`
1118 (where `n` is zero), to ensure that two elements of the matrix
1119 space (empty matrices) can be multiplied. For algebras of
1120 matrices, this returns the space in which their
1121 real embeddings live.
1125 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
1126 ....: JordanSpinEJA,
1127 ....: QuaternionHermitianEJA,
1132 By default, the matrix representation is just a column-matrix
1133 equivalent to the vector representation::
1135 sage: J = JordanSpinEJA(3)
1136 sage: J.matrix_space()
1137 Full MatrixSpace of 3 by 1 dense matrices over Algebraic
1140 The matrix representation in the trivial algebra is
1141 zero-by-zero instead of the usual `n`-by-one::
1143 sage: J = TrivialEJA()
1144 sage: J.matrix_space()
1145 Full MatrixSpace of 0 by 0 dense matrices over Algebraic
1148 The matrix space for complex/quaternion Hermitian matrix EJA
1149 is the space in which their real-embeddings live, not the
1150 original complex/quaternion matrix space::
1152 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1153 sage: J.matrix_space()
1154 Module of 2 by 2 matrices with entries in Algebraic Field over
1155 the scalar ring Rational Field
1156 sage: J = QuaternionHermitianEJA(1,field=QQ,orthonormalize=False)
1157 sage: J.matrix_space()
1158 Module of 1 by 1 matrices with entries in Quaternion
1159 Algebra (-1, -1) with base ring Rational Field over
1160 the scalar ring Rational Field
1163 return self
._matrix
_space
1169 Return the unit element of this algebra.
1173 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1178 We can compute unit element in the Hadamard EJA::
1180 sage: J = HadamardEJA(5)
1182 b0 + b1 + b2 + b3 + b4
1184 The unit element in the Hadamard EJA is inherited in the
1185 subalgebras generated by its elements::
1187 sage: J = HadamardEJA(5)
1189 b0 + b1 + b2 + b3 + b4
1190 sage: x = sum(J.gens())
1191 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1194 sage: A.one().superalgebra_element()
1195 b0 + b1 + b2 + b3 + b4
1199 The identity element acts like the identity, regardless of
1200 whether or not we orthonormalize::
1202 sage: set_random_seed()
1203 sage: J = random_eja()
1204 sage: x = J.random_element()
1205 sage: J.one()*x == x and x*J.one() == x
1207 sage: A = x.subalgebra_generated_by()
1208 sage: y = A.random_element()
1209 sage: A.one()*y == y and y*A.one() == y
1214 sage: set_random_seed()
1215 sage: J = random_eja(field=QQ, orthonormalize=False)
1216 sage: x = J.random_element()
1217 sage: J.one()*x == x and x*J.one() == x
1219 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1220 sage: y = A.random_element()
1221 sage: A.one()*y == y and y*A.one() == y
1224 The matrix of the unit element's operator is the identity,
1225 regardless of the base field and whether or not we
1228 sage: set_random_seed()
1229 sage: J = random_eja()
1230 sage: actual = J.one().operator().matrix()
1231 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1232 sage: actual == expected
1234 sage: x = J.random_element()
1235 sage: A = x.subalgebra_generated_by()
1236 sage: actual = A.one().operator().matrix()
1237 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1238 sage: actual == expected
1243 sage: set_random_seed()
1244 sage: J = random_eja(field=QQ, orthonormalize=False)
1245 sage: actual = J.one().operator().matrix()
1246 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1247 sage: actual == expected
1249 sage: x = J.random_element()
1250 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1251 sage: actual = A.one().operator().matrix()
1252 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1253 sage: actual == expected
1256 Ensure that the cached unit element (often precomputed by
1257 hand) agrees with the computed one::
1259 sage: set_random_seed()
1260 sage: J = random_eja()
1261 sage: cached = J.one()
1262 sage: J.one.clear_cache()
1263 sage: J.one() == cached
1268 sage: set_random_seed()
1269 sage: J = random_eja(field=QQ, orthonormalize=False)
1270 sage: cached = J.one()
1271 sage: J.one.clear_cache()
1272 sage: J.one() == cached
1276 # We can brute-force compute the matrices of the operators
1277 # that correspond to the basis elements of this algebra.
1278 # If some linear combination of those basis elements is the
1279 # algebra identity, then the same linear combination of
1280 # their matrices has to be the identity matrix.
1282 # Of course, matrices aren't vectors in sage, so we have to
1283 # appeal to the "long vectors" isometry.
1284 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
1286 # Now we use basic linear algebra to find the coefficients,
1287 # of the matrices-as-vectors-linear-combination, which should
1288 # work for the original algebra basis too.
1289 A
= matrix(self
.base_ring(), oper_vecs
)
1291 # We used the isometry on the left-hand side already, but we
1292 # still need to do it for the right-hand side. Recall that we
1293 # wanted something that summed to the identity matrix.
1294 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
1296 # Now if there's an identity element in the algebra, this
1297 # should work. We solve on the left to avoid having to
1298 # transpose the matrix "A".
1299 return self
.from_vector(A
.solve_left(b
))
1302 def peirce_decomposition(self
, c
):
1304 The Peirce decomposition of this algebra relative to the
1307 In the future, this can be extended to a complete system of
1308 orthogonal idempotents.
1312 - ``c`` -- an idempotent of this algebra.
1316 A triple (J0, J5, J1) containing two subalgebras and one subspace
1319 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
1320 corresponding to the eigenvalue zero.
1322 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
1323 corresponding to the eigenvalue one-half.
1325 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
1326 corresponding to the eigenvalue one.
1328 These are the only possible eigenspaces for that operator, and this
1329 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
1330 orthogonal, and are subalgebras of this algebra with the appropriate
1335 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
1339 The canonical example comes from the symmetric matrices, which
1340 decompose into diagonal and off-diagonal parts::
1342 sage: J = RealSymmetricEJA(3)
1343 sage: C = matrix(QQ, [ [1,0,0],
1347 sage: J0,J5,J1 = J.peirce_decomposition(c)
1349 Euclidean Jordan algebra of dimension 1...
1351 Vector space of degree 6 and dimension 2...
1353 Euclidean Jordan algebra of dimension 3...
1354 sage: J0.one().to_matrix()
1358 sage: orig_df = AA.options.display_format
1359 sage: AA.options.display_format = 'radical'
1360 sage: J.from_vector(J5.basis()[0]).to_matrix()
1364 sage: J.from_vector(J5.basis()[1]).to_matrix()
1368 sage: AA.options.display_format = orig_df
1369 sage: J1.one().to_matrix()
1376 Every algebra decomposes trivially with respect to its identity
1379 sage: set_random_seed()
1380 sage: J = random_eja()
1381 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
1382 sage: J0.dimension() == 0 and J5.dimension() == 0
1384 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
1387 The decomposition is into eigenspaces, and its components are
1388 therefore necessarily orthogonal. Moreover, the identity
1389 elements in the two subalgebras are the projections onto their
1390 respective subspaces of the superalgebra's identity element::
1392 sage: set_random_seed()
1393 sage: J = random_eja()
1394 sage: x = J.random_element()
1395 sage: if not J.is_trivial():
1396 ....: while x.is_nilpotent():
1397 ....: x = J.random_element()
1398 sage: c = x.subalgebra_idempotent()
1399 sage: J0,J5,J1 = J.peirce_decomposition(c)
1401 sage: for (w,y,z) in zip(J0.basis(), J5.basis(), J1.basis()):
1402 ....: w = w.superalgebra_element()
1403 ....: y = J.from_vector(y)
1404 ....: z = z.superalgebra_element()
1405 ....: ipsum += w.inner_product(y).abs()
1406 ....: ipsum += w.inner_product(z).abs()
1407 ....: ipsum += y.inner_product(z).abs()
1410 sage: J1(c) == J1.one()
1412 sage: J0(J.one() - c) == J0.one()
1416 if not c
.is_idempotent():
1417 raise ValueError("element is not idempotent: %s" % c
)
1419 # Default these to what they should be if they turn out to be
1420 # trivial, because eigenspaces_left() won't return eigenvalues
1421 # corresponding to trivial spaces (e.g. it returns only the
1422 # eigenspace corresponding to lambda=1 if you take the
1423 # decomposition relative to the identity element).
1424 trivial
= self
.subalgebra((), check_axioms
=False)
1425 J0
= trivial
# eigenvalue zero
1426 J5
= VectorSpace(self
.base_ring(), 0) # eigenvalue one-half
1427 J1
= trivial
# eigenvalue one
1429 for (eigval
, eigspace
) in c
.operator().matrix().right_eigenspaces():
1430 if eigval
== ~
(self
.base_ring()(2)):
1433 gens
= tuple( self
.from_vector(b
) for b
in eigspace
.basis() )
1434 subalg
= self
.subalgebra(gens
, check_axioms
=False)
1440 raise ValueError("unexpected eigenvalue: %s" % eigval
)
1445 def random_element(self
, thorough
=False):
1447 Return a random element of this algebra.
1449 Our algebra superclass method only returns a linear
1450 combination of at most two basis elements. We instead
1451 want the vector space "random element" method that
1452 returns a more diverse selection.
1456 - ``thorough`` -- (boolean; default False) whether or not we
1457 should generate irrational coefficients for the random
1458 element when our base ring is irrational; this slows the
1459 algebra operations to a crawl, but any truly random method
1463 # For a general base ring... maybe we can trust this to do the
1464 # right thing? Unlikely, but.
1465 V
= self
.vector_space()
1466 v
= V
.random_element()
1468 if self
.base_ring() is AA
:
1469 # The "random element" method of the algebraic reals is
1470 # stupid at the moment, and only returns integers between
1471 # -2 and 2, inclusive:
1473 # https://trac.sagemath.org/ticket/30875
1475 # Instead, we implement our own "random vector" method,
1476 # and then coerce that into the algebra. We use the vector
1477 # space degree here instead of the dimension because a
1478 # subalgebra could (for example) be spanned by only two
1479 # vectors, each with five coordinates. We need to
1480 # generate all five coordinates.
1482 v
*= QQbar
.random_element().real()
1484 v
*= QQ
.random_element()
1486 return self
.from_vector(V
.coordinate_vector(v
))
1488 def random_elements(self
, count
, thorough
=False):
1490 Return ``count`` random elements as a tuple.
1494 - ``thorough`` -- (boolean; default False) whether or not we
1495 should generate irrational coefficients for the random
1496 elements when our base ring is irrational; this slows the
1497 algebra operations to a crawl, but any truly random method
1502 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1506 sage: J = JordanSpinEJA(3)
1507 sage: x,y,z = J.random_elements(3)
1508 sage: all( [ x in J, y in J, z in J ])
1510 sage: len( J.random_elements(10) ) == 10
1514 return tuple( self
.random_element(thorough
)
1515 for idx
in range(count
) )
1519 def _charpoly_coefficients(self
):
1521 The `r` polynomial coefficients of the "characteristic polynomial
1526 sage: from mjo.eja.eja_algebra import random_eja
1530 The theory shows that these are all homogeneous polynomials of
1533 sage: set_random_seed()
1534 sage: J = random_eja()
1535 sage: all(p.is_homogeneous() for p in J._charpoly_coefficients())
1539 n
= self
.dimension()
1540 R
= self
.coordinate_polynomial_ring()
1542 F
= R
.fraction_field()
1545 # From a result in my book, these are the entries of the
1546 # basis representation of L_x.
1547 return sum( vars[k
]*self
.monomial(k
).operator().matrix()[i
,j
]
1550 L_x
= matrix(F
, n
, n
, L_x_i_j
)
1553 if self
.rank
.is_in_cache():
1555 # There's no need to pad the system with redundant
1556 # columns if we *know* they'll be redundant.
1559 # Compute an extra power in case the rank is equal to
1560 # the dimension (otherwise, we would stop at x^(r-1)).
1561 x_powers
= [ (L_x
**k
)*self
.one().to_vector()
1562 for k
in range(n
+1) ]
1563 A
= matrix
.column(F
, x_powers
[:n
])
1564 AE
= A
.extended_echelon_form()
1571 # The theory says that only the first "r" coefficients are
1572 # nonzero, and they actually live in the original polynomial
1573 # ring and not the fraction field. We negate them because in
1574 # the actual characteristic polynomial, they get moved to the
1575 # other side where x^r lives. We don't bother to trim A_rref
1576 # down to a square matrix and solve the resulting system,
1577 # because the upper-left r-by-r portion of A_rref is
1578 # guaranteed to be the identity matrix, so e.g.
1580 # A_rref.solve_right(Y)
1582 # would just be returning Y.
1583 return (-E
*b
)[:r
].change_ring(R
)
1588 Return the rank of this EJA.
1590 This is a cached method because we know the rank a priori for
1591 all of the algebras we can construct. Thus we can avoid the
1592 expensive ``_charpoly_coefficients()`` call unless we truly
1593 need to compute the whole characteristic polynomial.
1597 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1598 ....: JordanSpinEJA,
1599 ....: RealSymmetricEJA,
1600 ....: ComplexHermitianEJA,
1601 ....: QuaternionHermitianEJA,
1606 The rank of the Jordan spin algebra is always two::
1608 sage: JordanSpinEJA(2).rank()
1610 sage: JordanSpinEJA(3).rank()
1612 sage: JordanSpinEJA(4).rank()
1615 The rank of the `n`-by-`n` Hermitian real, complex, or
1616 quaternion matrices is `n`::
1618 sage: RealSymmetricEJA(4).rank()
1620 sage: ComplexHermitianEJA(3).rank()
1622 sage: QuaternionHermitianEJA(2).rank()
1627 Ensure that every EJA that we know how to construct has a
1628 positive integer rank, unless the algebra is trivial in
1629 which case its rank will be zero::
1631 sage: set_random_seed()
1632 sage: J = random_eja()
1636 sage: r > 0 or (r == 0 and J.is_trivial())
1639 Ensure that computing the rank actually works, since the ranks
1640 of all simple algebras are known and will be cached by default::
1642 sage: set_random_seed() # long time
1643 sage: J = random_eja() # long time
1644 sage: cached = J.rank() # long time
1645 sage: J.rank.clear_cache() # long time
1646 sage: J.rank() == cached # long time
1650 return len(self
._charpoly
_coefficients
())
1653 def subalgebra(self
, basis
, **kwargs
):
1655 Create a subalgebra of this algebra from the given basis.
1657 from mjo
.eja
.eja_subalgebra
import FiniteDimensionalEJASubalgebra
1658 return FiniteDimensionalEJASubalgebra(self
, basis
, **kwargs
)
1661 def vector_space(self
):
1663 Return the vector space that underlies this algebra.
1667 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1671 sage: J = RealSymmetricEJA(2)
1672 sage: J.vector_space()
1673 Vector space of dimension 3 over...
1676 return self
.zero().to_vector().parent().ambient_vector_space()
1680 class RationalBasisEJA(FiniteDimensionalEJA
):
1682 Algebras whose supplied basis elements have all rational entries.
1686 sage: from mjo.eja.eja_algebra import BilinearFormEJA
1690 The supplied basis is orthonormalized by default::
1692 sage: B = matrix(QQ, [[1, 0, 0], [0, 25, -32], [0, -32, 41]])
1693 sage: J = BilinearFormEJA(B)
1694 sage: J.matrix_basis()
1711 # Abuse the check_field parameter to check that the entries of
1712 # out basis (in ambient coordinates) are in the field QQ.
1713 # Use _all2list to get the vector coordinates of octonion
1714 # entries and not the octonions themselves (which are not
1716 if not all( all(b_i
in QQ
for b_i
in _all2list(b
))
1718 raise TypeError("basis not rational")
1720 super().__init
__(basis
,
1724 check_field
=check_field
,
1727 self
._rational
_algebra
= None
1729 # There's no point in constructing the extra algebra if this
1730 # one is already rational.
1732 # Note: the same Jordan and inner-products work here,
1733 # because they are necessarily defined with respect to
1734 # ambient coordinates and not any particular basis.
1735 self
._rational
_algebra
= FiniteDimensionalEJA(
1740 matrix_space
=self
.matrix_space(),
1741 associative
=self
.is_associative(),
1742 orthonormalize
=False,
1746 def rational_algebra(self
):
1747 # Using None as a flag here (rather than just assigning "self"
1748 # to self._rational_algebra by default) feels a little bit
1749 # more sane to me in a garbage-collected environment.
1750 if self
._rational
_algebra
is None:
1753 return self
._rational
_algebra
1756 def _charpoly_coefficients(self
):
1760 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1761 ....: JordanSpinEJA)
1765 The base ring of the resulting polynomial coefficients is what
1766 it should be, and not the rationals (unless the algebra was
1767 already over the rationals)::
1769 sage: J = JordanSpinEJA(3)
1770 sage: J._charpoly_coefficients()
1771 (X1^2 - X2^2 - X3^2, -2*X1)
1772 sage: a0 = J._charpoly_coefficients()[0]
1774 Algebraic Real Field
1775 sage: a0.base_ring()
1776 Algebraic Real Field
1779 if self
.rational_algebra() is self
:
1780 # Bypass the hijinks if they won't benefit us.
1781 return super()._charpoly
_coefficients
()
1783 # Do the computation over the rationals. The answer will be
1784 # the same, because all we've done is a change of basis.
1785 # Then, change back from QQ to our real base ring
1786 a
= ( a_i
.change_ring(self
.base_ring())
1787 for a_i
in self
.rational_algebra()._charpoly
_coefficients
() )
1789 # Otherwise, convert the coordinate variables back to the
1790 # deorthonormalized ones.
1791 R
= self
.coordinate_polynomial_ring()
1792 from sage
.modules
.free_module_element
import vector
1793 X
= vector(R
, R
.gens())
1794 BX
= self
._deortho
_matrix
*X
1796 subs_dict
= { X[i]: BX[i] for i in range(len(X)) }
1797 return tuple( a_i
.subs(subs_dict
) for a_i
in a
)
1799 class ConcreteEJA(FiniteDimensionalEJA
):
1801 A class for the Euclidean Jordan algebras that we know by name.
1803 These are the Jordan algebras whose basis, multiplication table,
1804 rank, and so on are known a priori. More to the point, they are
1805 the Euclidean Jordan algebras for which we are able to conjure up
1806 a "random instance."
1810 sage: from mjo.eja.eja_algebra import ConcreteEJA
1814 Our basis is normalized with respect to the algebra's inner
1815 product, unless we specify otherwise::
1817 sage: set_random_seed()
1818 sage: J = ConcreteEJA.random_instance()
1819 sage: all( b.norm() == 1 for b in J.gens() )
1822 Since our basis is orthonormal with respect to the algebra's inner
1823 product, and since we know that this algebra is an EJA, any
1824 left-multiplication operator's matrix will be symmetric because
1825 natural->EJA basis representation is an isometry and within the
1826 EJA the operator is self-adjoint by the Jordan axiom::
1828 sage: set_random_seed()
1829 sage: J = ConcreteEJA.random_instance()
1830 sage: x = J.random_element()
1831 sage: x.operator().is_self_adjoint()
1836 def _max_random_instance_dimension():
1838 The maximum dimension of any random instance. Ten dimensions seems
1839 to be about the point where everything takes a turn for the
1840 worse. And dimension ten (but not nine) allows the 4-by-4 real
1841 Hermitian matrices, the 2-by-2 quaternion Hermitian matrices,
1842 and the 2-by-2 octonion Hermitian matrices.
1847 def _max_random_instance_size(max_dimension
):
1849 Return an integer "size" that is an upper bound on the size of
1850 this algebra when it is used in a random test case. This size
1851 (which can be passed to the algebra's constructor) is itself
1852 based on the ``max_dimension`` parameter.
1854 This method must be implemented in each subclass.
1856 raise NotImplementedError
1859 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
1861 Return a random instance of this type of algebra whose dimension
1862 is less than or equal to the lesser of ``max_dimension`` and
1863 the value returned by ``_max_random_instance_dimension()``. If
1864 the dimension bound is omitted, then only the
1865 ``_max_random_instance_dimension()`` is used as a bound.
1867 This method should be implemented in each subclass.
1871 sage: from mjo.eja.eja_algebra import ConcreteEJA
1875 Both the class bound and the ``max_dimension`` argument are upper
1876 bounds on the dimension of the algebra returned::
1878 sage: from sage.misc.prandom import choice
1879 sage: eja_class = choice(ConcreteEJA.__subclasses__())
1880 sage: class_max_d = eja_class._max_random_instance_dimension()
1881 sage: J = eja_class.random_instance(max_dimension=20,
1883 ....: orthonormalize=False)
1884 sage: J.dimension() <= class_max_d
1886 sage: J = eja_class.random_instance(max_dimension=2,
1888 ....: orthonormalize=False)
1889 sage: J.dimension() <= 2
1893 from sage
.misc
.prandom
import choice
1894 eja_class
= choice(cls
.__subclasses
__())
1896 # These all bubble up to the RationalBasisEJA superclass
1897 # constructor, so any (kw)args valid there are also valid
1899 return eja_class
.random_instance(max_dimension
, *args
, **kwargs
)
1902 class MatrixEJA(FiniteDimensionalEJA
):
1904 def _denormalized_basis(A
):
1906 Returns a basis for the space of complex Hermitian n-by-n matrices.
1908 Why do we embed these? Basically, because all of numerical linear
1909 algebra assumes that you're working with vectors consisting of `n`
1910 entries from a field and scalars from the same field. There's no way
1911 to tell SageMath that (for example) the vectors contain complex
1912 numbers, while the scalar field is real.
1916 sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
1917 ....: QuaternionMatrixAlgebra,
1918 ....: OctonionMatrixAlgebra)
1919 sage: from mjo.eja.eja_algebra import MatrixEJA
1923 sage: set_random_seed()
1924 sage: n = ZZ.random_element(1,5)
1925 sage: A = MatrixSpace(QQ, n)
1926 sage: B = MatrixEJA._denormalized_basis(A)
1927 sage: all( M.is_hermitian() for M in B)
1932 sage: set_random_seed()
1933 sage: n = ZZ.random_element(1,5)
1934 sage: A = ComplexMatrixAlgebra(n, scalars=QQ)
1935 sage: B = MatrixEJA._denormalized_basis(A)
1936 sage: all( M.is_hermitian() for M in B)
1941 sage: set_random_seed()
1942 sage: n = ZZ.random_element(1,5)
1943 sage: A = QuaternionMatrixAlgebra(n, scalars=QQ)
1944 sage: B = MatrixEJA._denormalized_basis(A)
1945 sage: all( M.is_hermitian() for M in B )
1950 sage: set_random_seed()
1951 sage: n = ZZ.random_element(1,5)
1952 sage: A = OctonionMatrixAlgebra(n, scalars=QQ)
1953 sage: B = MatrixEJA._denormalized_basis(A)
1954 sage: all( M.is_hermitian() for M in B )
1958 # These work for real MatrixSpace, whose monomials only have
1959 # two coordinates (because the last one would always be "1").
1960 es
= A
.base_ring().gens()
1961 gen
= lambda A
,m
: A
.monomial(m
[:2])
1963 if hasattr(A
, 'entry_algebra_gens'):
1964 # We've got a MatrixAlgebra, and its monomials will have
1965 # three coordinates.
1966 es
= A
.entry_algebra_gens()
1967 gen
= lambda A
,m
: A
.monomial(m
)
1970 for i
in range(A
.nrows()):
1971 for j
in range(i
+1):
1973 E_ii
= gen(A
, (i
,j
,es
[0]))
1977 E_ij
= gen(A
, (i
,j
,e
))
1978 E_ij
+= E_ij
.conjugate_transpose()
1981 return tuple( basis
)
1984 def jordan_product(X
,Y
):
1985 return (X
*Y
+ Y
*X
)/2
1988 def trace_inner_product(X
,Y
):
1990 A trace inner-product for matrices that aren't embedded in the
1991 reals. It takes MATRICES as arguments, not EJA elements.
1995 sage: from mjo.eja.eja_algebra import (RealSymmetricEJA,
1996 ....: ComplexHermitianEJA,
1997 ....: QuaternionHermitianEJA,
1998 ....: OctonionHermitianEJA)
2002 sage: J = RealSymmetricEJA(2,field=QQ,orthonormalize=False)
2003 sage: I = J.one().to_matrix()
2004 sage: J.trace_inner_product(I, -I)
2009 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
2010 sage: I = J.one().to_matrix()
2011 sage: J.trace_inner_product(I, -I)
2016 sage: J = QuaternionHermitianEJA(2,field=QQ,orthonormalize=False)
2017 sage: I = J.one().to_matrix()
2018 sage: J.trace_inner_product(I, -I)
2023 sage: J = OctonionHermitianEJA(2,field=QQ,orthonormalize=False)
2024 sage: I = J.one().to_matrix()
2025 sage: J.trace_inner_product(I, -I)
2030 if hasattr(tr
, 'coefficient'):
2031 # Works for octonions, and has to come first because they
2032 # also have a "real()" method that doesn't return an
2033 # element of the scalar ring.
2034 return tr
.coefficient(0)
2035 elif hasattr(tr
, 'coefficient_tuple'):
2036 # Works for quaternions.
2037 return tr
.coefficient_tuple()[0]
2039 # Works for real and complex numbers.
2043 def __init__(self
, matrix_space
, **kwargs
):
2044 # We know this is a valid EJA, but will double-check
2045 # if the user passes check_axioms=True.
2046 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2049 super().__init
__(self
._denormalized
_basis
(matrix_space
),
2050 self
.jordan_product
,
2051 self
.trace_inner_product
,
2052 field
=matrix_space
.base_ring(),
2053 matrix_space
=matrix_space
,
2056 self
.rank
.set_cache(matrix_space
.nrows())
2057 self
.one
.set_cache( self(matrix_space
.one()) )
2059 class RealSymmetricEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2061 The rank-n simple EJA consisting of real symmetric n-by-n
2062 matrices, the usual symmetric Jordan product, and the trace inner
2063 product. It has dimension `(n^2 + n)/2` over the reals.
2067 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
2071 sage: J = RealSymmetricEJA(2)
2072 sage: b0, b1, b2 = J.gens()
2080 In theory, our "field" can be any subfield of the reals::
2082 sage: RealSymmetricEJA(2, field=RDF, check_axioms=True)
2083 Euclidean Jordan algebra of dimension 3 over Real Double Field
2084 sage: RealSymmetricEJA(2, field=RR, check_axioms=True)
2085 Euclidean Jordan algebra of dimension 3 over Real Field with
2086 53 bits of precision
2090 The dimension of this algebra is `(n^2 + n) / 2`::
2092 sage: set_random_seed()
2093 sage: d = RealSymmetricEJA._max_random_instance_dimension()
2094 sage: n = RealSymmetricEJA._max_random_instance_size(d)
2095 sage: J = RealSymmetricEJA(n)
2096 sage: J.dimension() == (n^2 + n)/2
2099 The Jordan multiplication is what we think it is::
2101 sage: set_random_seed()
2102 sage: J = RealSymmetricEJA.random_instance()
2103 sage: x,y = J.random_elements(2)
2104 sage: actual = (x*y).to_matrix()
2105 sage: X = x.to_matrix()
2106 sage: Y = y.to_matrix()
2107 sage: expected = (X*Y + Y*X)/2
2108 sage: actual == expected
2110 sage: J(expected) == x*y
2113 We can change the generator prefix::
2115 sage: RealSymmetricEJA(3, prefix='q').gens()
2116 (q0, q1, q2, q3, q4, q5)
2118 We can construct the (trivial) algebra of rank zero::
2120 sage: RealSymmetricEJA(0)
2121 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2125 def _max_random_instance_size(max_dimension
):
2126 # Obtained by solving d = (n^2 + n)/2.
2127 # The ZZ-int-ZZ thing is just "floor."
2128 return ZZ(int(ZZ(8*max_dimension
+ 1).sqrt()/2 - 1/2))
2131 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2133 Return a random instance of this type of algebra.
2135 class_max_d
= cls
._max
_random
_instance
_dimension
()
2136 if (max_dimension
is None or max_dimension
> class_max_d
):
2137 max_dimension
= class_max_d
2138 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2139 n
= ZZ
.random_element(max_size
+ 1)
2140 return cls(n
, **kwargs
)
2142 def __init__(self
, n
, field
=AA
, **kwargs
):
2143 # We know this is a valid EJA, but will double-check
2144 # if the user passes check_axioms=True.
2145 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2147 A
= MatrixSpace(field
, n
)
2148 super().__init
__(A
, **kwargs
)
2150 from mjo
.eja
.eja_cache
import real_symmetric_eja_coeffs
2151 a
= real_symmetric_eja_coeffs(self
)
2153 self
.rational_algebra()._charpoly
_coefficients
.set_cache(a
)
2157 class ComplexHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2159 The rank-n simple EJA consisting of complex Hermitian n-by-n
2160 matrices over the real numbers, the usual symmetric Jordan product,
2161 and the real-part-of-trace inner product. It has dimension `n^2` over
2166 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
2170 In theory, our "field" can be any subfield of the reals, but we
2171 can't use inexact real fields at the moment because SageMath
2172 doesn't know how to convert their elements into complex numbers,
2173 or even into algebraic reals::
2176 Traceback (most recent call last):
2178 TypeError: Illegal initializer for algebraic number
2180 Traceback (most recent call last):
2182 TypeError: Illegal initializer for algebraic number
2184 This causes the following error when we try to scale a matrix of
2185 complex numbers by an inexact real number::
2187 sage: ComplexHermitianEJA(2,field=RR)
2188 Traceback (most recent call last):
2190 TypeError: Unable to coerce entries (=(1.00000000000000,
2191 -0.000000000000000)) to coefficients in Algebraic Real Field
2195 The dimension of this algebra is `n^2`::
2197 sage: set_random_seed()
2198 sage: d = ComplexHermitianEJA._max_random_instance_dimension()
2199 sage: n = ComplexHermitianEJA._max_random_instance_size(d)
2200 sage: J = ComplexHermitianEJA(n)
2201 sage: J.dimension() == n^2
2204 The Jordan multiplication is what we think it is::
2206 sage: set_random_seed()
2207 sage: J = ComplexHermitianEJA.random_instance()
2208 sage: x,y = J.random_elements(2)
2209 sage: actual = (x*y).to_matrix()
2210 sage: X = x.to_matrix()
2211 sage: Y = y.to_matrix()
2212 sage: expected = (X*Y + Y*X)/2
2213 sage: actual == expected
2215 sage: J(expected) == x*y
2218 We can change the generator prefix::
2220 sage: ComplexHermitianEJA(2, prefix='z').gens()
2223 We can construct the (trivial) algebra of rank zero::
2225 sage: ComplexHermitianEJA(0)
2226 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2229 def __init__(self
, n
, field
=AA
, **kwargs
):
2230 # We know this is a valid EJA, but will double-check
2231 # if the user passes check_axioms=True.
2232 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2234 from mjo
.hurwitz
import ComplexMatrixAlgebra
2235 A
= ComplexMatrixAlgebra(n
, scalars
=field
)
2236 super().__init
__(A
, **kwargs
)
2238 from mjo
.eja
.eja_cache
import complex_hermitian_eja_coeffs
2239 a
= complex_hermitian_eja_coeffs(self
)
2241 self
.rational_algebra()._charpoly
_coefficients
.set_cache(a
)
2244 def _max_random_instance_size(max_dimension
):
2245 # Obtained by solving d = n^2.
2246 # The ZZ-int-ZZ thing is just "floor."
2247 return ZZ(int(ZZ(max_dimension
).sqrt()))
2250 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2252 Return a random instance of this type of algebra.
2254 class_max_d
= cls
._max
_random
_instance
_dimension
()
2255 if (max_dimension
is None or max_dimension
> class_max_d
):
2256 max_dimension
= class_max_d
2257 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2258 n
= ZZ
.random_element(max_size
+ 1)
2259 return cls(n
, **kwargs
)
2262 class QuaternionHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2264 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2265 matrices, the usual symmetric Jordan product, and the
2266 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2271 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2275 In theory, our "field" can be any subfield of the reals::
2277 sage: QuaternionHermitianEJA(2, field=RDF, check_axioms=True)
2278 Euclidean Jordan algebra of dimension 6 over Real Double Field
2279 sage: QuaternionHermitianEJA(2, field=RR, check_axioms=True)
2280 Euclidean Jordan algebra of dimension 6 over Real Field with
2281 53 bits of precision
2285 The dimension of this algebra is `2*n^2 - n`::
2287 sage: set_random_seed()
2288 sage: d = QuaternionHermitianEJA._max_random_instance_dimension()
2289 sage: n = QuaternionHermitianEJA._max_random_instance_size(d)
2290 sage: J = QuaternionHermitianEJA(n)
2291 sage: J.dimension() == 2*(n^2) - n
2294 The Jordan multiplication is what we think it is::
2296 sage: set_random_seed()
2297 sage: J = QuaternionHermitianEJA.random_instance()
2298 sage: x,y = J.random_elements(2)
2299 sage: actual = (x*y).to_matrix()
2300 sage: X = x.to_matrix()
2301 sage: Y = y.to_matrix()
2302 sage: expected = (X*Y + Y*X)/2
2303 sage: actual == expected
2305 sage: J(expected) == x*y
2308 We can change the generator prefix::
2310 sage: QuaternionHermitianEJA(2, prefix='a').gens()
2311 (a0, a1, a2, a3, a4, a5)
2313 We can construct the (trivial) algebra of rank zero::
2315 sage: QuaternionHermitianEJA(0)
2316 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2319 def __init__(self
, n
, field
=AA
, **kwargs
):
2320 # We know this is a valid EJA, but will double-check
2321 # if the user passes check_axioms=True.
2322 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2324 from mjo
.hurwitz
import QuaternionMatrixAlgebra
2325 A
= QuaternionMatrixAlgebra(n
, scalars
=field
)
2326 super().__init
__(A
, **kwargs
)
2328 from mjo
.eja
.eja_cache
import quaternion_hermitian_eja_coeffs
2329 a
= quaternion_hermitian_eja_coeffs(self
)
2331 self
.rational_algebra()._charpoly
_coefficients
.set_cache(a
)
2336 def _max_random_instance_size(max_dimension
):
2338 The maximum rank of a random QuaternionHermitianEJA.
2340 # Obtained by solving d = 2n^2 - n.
2341 # The ZZ-int-ZZ thing is just "floor."
2342 return ZZ(int(ZZ(8*max_dimension
+ 1).sqrt()/4 + 1/4))
2345 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2347 Return a random instance of this type of algebra.
2349 class_max_d
= cls
._max
_random
_instance
_dimension
()
2350 if (max_dimension
is None or max_dimension
> class_max_d
):
2351 max_dimension
= class_max_d
2352 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2353 n
= ZZ
.random_element(max_size
+ 1)
2354 return cls(n
, **kwargs
)
2356 class OctonionHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2360 sage: from mjo.eja.eja_algebra import (FiniteDimensionalEJA,
2361 ....: OctonionHermitianEJA)
2362 sage: from mjo.hurwitz import Octonions, OctonionMatrixAlgebra
2366 The 3-by-3 algebra satisfies the axioms of an EJA::
2368 sage: OctonionHermitianEJA(3, # long time
2369 ....: field=QQ, # long time
2370 ....: orthonormalize=False, # long time
2371 ....: check_axioms=True) # long time
2372 Euclidean Jordan algebra of dimension 27 over Rational Field
2374 After a change-of-basis, the 2-by-2 algebra has the same
2375 multiplication table as the ten-dimensional Jordan spin algebra::
2377 sage: A = OctonionMatrixAlgebra(2,Octonions(QQ),QQ)
2378 sage: b = OctonionHermitianEJA._denormalized_basis(A)
2379 sage: basis = (b[0] + b[9],) + b[1:9] + (b[0] - b[9],)
2380 sage: jp = OctonionHermitianEJA.jordan_product
2381 sage: ip = OctonionHermitianEJA.trace_inner_product
2382 sage: J = FiniteDimensionalEJA(basis,
2386 ....: orthonormalize=False)
2387 sage: J.multiplication_table()
2388 +----++----+----+----+----+----+----+----+----+----+----+
2389 | * || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2390 +====++====+====+====+====+====+====+====+====+====+====+
2391 | b0 || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2392 +----++----+----+----+----+----+----+----+----+----+----+
2393 | b1 || b1 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2394 +----++----+----+----+----+----+----+----+----+----+----+
2395 | b2 || b2 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2396 +----++----+----+----+----+----+----+----+----+----+----+
2397 | b3 || b3 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 |
2398 +----++----+----+----+----+----+----+----+----+----+----+
2399 | b4 || b4 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 |
2400 +----++----+----+----+----+----+----+----+----+----+----+
2401 | b5 || b5 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 |
2402 +----++----+----+----+----+----+----+----+----+----+----+
2403 | b6 || b6 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 |
2404 +----++----+----+----+----+----+----+----+----+----+----+
2405 | b7 || b7 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 |
2406 +----++----+----+----+----+----+----+----+----+----+----+
2407 | b8 || b8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 |
2408 +----++----+----+----+----+----+----+----+----+----+----+
2409 | b9 || b9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 |
2410 +----++----+----+----+----+----+----+----+----+----+----+
2414 We can actually construct the 27-dimensional Albert algebra,
2415 and we get the right unit element if we recompute it::
2417 sage: J = OctonionHermitianEJA(3, # long time
2418 ....: field=QQ, # long time
2419 ....: orthonormalize=False) # long time
2420 sage: J.one.clear_cache() # long time
2421 sage: J.one() # long time
2423 sage: J.one().to_matrix() # long time
2432 The 2-by-2 algebra is isomorphic to the ten-dimensional Jordan
2433 spin algebra, but just to be sure, we recompute its rank::
2435 sage: J = OctonionHermitianEJA(2, # long time
2436 ....: field=QQ, # long time
2437 ....: orthonormalize=False) # long time
2438 sage: J.rank.clear_cache() # long time
2439 sage: J.rank() # long time
2444 def _max_random_instance_size(max_dimension
):
2446 The maximum rank of a random QuaternionHermitianEJA.
2448 # There's certainly a formula for this, but with only four
2449 # cases to worry about, I'm not that motivated to derive it.
2450 if max_dimension
>= 27:
2452 elif max_dimension
>= 10:
2454 elif max_dimension
>= 1:
2460 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2462 Return a random instance of this type of algebra.
2464 class_max_d
= cls
._max
_random
_instance
_dimension
()
2465 if (max_dimension
is None or max_dimension
> class_max_d
):
2466 max_dimension
= class_max_d
2467 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2468 n
= ZZ
.random_element(max_size
+ 1)
2469 return cls(n
, **kwargs
)
2471 def __init__(self
, n
, field
=AA
, **kwargs
):
2473 # Otherwise we don't get an EJA.
2474 raise ValueError("n cannot exceed 3")
2476 # We know this is a valid EJA, but will double-check
2477 # if the user passes check_axioms=True.
2478 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2480 from mjo
.hurwitz
import OctonionMatrixAlgebra
2481 A
= OctonionMatrixAlgebra(n
, scalars
=field
)
2482 super().__init
__(A
, **kwargs
)
2484 from mjo
.eja
.eja_cache
import octonion_hermitian_eja_coeffs
2485 a
= octonion_hermitian_eja_coeffs(self
)
2487 self
.rational_algebra()._charpoly
_coefficients
.set_cache(a
)
2490 class AlbertEJA(OctonionHermitianEJA
):
2492 The Albert algebra is the algebra of three-by-three Hermitian
2493 matrices whose entries are octonions.
2497 sage: from mjo.eja.eja_algebra import AlbertEJA
2501 sage: AlbertEJA(field=QQ, orthonormalize=False)
2502 Euclidean Jordan algebra of dimension 27 over Rational Field
2503 sage: AlbertEJA() # long time
2504 Euclidean Jordan algebra of dimension 27 over Algebraic Real Field
2507 def __init__(self
, *args
, **kwargs
):
2508 super().__init
__(3, *args
, **kwargs
)
2511 class HadamardEJA(RationalBasisEJA
, ConcreteEJA
):
2513 Return the Euclidean Jordan algebra on `R^n` with the Hadamard
2514 (pointwise real-number multiplication) Jordan product and the
2515 usual inner-product.
2517 This is nothing more than the Cartesian product of ``n`` copies of
2518 the one-dimensional Jordan spin algebra, and is the most common
2519 example of a non-simple Euclidean Jordan algebra.
2523 sage: from mjo.eja.eja_algebra import HadamardEJA
2527 This multiplication table can be verified by hand::
2529 sage: J = HadamardEJA(3)
2530 sage: b0,b1,b2 = J.gens()
2546 We can change the generator prefix::
2548 sage: HadamardEJA(3, prefix='r').gens()
2551 def __init__(self
, n
, field
=AA
, **kwargs
):
2552 MS
= MatrixSpace(field
, n
, 1)
2555 jordan_product
= lambda x
,y
: x
2556 inner_product
= lambda x
,y
: x
2558 def jordan_product(x
,y
):
2559 return MS( xi
*yi
for (xi
,yi
) in zip(x
,y
) )
2561 def inner_product(x
,y
):
2564 # New defaults for keyword arguments. Don't orthonormalize
2565 # because our basis is already orthonormal with respect to our
2566 # inner-product. Don't check the axioms, because we know this
2567 # is a valid EJA... but do double-check if the user passes
2568 # check_axioms=True. Note: we DON'T override the "check_field"
2569 # default here, because the user can pass in a field!
2570 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2571 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2573 column_basis
= tuple( MS(b
) for b
in FreeModule(field
, n
).basis() )
2574 super().__init
__(column_basis
,
2581 self
.rank
.set_cache(n
)
2583 self
.one
.set_cache( self
.sum(self
.gens()) )
2586 def _max_random_instance_dimension():
2588 There's no reason to go higher than five here. That's
2589 enough to get the point across.
2594 def _max_random_instance_size(max_dimension
):
2596 The maximum size (=dimension) of a random HadamardEJA.
2598 return max_dimension
2601 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2603 Return a random instance of this type of algebra.
2605 class_max_d
= cls
._max
_random
_instance
_dimension
()
2606 if (max_dimension
is None or max_dimension
> class_max_d
):
2607 max_dimension
= class_max_d
2608 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2609 n
= ZZ
.random_element(max_size
+ 1)
2610 return cls(n
, **kwargs
)
2613 class BilinearFormEJA(RationalBasisEJA
, ConcreteEJA
):
2615 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2616 with the half-trace inner product and jordan product ``x*y =
2617 (<Bx,y>,y_bar>, x0*y_bar + y0*x_bar)`` where `B = 1 \times B22` is
2618 a symmetric positive-definite "bilinear form" matrix. Its
2619 dimension is the size of `B`, and it has rank two in dimensions
2620 larger than two. It reduces to the ``JordanSpinEJA`` when `B` is
2621 the identity matrix of order ``n``.
2623 We insist that the one-by-one upper-left identity block of `B` be
2624 passed in as well so that we can be passed a matrix of size zero
2625 to construct a trivial algebra.
2629 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
2630 ....: JordanSpinEJA)
2634 When no bilinear form is specified, the identity matrix is used,
2635 and the resulting algebra is the Jordan spin algebra::
2637 sage: B = matrix.identity(AA,3)
2638 sage: J0 = BilinearFormEJA(B)
2639 sage: J1 = JordanSpinEJA(3)
2640 sage: J0.multiplication_table() == J0.multiplication_table()
2643 An error is raised if the matrix `B` does not correspond to a
2644 positive-definite bilinear form::
2646 sage: B = matrix.random(QQ,2,3)
2647 sage: J = BilinearFormEJA(B)
2648 Traceback (most recent call last):
2650 ValueError: bilinear form is not positive-definite
2651 sage: B = matrix.zero(QQ,3)
2652 sage: J = BilinearFormEJA(B)
2653 Traceback (most recent call last):
2655 ValueError: bilinear form is not positive-definite
2659 We can create a zero-dimensional algebra::
2661 sage: B = matrix.identity(AA,0)
2662 sage: J = BilinearFormEJA(B)
2666 We can check the multiplication condition given in the Jordan, von
2667 Neumann, and Wigner paper (and also discussed on my "On the
2668 symmetry..." paper). Note that this relies heavily on the standard
2669 choice of basis, as does anything utilizing the bilinear form
2670 matrix. We opt not to orthonormalize the basis, because if we
2671 did, we would have to normalize the `s_{i}` in a similar manner::
2673 sage: set_random_seed()
2674 sage: n = ZZ.random_element(5)
2675 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2676 sage: B11 = matrix.identity(QQ,1)
2677 sage: B22 = M.transpose()*M
2678 sage: B = block_matrix(2,2,[ [B11,0 ],
2680 sage: J = BilinearFormEJA(B, orthonormalize=False)
2681 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
2682 sage: V = J.vector_space()
2683 sage: sis = [ J( V([0] + (M.inverse()*ei).list()).column() )
2684 ....: for ei in eis ]
2685 sage: actual = [ sis[i]*sis[j]
2686 ....: for i in range(n-1)
2687 ....: for j in range(n-1) ]
2688 sage: expected = [ J.one() if i == j else J.zero()
2689 ....: for i in range(n-1)
2690 ....: for j in range(n-1) ]
2691 sage: actual == expected
2695 def __init__(self
, B
, field
=AA
, **kwargs
):
2696 # The matrix "B" is supplied by the user in most cases,
2697 # so it makes sense to check whether or not its positive-
2698 # definite unless we are specifically asked not to...
2699 if ("check_axioms" not in kwargs
) or kwargs
["check_axioms"]:
2700 if not B
.is_positive_definite():
2701 raise ValueError("bilinear form is not positive-definite")
2703 # However, all of the other data for this EJA is computed
2704 # by us in manner that guarantees the axioms are
2705 # satisfied. So, again, unless we are specifically asked to
2706 # verify things, we'll skip the rest of the checks.
2707 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2710 MS
= MatrixSpace(field
, n
, 1)
2712 def inner_product(x
,y
):
2713 return (y
.T
*B
*x
)[0,0]
2715 def jordan_product(x
,y
):
2720 z0
= inner_product(y
,x
)
2721 zbar
= y0
*xbar
+ x0
*ybar
2722 return MS([z0
] + zbar
.list())
2724 column_basis
= tuple( MS(b
) for b
in FreeModule(field
, n
).basis() )
2726 # TODO: I haven't actually checked this, but it seems legit.
2731 super().__init
__(column_basis
,
2736 associative
=associative
,
2739 # The rank of this algebra is two, unless we're in a
2740 # one-dimensional ambient space (because the rank is bounded
2741 # by the ambient dimension).
2742 self
.rank
.set_cache(min(n
,2))
2744 self
.one
.set_cache( self
.zero() )
2746 self
.one
.set_cache( self
.monomial(0) )
2749 def _max_random_instance_dimension():
2751 There's no reason to go higher than five here. That's
2752 enough to get the point across.
2757 def _max_random_instance_size(max_dimension
):
2759 The maximum size (=dimension) of a random BilinearFormEJA.
2761 return max_dimension
2764 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2766 Return a random instance of this algebra.
2768 class_max_d
= cls
._max
_random
_instance
_dimension
()
2769 if (max_dimension
is None or max_dimension
> class_max_d
):
2770 max_dimension
= class_max_d
2771 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2772 n
= ZZ
.random_element(max_size
+ 1)
2775 B
= matrix
.identity(ZZ
, n
)
2776 return cls(B
, **kwargs
)
2778 B11
= matrix
.identity(ZZ
, 1)
2779 M
= matrix
.random(ZZ
, n
-1)
2780 I
= matrix
.identity(ZZ
, n
-1)
2782 while alpha
.is_zero():
2783 alpha
= ZZ
.random_element().abs()
2785 B22
= M
.transpose()*M
+ alpha
*I
2787 from sage
.matrix
.special
import block_matrix
2788 B
= block_matrix(2,2, [ [B11
, ZZ(0) ],
2791 return cls(B
, **kwargs
)
2794 class JordanSpinEJA(BilinearFormEJA
):
2796 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2797 with the usual inner product and jordan product ``x*y =
2798 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2803 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2807 This multiplication table can be verified by hand::
2809 sage: J = JordanSpinEJA(4)
2810 sage: b0,b1,b2,b3 = J.gens()
2826 We can change the generator prefix::
2828 sage: JordanSpinEJA(2, prefix='B').gens()
2833 Ensure that we have the usual inner product on `R^n`::
2835 sage: set_random_seed()
2836 sage: J = JordanSpinEJA.random_instance()
2837 sage: x,y = J.random_elements(2)
2838 sage: actual = x.inner_product(y)
2839 sage: expected = x.to_vector().inner_product(y.to_vector())
2840 sage: actual == expected
2844 def __init__(self
, n
, *args
, **kwargs
):
2845 # This is a special case of the BilinearFormEJA with the
2846 # identity matrix as its bilinear form.
2847 B
= matrix
.identity(ZZ
, n
)
2849 # Don't orthonormalize because our basis is already
2850 # orthonormal with respect to our inner-product.
2851 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2853 # But also don't pass check_field=False here, because the user
2854 # can pass in a field!
2855 super().__init
__(B
, *args
, **kwargs
)
2858 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2860 Return a random instance of this type of algebra.
2862 Needed here to override the implementation for ``BilinearFormEJA``.
2864 class_max_d
= cls
._max
_random
_instance
_dimension
()
2865 if (max_dimension
is None or max_dimension
> class_max_d
):
2866 max_dimension
= class_max_d
2867 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2868 n
= ZZ
.random_element(max_size
+ 1)
2869 return cls(n
, **kwargs
)
2872 class TrivialEJA(RationalBasisEJA
, ConcreteEJA
):
2874 The trivial Euclidean Jordan algebra consisting of only a zero element.
2878 sage: from mjo.eja.eja_algebra import TrivialEJA
2882 sage: J = TrivialEJA()
2889 sage: 7*J.one()*12*J.one()
2891 sage: J.one().inner_product(J.one())
2893 sage: J.one().norm()
2895 sage: J.one().subalgebra_generated_by()
2896 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2901 def __init__(self
, field
=AA
, **kwargs
):
2902 jordan_product
= lambda x
,y
: x
2903 inner_product
= lambda x
,y
: field
.zero()
2905 MS
= MatrixSpace(field
,0)
2907 # New defaults for keyword arguments
2908 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2909 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2911 super().__init
__(basis
,
2919 # The rank is zero using my definition, namely the dimension of the
2920 # largest subalgebra generated by any element.
2921 self
.rank
.set_cache(0)
2922 self
.one
.set_cache( self
.zero() )
2925 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2926 # We don't take a "size" argument so the superclass method is
2927 # inappropriate for us. The ``max_dimension`` argument is
2928 # included so that if this method is called generically with a
2929 # ``max_dimension=<whatever>`` argument, we don't try to pass
2930 # it on to the algebra constructor.
2931 return cls(**kwargs
)
2934 class CartesianProductEJA(FiniteDimensionalEJA
):
2936 The external (orthogonal) direct sum of two or more Euclidean
2937 Jordan algebras. Every Euclidean Jordan algebra decomposes into an
2938 orthogonal direct sum of simple Euclidean Jordan algebras which is
2939 then isometric to a Cartesian product, so no generality is lost by
2940 providing only this construction.
2944 sage: from mjo.eja.eja_algebra import (random_eja,
2945 ....: CartesianProductEJA,
2946 ....: ComplexHermitianEJA,
2948 ....: JordanSpinEJA,
2949 ....: RealSymmetricEJA)
2953 The Jordan product is inherited from our factors and implemented by
2954 our CombinatorialFreeModule Cartesian product superclass::
2956 sage: set_random_seed()
2957 sage: J1 = HadamardEJA(2)
2958 sage: J2 = RealSymmetricEJA(2)
2959 sage: J = cartesian_product([J1,J2])
2960 sage: x,y = J.random_elements(2)
2964 The ability to retrieve the original factors is implemented by our
2965 CombinatorialFreeModule Cartesian product superclass::
2967 sage: J1 = HadamardEJA(2, field=QQ)
2968 sage: J2 = JordanSpinEJA(3, field=QQ)
2969 sage: J = cartesian_product([J1,J2])
2970 sage: J.cartesian_factors()
2971 (Euclidean Jordan algebra of dimension 2 over Rational Field,
2972 Euclidean Jordan algebra of dimension 3 over Rational Field)
2974 You can provide more than two factors::
2976 sage: J1 = HadamardEJA(2)
2977 sage: J2 = JordanSpinEJA(3)
2978 sage: J3 = RealSymmetricEJA(3)
2979 sage: cartesian_product([J1,J2,J3])
2980 Euclidean Jordan algebra of dimension 2 over Algebraic Real
2981 Field (+) Euclidean Jordan algebra of dimension 3 over Algebraic
2982 Real Field (+) Euclidean Jordan algebra of dimension 6 over
2983 Algebraic Real Field
2985 Rank is additive on a Cartesian product::
2987 sage: J1 = HadamardEJA(1)
2988 sage: J2 = RealSymmetricEJA(2)
2989 sage: J = cartesian_product([J1,J2])
2990 sage: J1.rank.clear_cache()
2991 sage: J2.rank.clear_cache()
2992 sage: J.rank.clear_cache()
2995 sage: J.rank() == J1.rank() + J2.rank()
2998 The same rank computation works over the rationals, with whatever
3001 sage: J1 = HadamardEJA(1, field=QQ, orthonormalize=False)
3002 sage: J2 = RealSymmetricEJA(2, field=QQ, orthonormalize=False)
3003 sage: J = cartesian_product([J1,J2])
3004 sage: J1.rank.clear_cache()
3005 sage: J2.rank.clear_cache()
3006 sage: J.rank.clear_cache()
3009 sage: J.rank() == J1.rank() + J2.rank()
3012 The product algebra will be associative if and only if all of its
3013 components are associative::
3015 sage: J1 = HadamardEJA(2)
3016 sage: J1.is_associative()
3018 sage: J2 = HadamardEJA(3)
3019 sage: J2.is_associative()
3021 sage: J3 = RealSymmetricEJA(3)
3022 sage: J3.is_associative()
3024 sage: CP1 = cartesian_product([J1,J2])
3025 sage: CP1.is_associative()
3027 sage: CP2 = cartesian_product([J1,J3])
3028 sage: CP2.is_associative()
3031 Cartesian products of Cartesian products work::
3033 sage: J1 = JordanSpinEJA(1)
3034 sage: J2 = JordanSpinEJA(1)
3035 sage: J3 = JordanSpinEJA(1)
3036 sage: J = cartesian_product([J1,cartesian_product([J2,J3])])
3037 sage: J.multiplication_table()
3038 +----++----+----+----+
3039 | * || b0 | b1 | b2 |
3040 +====++====+====+====+
3041 | b0 || b0 | 0 | 0 |
3042 +----++----+----+----+
3043 | b1 || 0 | b1 | 0 |
3044 +----++----+----+----+
3045 | b2 || 0 | 0 | b2 |
3046 +----++----+----+----+
3047 sage: HadamardEJA(3).multiplication_table()
3048 +----++----+----+----+
3049 | * || b0 | b1 | b2 |
3050 +====++====+====+====+
3051 | b0 || b0 | 0 | 0 |
3052 +----++----+----+----+
3053 | b1 || 0 | b1 | 0 |
3054 +----++----+----+----+
3055 | b2 || 0 | 0 | b2 |
3056 +----++----+----+----+
3058 The "matrix space" of a Cartesian product always consists of
3059 ordered pairs (or triples, or...) whose components are the
3060 matrix spaces of its factors::
3062 sage: J1 = HadamardEJA(2)
3063 sage: J2 = ComplexHermitianEJA(2)
3064 sage: J = cartesian_product([J1,J2])
3065 sage: J.matrix_space()
3066 The Cartesian product of (Full MatrixSpace of 2 by 1 dense
3067 matrices over Algebraic Real Field, Module of 2 by 2 matrices
3068 with entries in Algebraic Field over the scalar ring Algebraic
3070 sage: J.one().to_matrix()[0]
3073 sage: J.one().to_matrix()[1]
3082 All factors must share the same base field::
3084 sage: J1 = HadamardEJA(2, field=QQ)
3085 sage: J2 = RealSymmetricEJA(2)
3086 sage: CartesianProductEJA((J1,J2))
3087 Traceback (most recent call last):
3089 ValueError: all factors must share the same base field
3091 The cached unit element is the same one that would be computed::
3093 sage: set_random_seed() # long time
3094 sage: J1 = random_eja() # long time
3095 sage: J2 = random_eja() # long time
3096 sage: J = cartesian_product([J1,J2]) # long time
3097 sage: actual = J.one() # long time
3098 sage: J.one.clear_cache() # long time
3099 sage: expected = J.one() # long time
3100 sage: actual == expected # long time
3103 def __init__(self
, factors
, **kwargs
):
3108 self
._sets
= factors
3110 field
= factors
[0].base_ring()
3111 if not all( J
.base_ring() == field
for J
in factors
):
3112 raise ValueError("all factors must share the same base field")
3114 # Figure out the category to use.
3115 associative
= all( f
.is_associative() for f
in factors
)
3116 category
= EuclideanJordanAlgebras(field
)
3117 if associative
: category
= category
.Associative()
3118 category
= category
.join([category
, category
.CartesianProducts()])
3120 # Compute my matrix space. We don't simply use the
3121 # ``cartesian_product()`` functor here because it acts
3122 # differently on SageMath MatrixSpaces and our custom
3123 # MatrixAlgebras, which are CombinatorialFreeModules. We
3124 # always want the result to be represented (and indexed) as an
3125 # ordered tuple. This category isn't perfect, but is good
3126 # enough for what we need to do.
3127 MS_cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
3128 MS_cat
= MS_cat
.Unital().CartesianProducts()
3129 MS_factors
= tuple( J
.matrix_space() for J
in factors
)
3130 from sage
.sets
.cartesian_product
import CartesianProduct
3131 self
._matrix
_space
= CartesianProduct(MS_factors
, MS_cat
)
3133 self
._matrix
_basis
= []
3134 zero
= self
._matrix
_space
.zero()
3136 for b
in factors
[i
].matrix_basis():
3139 self
._matrix
_basis
.append(z
)
3141 self
._matrix
_basis
= tuple( self
._matrix
_space
(b
)
3142 for b
in self
._matrix
_basis
)
3143 n
= len(self
._matrix
_basis
)
3145 # We already have what we need for the super-superclass constructor.
3146 CombinatorialFreeModule
.__init
__(self
,
3153 # Now create the vector space for the algebra, which will have
3154 # its own set of non-ambient coordinates (in terms of the
3156 degree
= sum( f
._matrix
_span
.ambient_vector_space().degree()
3158 V
= VectorSpace(field
, degree
)
3159 vector_basis
= tuple( V(_all2list(b
)) for b
in self
._matrix
_basis
)
3161 # Save the span of our matrix basis (when written out as long
3162 # vectors) because otherwise we'll have to reconstruct it
3163 # every time we want to coerce a matrix into the algebra.
3164 self
._matrix
_span
= V
.span_of_basis( vector_basis
, check
=False)
3166 # Since we don't (re)orthonormalize the basis, the FDEJA
3167 # constructor is going to set self._deortho_matrix to the
3168 # identity matrix. Here we set it to the correct value using
3169 # the deortho matrices from our factors.
3170 self
._deortho
_matrix
= matrix
.block_diagonal(
3171 [J
._deortho
_matrix
for J
in factors
]
3174 self
._inner
_product
_matrix
= matrix
.block_diagonal(
3175 [J
._inner
_product
_matrix
for J
in factors
]
3177 self
._inner
_product
_matrix
._cache
= {'hermitian': True}
3178 self
._inner
_product
_matrix
.set_immutable()
3180 # Building the multiplication table is a bit more tricky
3181 # because we have to embed the entries of the factors'
3182 # multiplication tables into the product EJA.
3184 self
._multiplication
_table
= [ [zed
for j
in range(i
+1)]
3187 # Keep track of an offset that tallies the dimensions of all
3188 # previous factors. If the second factor is dim=2 and if the
3189 # first one is dim=3, then we want to skip the first 3x3 block
3190 # when copying the multiplication table for the second factor.
3193 phi_f
= self
.cartesian_embedding(f
)
3194 factor_dim
= factors
[f
].dimension()
3195 for i
in range(factor_dim
):
3196 for j
in range(i
+1):
3197 f_ij
= factors
[f
]._multiplication
_table
[i
][j
]
3199 self
._multiplication
_table
[offset
+i
][offset
+j
] = e
3200 offset
+= factor_dim
3202 self
.rank
.set_cache(sum(J
.rank() for J
in factors
))
3203 ones
= tuple(J
.one().to_matrix() for J
in factors
)
3204 self
.one
.set_cache(self(ones
))
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
)
3224 def cartesian_projection(self
, i
):
3228 sage: from mjo.eja.eja_algebra import (random_eja,
3229 ....: JordanSpinEJA,
3231 ....: RealSymmetricEJA,
3232 ....: ComplexHermitianEJA)
3236 The projection morphisms are Euclidean Jordan algebra
3239 sage: J1 = HadamardEJA(2)
3240 sage: J2 = RealSymmetricEJA(2)
3241 sage: J = cartesian_product([J1,J2])
3242 sage: J.cartesian_projection(0)
3243 Linear operator between finite-dimensional Euclidean Jordan
3244 algebras represented by the matrix:
3247 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3248 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3249 Algebraic Real Field
3250 Codomain: Euclidean Jordan algebra of dimension 2 over Algebraic
3252 sage: J.cartesian_projection(1)
3253 Linear operator between finite-dimensional Euclidean Jordan
3254 algebras represented by the matrix:
3258 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3259 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3260 Algebraic Real Field
3261 Codomain: Euclidean Jordan algebra of dimension 3 over Algebraic
3264 The projections work the way you'd expect on the vector
3265 representation of an element::
3267 sage: J1 = JordanSpinEJA(2)
3268 sage: J2 = ComplexHermitianEJA(2)
3269 sage: J = cartesian_product([J1,J2])
3270 sage: pi_left = J.cartesian_projection(0)
3271 sage: pi_right = J.cartesian_projection(1)
3272 sage: pi_left(J.one()).to_vector()
3274 sage: pi_right(J.one()).to_vector()
3276 sage: J.one().to_vector()
3281 The answer never changes::
3283 sage: set_random_seed()
3284 sage: J1 = random_eja()
3285 sage: J2 = random_eja()
3286 sage: J = cartesian_product([J1,J2])
3287 sage: P0 = J.cartesian_projection(0)
3288 sage: P1 = J.cartesian_projection(0)
3293 offset
= sum( self
.cartesian_factor(k
).dimension()
3295 Ji
= self
.cartesian_factor(i
)
3296 Pi
= self
._module
_morphism
(lambda j
: Ji
.monomial(j
- offset
),
3299 return FiniteDimensionalEJAOperator(self
,Ji
,Pi
.matrix())
3302 def cartesian_embedding(self
, i
):
3306 sage: from mjo.eja.eja_algebra import (random_eja,
3307 ....: JordanSpinEJA,
3309 ....: RealSymmetricEJA)
3313 The embedding morphisms are Euclidean Jordan algebra
3316 sage: J1 = HadamardEJA(2)
3317 sage: J2 = RealSymmetricEJA(2)
3318 sage: J = cartesian_product([J1,J2])
3319 sage: J.cartesian_embedding(0)
3320 Linear operator between finite-dimensional Euclidean Jordan
3321 algebras represented by the matrix:
3327 Domain: Euclidean Jordan algebra of dimension 2 over
3328 Algebraic Real Field
3329 Codomain: Euclidean Jordan algebra of dimension 2 over
3330 Algebraic Real Field (+) Euclidean Jordan algebra of
3331 dimension 3 over Algebraic Real Field
3332 sage: J.cartesian_embedding(1)
3333 Linear operator between finite-dimensional Euclidean Jordan
3334 algebras represented by the matrix:
3340 Domain: Euclidean Jordan algebra of dimension 3 over
3341 Algebraic Real Field
3342 Codomain: Euclidean Jordan algebra of dimension 2 over
3343 Algebraic Real Field (+) Euclidean Jordan algebra of
3344 dimension 3 over Algebraic Real Field
3346 The embeddings work the way you'd expect on the vector
3347 representation of an element::
3349 sage: J1 = JordanSpinEJA(3)
3350 sage: J2 = RealSymmetricEJA(2)
3351 sage: J = cartesian_product([J1,J2])
3352 sage: iota_left = J.cartesian_embedding(0)
3353 sage: iota_right = J.cartesian_embedding(1)
3354 sage: iota_left(J1.zero()) == J.zero()
3356 sage: iota_right(J2.zero()) == J.zero()
3358 sage: J1.one().to_vector()
3360 sage: iota_left(J1.one()).to_vector()
3362 sage: J2.one().to_vector()
3364 sage: iota_right(J2.one()).to_vector()
3366 sage: J.one().to_vector()
3371 The answer never changes::
3373 sage: set_random_seed()
3374 sage: J1 = random_eja()
3375 sage: J2 = random_eja()
3376 sage: J = cartesian_product([J1,J2])
3377 sage: E0 = J.cartesian_embedding(0)
3378 sage: E1 = J.cartesian_embedding(0)
3382 Composing a projection with the corresponding inclusion should
3383 produce the identity map, and mismatching them should produce
3386 sage: set_random_seed()
3387 sage: J1 = random_eja()
3388 sage: J2 = random_eja()
3389 sage: J = cartesian_product([J1,J2])
3390 sage: iota_left = J.cartesian_embedding(0)
3391 sage: iota_right = J.cartesian_embedding(1)
3392 sage: pi_left = J.cartesian_projection(0)
3393 sage: pi_right = J.cartesian_projection(1)
3394 sage: pi_left*iota_left == J1.one().operator()
3396 sage: pi_right*iota_right == J2.one().operator()
3398 sage: (pi_left*iota_right).is_zero()
3400 sage: (pi_right*iota_left).is_zero()
3404 offset
= sum( self
.cartesian_factor(k
).dimension()
3406 Ji
= self
.cartesian_factor(i
)
3407 Ei
= Ji
._module
_morphism
(lambda j
: self
.monomial(j
+ offset
),
3409 return FiniteDimensionalEJAOperator(Ji
,self
,Ei
.matrix())
3413 FiniteDimensionalEJA
.CartesianProduct
= CartesianProductEJA
3415 class RationalBasisCartesianProductEJA(CartesianProductEJA
,
3418 A separate class for products of algebras for which we know a
3423 sage: from mjo.eja.eja_algebra import (FiniteDimensionalEJA,
3425 ....: JordanSpinEJA,
3426 ....: RealSymmetricEJA)
3430 This gives us fast characteristic polynomial computations in
3431 product algebras, too::
3434 sage: J1 = JordanSpinEJA(2)
3435 sage: J2 = RealSymmetricEJA(3)
3436 sage: J = cartesian_product([J1,J2])
3437 sage: J.characteristic_polynomial_of().degree()
3444 The ``cartesian_product()`` function only uses the first factor to
3445 decide where the result will live; thus we have to be careful to
3446 check that all factors do indeed have a ``rational_algebra()`` method
3447 before we construct an algebra that claims to have a rational basis::
3449 sage: J1 = HadamardEJA(2)
3450 sage: jp = lambda X,Y: X*Y
3451 sage: ip = lambda X,Y: X[0,0]*Y[0,0]
3452 sage: b1 = matrix(QQ, [[1]])
3453 sage: J2 = FiniteDimensionalEJA((b1,), jp, ip)
3454 sage: cartesian_product([J2,J1]) # factor one not RationalBasisEJA
3455 Euclidean Jordan algebra of dimension 1 over Algebraic Real
3456 Field (+) Euclidean Jordan algebra of dimension 2 over Algebraic
3458 sage: cartesian_product([J1,J2]) # factor one is RationalBasisEJA
3459 Traceback (most recent call last):
3461 ValueError: factor not a RationalBasisEJA
3464 def __init__(self
, algebras
, **kwargs
):
3465 if not all( hasattr(r
, "rational_algebra") for r
in algebras
):
3466 raise ValueError("factor not a RationalBasisEJA")
3468 CartesianProductEJA
.__init
__(self
, algebras
, **kwargs
)
3471 def rational_algebra(self
):
3472 if self
.base_ring() is QQ
:
3475 return cartesian_product([
3476 r
.rational_algebra() for r
in self
.cartesian_factors()
3480 RationalBasisEJA
.CartesianProduct
= RationalBasisCartesianProductEJA
3482 def random_eja(max_dimension
=None, *args
, **kwargs
):
3487 sage: from mjo.eja.eja_algebra import random_eja
3491 sage: set_random_seed()
3492 sage: n = ZZ.random_element(1,5)
3493 sage: J = random_eja(max_dimension=n, field=QQ, orthonormalize=False)
3494 sage: J.dimension() <= n
3498 # Use the ConcreteEJA default as the total upper bound (regardless
3499 # of any whether or not any individual factors set a lower limit).
3500 if max_dimension
is None:
3501 max_dimension
= ConcreteEJA
._max
_random
_instance
_dimension
()
3502 J1
= ConcreteEJA
.random_instance(max_dimension
, *args
, **kwargs
)
3505 # Roll the dice to see if we attempt a Cartesian product.
3506 dice_roll
= ZZ
.random_element(len(ConcreteEJA
.__subclasses
__()) + 1)
3507 new_max_dimension
= max_dimension
- J1
.dimension()
3508 if new_max_dimension
== 0 or dice_roll
!= 0:
3509 # If it's already as big as we're willing to tolerate, just
3510 # return it and don't worry about Cartesian products.
3513 # Use random_eja() again so we can get more than two factors
3514 # if the sub-call also Decides on a cartesian product.
3515 J2
= random_eja(new_max_dimension
, *args
, **kwargs
)
3516 return cartesian_product([J1
,J2
])