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 class FiniteDimensionalEJA(CombinatorialFreeModule
):
175 A finite-dimensional Euclidean Jordan algebra.
179 - ``basis`` -- a tuple; a tuple of basis elements in "matrix
180 form," which must be the same form as the arguments to
181 ``jordan_product`` and ``inner_product``. In reality, "matrix
182 form" can be either vectors, matrices, or a Cartesian product
183 (ordered tuple) of vectors or matrices. All of these would
184 ideally be vector spaces in sage with no special-casing
185 needed; but in reality we turn vectors into column-matrices
186 and Cartesian products `(a,b)` into column matrices
187 `(a,b)^{T}` after converting `a` and `b` themselves.
189 - ``jordan_product`` -- a function; afunction of two ``basis``
190 elements (in matrix form) that returns their jordan product,
191 also in matrix form; this will be applied to ``basis`` to
192 compute a multiplication table for the algebra.
194 - ``inner_product`` -- a function; a function of two ``basis``
195 elements (in matrix form) that returns their inner
196 product. This will be applied to ``basis`` to compute an
197 inner-product table (basically a matrix) for this algebra.
199 - ``matrix_space`` -- the space that your matrix basis lives in,
200 or ``None`` (the default). So long as your basis does not have
201 length zero you can omit this. But in trivial algebras, it is
204 - ``field`` -- a subfield of the reals (default: ``AA``); the scalar
205 field for the algebra.
207 - ``orthonormalize`` -- boolean (default: ``True``); whether or
208 not to orthonormalize the basis. Doing so is expensive and
209 generally rules out using the rationals as your ``field``, but
210 is required for spectral decompositions.
214 sage: from mjo.eja.eja_algebra import random_eja
218 We should compute that an element subalgebra is associative even
219 if we circumvent the element method::
221 sage: set_random_seed()
222 sage: J = random_eja(field=QQ,orthonormalize=False)
223 sage: x = J.random_element()
224 sage: A = x.subalgebra_generated_by(orthonormalize=False)
225 sage: basis = tuple(b.superalgebra_element() for b in A.basis())
226 sage: J.subalgebra(basis, orthonormalize=False).is_associative()
229 Element
= FiniteDimensionalEJAElement
239 cartesian_product
=False,
247 if not field
.is_subring(RR
):
248 # Note: this does return true for the real algebraic
249 # field, the rationals, and any quadratic field where
250 # we've specified a real embedding.
251 raise ValueError("scalar field is not real")
254 # Check commutativity of the Jordan and inner-products.
255 # This has to be done before we build the multiplication
256 # and inner-product tables/matrices, because we take
257 # advantage of symmetry in the process.
258 if not all( jordan_product(bi
,bj
) == jordan_product(bj
,bi
)
261 raise ValueError("Jordan product is not commutative")
263 if not all( inner_product(bi
,bj
) == inner_product(bj
,bi
)
266 raise ValueError("inner-product is not commutative")
269 category
= MagmaticAlgebras(field
).FiniteDimensional()
270 category
= category
.WithBasis().Unital().Commutative()
273 # All zero- and one-dimensional algebras are just the real
274 # numbers with (some positive multiples of) the usual
275 # multiplication as its Jordan and inner-product.
277 if associative
is None:
278 # We should figure it out. As with check_axioms, we have to do
279 # this without the help of the _jordan_product_is_associative()
280 # method because we need to know the category before we
281 # initialize the algebra.
282 associative
= all( jordan_product(jordan_product(bi
,bj
),bk
)
284 jordan_product(bi
,jordan_product(bj
,bk
))
290 # Element subalgebras can take advantage of this.
291 category
= category
.Associative()
292 if cartesian_product
:
293 # Use join() here because otherwise we only get the
294 # "Cartesian product of..." and not the things themselves.
295 category
= category
.join([category
,
296 category
.CartesianProducts()])
298 # Call the superclass constructor so that we can use its from_vector()
299 # method to build our multiplication table.
300 CombinatorialFreeModule
.__init
__(self
,
307 # Now comes all of the hard work. We'll be constructing an
308 # ambient vector space V that our (vectorized) basis lives in,
309 # as well as a subspace W of V spanned by those (vectorized)
310 # basis elements. The W-coordinates are the coefficients that
311 # we see in things like x = 1*b1 + 2*b2.
315 degree
= len(_all2list(basis
[0]))
317 # Build an ambient space that fits our matrix basis when
318 # written out as "long vectors."
319 V
= VectorSpace(field
, degree
)
321 # The matrix that will hold the orthonormal -> unorthonormal
322 # coordinate transformation. Default to an identity matrix of
323 # the appropriate size to avoid special cases for None
325 self
._deortho
_matrix
= matrix
.identity(field
,n
)
328 # Save a copy of the un-orthonormalized basis for later.
329 # Convert it to ambient V (vector) coordinates while we're
330 # at it, because we'd have to do it later anyway.
331 deortho_vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
333 from mjo
.eja
.eja_utils
import gram_schmidt
334 basis
= tuple(gram_schmidt(basis
, inner_product
))
336 # Save the (possibly orthonormalized) matrix basis for
337 # later, as well as the space that its elements live in.
338 # In most cases we can deduce the matrix space, but when
339 # n == 0 (that is, there are no basis elements) we cannot.
340 self
._matrix
_basis
= basis
341 if matrix_space
is None:
342 self
._matrix
_space
= self
._matrix
_basis
[0].parent()
344 self
._matrix
_space
= matrix_space
346 # Now create the vector space for the algebra, which will have
347 # its own set of non-ambient coordinates (in terms of the
349 vector_basis
= tuple( V(_all2list(b
)) for b
in basis
)
351 # Save the span of our matrix basis (when written out as long
352 # vectors) because otherwise we'll have to reconstruct it
353 # every time we want to coerce a matrix into the algebra.
354 self
._matrix
_span
= V
.span_of_basis( vector_basis
, check
=check_axioms
)
357 # Now "self._matrix_span" is the vector space of our
358 # algebra coordinates. The variables "X1", "X2",... refer
359 # to the entries of vectors in self._matrix_span. Thus to
360 # convert back and forth between the orthonormal
361 # coordinates and the given ones, we need to stick the
362 # original basis in self._matrix_span.
363 U
= V
.span_of_basis( deortho_vector_basis
, check
=check_axioms
)
364 self
._deortho
_matrix
= matrix
.column( U
.coordinate_vector(q
)
365 for q
in vector_basis
)
368 # Now we actually compute the multiplication and inner-product
369 # tables/matrices using the possibly-orthonormalized basis.
370 self
._inner
_product
_matrix
= matrix
.identity(field
, n
)
371 self
._multiplication
_table
= [ [0 for j
in range(i
+1)]
374 # Note: the Jordan and inner-products are defined in terms
375 # of the ambient basis. It's important that their arguments
376 # are in ambient coordinates as well.
379 # ortho basis w.r.t. ambient coords
383 # The jordan product returns a matrixy answer, so we
384 # have to convert it to the algebra coordinates.
385 elt
= jordan_product(q_i
, q_j
)
386 elt
= self
._matrix
_span
.coordinate_vector(V(_all2list(elt
)))
387 self
._multiplication
_table
[i
][j
] = self
.from_vector(elt
)
389 if not orthonormalize
:
390 # If we're orthonormalizing the basis with respect
391 # to an inner-product, then the inner-product
392 # matrix with respect to the resulting basis is
393 # just going to be the identity.
394 ip
= inner_product(q_i
, q_j
)
395 self
._inner
_product
_matrix
[i
,j
] = ip
396 self
._inner
_product
_matrix
[j
,i
] = ip
398 self
._inner
_product
_matrix
._cache
= {'hermitian': True}
399 self
._inner
_product
_matrix
.set_immutable()
402 if not self
._is
_jordanian
():
403 raise ValueError("Jordan identity does not hold")
404 if not self
._inner
_product
_is
_associative
():
405 raise ValueError("inner product is not associative")
408 def _coerce_map_from_base_ring(self
):
410 Disable the map from the base ring into the algebra.
412 Performing a nonsense conversion like this automatically
413 is counterpedagogical. The fallback is to try the usual
414 element constructor, which should also fail.
418 sage: from mjo.eja.eja_algebra import random_eja
422 sage: set_random_seed()
423 sage: J = random_eja()
425 Traceback (most recent call last):
427 ValueError: not an element of this algebra
433 def product_on_basis(self
, i
, j
):
435 Returns the Jordan product of the `i` and `j`th basis elements.
437 This completely defines the Jordan product on the algebra, and
438 is used direclty by our superclass machinery to implement
443 sage: from mjo.eja.eja_algebra import random_eja
447 sage: set_random_seed()
448 sage: J = random_eja()
449 sage: n = J.dimension()
452 sage: bi_bj = J.zero()*J.zero()
454 ....: i = ZZ.random_element(n)
455 ....: j = ZZ.random_element(n)
456 ....: bi = J.monomial(i)
457 ....: bj = J.monomial(j)
458 ....: bi_bj = J.product_on_basis(i,j)
463 # We only stored the lower-triangular portion of the
464 # multiplication table.
466 return self
._multiplication
_table
[i
][j
]
468 return self
._multiplication
_table
[j
][i
]
470 def inner_product(self
, x
, y
):
472 The inner product associated with this Euclidean Jordan algebra.
474 Defaults to the trace inner product, but can be overridden by
475 subclasses if they are sure that the necessary properties are
480 sage: from mjo.eja.eja_algebra import (random_eja,
482 ....: BilinearFormEJA)
486 Our inner product is "associative," which means the following for
487 a symmetric bilinear form::
489 sage: set_random_seed()
490 sage: J = random_eja()
491 sage: x,y,z = J.random_elements(3)
492 sage: (x*y).inner_product(z) == y.inner_product(x*z)
497 Ensure that this is the usual inner product for the algebras
500 sage: set_random_seed()
501 sage: J = HadamardEJA.random_instance()
502 sage: x,y = J.random_elements(2)
503 sage: actual = x.inner_product(y)
504 sage: expected = x.to_vector().inner_product(y.to_vector())
505 sage: actual == expected
508 Ensure that this is one-half of the trace inner-product in a
509 BilinearFormEJA that isn't just the reals (when ``n`` isn't
510 one). This is in Faraut and Koranyi, and also my "On the
513 sage: set_random_seed()
514 sage: J = BilinearFormEJA.random_instance()
515 sage: n = J.dimension()
516 sage: x = J.random_element()
517 sage: y = J.random_element()
518 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
522 B
= self
._inner
_product
_matrix
523 return (B
*x
.to_vector()).inner_product(y
.to_vector())
526 def is_associative(self
):
528 Return whether or not this algebra's Jordan product is associative.
532 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
536 sage: J = ComplexHermitianEJA(3, field=QQ, orthonormalize=False)
537 sage: J.is_associative()
539 sage: x = sum(J.gens())
540 sage: A = x.subalgebra_generated_by(orthonormalize=False)
541 sage: A.is_associative()
545 return "Associative" in self
.category().axioms()
547 def _is_commutative(self
):
549 Whether or not this algebra's multiplication table is commutative.
551 This method should of course always return ``True``, unless
552 this algebra was constructed with ``check_axioms=False`` and
553 passed an invalid multiplication table.
555 return all( x
*y
== y
*x
for x
in self
.gens() for y
in self
.gens() )
557 def _is_jordanian(self
):
559 Whether or not this algebra's multiplication table respects the
560 Jordan identity `(x^{2})(xy) = x(x^{2}y)`.
562 We only check one arrangement of `x` and `y`, so for a
563 ``True`` result to be truly true, you should also check
564 :meth:`_is_commutative`. This method should of course always
565 return ``True``, unless this algebra was constructed with
566 ``check_axioms=False`` and passed an invalid multiplication table.
568 return all( (self
.monomial(i
)**2)*(self
.monomial(i
)*self
.monomial(j
))
570 (self
.monomial(i
))*((self
.monomial(i
)**2)*self
.monomial(j
))
571 for i
in range(self
.dimension())
572 for j
in range(self
.dimension()) )
574 def _jordan_product_is_associative(self
):
576 Return whether or not this algebra's Jordan product is
577 associative; that is, whether or not `x*(y*z) = (x*y)*z`
580 This method should agree with :meth:`is_associative` unless
581 you lied about the value of the ``associative`` parameter
582 when you constructed the algebra.
586 sage: from mjo.eja.eja_algebra import (random_eja,
587 ....: RealSymmetricEJA,
588 ....: ComplexHermitianEJA,
589 ....: QuaternionHermitianEJA)
593 sage: J = RealSymmetricEJA(4, orthonormalize=False)
594 sage: J._jordan_product_is_associative()
596 sage: x = sum(J.gens())
597 sage: A = x.subalgebra_generated_by()
598 sage: A._jordan_product_is_associative()
603 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
604 sage: J._jordan_product_is_associative()
606 sage: x = sum(J.gens())
607 sage: A = x.subalgebra_generated_by(orthonormalize=False)
608 sage: A._jordan_product_is_associative()
613 sage: J = QuaternionHermitianEJA(2)
614 sage: J._jordan_product_is_associative()
616 sage: x = sum(J.gens())
617 sage: A = x.subalgebra_generated_by()
618 sage: A._jordan_product_is_associative()
623 The values we've presupplied to the constructors agree with
626 sage: set_random_seed()
627 sage: J = random_eja()
628 sage: J.is_associative() == J._jordan_product_is_associative()
634 # Used to check whether or not something is zero.
637 # I don't know of any examples that make this magnitude
638 # necessary because I don't know how to make an
639 # associative algebra when the element subalgebra
640 # construction is unreliable (as it is over RDF; we can't
641 # find the degree of an element because we can't compute
642 # the rank of a matrix). But even multiplication of floats
643 # is non-associative, so *some* epsilon is needed... let's
644 # just take the one from _inner_product_is_associative?
647 for i
in range(self
.dimension()):
648 for j
in range(self
.dimension()):
649 for k
in range(self
.dimension()):
653 diff
= (x
*y
)*z
- x
*(y
*z
)
655 if diff
.norm() > epsilon
:
660 def _inner_product_is_associative(self
):
662 Return whether or not this algebra's inner product `B` is
663 associative; that is, whether or not `B(xy,z) = B(x,yz)`.
665 This method should of course always return ``True``, unless
666 this algebra was constructed with ``check_axioms=False`` and
667 passed an invalid Jordan or inner-product.
671 # Used to check whether or not something is zero.
674 # This choice is sufficient to allow the construction of
675 # QuaternionHermitianEJA(2, field=RDF) with check_axioms=True.
678 for i
in range(self
.dimension()):
679 for j
in range(self
.dimension()):
680 for k
in range(self
.dimension()):
684 diff
= (x
*y
).inner_product(z
) - x
.inner_product(y
*z
)
686 if diff
.abs() > epsilon
:
691 def _element_constructor_(self
, elt
):
693 Construct an element of this algebra or a subalgebra from its
694 EJA element, vector, or matrix representation.
696 This gets called only after the parent element _call_ method
697 fails to find a coercion for the argument.
701 sage: from mjo.eja.eja_algebra import (random_eja,
704 ....: RealSymmetricEJA)
708 The identity in `S^n` is converted to the identity in the EJA::
710 sage: J = RealSymmetricEJA(3)
711 sage: I = matrix.identity(QQ,3)
712 sage: J(I) == J.one()
715 This skew-symmetric matrix can't be represented in the EJA::
717 sage: J = RealSymmetricEJA(3)
718 sage: A = matrix(QQ,3, lambda i,j: i-j)
720 Traceback (most recent call last):
722 ValueError: not an element of this algebra
724 Tuples work as well, provided that the matrix basis for the
725 algebra consists of them::
727 sage: J1 = HadamardEJA(3)
728 sage: J2 = RealSymmetricEJA(2)
729 sage: J = cartesian_product([J1,J2])
730 sage: J( (J1.matrix_basis()[1], J2.matrix_basis()[2]) )
733 Subalgebra elements are embedded into the superalgebra::
735 sage: J = JordanSpinEJA(3)
738 sage: x = sum(J.gens())
739 sage: A = x.subalgebra_generated_by()
745 Ensure that we can convert any element back and forth
746 faithfully between its matrix and algebra representations::
748 sage: set_random_seed()
749 sage: J = random_eja()
750 sage: x = J.random_element()
751 sage: J(x.to_matrix()) == x
754 We cannot coerce elements between algebras just because their
755 matrix representations are compatible::
757 sage: J1 = HadamardEJA(3)
758 sage: J2 = JordanSpinEJA(3)
760 Traceback (most recent call last):
762 ValueError: not an element of this algebra
764 Traceback (most recent call last):
766 ValueError: not an element of this algebra
769 msg
= "not an element of this algebra"
770 if elt
in self
.base_ring():
771 # Ensure that no base ring -> algebra coercion is performed
772 # by this method. There's some stupidity in sage that would
773 # otherwise propagate to this method; for example, sage thinks
774 # that the integer 3 belongs to the space of 2-by-2 matrices.
775 raise ValueError(msg
)
777 if hasattr(elt
, 'superalgebra_element'):
778 # Handle subalgebra elements
779 if elt
.parent().superalgebra() == self
:
780 return elt
.superalgebra_element()
782 if hasattr(elt
, 'sparse_vector'):
783 # Convert a vector into a column-matrix. We check for
784 # "sparse_vector" and not "column" because matrices also
785 # have a "column" method.
788 if elt
not in self
.matrix_space():
789 raise ValueError(msg
)
791 # Thanks for nothing! Matrix spaces aren't vector spaces in
792 # Sage, so we have to figure out its matrix-basis coordinates
793 # ourselves. We use the basis space's ring instead of the
794 # element's ring because the basis space might be an algebraic
795 # closure whereas the base ring of the 3-by-3 identity matrix
796 # could be QQ instead of QQbar.
798 # And, we also have to handle Cartesian product bases (when
799 # the matrix basis consists of tuples) here. The "good news"
800 # is that we're already converting everything to long vectors,
801 # and that strategy works for tuples as well.
803 elt
= self
._matrix
_span
.ambient_vector_space()(_all2list(elt
))
806 coords
= self
._matrix
_span
.coordinate_vector(elt
)
807 except ArithmeticError: # vector is not in free module
808 raise ValueError(msg
)
810 return self
.from_vector(coords
)
814 Return a string representation of ``self``.
818 sage: from mjo.eja.eja_algebra import JordanSpinEJA
822 Ensure that it says what we think it says::
824 sage: JordanSpinEJA(2, field=AA)
825 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
826 sage: JordanSpinEJA(3, field=RDF)
827 Euclidean Jordan algebra of dimension 3 over Real Double Field
830 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
831 return fmt
.format(self
.dimension(), self
.base_ring())
835 def characteristic_polynomial_of(self
):
837 Return the algebra's "characteristic polynomial of" function,
838 which is itself a multivariate polynomial that, when evaluated
839 at the coordinates of some algebra element, returns that
840 element's characteristic polynomial.
842 The resulting polynomial has `n+1` variables, where `n` is the
843 dimension of this algebra. The first `n` variables correspond to
844 the coordinates of an algebra element: when evaluated at the
845 coordinates of an algebra element with respect to a certain
846 basis, the result is a univariate polynomial (in the one
847 remaining variable ``t``), namely the characteristic polynomial
852 sage: from mjo.eja.eja_algebra import JordanSpinEJA, TrivialEJA
856 The characteristic polynomial in the spin algebra is given in
857 Alizadeh, Example 11.11::
859 sage: J = JordanSpinEJA(3)
860 sage: p = J.characteristic_polynomial_of(); p
861 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
862 sage: xvec = J.one().to_vector()
866 By definition, the characteristic polynomial is a monic
867 degree-zero polynomial in a rank-zero algebra. Note that
868 Cayley-Hamilton is indeed satisfied since the polynomial
869 ``1`` evaluates to the identity element of the algebra on
872 sage: J = TrivialEJA()
873 sage: J.characteristic_polynomial_of()
880 # The list of coefficient polynomials a_0, a_1, a_2, ..., a_(r-1).
881 a
= self
._charpoly
_coefficients
()
883 # We go to a bit of trouble here to reorder the
884 # indeterminates, so that it's easier to evaluate the
885 # characteristic polynomial at x's coordinates and get back
886 # something in terms of t, which is what we want.
887 S
= PolynomialRing(self
.base_ring(),'t')
891 S
= PolynomialRing(S
, R
.variable_names())
894 return (t
**r
+ sum( a
[k
]*(t
**k
) for k
in range(r
) ))
896 def coordinate_polynomial_ring(self
):
898 The multivariate polynomial ring in which this algebra's
899 :meth:`characteristic_polynomial_of` lives.
903 sage: from mjo.eja.eja_algebra import (HadamardEJA,
904 ....: RealSymmetricEJA)
908 sage: J = HadamardEJA(2)
909 sage: J.coordinate_polynomial_ring()
910 Multivariate Polynomial Ring in X1, X2...
911 sage: J = RealSymmetricEJA(3,field=QQ,orthonormalize=False)
912 sage: J.coordinate_polynomial_ring()
913 Multivariate Polynomial Ring in X1, X2, X3, X4, X5, X6...
916 var_names
= tuple( "X%d" % z
for z
in range(1, self
.dimension()+1) )
917 return PolynomialRing(self
.base_ring(), var_names
)
919 def inner_product(self
, x
, y
):
921 The inner product associated with this Euclidean Jordan algebra.
923 Defaults to the trace inner product, but can be overridden by
924 subclasses if they are sure that the necessary properties are
929 sage: from mjo.eja.eja_algebra import (random_eja,
931 ....: BilinearFormEJA)
935 Our inner product is "associative," which means the following for
936 a symmetric bilinear form::
938 sage: set_random_seed()
939 sage: J = random_eja()
940 sage: x,y,z = J.random_elements(3)
941 sage: (x*y).inner_product(z) == y.inner_product(x*z)
946 Ensure that this is the usual inner product for the algebras
949 sage: set_random_seed()
950 sage: J = HadamardEJA.random_instance()
951 sage: x,y = J.random_elements(2)
952 sage: actual = x.inner_product(y)
953 sage: expected = x.to_vector().inner_product(y.to_vector())
954 sage: actual == expected
957 Ensure that this is one-half of the trace inner-product in a
958 BilinearFormEJA that isn't just the reals (when ``n`` isn't
959 one). This is in Faraut and Koranyi, and also my "On the
962 sage: set_random_seed()
963 sage: J = BilinearFormEJA.random_instance()
964 sage: n = J.dimension()
965 sage: x = J.random_element()
966 sage: y = J.random_element()
967 sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
970 B
= self
._inner
_product
_matrix
971 return (B
*x
.to_vector()).inner_product(y
.to_vector())
974 def is_trivial(self
):
976 Return whether or not this algebra is trivial.
978 A trivial algebra contains only the zero element.
982 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
987 sage: J = ComplexHermitianEJA(3)
993 sage: J = TrivialEJA()
998 return self
.dimension() == 0
1001 def multiplication_table(self
):
1003 Return a visual representation of this algebra's multiplication
1004 table (on basis elements).
1008 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1012 sage: J = JordanSpinEJA(4)
1013 sage: J.multiplication_table()
1014 +----++----+----+----+----+
1015 | * || b0 | b1 | b2 | b3 |
1016 +====++====+====+====+====+
1017 | b0 || b0 | b1 | b2 | b3 |
1018 +----++----+----+----+----+
1019 | b1 || b1 | b0 | 0 | 0 |
1020 +----++----+----+----+----+
1021 | b2 || b2 | 0 | b0 | 0 |
1022 +----++----+----+----+----+
1023 | b3 || b3 | 0 | 0 | b0 |
1024 +----++----+----+----+----+
1027 n
= self
.dimension()
1028 # Prepend the header row.
1029 M
= [["*"] + list(self
.gens())]
1031 # And to each subsequent row, prepend an entry that belongs to
1032 # the left-side "header column."
1033 M
+= [ [self
.monomial(i
)] + [ self
.monomial(i
)*self
.monomial(j
)
1037 return table(M
, header_row
=True, header_column
=True, frame
=True)
1040 def matrix_basis(self
):
1042 Return an (often more natural) representation of this algebras
1043 basis as an ordered tuple of matrices.
1045 Every finite-dimensional Euclidean Jordan Algebra is a, up to
1046 Jordan isomorphism, a direct sum of five simple
1047 algebras---four of which comprise Hermitian matrices. And the
1048 last type of algebra can of course be thought of as `n`-by-`1`
1049 column matrices (ambiguusly called column vectors) to avoid
1050 special cases. As a result, matrices (and column vectors) are
1051 a natural representation format for Euclidean Jordan algebra
1054 But, when we construct an algebra from a basis of matrices,
1055 those matrix representations are lost in favor of coordinate
1056 vectors *with respect to* that basis. We could eventually
1057 convert back if we tried hard enough, but having the original
1058 representations handy is valuable enough that we simply store
1059 them and return them from this method.
1061 Why implement this for non-matrix algebras? Avoiding special
1062 cases for the :class:`BilinearFormEJA` pays with simplicity in
1063 its own right. But mainly, we would like to be able to assume
1064 that elements of a :class:`CartesianProductEJA` can be displayed
1065 nicely, without having to have special classes for direct sums
1066 one of whose components was a matrix algebra.
1070 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
1071 ....: RealSymmetricEJA)
1075 sage: J = RealSymmetricEJA(2)
1077 Finite family {0: b0, 1: b1, 2: b2}
1078 sage: J.matrix_basis()
1080 [1 0] [ 0 0.7071067811865475?] [0 0]
1081 [0 0], [0.7071067811865475? 0], [0 1]
1086 sage: J = JordanSpinEJA(2)
1088 Finite family {0: b0, 1: b1}
1089 sage: J.matrix_basis()
1095 return self
._matrix
_basis
1098 def matrix_space(self
):
1100 Return the matrix space in which this algebra's elements live, if
1101 we think of them as matrices (including column vectors of the
1104 "By default" this will be an `n`-by-`1` column-matrix space,
1105 except when the algebra is trivial. There it's `n`-by-`n`
1106 (where `n` is zero), to ensure that two elements of the matrix
1107 space (empty matrices) can be multiplied. For algebras of
1108 matrices, this returns the space in which their
1109 real embeddings live.
1113 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
1114 ....: JordanSpinEJA,
1115 ....: QuaternionHermitianEJA,
1120 By default, the matrix representation is just a column-matrix
1121 equivalent to the vector representation::
1123 sage: J = JordanSpinEJA(3)
1124 sage: J.matrix_space()
1125 Full MatrixSpace of 3 by 1 dense matrices over Algebraic
1128 The matrix representation in the trivial algebra is
1129 zero-by-zero instead of the usual `n`-by-one::
1131 sage: J = TrivialEJA()
1132 sage: J.matrix_space()
1133 Full MatrixSpace of 0 by 0 dense matrices over Algebraic
1136 The matrix space for complex/quaternion Hermitian matrix EJA
1137 is the space in which their real-embeddings live, not the
1138 original complex/quaternion matrix space::
1140 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1141 sage: J.matrix_space()
1142 Module of 2 by 2 matrices with entries in Algebraic Field over
1143 the scalar ring Rational Field
1144 sage: J = QuaternionHermitianEJA(1,field=QQ,orthonormalize=False)
1145 sage: J.matrix_space()
1146 Module of 1 by 1 matrices with entries in Quaternion
1147 Algebra (-1, -1) with base ring Rational Field over
1148 the scalar ring Rational Field
1151 return self
._matrix
_space
1157 Return the unit element of this algebra.
1161 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1166 We can compute unit element in the Hadamard EJA::
1168 sage: J = HadamardEJA(5)
1170 b0 + b1 + b2 + b3 + b4
1172 The unit element in the Hadamard EJA is inherited in the
1173 subalgebras generated by its elements::
1175 sage: J = HadamardEJA(5)
1177 b0 + b1 + b2 + b3 + b4
1178 sage: x = sum(J.gens())
1179 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1182 sage: A.one().superalgebra_element()
1183 b0 + b1 + b2 + b3 + b4
1187 The identity element acts like the identity, regardless of
1188 whether or not we orthonormalize::
1190 sage: set_random_seed()
1191 sage: J = random_eja()
1192 sage: x = J.random_element()
1193 sage: J.one()*x == x and x*J.one() == x
1195 sage: A = x.subalgebra_generated_by()
1196 sage: y = A.random_element()
1197 sage: A.one()*y == y and y*A.one() == y
1202 sage: set_random_seed()
1203 sage: J = random_eja(field=QQ, orthonormalize=False)
1204 sage: x = J.random_element()
1205 sage: J.one()*x == x and x*J.one() == x
1207 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1208 sage: y = A.random_element()
1209 sage: A.one()*y == y and y*A.one() == y
1212 The matrix of the unit element's operator is the identity,
1213 regardless of the base field and whether or not we
1216 sage: set_random_seed()
1217 sage: J = random_eja()
1218 sage: actual = J.one().operator().matrix()
1219 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1220 sage: actual == expected
1222 sage: x = J.random_element()
1223 sage: A = x.subalgebra_generated_by()
1224 sage: actual = A.one().operator().matrix()
1225 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1226 sage: actual == expected
1231 sage: set_random_seed()
1232 sage: J = random_eja(field=QQ, orthonormalize=False)
1233 sage: actual = J.one().operator().matrix()
1234 sage: expected = matrix.identity(J.base_ring(), J.dimension())
1235 sage: actual == expected
1237 sage: x = J.random_element()
1238 sage: A = x.subalgebra_generated_by(orthonormalize=False)
1239 sage: actual = A.one().operator().matrix()
1240 sage: expected = matrix.identity(A.base_ring(), A.dimension())
1241 sage: actual == expected
1244 Ensure that the cached unit element (often precomputed by
1245 hand) agrees with the computed one::
1247 sage: set_random_seed()
1248 sage: J = random_eja()
1249 sage: cached = J.one()
1250 sage: J.one.clear_cache()
1251 sage: J.one() == cached
1256 sage: set_random_seed()
1257 sage: J = random_eja(field=QQ, orthonormalize=False)
1258 sage: cached = J.one()
1259 sage: J.one.clear_cache()
1260 sage: J.one() == cached
1264 # We can brute-force compute the matrices of the operators
1265 # that correspond to the basis elements of this algebra.
1266 # If some linear combination of those basis elements is the
1267 # algebra identity, then the same linear combination of
1268 # their matrices has to be the identity matrix.
1270 # Of course, matrices aren't vectors in sage, so we have to
1271 # appeal to the "long vectors" isometry.
1272 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
1274 # Now we use basic linear algebra to find the coefficients,
1275 # of the matrices-as-vectors-linear-combination, which should
1276 # work for the original algebra basis too.
1277 A
= matrix(self
.base_ring(), oper_vecs
)
1279 # We used the isometry on the left-hand side already, but we
1280 # still need to do it for the right-hand side. Recall that we
1281 # wanted something that summed to the identity matrix.
1282 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
1284 # Now if there's an identity element in the algebra, this
1285 # should work. We solve on the left to avoid having to
1286 # transpose the matrix "A".
1287 return self
.from_vector(A
.solve_left(b
))
1290 def peirce_decomposition(self
, c
):
1292 The Peirce decomposition of this algebra relative to the
1295 In the future, this can be extended to a complete system of
1296 orthogonal idempotents.
1300 - ``c`` -- an idempotent of this algebra.
1304 A triple (J0, J5, J1) containing two subalgebras and one subspace
1307 - ``J0`` -- the algebra on the eigenspace of ``c.operator()``
1308 corresponding to the eigenvalue zero.
1310 - ``J5`` -- the eigenspace (NOT a subalgebra) of ``c.operator()``
1311 corresponding to the eigenvalue one-half.
1313 - ``J1`` -- the algebra on the eigenspace of ``c.operator()``
1314 corresponding to the eigenvalue one.
1316 These are the only possible eigenspaces for that operator, and this
1317 algebra is a direct sum of them. The spaces ``J0`` and ``J1`` are
1318 orthogonal, and are subalgebras of this algebra with the appropriate
1323 sage: from mjo.eja.eja_algebra import random_eja, RealSymmetricEJA
1327 The canonical example comes from the symmetric matrices, which
1328 decompose into diagonal and off-diagonal parts::
1330 sage: J = RealSymmetricEJA(3)
1331 sage: C = matrix(QQ, [ [1,0,0],
1335 sage: J0,J5,J1 = J.peirce_decomposition(c)
1337 Euclidean Jordan algebra of dimension 1...
1339 Vector space of degree 6 and dimension 2...
1341 Euclidean Jordan algebra of dimension 3...
1342 sage: J0.one().to_matrix()
1346 sage: orig_df = AA.options.display_format
1347 sage: AA.options.display_format = 'radical'
1348 sage: J.from_vector(J5.basis()[0]).to_matrix()
1352 sage: J.from_vector(J5.basis()[1]).to_matrix()
1356 sage: AA.options.display_format = orig_df
1357 sage: J1.one().to_matrix()
1364 Every algebra decomposes trivially with respect to its identity
1367 sage: set_random_seed()
1368 sage: J = random_eja()
1369 sage: J0,J5,J1 = J.peirce_decomposition(J.one())
1370 sage: J0.dimension() == 0 and J5.dimension() == 0
1372 sage: J1.superalgebra() == J and J1.dimension() == J.dimension()
1375 The decomposition is into eigenspaces, and its components are
1376 therefore necessarily orthogonal. Moreover, the identity
1377 elements in the two subalgebras are the projections onto their
1378 respective subspaces of the superalgebra's identity element::
1380 sage: set_random_seed()
1381 sage: J = random_eja()
1382 sage: x = J.random_element()
1383 sage: if not J.is_trivial():
1384 ....: while x.is_nilpotent():
1385 ....: x = J.random_element()
1386 sage: c = x.subalgebra_idempotent()
1387 sage: J0,J5,J1 = J.peirce_decomposition(c)
1389 sage: for (w,y,z) in zip(J0.basis(), J5.basis(), J1.basis()):
1390 ....: w = w.superalgebra_element()
1391 ....: y = J.from_vector(y)
1392 ....: z = z.superalgebra_element()
1393 ....: ipsum += w.inner_product(y).abs()
1394 ....: ipsum += w.inner_product(z).abs()
1395 ....: ipsum += y.inner_product(z).abs()
1398 sage: J1(c) == J1.one()
1400 sage: J0(J.one() - c) == J0.one()
1404 if not c
.is_idempotent():
1405 raise ValueError("element is not idempotent: %s" % c
)
1407 # Default these to what they should be if they turn out to be
1408 # trivial, because eigenspaces_left() won't return eigenvalues
1409 # corresponding to trivial spaces (e.g. it returns only the
1410 # eigenspace corresponding to lambda=1 if you take the
1411 # decomposition relative to the identity element).
1412 trivial
= self
.subalgebra(())
1413 J0
= trivial
# eigenvalue zero
1414 J5
= VectorSpace(self
.base_ring(), 0) # eigenvalue one-half
1415 J1
= trivial
# eigenvalue one
1417 for (eigval
, eigspace
) in c
.operator().matrix().right_eigenspaces():
1418 if eigval
== ~
(self
.base_ring()(2)):
1421 gens
= tuple( self
.from_vector(b
) for b
in eigspace
.basis() )
1422 subalg
= self
.subalgebra(gens
, check_axioms
=False)
1428 raise ValueError("unexpected eigenvalue: %s" % eigval
)
1433 def random_element(self
, thorough
=False):
1435 Return a random element of this algebra.
1437 Our algebra superclass method only returns a linear
1438 combination of at most two basis elements. We instead
1439 want the vector space "random element" method that
1440 returns a more diverse selection.
1444 - ``thorough`` -- (boolean; default False) whether or not we
1445 should generate irrational coefficients for the random
1446 element when our base ring is irrational; this slows the
1447 algebra operations to a crawl, but any truly random method
1451 # For a general base ring... maybe we can trust this to do the
1452 # right thing? Unlikely, but.
1453 V
= self
.vector_space()
1454 v
= V
.random_element()
1456 if self
.base_ring() is AA
:
1457 # The "random element" method of the algebraic reals is
1458 # stupid at the moment, and only returns integers between
1459 # -2 and 2, inclusive:
1461 # https://trac.sagemath.org/ticket/30875
1463 # Instead, we implement our own "random vector" method,
1464 # and then coerce that into the algebra. We use the vector
1465 # space degree here instead of the dimension because a
1466 # subalgebra could (for example) be spanned by only two
1467 # vectors, each with five coordinates. We need to
1468 # generate all five coordinates.
1470 v
*= QQbar
.random_element().real()
1472 v
*= QQ
.random_element()
1474 return self
.from_vector(V
.coordinate_vector(v
))
1476 def random_elements(self
, count
, thorough
=False):
1478 Return ``count`` random elements as a tuple.
1482 - ``thorough`` -- (boolean; default False) whether or not we
1483 should generate irrational coefficients for the random
1484 elements when our base ring is irrational; this slows the
1485 algebra operations to a crawl, but any truly random method
1490 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1494 sage: J = JordanSpinEJA(3)
1495 sage: x,y,z = J.random_elements(3)
1496 sage: all( [ x in J, y in J, z in J ])
1498 sage: len( J.random_elements(10) ) == 10
1502 return tuple( self
.random_element(thorough
)
1503 for idx
in range(count
) )
1507 def _charpoly_coefficients(self
):
1509 The `r` polynomial coefficients of the "characteristic polynomial
1514 sage: from mjo.eja.eja_algebra import random_eja
1518 The theory shows that these are all homogeneous polynomials of
1521 sage: set_random_seed()
1522 sage: J = random_eja()
1523 sage: all(p.is_homogeneous() for p in J._charpoly_coefficients())
1527 n
= self
.dimension()
1528 R
= self
.coordinate_polynomial_ring()
1530 F
= R
.fraction_field()
1533 # From a result in my book, these are the entries of the
1534 # basis representation of L_x.
1535 return sum( vars[k
]*self
.monomial(k
).operator().matrix()[i
,j
]
1538 L_x
= matrix(F
, n
, n
, L_x_i_j
)
1541 if self
.rank
.is_in_cache():
1543 # There's no need to pad the system with redundant
1544 # columns if we *know* they'll be redundant.
1547 # Compute an extra power in case the rank is equal to
1548 # the dimension (otherwise, we would stop at x^(r-1)).
1549 x_powers
= [ (L_x
**k
)*self
.one().to_vector()
1550 for k
in range(n
+1) ]
1551 A
= matrix
.column(F
, x_powers
[:n
])
1552 AE
= A
.extended_echelon_form()
1559 # The theory says that only the first "r" coefficients are
1560 # nonzero, and they actually live in the original polynomial
1561 # ring and not the fraction field. We negate them because in
1562 # the actual characteristic polynomial, they get moved to the
1563 # other side where x^r lives. We don't bother to trim A_rref
1564 # down to a square matrix and solve the resulting system,
1565 # because the upper-left r-by-r portion of A_rref is
1566 # guaranteed to be the identity matrix, so e.g.
1568 # A_rref.solve_right(Y)
1570 # would just be returning Y.
1571 return (-E
*b
)[:r
].change_ring(R
)
1576 Return the rank of this EJA.
1578 This is a cached method because we know the rank a priori for
1579 all of the algebras we can construct. Thus we can avoid the
1580 expensive ``_charpoly_coefficients()`` call unless we truly
1581 need to compute the whole characteristic polynomial.
1585 sage: from mjo.eja.eja_algebra import (HadamardEJA,
1586 ....: JordanSpinEJA,
1587 ....: RealSymmetricEJA,
1588 ....: ComplexHermitianEJA,
1589 ....: QuaternionHermitianEJA,
1594 The rank of the Jordan spin algebra is always two::
1596 sage: JordanSpinEJA(2).rank()
1598 sage: JordanSpinEJA(3).rank()
1600 sage: JordanSpinEJA(4).rank()
1603 The rank of the `n`-by-`n` Hermitian real, complex, or
1604 quaternion matrices is `n`::
1606 sage: RealSymmetricEJA(4).rank()
1608 sage: ComplexHermitianEJA(3).rank()
1610 sage: QuaternionHermitianEJA(2).rank()
1615 Ensure that every EJA that we know how to construct has a
1616 positive integer rank, unless the algebra is trivial in
1617 which case its rank will be zero::
1619 sage: set_random_seed()
1620 sage: J = random_eja()
1624 sage: r > 0 or (r == 0 and J.is_trivial())
1627 Ensure that computing the rank actually works, since the ranks
1628 of all simple algebras are known and will be cached by default::
1630 sage: set_random_seed() # long time
1631 sage: J = random_eja() # long time
1632 sage: cached = J.rank() # long time
1633 sage: J.rank.clear_cache() # long time
1634 sage: J.rank() == cached # long time
1638 return len(self
._charpoly
_coefficients
())
1641 def subalgebra(self
, basis
, **kwargs
):
1643 Create a subalgebra of this algebra from the given basis.
1645 from mjo
.eja
.eja_subalgebra
import FiniteDimensionalEJASubalgebra
1646 return FiniteDimensionalEJASubalgebra(self
, basis
, **kwargs
)
1649 def vector_space(self
):
1651 Return the vector space that underlies this algebra.
1655 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1659 sage: J = RealSymmetricEJA(2)
1660 sage: J.vector_space()
1661 Vector space of dimension 3 over...
1664 return self
.zero().to_vector().parent().ambient_vector_space()
1668 class RationalBasisEJA(FiniteDimensionalEJA
):
1670 Algebras whose supplied basis elements have all rational entries.
1674 sage: from mjo.eja.eja_algebra import BilinearFormEJA
1678 The supplied basis is orthonormalized by default::
1680 sage: B = matrix(QQ, [[1, 0, 0], [0, 25, -32], [0, -32, 41]])
1681 sage: J = BilinearFormEJA(B)
1682 sage: J.matrix_basis()
1699 # Abuse the check_field parameter to check that the entries of
1700 # out basis (in ambient coordinates) are in the field QQ.
1701 # Use _all2list to get the vector coordinates of octonion
1702 # entries and not the octonions themselves (which are not
1704 if not all( all(b_i
in QQ
for b_i
in _all2list(b
))
1706 raise TypeError("basis not rational")
1708 super().__init
__(basis
,
1712 check_field
=check_field
,
1715 self
._rational
_algebra
= None
1717 # There's no point in constructing the extra algebra if this
1718 # one is already rational.
1720 # Note: the same Jordan and inner-products work here,
1721 # because they are necessarily defined with respect to
1722 # ambient coordinates and not any particular basis.
1723 self
._rational
_algebra
= FiniteDimensionalEJA(
1728 matrix_space
=self
.matrix_space(),
1729 associative
=self
.is_associative(),
1730 orthonormalize
=False,
1735 def _charpoly_coefficients(self
):
1739 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
1740 ....: JordanSpinEJA)
1744 The base ring of the resulting polynomial coefficients is what
1745 it should be, and not the rationals (unless the algebra was
1746 already over the rationals)::
1748 sage: J = JordanSpinEJA(3)
1749 sage: J._charpoly_coefficients()
1750 (X1^2 - X2^2 - X3^2, -2*X1)
1751 sage: a0 = J._charpoly_coefficients()[0]
1753 Algebraic Real Field
1754 sage: a0.base_ring()
1755 Algebraic Real Field
1758 if self
._rational
_algebra
is None:
1759 # There's no need to construct *another* algebra over the
1760 # rationals if this one is already over the
1761 # rationals. Likewise, if we never orthonormalized our
1762 # basis, we might as well just use the given one.
1763 return super()._charpoly
_coefficients
()
1765 # Do the computation over the rationals. The answer will be
1766 # the same, because all we've done is a change of basis.
1767 # Then, change back from QQ to our real base ring
1768 a
= ( a_i
.change_ring(self
.base_ring())
1769 for a_i
in self
._rational
_algebra
._charpoly
_coefficients
() )
1771 # Otherwise, convert the coordinate variables back to the
1772 # deorthonormalized ones.
1773 R
= self
.coordinate_polynomial_ring()
1774 from sage
.modules
.free_module_element
import vector
1775 X
= vector(R
, R
.gens())
1776 BX
= self
._deortho
_matrix
*X
1778 subs_dict
= { X[i]: BX[i] for i in range(len(X)) }
1779 return tuple( a_i
.subs(subs_dict
) for a_i
in a
)
1781 class ConcreteEJA(FiniteDimensionalEJA
):
1783 A class for the Euclidean Jordan algebras that we know by name.
1785 These are the Jordan algebras whose basis, multiplication table,
1786 rank, and so on are known a priori. More to the point, they are
1787 the Euclidean Jordan algebras for which we are able to conjure up
1788 a "random instance."
1792 sage: from mjo.eja.eja_algebra import ConcreteEJA
1796 Our basis is normalized with respect to the algebra's inner
1797 product, unless we specify otherwise::
1799 sage: set_random_seed()
1800 sage: J = ConcreteEJA.random_instance()
1801 sage: all( b.norm() == 1 for b in J.gens() )
1804 Since our basis is orthonormal with respect to the algebra's inner
1805 product, and since we know that this algebra is an EJA, any
1806 left-multiplication operator's matrix will be symmetric because
1807 natural->EJA basis representation is an isometry and within the
1808 EJA the operator is self-adjoint by the Jordan axiom::
1810 sage: set_random_seed()
1811 sage: J = ConcreteEJA.random_instance()
1812 sage: x = J.random_element()
1813 sage: x.operator().is_self_adjoint()
1818 def _max_random_instance_dimension():
1820 The maximum dimension of any random instance. Ten dimensions seems
1821 to be about the point where everything takes a turn for the
1822 worse. And dimension ten (but not nine) allows the 4-by-4 real
1823 Hermitian matrices, the 2-by-2 quaternion Hermitian matrices,
1824 and the 2-by-2 octonion Hermitian matrices.
1829 def _max_random_instance_size(max_dimension
):
1831 Return an integer "size" that is an upper bound on the size of
1832 this algebra when it is used in a random test case. This size
1833 (which can be passed to the algebra's constructor) is itself
1834 based on the ``max_dimension`` parameter.
1836 This method must be implemented in each subclass.
1838 raise NotImplementedError
1841 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
1843 Return a random instance of this type of algebra whose dimension
1844 is less than or equal to the lesser of ``max_dimension`` and
1845 the value returned by ``_max_random_instance_dimension()``. If
1846 the dimension bound is omitted, then only the
1847 ``_max_random_instance_dimension()`` is used as a bound.
1849 This method should be implemented in each subclass.
1853 sage: from mjo.eja.eja_algebra import ConcreteEJA
1857 Both the class bound and the ``max_dimension`` argument are upper
1858 bounds on the dimension of the algebra returned::
1860 sage: from sage.misc.prandom import choice
1861 sage: eja_class = choice(ConcreteEJA.__subclasses__())
1862 sage: class_max_d = eja_class._max_random_instance_dimension()
1863 sage: J = eja_class.random_instance(max_dimension=20,
1865 ....: orthonormalize=False)
1866 sage: J.dimension() <= class_max_d
1868 sage: J = eja_class.random_instance(max_dimension=2,
1870 ....: orthonormalize=False)
1871 sage: J.dimension() <= 2
1875 from sage
.misc
.prandom
import choice
1876 eja_class
= choice(cls
.__subclasses
__())
1878 # These all bubble up to the RationalBasisEJA superclass
1879 # constructor, so any (kw)args valid there are also valid
1881 return eja_class
.random_instance(max_dimension
, *args
, **kwargs
)
1884 class MatrixEJA(FiniteDimensionalEJA
):
1886 def _denormalized_basis(A
):
1888 Returns a basis for the space of complex Hermitian n-by-n matrices.
1890 Why do we embed these? Basically, because all of numerical linear
1891 algebra assumes that you're working with vectors consisting of `n`
1892 entries from a field and scalars from the same field. There's no way
1893 to tell SageMath that (for example) the vectors contain complex
1894 numbers, while the scalar field is real.
1898 sage: from mjo.hurwitz import (ComplexMatrixAlgebra,
1899 ....: QuaternionMatrixAlgebra,
1900 ....: OctonionMatrixAlgebra)
1901 sage: from mjo.eja.eja_algebra import MatrixEJA
1905 sage: set_random_seed()
1906 sage: n = ZZ.random_element(1,5)
1907 sage: A = MatrixSpace(QQ, n)
1908 sage: B = MatrixEJA._denormalized_basis(A)
1909 sage: all( M.is_hermitian() for M in B)
1914 sage: set_random_seed()
1915 sage: n = ZZ.random_element(1,5)
1916 sage: A = ComplexMatrixAlgebra(n, scalars=QQ)
1917 sage: B = MatrixEJA._denormalized_basis(A)
1918 sage: all( M.is_hermitian() for M in B)
1923 sage: set_random_seed()
1924 sage: n = ZZ.random_element(1,5)
1925 sage: A = QuaternionMatrixAlgebra(n, scalars=QQ)
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 = OctonionMatrixAlgebra(n, scalars=QQ)
1935 sage: B = MatrixEJA._denormalized_basis(A)
1936 sage: all( M.is_hermitian() for M in B )
1940 # These work for real MatrixSpace, whose monomials only have
1941 # two coordinates (because the last one would always be "1").
1942 es
= A
.base_ring().gens()
1943 gen
= lambda A
,m
: A
.monomial(m
[:2])
1945 if hasattr(A
, 'entry_algebra_gens'):
1946 # We've got a MatrixAlgebra, and its monomials will have
1947 # three coordinates.
1948 es
= A
.entry_algebra_gens()
1949 gen
= lambda A
,m
: A
.monomial(m
)
1952 for i
in range(A
.nrows()):
1953 for j
in range(i
+1):
1955 E_ii
= gen(A
, (i
,j
,es
[0]))
1959 E_ij
= gen(A
, (i
,j
,e
))
1960 E_ij
+= E_ij
.conjugate_transpose()
1963 return tuple( basis
)
1966 def jordan_product(X
,Y
):
1967 return (X
*Y
+ Y
*X
)/2
1970 def trace_inner_product(X
,Y
):
1972 A trace inner-product for matrices that aren't embedded in the
1973 reals. It takes MATRICES as arguments, not EJA elements.
1977 sage: from mjo.eja.eja_algebra import (RealSymmetricEJA,
1978 ....: ComplexHermitianEJA,
1979 ....: QuaternionHermitianEJA,
1980 ....: OctonionHermitianEJA)
1984 sage: J = RealSymmetricEJA(2,field=QQ,orthonormalize=False)
1985 sage: I = J.one().to_matrix()
1986 sage: J.trace_inner_product(I, -I)
1991 sage: J = ComplexHermitianEJA(2,field=QQ,orthonormalize=False)
1992 sage: I = J.one().to_matrix()
1993 sage: J.trace_inner_product(I, -I)
1998 sage: J = QuaternionHermitianEJA(2,field=QQ,orthonormalize=False)
1999 sage: I = J.one().to_matrix()
2000 sage: J.trace_inner_product(I, -I)
2005 sage: J = OctonionHermitianEJA(2,field=QQ,orthonormalize=False)
2006 sage: I = J.one().to_matrix()
2007 sage: J.trace_inner_product(I, -I)
2012 if hasattr(tr
, 'coefficient'):
2013 # Works for octonions, and has to come first because they
2014 # also have a "real()" method that doesn't return an
2015 # element of the scalar ring.
2016 return tr
.coefficient(0)
2017 elif hasattr(tr
, 'coefficient_tuple'):
2018 # Works for quaternions.
2019 return tr
.coefficient_tuple()[0]
2021 # Works for real and complex numbers.
2025 def __init__(self
, matrix_space
, **kwargs
):
2026 # We know this is a valid EJA, but will double-check
2027 # if the user passes check_axioms=True.
2028 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2031 super().__init
__(self
._denormalized
_basis
(matrix_space
),
2032 self
.jordan_product
,
2033 self
.trace_inner_product
,
2034 field
=matrix_space
.base_ring(),
2035 matrix_space
=matrix_space
,
2038 self
.rank
.set_cache(matrix_space
.nrows())
2039 self
.one
.set_cache( self(matrix_space
.one()) )
2041 class RealSymmetricEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2043 The rank-n simple EJA consisting of real symmetric n-by-n
2044 matrices, the usual symmetric Jordan product, and the trace inner
2045 product. It has dimension `(n^2 + n)/2` over the reals.
2049 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
2053 sage: J = RealSymmetricEJA(2)
2054 sage: b0, b1, b2 = J.gens()
2062 In theory, our "field" can be any subfield of the reals::
2064 sage: RealSymmetricEJA(2, field=RDF, check_axioms=True)
2065 Euclidean Jordan algebra of dimension 3 over Real Double Field
2066 sage: RealSymmetricEJA(2, field=RR, check_axioms=True)
2067 Euclidean Jordan algebra of dimension 3 over Real Field with
2068 53 bits of precision
2072 The dimension of this algebra is `(n^2 + n) / 2`::
2074 sage: set_random_seed()
2075 sage: d = RealSymmetricEJA._max_random_instance_dimension()
2076 sage: n = RealSymmetricEJA._max_random_instance_size(d)
2077 sage: J = RealSymmetricEJA(n)
2078 sage: J.dimension() == (n^2 + n)/2
2081 The Jordan multiplication is what we think it is::
2083 sage: set_random_seed()
2084 sage: J = RealSymmetricEJA.random_instance()
2085 sage: x,y = J.random_elements(2)
2086 sage: actual = (x*y).to_matrix()
2087 sage: X = x.to_matrix()
2088 sage: Y = y.to_matrix()
2089 sage: expected = (X*Y + Y*X)/2
2090 sage: actual == expected
2092 sage: J(expected) == x*y
2095 We can change the generator prefix::
2097 sage: RealSymmetricEJA(3, prefix='q').gens()
2098 (q0, q1, q2, q3, q4, q5)
2100 We can construct the (trivial) algebra of rank zero::
2102 sage: RealSymmetricEJA(0)
2103 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2107 def _max_random_instance_size(max_dimension
):
2108 # Obtained by solving d = (n^2 + n)/2.
2109 # The ZZ-int-ZZ thing is just "floor."
2110 return ZZ(int(ZZ(8*max_dimension
+ 1).sqrt()/2 - 1/2))
2113 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2115 Return a random instance of this type of algebra.
2117 class_max_d
= cls
._max
_random
_instance
_dimension
()
2118 if (max_dimension
is None or max_dimension
> class_max_d
):
2119 max_dimension
= class_max_d
2120 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2121 n
= ZZ
.random_element(max_size
+ 1)
2122 return cls(n
, **kwargs
)
2124 def __init__(self
, n
, field
=AA
, **kwargs
):
2125 # We know this is a valid EJA, but will double-check
2126 # if the user passes check_axioms=True.
2127 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2129 A
= MatrixSpace(field
, n
)
2130 super().__init
__(A
, **kwargs
)
2132 from mjo
.eja
.eja_cache
import real_symmetric_eja_coeffs
2133 a
= real_symmetric_eja_coeffs(self
)
2135 if self
._rational
_algebra
is None:
2136 self
._charpoly
_coefficients
.set_cache(a
)
2138 self
._rational
_algebra
._charpoly
_coefficients
.set_cache(a
)
2142 class ComplexHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2144 The rank-n simple EJA consisting of complex Hermitian n-by-n
2145 matrices over the real numbers, the usual symmetric Jordan product,
2146 and the real-part-of-trace inner product. It has dimension `n^2` over
2151 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
2155 In theory, our "field" can be any subfield of the reals, but we
2156 can't use inexact real fields at the moment because SageMath
2157 doesn't know how to convert their elements into complex numbers,
2158 or even into algebraic reals::
2161 Traceback (most recent call last):
2163 TypeError: Illegal initializer for algebraic number
2165 Traceback (most recent call last):
2167 TypeError: Illegal initializer for algebraic number
2169 This causes the following error when we try to scale a matrix of
2170 complex numbers by an inexact real number::
2172 sage: ComplexHermitianEJA(2,field=RR)
2173 Traceback (most recent call last):
2175 TypeError: Unable to coerce entries (=(1.00000000000000,
2176 -0.000000000000000)) to coefficients in Algebraic Real Field
2180 The dimension of this algebra is `n^2`::
2182 sage: set_random_seed()
2183 sage: d = ComplexHermitianEJA._max_random_instance_dimension()
2184 sage: n = ComplexHermitianEJA._max_random_instance_size(d)
2185 sage: J = ComplexHermitianEJA(n)
2186 sage: J.dimension() == n^2
2189 The Jordan multiplication is what we think it is::
2191 sage: set_random_seed()
2192 sage: J = ComplexHermitianEJA.random_instance()
2193 sage: x,y = J.random_elements(2)
2194 sage: actual = (x*y).to_matrix()
2195 sage: X = x.to_matrix()
2196 sage: Y = y.to_matrix()
2197 sage: expected = (X*Y + Y*X)/2
2198 sage: actual == expected
2200 sage: J(expected) == x*y
2203 We can change the generator prefix::
2205 sage: ComplexHermitianEJA(2, prefix='z').gens()
2208 We can construct the (trivial) algebra of rank zero::
2210 sage: ComplexHermitianEJA(0)
2211 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2214 def __init__(self
, n
, field
=AA
, **kwargs
):
2215 # We know this is a valid EJA, but will double-check
2216 # if the user passes check_axioms=True.
2217 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2219 from mjo
.hurwitz
import ComplexMatrixAlgebra
2220 A
= ComplexMatrixAlgebra(n
, scalars
=field
)
2221 super().__init
__(A
, **kwargs
)
2223 from mjo
.eja
.eja_cache
import complex_hermitian_eja_coeffs
2224 a
= complex_hermitian_eja_coeffs(self
)
2226 if self
._rational
_algebra
is None:
2227 self
._charpoly
_coefficients
.set_cache(a
)
2229 self
._rational
_algebra
._charpoly
_coefficients
.set_cache(a
)
2232 def _max_random_instance_size(max_dimension
):
2233 # Obtained by solving d = n^2.
2234 # The ZZ-int-ZZ thing is just "floor."
2235 return ZZ(int(ZZ(max_dimension
).sqrt()))
2238 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2240 Return a random instance of this type of algebra.
2242 class_max_d
= cls
._max
_random
_instance
_dimension
()
2243 if (max_dimension
is None or max_dimension
> class_max_d
):
2244 max_dimension
= class_max_d
2245 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2246 n
= ZZ
.random_element(max_size
+ 1)
2247 return cls(n
, **kwargs
)
2250 class QuaternionHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2252 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
2253 matrices, the usual symmetric Jordan product, and the
2254 real-part-of-trace inner product. It has dimension `2n^2 - n` over
2259 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
2263 In theory, our "field" can be any subfield of the reals::
2265 sage: QuaternionHermitianEJA(2, field=RDF, check_axioms=True)
2266 Euclidean Jordan algebra of dimension 6 over Real Double Field
2267 sage: QuaternionHermitianEJA(2, field=RR, check_axioms=True)
2268 Euclidean Jordan algebra of dimension 6 over Real Field with
2269 53 bits of precision
2273 The dimension of this algebra is `2*n^2 - n`::
2275 sage: set_random_seed()
2276 sage: d = QuaternionHermitianEJA._max_random_instance_dimension()
2277 sage: n = QuaternionHermitianEJA._max_random_instance_size(d)
2278 sage: J = QuaternionHermitianEJA(n)
2279 sage: J.dimension() == 2*(n^2) - n
2282 The Jordan multiplication is what we think it is::
2284 sage: set_random_seed()
2285 sage: J = QuaternionHermitianEJA.random_instance()
2286 sage: x,y = J.random_elements(2)
2287 sage: actual = (x*y).to_matrix()
2288 sage: X = x.to_matrix()
2289 sage: Y = y.to_matrix()
2290 sage: expected = (X*Y + Y*X)/2
2291 sage: actual == expected
2293 sage: J(expected) == x*y
2296 We can change the generator prefix::
2298 sage: QuaternionHermitianEJA(2, prefix='a').gens()
2299 (a0, a1, a2, a3, a4, a5)
2301 We can construct the (trivial) algebra of rank zero::
2303 sage: QuaternionHermitianEJA(0)
2304 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2307 def __init__(self
, n
, field
=AA
, **kwargs
):
2308 # We know this is a valid EJA, but will double-check
2309 # if the user passes check_axioms=True.
2310 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2312 from mjo
.hurwitz
import QuaternionMatrixAlgebra
2313 A
= QuaternionMatrixAlgebra(n
, scalars
=field
)
2314 super().__init
__(A
, **kwargs
)
2316 from mjo
.eja
.eja_cache
import quaternion_hermitian_eja_coeffs
2317 a
= quaternion_hermitian_eja_coeffs(self
)
2319 if self
._rational
_algebra
is None:
2320 self
._charpoly
_coefficients
.set_cache(a
)
2322 self
._rational
_algebra
._charpoly
_coefficients
.set_cache(a
)
2327 def _max_random_instance_size(max_dimension
):
2329 The maximum rank of a random QuaternionHermitianEJA.
2331 # Obtained by solving d = 2n^2 - n.
2332 # The ZZ-int-ZZ thing is just "floor."
2333 return ZZ(int(ZZ(8*max_dimension
+ 1).sqrt()/4 + 1/4))
2336 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2338 Return a random instance of this type of algebra.
2340 class_max_d
= cls
._max
_random
_instance
_dimension
()
2341 if (max_dimension
is None or max_dimension
> class_max_d
):
2342 max_dimension
= class_max_d
2343 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2344 n
= ZZ
.random_element(max_size
+ 1)
2345 return cls(n
, **kwargs
)
2347 class OctonionHermitianEJA(MatrixEJA
, RationalBasisEJA
, ConcreteEJA
):
2351 sage: from mjo.eja.eja_algebra import (FiniteDimensionalEJA,
2352 ....: OctonionHermitianEJA)
2353 sage: from mjo.hurwitz import Octonions, OctonionMatrixAlgebra
2357 The 3-by-3 algebra satisfies the axioms of an EJA::
2359 sage: OctonionHermitianEJA(3, # long time
2360 ....: field=QQ, # long time
2361 ....: orthonormalize=False, # long time
2362 ....: check_axioms=True) # long time
2363 Euclidean Jordan algebra of dimension 27 over Rational Field
2365 After a change-of-basis, the 2-by-2 algebra has the same
2366 multiplication table as the ten-dimensional Jordan spin algebra::
2368 sage: A = OctonionMatrixAlgebra(2,Octonions(QQ),QQ)
2369 sage: b = OctonionHermitianEJA._denormalized_basis(A)
2370 sage: basis = (b[0] + b[9],) + b[1:9] + (b[0] - b[9],)
2371 sage: jp = OctonionHermitianEJA.jordan_product
2372 sage: ip = OctonionHermitianEJA.trace_inner_product
2373 sage: J = FiniteDimensionalEJA(basis,
2377 ....: orthonormalize=False)
2378 sage: J.multiplication_table()
2379 +----++----+----+----+----+----+----+----+----+----+----+
2380 | * || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2381 +====++====+====+====+====+====+====+====+====+====+====+
2382 | b0 || b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8 | b9 |
2383 +----++----+----+----+----+----+----+----+----+----+----+
2384 | b1 || b1 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2385 +----++----+----+----+----+----+----+----+----+----+----+
2386 | b2 || b2 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2387 +----++----+----+----+----+----+----+----+----+----+----+
2388 | b3 || b3 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 | 0 |
2389 +----++----+----+----+----+----+----+----+----+----+----+
2390 | b4 || b4 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 | 0 |
2391 +----++----+----+----+----+----+----+----+----+----+----+
2392 | b5 || b5 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 | 0 |
2393 +----++----+----+----+----+----+----+----+----+----+----+
2394 | b6 || b6 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 | 0 |
2395 +----++----+----+----+----+----+----+----+----+----+----+
2396 | b7 || b7 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 | 0 |
2397 +----++----+----+----+----+----+----+----+----+----+----+
2398 | b8 || b8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 | 0 |
2399 +----++----+----+----+----+----+----+----+----+----+----+
2400 | b9 || b9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | b0 |
2401 +----++----+----+----+----+----+----+----+----+----+----+
2405 We can actually construct the 27-dimensional Albert algebra,
2406 and we get the right unit element if we recompute it::
2408 sage: J = OctonionHermitianEJA(3, # long time
2409 ....: field=QQ, # long time
2410 ....: orthonormalize=False) # long time
2411 sage: J.one.clear_cache() # long time
2412 sage: J.one() # long time
2414 sage: J.one().to_matrix() # long time
2423 The 2-by-2 algebra is isomorphic to the ten-dimensional Jordan
2424 spin algebra, but just to be sure, we recompute its rank::
2426 sage: J = OctonionHermitianEJA(2, # long time
2427 ....: field=QQ, # long time
2428 ....: orthonormalize=False) # long time
2429 sage: J.rank.clear_cache() # long time
2430 sage: J.rank() # long time
2435 def _max_random_instance_size(max_dimension
):
2437 The maximum rank of a random QuaternionHermitianEJA.
2439 # There's certainly a formula for this, but with only four
2440 # cases to worry about, I'm not that motivated to derive it.
2441 if max_dimension
>= 27:
2443 elif max_dimension
>= 10:
2445 elif max_dimension
>= 1:
2451 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2453 Return a random instance of this type of algebra.
2455 class_max_d
= cls
._max
_random
_instance
_dimension
()
2456 if (max_dimension
is None or max_dimension
> class_max_d
):
2457 max_dimension
= class_max_d
2458 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2459 n
= ZZ
.random_element(max_size
+ 1)
2460 return cls(n
, **kwargs
)
2462 def __init__(self
, n
, field
=AA
, **kwargs
):
2464 # Otherwise we don't get an EJA.
2465 raise ValueError("n cannot exceed 3")
2467 # We know this is a valid EJA, but will double-check
2468 # if the user passes check_axioms=True.
2469 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2471 from mjo
.hurwitz
import OctonionMatrixAlgebra
2472 A
= OctonionMatrixAlgebra(n
, scalars
=field
)
2473 super().__init
__(A
, **kwargs
)
2475 from mjo
.eja
.eja_cache
import octonion_hermitian_eja_coeffs
2476 a
= octonion_hermitian_eja_coeffs(self
)
2478 if self
._rational
_algebra
is None:
2479 self
._charpoly
_coefficients
.set_cache(a
)
2481 self
._rational
_algebra
._charpoly
_coefficients
.set_cache(a
)
2484 class AlbertEJA(OctonionHermitianEJA
):
2486 The Albert algebra is the algebra of three-by-three Hermitian
2487 matrices whose entries are octonions.
2491 sage: from mjo.eja.eja_algebra import AlbertEJA
2495 sage: AlbertEJA(field=QQ, orthonormalize=False)
2496 Euclidean Jordan algebra of dimension 27 over Rational Field
2497 sage: AlbertEJA() # long time
2498 Euclidean Jordan algebra of dimension 27 over Algebraic Real Field
2501 def __init__(self
, *args
, **kwargs
):
2502 super().__init
__(3, *args
, **kwargs
)
2505 class HadamardEJA(RationalBasisEJA
, ConcreteEJA
):
2507 Return the Euclidean Jordan algebra on `R^n` with the Hadamard
2508 (pointwise real-number multiplication) Jordan product and the
2509 usual inner-product.
2511 This is nothing more than the Cartesian product of ``n`` copies of
2512 the one-dimensional Jordan spin algebra, and is the most common
2513 example of a non-simple Euclidean Jordan algebra.
2517 sage: from mjo.eja.eja_algebra import HadamardEJA
2521 This multiplication table can be verified by hand::
2523 sage: J = HadamardEJA(3)
2524 sage: b0,b1,b2 = J.gens()
2540 We can change the generator prefix::
2542 sage: HadamardEJA(3, prefix='r').gens()
2545 def __init__(self
, n
, field
=AA
, **kwargs
):
2546 MS
= MatrixSpace(field
, n
, 1)
2549 jordan_product
= lambda x
,y
: x
2550 inner_product
= lambda x
,y
: x
2552 def jordan_product(x
,y
):
2553 return MS( xi
*yi
for (xi
,yi
) in zip(x
,y
) )
2555 def inner_product(x
,y
):
2558 # New defaults for keyword arguments. Don't orthonormalize
2559 # because our basis is already orthonormal with respect to our
2560 # inner-product. Don't check the axioms, because we know this
2561 # is a valid EJA... but do double-check if the user passes
2562 # check_axioms=True. Note: we DON'T override the "check_field"
2563 # default here, because the user can pass in a field!
2564 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2565 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2567 column_basis
= tuple( MS(b
) for b
in FreeModule(field
, n
).basis() )
2568 super().__init
__(column_basis
,
2575 self
.rank
.set_cache(n
)
2577 self
.one
.set_cache( self
.sum(self
.gens()) )
2580 def _max_random_instance_dimension():
2582 There's no reason to go higher than five here. That's
2583 enough to get the point across.
2588 def _max_random_instance_size(max_dimension
):
2590 The maximum size (=dimension) of a random HadamardEJA.
2592 return max_dimension
2595 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2597 Return a random instance of this type of algebra.
2599 class_max_d
= cls
._max
_random
_instance
_dimension
()
2600 if (max_dimension
is None or max_dimension
> class_max_d
):
2601 max_dimension
= class_max_d
2602 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2603 n
= ZZ
.random_element(max_size
+ 1)
2604 return cls(n
, **kwargs
)
2607 class BilinearFormEJA(RationalBasisEJA
, ConcreteEJA
):
2609 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2610 with the half-trace inner product and jordan product ``x*y =
2611 (<Bx,y>,y_bar>, x0*y_bar + y0*x_bar)`` where `B = 1 \times B22` is
2612 a symmetric positive-definite "bilinear form" matrix. Its
2613 dimension is the size of `B`, and it has rank two in dimensions
2614 larger than two. It reduces to the ``JordanSpinEJA`` when `B` is
2615 the identity matrix of order ``n``.
2617 We insist that the one-by-one upper-left identity block of `B` be
2618 passed in as well so that we can be passed a matrix of size zero
2619 to construct a trivial algebra.
2623 sage: from mjo.eja.eja_algebra import (BilinearFormEJA,
2624 ....: JordanSpinEJA)
2628 When no bilinear form is specified, the identity matrix is used,
2629 and the resulting algebra is the Jordan spin algebra::
2631 sage: B = matrix.identity(AA,3)
2632 sage: J0 = BilinearFormEJA(B)
2633 sage: J1 = JordanSpinEJA(3)
2634 sage: J0.multiplication_table() == J0.multiplication_table()
2637 An error is raised if the matrix `B` does not correspond to a
2638 positive-definite bilinear form::
2640 sage: B = matrix.random(QQ,2,3)
2641 sage: J = BilinearFormEJA(B)
2642 Traceback (most recent call last):
2644 ValueError: bilinear form is not positive-definite
2645 sage: B = matrix.zero(QQ,3)
2646 sage: J = BilinearFormEJA(B)
2647 Traceback (most recent call last):
2649 ValueError: bilinear form is not positive-definite
2653 We can create a zero-dimensional algebra::
2655 sage: B = matrix.identity(AA,0)
2656 sage: J = BilinearFormEJA(B)
2660 We can check the multiplication condition given in the Jordan, von
2661 Neumann, and Wigner paper (and also discussed on my "On the
2662 symmetry..." paper). Note that this relies heavily on the standard
2663 choice of basis, as does anything utilizing the bilinear form
2664 matrix. We opt not to orthonormalize the basis, because if we
2665 did, we would have to normalize the `s_{i}` in a similar manner::
2667 sage: set_random_seed()
2668 sage: n = ZZ.random_element(5)
2669 sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
2670 sage: B11 = matrix.identity(QQ,1)
2671 sage: B22 = M.transpose()*M
2672 sage: B = block_matrix(2,2,[ [B11,0 ],
2674 sage: J = BilinearFormEJA(B, orthonormalize=False)
2675 sage: eis = VectorSpace(M.base_ring(), M.ncols()).basis()
2676 sage: V = J.vector_space()
2677 sage: sis = [ J( V([0] + (M.inverse()*ei).list()).column() )
2678 ....: for ei in eis ]
2679 sage: actual = [ sis[i]*sis[j]
2680 ....: for i in range(n-1)
2681 ....: for j in range(n-1) ]
2682 sage: expected = [ J.one() if i == j else J.zero()
2683 ....: for i in range(n-1)
2684 ....: for j in range(n-1) ]
2685 sage: actual == expected
2689 def __init__(self
, B
, field
=AA
, **kwargs
):
2690 # The matrix "B" is supplied by the user in most cases,
2691 # so it makes sense to check whether or not its positive-
2692 # definite unless we are specifically asked not to...
2693 if ("check_axioms" not in kwargs
) or kwargs
["check_axioms"]:
2694 if not B
.is_positive_definite():
2695 raise ValueError("bilinear form is not positive-definite")
2697 # However, all of the other data for this EJA is computed
2698 # by us in manner that guarantees the axioms are
2699 # satisfied. So, again, unless we are specifically asked to
2700 # verify things, we'll skip the rest of the checks.
2701 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2704 MS
= MatrixSpace(field
, n
, 1)
2706 def inner_product(x
,y
):
2707 return (y
.T
*B
*x
)[0,0]
2709 def jordan_product(x
,y
):
2714 z0
= inner_product(y
,x
)
2715 zbar
= y0
*xbar
+ x0
*ybar
2716 return MS([z0
] + zbar
.list())
2718 column_basis
= tuple( MS(b
) for b
in FreeModule(field
, n
).basis() )
2720 # TODO: I haven't actually checked this, but it seems legit.
2725 super().__init
__(column_basis
,
2730 associative
=associative
,
2733 # The rank of this algebra is two, unless we're in a
2734 # one-dimensional ambient space (because the rank is bounded
2735 # by the ambient dimension).
2736 self
.rank
.set_cache(min(n
,2))
2738 self
.one
.set_cache( self
.zero() )
2740 self
.one
.set_cache( self
.monomial(0) )
2743 def _max_random_instance_dimension():
2745 There's no reason to go higher than five here. That's
2746 enough to get the point across.
2751 def _max_random_instance_size(max_dimension
):
2753 The maximum size (=dimension) of a random BilinearFormEJA.
2755 return max_dimension
2758 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2760 Return a random instance of this algebra.
2762 class_max_d
= cls
._max
_random
_instance
_dimension
()
2763 if (max_dimension
is None or max_dimension
> class_max_d
):
2764 max_dimension
= class_max_d
2765 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2766 n
= ZZ
.random_element(max_size
+ 1)
2769 B
= matrix
.identity(ZZ
, n
)
2770 return cls(B
, **kwargs
)
2772 B11
= matrix
.identity(ZZ
, 1)
2773 M
= matrix
.random(ZZ
, n
-1)
2774 I
= matrix
.identity(ZZ
, n
-1)
2776 while alpha
.is_zero():
2777 alpha
= ZZ
.random_element().abs()
2779 B22
= M
.transpose()*M
+ alpha
*I
2781 from sage
.matrix
.special
import block_matrix
2782 B
= block_matrix(2,2, [ [B11
, ZZ(0) ],
2785 return cls(B
, **kwargs
)
2788 class JordanSpinEJA(BilinearFormEJA
):
2790 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
2791 with the usual inner product and jordan product ``x*y =
2792 (<x,y>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
2797 sage: from mjo.eja.eja_algebra import JordanSpinEJA
2801 This multiplication table can be verified by hand::
2803 sage: J = JordanSpinEJA(4)
2804 sage: b0,b1,b2,b3 = J.gens()
2820 We can change the generator prefix::
2822 sage: JordanSpinEJA(2, prefix='B').gens()
2827 Ensure that we have the usual inner product on `R^n`::
2829 sage: set_random_seed()
2830 sage: J = JordanSpinEJA.random_instance()
2831 sage: x,y = J.random_elements(2)
2832 sage: actual = x.inner_product(y)
2833 sage: expected = x.to_vector().inner_product(y.to_vector())
2834 sage: actual == expected
2838 def __init__(self
, n
, *args
, **kwargs
):
2839 # This is a special case of the BilinearFormEJA with the
2840 # identity matrix as its bilinear form.
2841 B
= matrix
.identity(ZZ
, n
)
2843 # Don't orthonormalize because our basis is already
2844 # orthonormal with respect to our inner-product.
2845 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2847 # But also don't pass check_field=False here, because the user
2848 # can pass in a field!
2849 super().__init
__(B
, *args
, **kwargs
)
2852 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2854 Return a random instance of this type of algebra.
2856 Needed here to override the implementation for ``BilinearFormEJA``.
2858 class_max_d
= cls
._max
_random
_instance
_dimension
()
2859 if (max_dimension
is None or max_dimension
> class_max_d
):
2860 max_dimension
= class_max_d
2861 max_size
= cls
._max
_random
_instance
_size
(max_dimension
)
2862 n
= ZZ
.random_element(max_size
+ 1)
2863 return cls(n
, **kwargs
)
2866 class TrivialEJA(RationalBasisEJA
, ConcreteEJA
):
2868 The trivial Euclidean Jordan algebra consisting of only a zero element.
2872 sage: from mjo.eja.eja_algebra import TrivialEJA
2876 sage: J = TrivialEJA()
2883 sage: 7*J.one()*12*J.one()
2885 sage: J.one().inner_product(J.one())
2887 sage: J.one().norm()
2889 sage: J.one().subalgebra_generated_by()
2890 Euclidean Jordan algebra of dimension 0 over Algebraic Real Field
2895 def __init__(self
, field
=AA
, **kwargs
):
2896 jordan_product
= lambda x
,y
: x
2897 inner_product
= lambda x
,y
: field
.zero()
2899 MS
= MatrixSpace(field
,0)
2901 # New defaults for keyword arguments
2902 if "orthonormalize" not in kwargs
: kwargs
["orthonormalize"] = False
2903 if "check_axioms" not in kwargs
: kwargs
["check_axioms"] = False
2905 super().__init
__(basis
,
2913 # The rank is zero using my definition, namely the dimension of the
2914 # largest subalgebra generated by any element.
2915 self
.rank
.set_cache(0)
2916 self
.one
.set_cache( self
.zero() )
2919 def random_instance(cls
, max_dimension
=None, *args
, **kwargs
):
2920 # We don't take a "size" argument so the superclass method is
2921 # inappropriate for us. The ``max_dimension`` argument is
2922 # included so that if this method is called generically with a
2923 # ``max_dimension=<whatever>`` argument, we don't try to pass
2924 # it on to the algebra constructor.
2925 return cls(**kwargs
)
2928 class CartesianProductEJA(FiniteDimensionalEJA
):
2930 The external (orthogonal) direct sum of two or more Euclidean
2931 Jordan algebras. Every Euclidean Jordan algebra decomposes into an
2932 orthogonal direct sum of simple Euclidean Jordan algebras which is
2933 then isometric to a Cartesian product, so no generality is lost by
2934 providing only this construction.
2938 sage: from mjo.eja.eja_algebra import (random_eja,
2939 ....: CartesianProductEJA,
2941 ....: JordanSpinEJA,
2942 ....: RealSymmetricEJA)
2946 The Jordan product is inherited from our factors and implemented by
2947 our CombinatorialFreeModule Cartesian product superclass::
2949 sage: set_random_seed()
2950 sage: J1 = HadamardEJA(2)
2951 sage: J2 = RealSymmetricEJA(2)
2952 sage: J = cartesian_product([J1,J2])
2953 sage: x,y = J.random_elements(2)
2957 The ability to retrieve the original factors is implemented by our
2958 CombinatorialFreeModule Cartesian product superclass::
2960 sage: J1 = HadamardEJA(2, field=QQ)
2961 sage: J2 = JordanSpinEJA(3, field=QQ)
2962 sage: J = cartesian_product([J1,J2])
2963 sage: J.cartesian_factors()
2964 (Euclidean Jordan algebra of dimension 2 over Rational Field,
2965 Euclidean Jordan algebra of dimension 3 over Rational Field)
2967 You can provide more than two factors::
2969 sage: J1 = HadamardEJA(2)
2970 sage: J2 = JordanSpinEJA(3)
2971 sage: J3 = RealSymmetricEJA(3)
2972 sage: cartesian_product([J1,J2,J3])
2973 Euclidean Jordan algebra of dimension 2 over Algebraic Real
2974 Field (+) Euclidean Jordan algebra of dimension 3 over Algebraic
2975 Real Field (+) Euclidean Jordan algebra of dimension 6 over
2976 Algebraic Real Field
2978 Rank is additive on a Cartesian product::
2980 sage: J1 = HadamardEJA(1)
2981 sage: J2 = RealSymmetricEJA(2)
2982 sage: J = cartesian_product([J1,J2])
2983 sage: J1.rank.clear_cache()
2984 sage: J2.rank.clear_cache()
2985 sage: J.rank.clear_cache()
2988 sage: J.rank() == J1.rank() + J2.rank()
2991 The same rank computation works over the rationals, with whatever
2994 sage: J1 = HadamardEJA(1, field=QQ, orthonormalize=False)
2995 sage: J2 = RealSymmetricEJA(2, field=QQ, orthonormalize=False)
2996 sage: J = cartesian_product([J1,J2])
2997 sage: J1.rank.clear_cache()
2998 sage: J2.rank.clear_cache()
2999 sage: J.rank.clear_cache()
3002 sage: J.rank() == J1.rank() + J2.rank()
3005 The product algebra will be associative if and only if all of its
3006 components are associative::
3008 sage: J1 = HadamardEJA(2)
3009 sage: J1.is_associative()
3011 sage: J2 = HadamardEJA(3)
3012 sage: J2.is_associative()
3014 sage: J3 = RealSymmetricEJA(3)
3015 sage: J3.is_associative()
3017 sage: CP1 = cartesian_product([J1,J2])
3018 sage: CP1.is_associative()
3020 sage: CP2 = cartesian_product([J1,J3])
3021 sage: CP2.is_associative()
3024 Cartesian products of Cartesian products work::
3026 sage: J1 = JordanSpinEJA(1)
3027 sage: J2 = JordanSpinEJA(1)
3028 sage: J3 = JordanSpinEJA(1)
3029 sage: J = cartesian_product([J1,cartesian_product([J2,J3])])
3030 sage: J.multiplication_table()
3031 +----++----+----+----+
3032 | * || b0 | b1 | b2 |
3033 +====++====+====+====+
3034 | b0 || b0 | 0 | 0 |
3035 +----++----+----+----+
3036 | b1 || 0 | b1 | 0 |
3037 +----++----+----+----+
3038 | b2 || 0 | 0 | b2 |
3039 +----++----+----+----+
3040 sage: HadamardEJA(3).multiplication_table()
3041 +----++----+----+----+
3042 | * || b0 | b1 | b2 |
3043 +====++====+====+====+
3044 | b0 || b0 | 0 | 0 |
3045 +----++----+----+----+
3046 | b1 || 0 | b1 | 0 |
3047 +----++----+----+----+
3048 | b2 || 0 | 0 | b2 |
3049 +----++----+----+----+
3053 All factors must share the same base field::
3055 sage: J1 = HadamardEJA(2, field=QQ)
3056 sage: J2 = RealSymmetricEJA(2)
3057 sage: CartesianProductEJA((J1,J2))
3058 Traceback (most recent call last):
3060 ValueError: all factors must share the same base field
3062 The cached unit element is the same one that would be computed::
3064 sage: set_random_seed() # long time
3065 sage: J1 = random_eja() # long time
3066 sage: J2 = random_eja() # long time
3067 sage: J = cartesian_product([J1,J2]) # long time
3068 sage: actual = J.one() # long time
3069 sage: J.one.clear_cache() # long time
3070 sage: expected = J.one() # long time
3071 sage: actual == expected # long time
3075 Element
= FiniteDimensionalEJAElement
3078 def __init__(self
, factors
, **kwargs
):
3083 self
._sets
= factors
3085 field
= factors
[0].base_ring()
3086 if not all( J
.base_ring() == field
for J
in factors
):
3087 raise ValueError("all factors must share the same base field")
3089 associative
= all( f
.is_associative() for f
in factors
)
3091 # Compute my matrix space. This category isn't perfect, but
3092 # is good enough for what we need to do.
3093 MS_cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
3094 MS_cat
= MS_cat
.Unital().CartesianProducts()
3095 MS_factors
= tuple( J
.matrix_space() for J
in factors
)
3096 from sage
.sets
.cartesian_product
import CartesianProduct
3097 MS
= CartesianProduct(MS_factors
, MS_cat
)
3102 for b
in factors
[i
].matrix_basis():
3107 basis
= tuple( MS(b
) for b
in basis
)
3109 # Define jordan/inner products that operate on that matrix_basis.
3110 def jordan_product(x
,y
):
3112 (factors
[i
](x
[i
])*factors
[i
](y
[i
])).to_matrix()
3116 def inner_product(x
, y
):
3118 factors
[i
](x
[i
]).inner_product(factors
[i
](y
[i
]))
3122 # There's no need to check the field since it already came
3123 # from an EJA. Likewise the axioms are guaranteed to be
3124 # satisfied, unless the guy writing this class sucks.
3126 # If you want the basis to be orthonormalized, orthonormalize
3128 FiniteDimensionalEJA
.__init
__(self
,
3134 orthonormalize
=False,
3135 associative
=associative
,
3136 cartesian_product
=True,
3140 # Since we don't (re)orthonormalize the basis, the FDEJA
3141 # constructor is going to set self._deortho_matrix to the
3142 # identity matrix. Here we set it to the correct value using
3143 # the deortho matrices from our factors.
3144 self
._deortho
_matrix
= matrix
.block_diagonal( [J
._deortho
_matrix
3147 self
.rank
.set_cache(sum(J
.rank() for J
in factors
))
3148 ones
= tuple(J
.one().to_matrix() for J
in factors
)
3149 self
.one
.set_cache(self(ones
))
3151 def cartesian_factors(self
):
3152 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
3155 def cartesian_factor(self
, i
):
3157 Return the ``i``th factor of this algebra.
3159 return self
._sets
[i
]
3162 # Copy/pasted from CombinatorialFreeModule_CartesianProduct.
3163 from sage
.categories
.cartesian_product
import cartesian_product
3164 return cartesian_product
.symbol
.join("%s" % factor
3165 for factor
in self
._sets
)
3167 def matrix_space(self
):
3169 Return the space that our matrix basis lives in as a Cartesian
3172 We don't simply use the ``cartesian_product()`` functor here
3173 because it acts differently on SageMath MatrixSpaces and our
3174 custom MatrixAlgebras, which are CombinatorialFreeModules. We
3175 always want the result to be represented (and indexed) as
3180 sage: from mjo.eja.eja_algebra import (ComplexHermitianEJA,
3182 ....: OctonionHermitianEJA,
3183 ....: RealSymmetricEJA)
3187 sage: J1 = HadamardEJA(1)
3188 sage: J2 = RealSymmetricEJA(2)
3189 sage: J = cartesian_product([J1,J2])
3190 sage: J.matrix_space()
3191 The Cartesian product of (Full MatrixSpace of 1 by 1 dense
3192 matrices over Algebraic Real Field, Full MatrixSpace of 2
3193 by 2 dense matrices over Algebraic Real Field)
3197 sage: J1 = ComplexHermitianEJA(1)
3198 sage: J2 = ComplexHermitianEJA(1)
3199 sage: J = cartesian_product([J1,J2])
3200 sage: J.one().to_matrix()[0]
3204 sage: J.one().to_matrix()[1]
3211 sage: J1 = OctonionHermitianEJA(1)
3212 sage: J2 = OctonionHermitianEJA(1)
3213 sage: J = cartesian_product([J1,J2])
3214 sage: J.one().to_matrix()[0]
3218 sage: J.one().to_matrix()[1]
3224 return super().matrix_space()
3228 def cartesian_projection(self
, i
):
3232 sage: from mjo.eja.eja_algebra import (random_eja,
3233 ....: JordanSpinEJA,
3235 ....: RealSymmetricEJA,
3236 ....: ComplexHermitianEJA)
3240 The projection morphisms are Euclidean Jordan algebra
3243 sage: J1 = HadamardEJA(2)
3244 sage: J2 = RealSymmetricEJA(2)
3245 sage: J = cartesian_product([J1,J2])
3246 sage: J.cartesian_projection(0)
3247 Linear operator between finite-dimensional Euclidean Jordan
3248 algebras represented by the matrix:
3251 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3252 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3253 Algebraic Real Field
3254 Codomain: Euclidean Jordan algebra of dimension 2 over Algebraic
3256 sage: J.cartesian_projection(1)
3257 Linear operator between finite-dimensional Euclidean Jordan
3258 algebras represented by the matrix:
3262 Domain: Euclidean Jordan algebra of dimension 2 over Algebraic
3263 Real Field (+) Euclidean Jordan algebra of dimension 3 over
3264 Algebraic Real Field
3265 Codomain: Euclidean Jordan algebra of dimension 3 over Algebraic
3268 The projections work the way you'd expect on the vector
3269 representation of an element::
3271 sage: J1 = JordanSpinEJA(2)
3272 sage: J2 = ComplexHermitianEJA(2)
3273 sage: J = cartesian_product([J1,J2])
3274 sage: pi_left = J.cartesian_projection(0)
3275 sage: pi_right = J.cartesian_projection(1)
3276 sage: pi_left(J.one()).to_vector()
3278 sage: pi_right(J.one()).to_vector()
3280 sage: J.one().to_vector()
3285 The answer never changes::
3287 sage: set_random_seed()
3288 sage: J1 = random_eja()
3289 sage: J2 = random_eja()
3290 sage: J = cartesian_product([J1,J2])
3291 sage: P0 = J.cartesian_projection(0)
3292 sage: P1 = J.cartesian_projection(0)
3297 offset
= sum( self
.cartesian_factor(k
).dimension()
3299 Ji
= self
.cartesian_factor(i
)
3300 Pi
= self
._module
_morphism
(lambda j
: Ji
.monomial(j
- offset
),
3303 return FiniteDimensionalEJAOperator(self
,Ji
,Pi
.matrix())
3306 def cartesian_embedding(self
, i
):
3310 sage: from mjo.eja.eja_algebra import (random_eja,
3311 ....: JordanSpinEJA,
3313 ....: RealSymmetricEJA)
3317 The embedding morphisms are Euclidean Jordan algebra
3320 sage: J1 = HadamardEJA(2)
3321 sage: J2 = RealSymmetricEJA(2)
3322 sage: J = cartesian_product([J1,J2])
3323 sage: J.cartesian_embedding(0)
3324 Linear operator between finite-dimensional Euclidean Jordan
3325 algebras represented by the matrix:
3331 Domain: Euclidean Jordan algebra of dimension 2 over
3332 Algebraic Real Field
3333 Codomain: Euclidean Jordan algebra of dimension 2 over
3334 Algebraic Real Field (+) Euclidean Jordan algebra of
3335 dimension 3 over Algebraic Real Field
3336 sage: J.cartesian_embedding(1)
3337 Linear operator between finite-dimensional Euclidean Jordan
3338 algebras represented by the matrix:
3344 Domain: Euclidean Jordan algebra of dimension 3 over
3345 Algebraic Real Field
3346 Codomain: Euclidean Jordan algebra of dimension 2 over
3347 Algebraic Real Field (+) Euclidean Jordan algebra of
3348 dimension 3 over Algebraic Real Field
3350 The embeddings work the way you'd expect on the vector
3351 representation of an element::
3353 sage: J1 = JordanSpinEJA(3)
3354 sage: J2 = RealSymmetricEJA(2)
3355 sage: J = cartesian_product([J1,J2])
3356 sage: iota_left = J.cartesian_embedding(0)
3357 sage: iota_right = J.cartesian_embedding(1)
3358 sage: iota_left(J1.zero()) == J.zero()
3360 sage: iota_right(J2.zero()) == J.zero()
3362 sage: J1.one().to_vector()
3364 sage: iota_left(J1.one()).to_vector()
3366 sage: J2.one().to_vector()
3368 sage: iota_right(J2.one()).to_vector()
3370 sage: J.one().to_vector()
3375 The answer never changes::
3377 sage: set_random_seed()
3378 sage: J1 = random_eja()
3379 sage: J2 = random_eja()
3380 sage: J = cartesian_product([J1,J2])
3381 sage: E0 = J.cartesian_embedding(0)
3382 sage: E1 = J.cartesian_embedding(0)
3386 Composing a projection with the corresponding inclusion should
3387 produce the identity map, and mismatching them should produce
3390 sage: set_random_seed()
3391 sage: J1 = random_eja()
3392 sage: J2 = random_eja()
3393 sage: J = cartesian_product([J1,J2])
3394 sage: iota_left = J.cartesian_embedding(0)
3395 sage: iota_right = J.cartesian_embedding(1)
3396 sage: pi_left = J.cartesian_projection(0)
3397 sage: pi_right = J.cartesian_projection(1)
3398 sage: pi_left*iota_left == J1.one().operator()
3400 sage: pi_right*iota_right == J2.one().operator()
3402 sage: (pi_left*iota_right).is_zero()
3404 sage: (pi_right*iota_left).is_zero()
3408 offset
= sum( self
.cartesian_factor(k
).dimension()
3410 Ji
= self
.cartesian_factor(i
)
3411 Ei
= Ji
._module
_morphism
(lambda j
: self
.monomial(j
+ offset
),
3413 return FiniteDimensionalEJAOperator(Ji
,self
,Ei
.matrix())
3417 FiniteDimensionalEJA
.CartesianProduct
= CartesianProductEJA
3419 class RationalBasisCartesianProductEJA(CartesianProductEJA
,
3422 A separate class for products of algebras for which we know a
3427 sage: from mjo.eja.eja_algebra import (HadamardEJA,
3428 ....: JordanSpinEJA,
3429 ....: OctonionHermitianEJA,
3430 ....: RealSymmetricEJA)
3434 This gives us fast characteristic polynomial computations in
3435 product algebras, too::
3438 sage: J1 = JordanSpinEJA(2)
3439 sage: J2 = RealSymmetricEJA(3)
3440 sage: J = cartesian_product([J1,J2])
3441 sage: J.characteristic_polynomial_of().degree()
3448 The ``cartesian_product()`` function only uses the first factor to
3449 decide where the result will live; thus we have to be careful to
3450 check that all factors do indeed have a `_rational_algebra` member
3451 before we try to access it::
3453 sage: J1 = OctonionHermitianEJA(1) # no rational basis
3454 sage: J2 = HadamardEJA(2)
3455 sage: cartesian_product([J1,J2])
3456 Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
3457 (+) Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
3458 sage: cartesian_product([J2,J1])
3459 Euclidean Jordan algebra of dimension 2 over Algebraic Real Field
3460 (+) Euclidean Jordan algebra of dimension 1 over Algebraic Real Field
3463 def __init__(self
, algebras
, **kwargs
):
3464 CartesianProductEJA
.__init
__(self
, algebras
, **kwargs
)
3466 self
._rational
_algebra
= None
3467 if self
.vector_space().base_field() is not QQ
:
3468 if all( hasattr(r
, "_rational_algebra") for r
in algebras
):
3469 self
._rational
_algebra
= cartesian_product([
3470 r
._rational
_algebra
for r
in algebras
3474 RationalBasisEJA
.CartesianProduct
= RationalBasisCartesianProductEJA
3476 def random_eja(max_dimension
=None, *args
, **kwargs
):
3481 sage: from mjo.eja.eja_algebra import random_eja
3485 sage: set_random_seed()
3486 sage: n = ZZ.random_element(1,5)
3487 sage: J = random_eja(max_dimension=n, field=QQ, orthonormalize=False)
3488 sage: J.dimension() <= n
3492 # Use the ConcreteEJA default as the total upper bound (regardless
3493 # of any whether or not any individual factors set a lower limit).
3494 if max_dimension
is None:
3495 max_dimension
= ConcreteEJA
._max
_random
_instance
_dimension
()
3496 J1
= ConcreteEJA
.random_instance(max_dimension
, *args
, **kwargs
)
3499 # Roll the dice to see if we attempt a Cartesian product.
3500 dice_roll
= ZZ
.random_element(len(ConcreteEJA
.__subclasses
__()) + 1)
3501 new_max_dimension
= max_dimension
- J1
.dimension()
3502 if new_max_dimension
== 0 or dice_roll
!= 0:
3503 # If it's already as big as we're willing to tolerate, just
3504 # return it and don't worry about Cartesian products.
3507 # Use random_eja() again so we can get more than two factors
3508 # if the sub-call also Decides on a cartesian product.
3509 J2
= random_eja(new_max_dimension
, *args
, **kwargs
)
3510 return cartesian_product([J1
,J2
])