2 Euclidean Jordan Algebras. These are formally-real Jordan Algebras;
3 specifically those where u^2 + v^2 = 0 implies that u = v = 0. They
4 are used in optimization, and have some additional nice methods beyond
5 what can be supported in a general Jordan Algebra.
8 from sage
.algebras
.quatalg
.quaternion_algebra
import QuaternionAlgebra
9 from sage
.categories
.magmatic_algebras
import MagmaticAlgebras
10 from sage
.combinat
.free_module
import CombinatorialFreeModule
11 from sage
.matrix
.constructor
import matrix
12 from sage
.matrix
.matrix_space
import MatrixSpace
13 from sage
.misc
.cachefunc
import cached_method
14 from sage
.misc
.prandom
import choice
15 from sage
.misc
.table
import table
16 from sage
.modules
.free_module
import FreeModule
, VectorSpace
17 from sage
.rings
.integer_ring
import ZZ
18 from sage
.rings
.number_field
.number_field
import NumberField
, QuadraticField
19 from sage
.rings
.polynomial
.polynomial_ring_constructor
import PolynomialRing
20 from sage
.rings
.rational_field
import QQ
21 from sage
.rings
.real_lazy
import CLF
, RLF
22 from sage
.structure
.element
import is_Matrix
24 from mjo
.eja
.eja_element
import FiniteDimensionalEuclideanJordanAlgebraElement
25 from mjo
.eja
.eja_utils
import _mat2vec
27 class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule
):
28 # This is an ugly hack needed to prevent the category framework
29 # from implementing a coercion from our base ring (e.g. the
30 # rationals) into the algebra. First of all -- such a coercion is
31 # nonsense to begin with. But more importantly, it tries to do so
32 # in the category of rings, and since our algebras aren't
33 # associative they generally won't be rings.
34 _no_generic_basering_coercion
= True
46 sage: from mjo.eja.eja_algebra import random_eja
50 By definition, Jordan multiplication commutes::
52 sage: set_random_seed()
53 sage: J = random_eja()
54 sage: x = J.random_element()
55 sage: y = J.random_element()
61 self
._natural
_basis
= natural_basis
63 # TODO: HACK for the charpoly.. needs redesign badly.
64 self
._basis
_normalizers
= None
67 category
= MagmaticAlgebras(field
).FiniteDimensional()
68 category
= category
.WithBasis().Unital()
70 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
72 range(len(mult_table
)),
75 self
.print_options(bracket
='')
77 # The multiplication table we're given is necessarily in terms
78 # of vectors, because we don't have an algebra yet for
79 # anything to be an element of. However, it's faster in the
80 # long run to have the multiplication table be in terms of
81 # algebra elements. We do this after calling the superclass
82 # constructor so that from_vector() knows what to do.
83 self
._multiplication
_table
= [ map(lambda x
: self
.from_vector(x
), ls
)
84 for ls
in mult_table
]
87 def _element_constructor_(self
, elt
):
89 Construct an element of this algebra from its natural
92 This gets called only after the parent element _call_ method
93 fails to find a coercion for the argument.
97 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
98 ....: RealCartesianProductEJA,
99 ....: RealSymmetricEJA)
103 The identity in `S^n` is converted to the identity in the EJA::
105 sage: J = RealSymmetricEJA(3)
106 sage: I = matrix.identity(QQ,3)
107 sage: J(I) == J.one()
110 This skew-symmetric matrix can't be represented in the EJA::
112 sage: J = RealSymmetricEJA(3)
113 sage: A = matrix(QQ,3, lambda i,j: i-j)
115 Traceback (most recent call last):
117 ArithmeticError: vector is not in free module
121 Ensure that we can convert any element of the two non-matrix
122 simple algebras (whose natural representations are their usual
123 vector representations) back and forth faithfully::
125 sage: set_random_seed()
126 sage: J = RealCartesianProductEJA(5)
127 sage: x = J.random_element()
128 sage: J(x.to_vector().column()) == x
130 sage: J = JordanSpinEJA(5)
131 sage: x = J.random_element()
132 sage: J(x.to_vector().column()) == x
137 # The superclass implementation of random_element()
138 # needs to be able to coerce "0" into the algebra.
141 natural_basis
= self
.natural_basis()
142 basis_space
= natural_basis
[0].matrix_space()
143 if elt
not in basis_space
:
144 raise ValueError("not a naturally-represented algebra element")
146 # Thanks for nothing! Matrix spaces aren't vector spaces in
147 # Sage, so we have to figure out its natural-basis coordinates
148 # ourselves. We use the basis space's ring instead of the
149 # element's ring because the basis space might be an algebraic
150 # closure whereas the base ring of the 3-by-3 identity matrix
151 # could be QQ instead of QQbar.
152 V
= VectorSpace(basis_space
.base_ring(), elt
.nrows()*elt
.ncols())
153 W
= V
.span_of_basis( _mat2vec(s
) for s
in natural_basis
)
154 coords
= W
.coordinate_vector(_mat2vec(elt
))
155 return self
.from_vector(coords
)
159 def _max_test_case_size():
161 Return an integer "size" that is an upper bound on the size of
162 this algebra when it is used in a random test
163 case. Unfortunately, the term "size" is quite vague -- when
164 dealing with `R^n` under either the Hadamard or Jordan spin
165 product, the "size" refers to the dimension `n`. When dealing
166 with a matrix algebra (real symmetric or complex/quaternion
167 Hermitian), it refers to the size of the matrix, which is
168 far less than the dimension of the underlying vector space.
170 We default to five in this class, which is safe in `R^n`. The
171 matrix algebra subclasses (or any class where the "size" is
172 interpreted to be far less than the dimension) should override
173 with a smaller number.
180 Return a string representation of ``self``.
184 sage: from mjo.eja.eja_algebra import JordanSpinEJA
188 Ensure that it says what we think it says::
190 sage: JordanSpinEJA(2, field=QQ)
191 Euclidean Jordan algebra of dimension 2 over Rational Field
192 sage: JordanSpinEJA(3, field=RDF)
193 Euclidean Jordan algebra of dimension 3 over Real Double Field
196 fmt
= "Euclidean Jordan algebra of dimension {} over {}"
197 return fmt
.format(self
.dimension(), self
.base_ring())
199 def product_on_basis(self
, i
, j
):
200 return self
._multiplication
_table
[i
][j
]
202 def _a_regular_element(self
):
204 Guess a regular element. Needed to compute the basis for our
205 characteristic polynomial coefficients.
209 sage: from mjo.eja.eja_algebra import random_eja
213 Ensure that this hacky method succeeds for every algebra that we
214 know how to construct::
216 sage: set_random_seed()
217 sage: J = random_eja()
218 sage: J._a_regular_element().is_regular()
223 z
= self
.sum( (i
+1)*gs
[i
] for i
in range(len(gs
)) )
224 if not z
.is_regular():
225 raise ValueError("don't know a regular element")
230 def _charpoly_basis_space(self
):
232 Return the vector space spanned by the basis used in our
233 characteristic polynomial coefficients. This is used not only to
234 compute those coefficients, but also any time we need to
235 evaluate the coefficients (like when we compute the trace or
238 z
= self
._a
_regular
_element
()
239 # Don't use the parent vector space directly here in case this
240 # happens to be a subalgebra. In that case, we would be e.g.
241 # two-dimensional but span_of_basis() would expect three
243 V
= VectorSpace(self
.base_ring(), self
.vector_space().dimension())
244 basis
= [ (z
**k
).to_vector() for k
in range(self
.rank()) ]
245 V1
= V
.span_of_basis( basis
)
246 b
= (V1
.basis() + V1
.complement().basis())
247 return V
.span_of_basis(b
)
252 def _charpoly_coeff(self
, i
):
254 Return the coefficient polynomial "a_{i}" of this algebra's
255 general characteristic polynomial.
257 Having this be a separate cached method lets us compute and
258 store the trace/determinant (a_{r-1} and a_{0} respectively)
259 separate from the entire characteristic polynomial.
261 if self
._basis
_normalizers
is not None:
262 # Must be a matrix class?
263 # WARNING/TODO: this whole mess is mis-designed.
264 n
= self
.natural_basis_space().nrows()
265 field
= self
.base_ring().base_ring() # yeeeeaaaahhh
266 J
= self
.__class
__(n
, field
, False)
267 (_
,x
,_
,_
) = J
._charpoly
_matrix
_system
()
268 p
= J
._charpoly
_coeff
(i
)
269 # p might be missing some vars, have to substitute "optionally"
270 pairs
= zip(x
.base_ring().gens(), self
._basis
_normalizers
)
271 substitutions
= { v: v*c for (v,c) in pairs }
272 return p
.subs(substitutions
)
274 (A_of_x
, x
, xr
, detA
) = self
._charpoly
_matrix
_system
()
275 R
= A_of_x
.base_ring()
277 # Guaranteed by theory
280 # Danger: the in-place modification is done for performance
281 # reasons (reconstructing a matrix with huge polynomial
282 # entries is slow), but I don't know how cached_method works,
283 # so it's highly possible that we're modifying some global
284 # list variable by reference, here. In other words, you
285 # probably shouldn't call this method twice on the same
286 # algebra, at the same time, in two threads
287 Ai_orig
= A_of_x
.column(i
)
288 A_of_x
.set_column(i
,xr
)
289 numerator
= A_of_x
.det()
290 A_of_x
.set_column(i
,Ai_orig
)
292 # We're relying on the theory here to ensure that each a_i is
293 # indeed back in R, and the added negative signs are to make
294 # the whole charpoly expression sum to zero.
295 return R(-numerator
/detA
)
299 def _charpoly_matrix_system(self
):
301 Compute the matrix whose entries A_ij are polynomials in
302 X1,...,XN, the vector ``x`` of variables X1,...,XN, the vector
303 corresponding to `x^r` and the determinent of the matrix A =
304 [A_ij]. In other words, all of the fixed (cachable) data needed
305 to compute the coefficients of the characteristic polynomial.
310 # Turn my vector space into a module so that "vectors" can
311 # have multivatiate polynomial entries.
312 names
= tuple('X' + str(i
) for i
in range(1,n
+1))
313 R
= PolynomialRing(self
.base_ring(), names
)
315 # Using change_ring() on the parent's vector space doesn't work
316 # here because, in a subalgebra, that vector space has a basis
317 # and change_ring() tries to bring the basis along with it. And
318 # that doesn't work unless the new ring is a PID, which it usually
322 # Now let x = (X1,X2,...,Xn) be the vector whose entries are
326 # And figure out the "left multiplication by x" matrix in
329 monomial_matrices
= [ self
.monomial(i
).operator().matrix()
330 for i
in range(n
) ] # don't recompute these!
332 ek
= self
.monomial(k
).to_vector()
334 sum( x
[i
]*(monomial_matrices
[i
]*ek
)
335 for i
in range(n
) ) )
336 Lx
= matrix
.column(R
, lmbx_cols
)
338 # Now we can compute powers of x "symbolically"
339 x_powers
= [self
.one().to_vector(), x
]
340 for d
in range(2, r
+1):
341 x_powers
.append( Lx
*(x_powers
[-1]) )
343 idmat
= matrix
.identity(R
, n
)
345 W
= self
._charpoly
_basis
_space
()
346 W
= W
.change_ring(R
.fraction_field())
348 # Starting with the standard coordinates x = (X1,X2,...,Xn)
349 # and then converting the entries to W-coordinates allows us
350 # to pass in the standard coordinates to the charpoly and get
351 # back the right answer. Specifically, with x = (X1,X2,...,Xn),
354 # W.coordinates(x^2) eval'd at (standard z-coords)
358 # W-coords of (standard coords of x^2 eval'd at std-coords of z)
360 # We want the middle equivalent thing in our matrix, but use
361 # the first equivalent thing instead so that we can pass in
362 # standard coordinates.
363 x_powers
= [ W
.coordinate_vector(xp
) for xp
in x_powers
]
364 l2
= [idmat
.column(k
-1) for k
in range(r
+1, n
+1)]
365 A_of_x
= matrix
.column(R
, n
, (x_powers
[:r
] + l2
))
366 return (A_of_x
, x
, x_powers
[r
], A_of_x
.det())
370 def characteristic_polynomial(self
):
372 Return a characteristic polynomial that works for all elements
375 The resulting polynomial has `n+1` variables, where `n` is the
376 dimension of this algebra. The first `n` variables correspond to
377 the coordinates of an algebra element: when evaluated at the
378 coordinates of an algebra element with respect to a certain
379 basis, the result is a univariate polynomial (in the one
380 remaining variable ``t``), namely the characteristic polynomial
385 sage: from mjo.eja.eja_algebra import JordanSpinEJA
389 The characteristic polynomial in the spin algebra is given in
390 Alizadeh, Example 11.11::
392 sage: J = JordanSpinEJA(3)
393 sage: p = J.characteristic_polynomial(); p
394 X1^2 - X2^2 - X3^2 + (-2*t)*X1 + t^2
395 sage: xvec = J.one().to_vector()
403 # The list of coefficient polynomials a_1, a_2, ..., a_n.
404 a
= [ self
._charpoly
_coeff
(i
) for i
in range(n
) ]
406 # We go to a bit of trouble here to reorder the
407 # indeterminates, so that it's easier to evaluate the
408 # characteristic polynomial at x's coordinates and get back
409 # something in terms of t, which is what we want.
411 S
= PolynomialRing(self
.base_ring(),'t')
413 S
= PolynomialRing(S
, R
.variable_names())
416 # Note: all entries past the rth should be zero. The
417 # coefficient of the highest power (x^r) is 1, but it doesn't
418 # appear in the solution vector which contains coefficients
419 # for the other powers (to make them sum to x^r).
421 a
[r
] = 1 # corresponds to x^r
423 # When the rank is equal to the dimension, trying to
424 # assign a[r] goes out-of-bounds.
425 a
.append(1) # corresponds to x^r
427 return sum( a
[k
]*(t
**k
) for k
in range(len(a
)) )
430 def inner_product(self
, x
, y
):
432 The inner product associated with this Euclidean Jordan algebra.
434 Defaults to the trace inner product, but can be overridden by
435 subclasses if they are sure that the necessary properties are
440 sage: from mjo.eja.eja_algebra import random_eja
444 The inner product must satisfy its axiom for this algebra to truly
445 be a Euclidean Jordan Algebra::
447 sage: set_random_seed()
448 sage: J = random_eja()
449 sage: x = J.random_element()
450 sage: y = J.random_element()
451 sage: z = J.random_element()
452 sage: (x*y).inner_product(z) == y.inner_product(x*z)
456 X
= x
.natural_representation()
457 Y
= y
.natural_representation()
458 return self
.natural_inner_product(X
,Y
)
461 def is_trivial(self
):
463 Return whether or not this algebra is trivial.
465 A trivial algebra contains only the zero element.
469 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
473 sage: J = ComplexHermitianEJA(3)
476 sage: A = J.zero().subalgebra_generated_by()
481 return self
.dimension() == 0
484 def multiplication_table(self
):
486 Return a visual representation of this algebra's multiplication
487 table (on basis elements).
491 sage: from mjo.eja.eja_algebra import JordanSpinEJA
495 sage: J = JordanSpinEJA(4)
496 sage: J.multiplication_table()
497 +----++----+----+----+----+
498 | * || e0 | e1 | e2 | e3 |
499 +====++====+====+====+====+
500 | e0 || e0 | e1 | e2 | e3 |
501 +----++----+----+----+----+
502 | e1 || e1 | e0 | 0 | 0 |
503 +----++----+----+----+----+
504 | e2 || e2 | 0 | e0 | 0 |
505 +----++----+----+----+----+
506 | e3 || e3 | 0 | 0 | e0 |
507 +----++----+----+----+----+
510 M
= list(self
._multiplication
_table
) # copy
511 for i
in range(len(M
)):
512 # M had better be "square"
513 M
[i
] = [self
.monomial(i
)] + M
[i
]
514 M
= [["*"] + list(self
.gens())] + M
515 return table(M
, header_row
=True, header_column
=True, frame
=True)
518 def natural_basis(self
):
520 Return a more-natural representation of this algebra's basis.
522 Every finite-dimensional Euclidean Jordan Algebra is a direct
523 sum of five simple algebras, four of which comprise Hermitian
524 matrices. This method returns the original "natural" basis
525 for our underlying vector space. (Typically, the natural basis
526 is used to construct the multiplication table in the first place.)
528 Note that this will always return a matrix. The standard basis
529 in `R^n` will be returned as `n`-by-`1` column matrices.
533 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
534 ....: RealSymmetricEJA)
538 sage: J = RealSymmetricEJA(2)
540 Finite family {0: e0, 1: e1, 2: e2}
541 sage: J.natural_basis()
543 [1 0] [ 0 1/2*sqrt2] [0 0]
544 [0 0], [1/2*sqrt2 0], [0 1]
549 sage: J = JordanSpinEJA(2)
551 Finite family {0: e0, 1: e1}
552 sage: J.natural_basis()
559 if self
._natural
_basis
is None:
560 M
= self
.natural_basis_space()
561 return tuple( M(b
.to_vector()) for b
in self
.basis() )
563 return self
._natural
_basis
566 def natural_basis_space(self
):
568 Return the matrix space in which this algebra's natural basis
571 if self
._natural
_basis
is None or len(self
._natural
_basis
) == 0:
572 return MatrixSpace(self
.base_ring(), self
.dimension(), 1)
574 return self
._natural
_basis
[0].matrix_space()
578 def natural_inner_product(X
,Y
):
580 Compute the inner product of two naturally-represented elements.
582 For example in the real symmetric matrix EJA, this will compute
583 the trace inner-product of two n-by-n symmetric matrices. The
584 default should work for the real cartesian product EJA, the
585 Jordan spin EJA, and the real symmetric matrices. The others
586 will have to be overridden.
588 return (X
.conjugate_transpose()*Y
).trace()
594 Return the unit element of this algebra.
598 sage: from mjo.eja.eja_algebra import (RealCartesianProductEJA,
603 sage: J = RealCartesianProductEJA(5)
605 e0 + e1 + e2 + e3 + e4
609 The identity element acts like the identity::
611 sage: set_random_seed()
612 sage: J = random_eja()
613 sage: x = J.random_element()
614 sage: J.one()*x == x and x*J.one() == x
617 The matrix of the unit element's operator is the identity::
619 sage: set_random_seed()
620 sage: J = random_eja()
621 sage: actual = J.one().operator().matrix()
622 sage: expected = matrix.identity(J.base_ring(), J.dimension())
623 sage: actual == expected
627 # We can brute-force compute the matrices of the operators
628 # that correspond to the basis elements of this algebra.
629 # If some linear combination of those basis elements is the
630 # algebra identity, then the same linear combination of
631 # their matrices has to be the identity matrix.
633 # Of course, matrices aren't vectors in sage, so we have to
634 # appeal to the "long vectors" isometry.
635 oper_vecs
= [ _mat2vec(g
.operator().matrix()) for g
in self
.gens() ]
637 # Now we use basis linear algebra to find the coefficients,
638 # of the matrices-as-vectors-linear-combination, which should
639 # work for the original algebra basis too.
640 A
= matrix
.column(self
.base_ring(), oper_vecs
)
642 # We used the isometry on the left-hand side already, but we
643 # still need to do it for the right-hand side. Recall that we
644 # wanted something that summed to the identity matrix.
645 b
= _mat2vec( matrix
.identity(self
.base_ring(), self
.dimension()) )
647 # Now if there's an identity element in the algebra, this should work.
648 coeffs
= A
.solve_right(b
)
649 return self
.linear_combination(zip(self
.gens(), coeffs
))
652 def random_element(self
):
653 # Temporary workaround for https://trac.sagemath.org/ticket/28327
654 if self
.is_trivial():
657 s
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
658 return s
.random_element()
663 Return the rank of this EJA.
667 The author knows of no algorithm to compute the rank of an EJA
668 where only the multiplication table is known. In lieu of one, we
669 require the rank to be specified when the algebra is created,
670 and simply pass along that number here.
674 sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
675 ....: RealSymmetricEJA,
676 ....: ComplexHermitianEJA,
677 ....: QuaternionHermitianEJA,
682 The rank of the Jordan spin algebra is always two::
684 sage: JordanSpinEJA(2).rank()
686 sage: JordanSpinEJA(3).rank()
688 sage: JordanSpinEJA(4).rank()
691 The rank of the `n`-by-`n` Hermitian real, complex, or
692 quaternion matrices is `n`::
694 sage: RealSymmetricEJA(2).rank()
696 sage: ComplexHermitianEJA(2).rank()
698 sage: QuaternionHermitianEJA(2).rank()
700 sage: RealSymmetricEJA(5).rank()
702 sage: ComplexHermitianEJA(5).rank()
704 sage: QuaternionHermitianEJA(5).rank()
709 Ensure that every EJA that we know how to construct has a
710 positive integer rank::
712 sage: set_random_seed()
713 sage: r = random_eja().rank()
714 sage: r in ZZ and r > 0
721 def vector_space(self
):
723 Return the vector space that underlies this algebra.
727 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
731 sage: J = RealSymmetricEJA(2)
732 sage: J.vector_space()
733 Vector space of dimension 3 over...
736 return self
.zero().to_vector().parent().ambient_vector_space()
739 Element
= FiniteDimensionalEuclideanJordanAlgebraElement
742 class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra
):
744 Return the Euclidean Jordan Algebra corresponding to the set
745 `R^n` under the Hadamard product.
747 Note: this is nothing more than the Cartesian product of ``n``
748 copies of the spin algebra. Once Cartesian product algebras
749 are implemented, this can go.
753 sage: from mjo.eja.eja_algebra import RealCartesianProductEJA
757 This multiplication table can be verified by hand::
759 sage: J = RealCartesianProductEJA(3)
760 sage: e0,e1,e2 = J.gens()
776 We can change the generator prefix::
778 sage: RealCartesianProductEJA(3, prefix='r').gens()
781 Our inner product satisfies the Jordan axiom::
783 sage: set_random_seed()
784 sage: n = ZZ.random_element(1,5)
785 sage: J = RealCartesianProductEJA(n)
786 sage: x = J.random_element()
787 sage: y = J.random_element()
788 sage: z = J.random_element()
789 sage: (x*y).inner_product(z) == y.inner_product(x*z)
793 def __init__(self
, n
, field
=QQ
, **kwargs
):
794 V
= VectorSpace(field
, n
)
795 mult_table
= [ [ V
.gen(i
)*(i
== j
) for j
in range(n
) ]
798 fdeja
= super(RealCartesianProductEJA
, self
)
799 return fdeja
.__init
__(field
, mult_table
, rank
=n
, **kwargs
)
801 def inner_product(self
, x
, y
):
803 Faster to reimplement than to use natural representations.
807 sage: from mjo.eja.eja_algebra import RealCartesianProductEJA
811 Ensure that this is the usual inner product for the algebras
814 sage: set_random_seed()
815 sage: n = ZZ.random_element(1,5)
816 sage: J = RealCartesianProductEJA(n)
817 sage: x = J.random_element()
818 sage: y = J.random_element()
819 sage: X = x.natural_representation()
820 sage: Y = y.natural_representation()
821 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
825 return x
.to_vector().inner_product(y
.to_vector())
830 Return a "random" finite-dimensional Euclidean Jordan Algebra.
834 For now, we choose a random natural number ``n`` (greater than zero)
835 and then give you back one of the following:
837 * The cartesian product of the rational numbers ``n`` times; this is
838 ``QQ^n`` with the Hadamard product.
840 * The Jordan spin algebra on ``QQ^n``.
842 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
845 * The ``n``-by-``n`` complex-rational Hermitian matrices embedded
846 in the space of ``2n``-by-``2n`` real symmetric matrices.
848 * The ``n``-by-``n`` quaternion-rational Hermitian matrices embedded
849 in the space of ``4n``-by-``4n`` real symmetric matrices.
851 Later this might be extended to return Cartesian products of the
856 sage: from mjo.eja.eja_algebra import random_eja
861 Euclidean Jordan algebra of dimension...
864 constructor
= choice([RealCartesianProductEJA
,
868 QuaternionHermitianEJA
])
869 n
= ZZ
.random_element(1, constructor
._max
_test
_case
_size
())
870 return constructor(n
, field
=QQ
)
874 def _real_symmetric_basis(n
, field
):
876 Return a basis for the space of real symmetric n-by-n matrices.
880 sage: from mjo.eja.eja_algebra import _real_symmetric_basis
884 sage: set_random_seed()
885 sage: n = ZZ.random_element(1,5)
886 sage: B = _real_symmetric_basis(n, QQ)
887 sage: all( M.is_symmetric() for M in B)
891 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
895 for j
in xrange(i
+1):
896 Eij
= matrix(field
, n
, lambda k
,l
: k
==i
and l
==j
)
900 Sij
= Eij
+ Eij
.transpose()
905 def _complex_hermitian_basis(n
, field
):
907 Returns a basis for the space of complex Hermitian n-by-n matrices.
909 Why do we embed these? Basically, because all of numerical linear
910 algebra assumes that you're working with vectors consisting of `n`
911 entries from a field and scalars from the same field. There's no way
912 to tell SageMath that (for example) the vectors contain complex
913 numbers, while the scalar field is real.
917 sage: from mjo.eja.eja_algebra import _complex_hermitian_basis
921 sage: set_random_seed()
922 sage: n = ZZ.random_element(1,5)
923 sage: field = QuadraticField(2, 'sqrt2')
924 sage: B = _complex_hermitian_basis(n, field)
925 sage: all( M.is_symmetric() for M in B)
929 R
= PolynomialRing(field
, 'z')
931 F
= NumberField(z
**2 + 1, 'I', embedding
=CLF(-1).sqrt())
934 # This is like the symmetric case, but we need to be careful:
936 # * We want conjugate-symmetry, not just symmetry.
937 # * The diagonal will (as a result) be real.
941 for j
in xrange(i
+1):
942 Eij
= matrix(F
, n
, lambda k
,l
: k
==i
and l
==j
)
944 Sij
= _embed_complex_matrix(Eij
)
947 # The second one has a minus because it's conjugated.
948 Sij_real
= _embed_complex_matrix(Eij
+ Eij
.transpose())
950 Sij_imag
= _embed_complex_matrix(I
*Eij
- I
*Eij
.transpose())
953 # Since we embedded these, we can drop back to the "field" that we
954 # started with instead of the complex extension "F".
955 return tuple( s
.change_ring(field
) for s
in S
)
959 def _quaternion_hermitian_basis(n
, field
):
961 Returns a basis for the space of quaternion Hermitian n-by-n matrices.
963 Why do we embed these? Basically, because all of numerical linear
964 algebra assumes that you're working with vectors consisting of `n`
965 entries from a field and scalars from the same field. There's no way
966 to tell SageMath that (for example) the vectors contain complex
967 numbers, while the scalar field is real.
971 sage: from mjo.eja.eja_algebra import _quaternion_hermitian_basis
975 sage: set_random_seed()
976 sage: n = ZZ.random_element(1,5)
977 sage: B = _quaternion_hermitian_basis(n, QQ)
978 sage: all( M.is_symmetric() for M in B )
982 Q
= QuaternionAlgebra(QQ
,-1,-1)
985 # This is like the symmetric case, but we need to be careful:
987 # * We want conjugate-symmetry, not just symmetry.
988 # * The diagonal will (as a result) be real.
992 for j
in xrange(i
+1):
993 Eij
= matrix(Q
, n
, lambda k
,l
: k
==i
and l
==j
)
995 Sij
= _embed_quaternion_matrix(Eij
)
998 # Beware, orthogonal but not normalized! The second,
999 # third, and fourth ones have a minus because they're
1001 Sij_real
= _embed_quaternion_matrix(Eij
+ Eij
.transpose())
1003 Sij_I
= _embed_quaternion_matrix(I
*Eij
- I
*Eij
.transpose())
1005 Sij_J
= _embed_quaternion_matrix(J
*Eij
- J
*Eij
.transpose())
1007 Sij_K
= _embed_quaternion_matrix(K
*Eij
- K
*Eij
.transpose())
1013 def _multiplication_table_from_matrix_basis(basis
):
1015 At least three of the five simple Euclidean Jordan algebras have the
1016 symmetric multiplication (A,B) |-> (AB + BA)/2, where the
1017 multiplication on the right is matrix multiplication. Given a basis
1018 for the underlying matrix space, this function returns a
1019 multiplication table (obtained by looping through the basis
1020 elements) for an algebra of those matrices.
1022 # In S^2, for example, we nominally have four coordinates even
1023 # though the space is of dimension three only. The vector space V
1024 # is supposed to hold the entire long vector, and the subspace W
1025 # of V will be spanned by the vectors that arise from symmetric
1026 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
1027 field
= basis
[0].base_ring()
1028 dimension
= basis
[0].nrows()
1030 V
= VectorSpace(field
, dimension
**2)
1031 W
= V
.span_of_basis( _mat2vec(s
) for s
in basis
)
1033 mult_table
= [[W
.zero() for j
in range(n
)] for i
in range(n
)]
1036 mat_entry
= (basis
[i
]*basis
[j
] + basis
[j
]*basis
[i
])/2
1037 mult_table
[i
][j
] = W
.coordinate_vector(_mat2vec(mat_entry
))
1042 def _embed_complex_matrix(M
):
1044 Embed the n-by-n complex matrix ``M`` into the space of real
1045 matrices of size 2n-by-2n via the map the sends each entry `z = a +
1046 bi` to the block matrix ``[[a,b],[-b,a]]``.
1050 sage: from mjo.eja.eja_algebra import _embed_complex_matrix
1054 sage: F = QuadraticField(-1, 'i')
1055 sage: x1 = F(4 - 2*i)
1056 sage: x2 = F(1 + 2*i)
1059 sage: M = matrix(F,2,[[x1,x2],[x3,x4]])
1060 sage: _embed_complex_matrix(M)
1069 Embedding is a homomorphism (isomorphism, in fact)::
1071 sage: set_random_seed()
1072 sage: n = ZZ.random_element(5)
1073 sage: F = QuadraticField(-1, 'i')
1074 sage: X = random_matrix(F, n)
1075 sage: Y = random_matrix(F, n)
1076 sage: actual = _embed_complex_matrix(X) * _embed_complex_matrix(Y)
1077 sage: expected = _embed_complex_matrix(X*Y)
1078 sage: actual == expected
1084 raise ValueError("the matrix 'M' must be square")
1085 field
= M
.base_ring()
1088 a
= z
.vector()[0] # real part, I guess
1089 b
= z
.vector()[1] # imag part, I guess
1090 blocks
.append(matrix(field
, 2, [[a
,b
],[-b
,a
]]))
1092 # We can drop the imaginaries here.
1093 return matrix
.block(field
.base_ring(), n
, blocks
)
1096 def _unembed_complex_matrix(M
):
1098 The inverse of _embed_complex_matrix().
1102 sage: from mjo.eja.eja_algebra import (_embed_complex_matrix,
1103 ....: _unembed_complex_matrix)
1107 sage: A = matrix(QQ,[ [ 1, 2, 3, 4],
1108 ....: [-2, 1, -4, 3],
1109 ....: [ 9, 10, 11, 12],
1110 ....: [-10, 9, -12, 11] ])
1111 sage: _unembed_complex_matrix(A)
1113 [ 10*i + 9 12*i + 11]
1117 Unembedding is the inverse of embedding::
1119 sage: set_random_seed()
1120 sage: F = QuadraticField(-1, 'i')
1121 sage: M = random_matrix(F, 3)
1122 sage: _unembed_complex_matrix(_embed_complex_matrix(M)) == M
1128 raise ValueError("the matrix 'M' must be square")
1129 if not n
.mod(2).is_zero():
1130 raise ValueError("the matrix 'M' must be a complex embedding")
1132 field
= M
.base_ring() # This should already have sqrt2
1133 R
= PolynomialRing(field
, 'z')
1135 F
= NumberField(z
**2 + 1,'i', embedding
=CLF(-1).sqrt())
1138 # Go top-left to bottom-right (reading order), converting every
1139 # 2-by-2 block we see to a single complex element.
1141 for k
in xrange(n
/2):
1142 for j
in xrange(n
/2):
1143 submat
= M
[2*k
:2*k
+2,2*j
:2*j
+2]
1144 if submat
[0,0] != submat
[1,1]:
1145 raise ValueError('bad on-diagonal submatrix')
1146 if submat
[0,1] != -submat
[1,0]:
1147 raise ValueError('bad off-diagonal submatrix')
1148 z
= submat
[0,0] + submat
[0,1]*i
1151 return matrix(F
, n
/2, elements
)
1154 def _embed_quaternion_matrix(M
):
1156 Embed the n-by-n quaternion matrix ``M`` into the space of real
1157 matrices of size 4n-by-4n by first sending each quaternion entry
1158 `z = a + bi + cj + dk` to the block-complex matrix
1159 ``[[a + bi, c+di],[-c + di, a-bi]]`, and then embedding those into
1164 sage: from mjo.eja.eja_algebra import _embed_quaternion_matrix
1168 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1169 sage: i,j,k = Q.gens()
1170 sage: x = 1 + 2*i + 3*j + 4*k
1171 sage: M = matrix(Q, 1, [[x]])
1172 sage: _embed_quaternion_matrix(M)
1178 Embedding is a homomorphism (isomorphism, in fact)::
1180 sage: set_random_seed()
1181 sage: n = ZZ.random_element(5)
1182 sage: Q = QuaternionAlgebra(QQ,-1,-1)
1183 sage: X = random_matrix(Q, n)
1184 sage: Y = random_matrix(Q, n)
1185 sage: actual = _embed_quaternion_matrix(X)*_embed_quaternion_matrix(Y)
1186 sage: expected = _embed_quaternion_matrix(X*Y)
1187 sage: actual == expected
1191 quaternions
= M
.base_ring()
1194 raise ValueError("the matrix 'M' must be square")
1196 F
= QuadraticField(-1, 'i')
1201 t
= z
.coefficient_tuple()
1206 cplx_matrix
= matrix(F
, 2, [[ a
+ b
*i
, c
+ d
*i
],
1207 [-c
+ d
*i
, a
- b
*i
]])
1208 blocks
.append(_embed_complex_matrix(cplx_matrix
))
1210 # We should have real entries by now, so use the realest field
1211 # we've got for the return value.
1212 return matrix
.block(quaternions
.base_ring(), n
, blocks
)
1215 def _unembed_quaternion_matrix(M
):
1217 The inverse of _embed_quaternion_matrix().
1221 sage: from mjo.eja.eja_algebra import (_embed_quaternion_matrix,
1222 ....: _unembed_quaternion_matrix)
1226 sage: M = matrix(QQ, [[ 1, 2, 3, 4],
1227 ....: [-2, 1, -4, 3],
1228 ....: [-3, 4, 1, -2],
1229 ....: [-4, -3, 2, 1]])
1230 sage: _unembed_quaternion_matrix(M)
1231 [1 + 2*i + 3*j + 4*k]
1235 Unembedding is the inverse of embedding::
1237 sage: set_random_seed()
1238 sage: Q = QuaternionAlgebra(QQ, -1, -1)
1239 sage: M = random_matrix(Q, 3)
1240 sage: _unembed_quaternion_matrix(_embed_quaternion_matrix(M)) == M
1246 raise ValueError("the matrix 'M' must be square")
1247 if not n
.mod(4).is_zero():
1248 raise ValueError("the matrix 'M' must be a complex embedding")
1250 # Use the base ring of the matrix to ensure that its entries can be
1251 # multiplied by elements of the quaternion algebra.
1252 field
= M
.base_ring()
1253 Q
= QuaternionAlgebra(field
,-1,-1)
1256 # Go top-left to bottom-right (reading order), converting every
1257 # 4-by-4 block we see to a 2-by-2 complex block, to a 1-by-1
1260 for l
in xrange(n
/4):
1261 for m
in xrange(n
/4):
1262 submat
= _unembed_complex_matrix(M
[4*l
:4*l
+4,4*m
:4*m
+4])
1263 if submat
[0,0] != submat
[1,1].conjugate():
1264 raise ValueError('bad on-diagonal submatrix')
1265 if submat
[0,1] != -submat
[1,0].conjugate():
1266 raise ValueError('bad off-diagonal submatrix')
1267 z
= submat
[0,0].vector()[0] # real part
1268 z
+= submat
[0,0].vector()[1]*i
# imag part
1269 z
+= submat
[0,1].vector()[0]*j
# real part
1270 z
+= submat
[0,1].vector()[1]*k
# imag part
1273 return matrix(Q
, n
/4, elements
)
1276 # The inner product used for the real symmetric simple EJA.
1277 # We keep it as a separate function because e.g. the complex
1278 # algebra uses the same inner product, except divided by 2.
1279 def _matrix_ip(X
,Y
):
1280 X_mat
= X
.natural_representation()
1281 Y_mat
= Y
.natural_representation()
1282 return (X_mat
*Y_mat
).trace()
1285 class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1287 The rank-n simple EJA consisting of real symmetric n-by-n
1288 matrices, the usual symmetric Jordan product, and the trace inner
1289 product. It has dimension `(n^2 + n)/2` over the reals.
1293 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
1297 sage: J = RealSymmetricEJA(2)
1298 sage: e0, e1, e2 = J.gens()
1308 The dimension of this algebra is `(n^2 + n) / 2`::
1310 sage: set_random_seed()
1311 sage: n = ZZ.random_element(1,5)
1312 sage: J = RealSymmetricEJA(n)
1313 sage: J.dimension() == (n^2 + n)/2
1316 The Jordan multiplication is what we think it is::
1318 sage: set_random_seed()
1319 sage: n = ZZ.random_element(1,5)
1320 sage: J = RealSymmetricEJA(n)
1321 sage: x = J.random_element()
1322 sage: y = J.random_element()
1323 sage: actual = (x*y).natural_representation()
1324 sage: X = x.natural_representation()
1325 sage: Y = y.natural_representation()
1326 sage: expected = (X*Y + Y*X)/2
1327 sage: actual == expected
1329 sage: J(expected) == x*y
1332 We can change the generator prefix::
1334 sage: RealSymmetricEJA(3, prefix='q').gens()
1335 (q0, q1, q2, q3, q4, q5)
1337 Our inner product satisfies the Jordan axiom::
1339 sage: set_random_seed()
1340 sage: n = ZZ.random_element(1,5)
1341 sage: J = RealSymmetricEJA(n)
1342 sage: x = J.random_element()
1343 sage: y = J.random_element()
1344 sage: z = J.random_element()
1345 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1348 Our natural basis is normalized with respect to the natural inner
1349 product unless we specify otherwise::
1351 sage: set_random_seed()
1352 sage: n = ZZ.random_element(1,5)
1353 sage: J = RealSymmetricEJA(n)
1354 sage: all( b.norm() == 1 for b in J.gens() )
1357 Since our natural basis is normalized with respect to the natural
1358 inner product, and since we know that this algebra is an EJA, any
1359 left-multiplication operator's matrix will be symmetric because
1360 natural->EJA basis representation is an isometry and within the EJA
1361 the operator is self-adjoint by the Jordan axiom::
1363 sage: set_random_seed()
1364 sage: n = ZZ.random_element(1,5)
1365 sage: x = RealSymmetricEJA(n).random_element()
1366 sage: x.operator().matrix().is_symmetric()
1370 def __init__(self
, n
, field
=QQ
, normalize_basis
=True, **kwargs
):
1371 S
= _real_symmetric_basis(n
, field
)
1373 if n
> 1 and normalize_basis
:
1374 # We'll need sqrt(2) to normalize the basis, and this
1375 # winds up in the multiplication table, so the whole
1376 # algebra needs to be over the field extension.
1377 R
= PolynomialRing(field
, 'z')
1380 if p
.is_irreducible():
1381 field
= NumberField(p
, 'sqrt2', embedding
=RLF(2).sqrt())
1382 S
= [ s
.change_ring(field
) for s
in S
]
1383 self
._basis
_normalizers
= tuple(
1384 ~
(self
.natural_inner_product(s
,s
).sqrt()) for s
in S
)
1385 S
= tuple( s
*c
for (s
,c
) in zip(S
,self
._basis
_normalizers
) )
1387 Qs
= _multiplication_table_from_matrix_basis(S
)
1389 fdeja
= super(RealSymmetricEJA
, self
)
1390 return fdeja
.__init
__(field
,
1397 def _max_test_case_size():
1401 class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1403 The rank-n simple EJA consisting of complex Hermitian n-by-n
1404 matrices over the real numbers, the usual symmetric Jordan product,
1405 and the real-part-of-trace inner product. It has dimension `n^2` over
1410 sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
1414 The dimension of this algebra is `n^2`::
1416 sage: set_random_seed()
1417 sage: n = ZZ.random_element(1,5)
1418 sage: J = ComplexHermitianEJA(n)
1419 sage: J.dimension() == n^2
1422 The Jordan multiplication is what we think it is::
1424 sage: set_random_seed()
1425 sage: n = ZZ.random_element(1,5)
1426 sage: J = ComplexHermitianEJA(n)
1427 sage: x = J.random_element()
1428 sage: y = J.random_element()
1429 sage: actual = (x*y).natural_representation()
1430 sage: X = x.natural_representation()
1431 sage: Y = y.natural_representation()
1432 sage: expected = (X*Y + Y*X)/2
1433 sage: actual == expected
1435 sage: J(expected) == x*y
1438 We can change the generator prefix::
1440 sage: ComplexHermitianEJA(2, prefix='z').gens()
1443 Our inner product satisfies the Jordan axiom::
1445 sage: set_random_seed()
1446 sage: n = ZZ.random_element(1,5)
1447 sage: J = ComplexHermitianEJA(n)
1448 sage: x = J.random_element()
1449 sage: y = J.random_element()
1450 sage: z = J.random_element()
1451 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1454 Our natural basis is normalized with respect to the natural inner
1455 product unless we specify otherwise::
1457 sage: set_random_seed()
1458 sage: n = ZZ.random_element(1,4)
1459 sage: J = ComplexHermitianEJA(n)
1460 sage: all( b.norm() == 1 for b in J.gens() )
1463 Since our natural basis is normalized with respect to the natural
1464 inner product, and since we know that this algebra is an EJA, any
1465 left-multiplication operator's matrix will be symmetric because
1466 natural->EJA basis representation is an isometry and within the EJA
1467 the operator is self-adjoint by the Jordan axiom::
1469 sage: set_random_seed()
1470 sage: n = ZZ.random_element(1,5)
1471 sage: x = ComplexHermitianEJA(n).random_element()
1472 sage: x.operator().matrix().is_symmetric()
1476 def __init__(self
, n
, field
=QQ
, normalize_basis
=True, **kwargs
):
1477 S
= _complex_hermitian_basis(n
, field
)
1479 if n
> 1 and normalize_basis
:
1480 # We'll need sqrt(2) to normalize the basis, and this
1481 # winds up in the multiplication table, so the whole
1482 # algebra needs to be over the field extension.
1483 R
= PolynomialRing(field
, 'z')
1486 if p
.is_irreducible():
1487 field
= NumberField(p
, 'sqrt2', embedding
=RLF(2).sqrt())
1488 S
= [ s
.change_ring(field
) for s
in S
]
1489 self
._basis
_normalizers
= tuple(
1490 ~
(self
.natural_inner_product(s
,s
).sqrt()) for s
in S
)
1491 S
= tuple( s
*c
for (s
,c
) in zip(S
,self
._basis
_normalizers
) )
1493 Qs
= _multiplication_table_from_matrix_basis(S
)
1495 fdeja
= super(ComplexHermitianEJA
, self
)
1496 return fdeja
.__init
__(field
,
1504 def _max_test_case_size():
1508 def natural_inner_product(X
,Y
):
1509 Xu
= _unembed_complex_matrix(X
)
1510 Yu
= _unembed_complex_matrix(Y
)
1511 # The trace need not be real; consider Xu = (i*I) and Yu = I.
1512 return ((Xu
*Yu
).trace()).vector()[0] # real part, I guess
1516 class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1518 The rank-n simple EJA consisting of self-adjoint n-by-n quaternion
1519 matrices, the usual symmetric Jordan product, and the
1520 real-part-of-trace inner product. It has dimension `2n^2 - n` over
1525 sage: from mjo.eja.eja_algebra import QuaternionHermitianEJA
1529 The dimension of this algebra is `2*n^2 - n`::
1531 sage: set_random_seed()
1532 sage: n = ZZ.random_element(1,4)
1533 sage: J = QuaternionHermitianEJA(n)
1534 sage: J.dimension() == 2*(n^2) - n
1537 The Jordan multiplication is what we think it is::
1539 sage: set_random_seed()
1540 sage: n = ZZ.random_element(1,4)
1541 sage: J = QuaternionHermitianEJA(n)
1542 sage: x = J.random_element()
1543 sage: y = J.random_element()
1544 sage: actual = (x*y).natural_representation()
1545 sage: X = x.natural_representation()
1546 sage: Y = y.natural_representation()
1547 sage: expected = (X*Y + Y*X)/2
1548 sage: actual == expected
1550 sage: J(expected) == x*y
1553 We can change the generator prefix::
1555 sage: QuaternionHermitianEJA(2, prefix='a').gens()
1556 (a0, a1, a2, a3, a4, a5)
1558 Our inner product satisfies the Jordan axiom::
1560 sage: set_random_seed()
1561 sage: n = ZZ.random_element(1,4)
1562 sage: J = QuaternionHermitianEJA(n)
1563 sage: x = J.random_element()
1564 sage: y = J.random_element()
1565 sage: z = J.random_element()
1566 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1569 Our natural basis is normalized with respect to the natural inner
1570 product unless we specify otherwise::
1572 sage: set_random_seed()
1573 sage: n = ZZ.random_element(1,4)
1574 sage: J = QuaternionHermitianEJA(n)
1575 sage: all( b.norm() == 1 for b in J.gens() )
1578 Since our natural basis is normalized with respect to the natural
1579 inner product, and since we know that this algebra is an EJA, any
1580 left-multiplication operator's matrix will be symmetric because
1581 natural->EJA basis representation is an isometry and within the EJA
1582 the operator is self-adjoint by the Jordan axiom::
1584 sage: set_random_seed()
1585 sage: n = ZZ.random_element(1,5)
1586 sage: x = QuaternionHermitianEJA(n).random_element()
1587 sage: x.operator().matrix().is_symmetric()
1591 def __init__(self
, n
, field
=QQ
, normalize_basis
=True, **kwargs
):
1592 S
= _quaternion_hermitian_basis(n
, field
)
1594 if n
> 1 and normalize_basis
:
1595 # We'll need sqrt(2) to normalize the basis, and this
1596 # winds up in the multiplication table, so the whole
1597 # algebra needs to be over the field extension.
1598 R
= PolynomialRing(field
, 'z')
1601 if p
.is_irreducible():
1602 field
= NumberField(p
, 'sqrt2', embedding
=RLF(2).sqrt())
1603 S
= [ s
.change_ring(field
) for s
in S
]
1604 self
._basis
_normalizers
= tuple(
1605 ~
(self
.natural_inner_product(s
,s
).sqrt()) for s
in S
)
1606 S
= tuple( s
*c
for (s
,c
) in zip(S
,self
._basis
_normalizers
) )
1608 Qs
= _multiplication_table_from_matrix_basis(S
)
1610 fdeja
= super(QuaternionHermitianEJA
, self
)
1611 return fdeja
.__init
__(field
,
1618 def _max_test_case_size():
1622 def natural_inner_product(X
,Y
):
1623 Xu
= _unembed_quaternion_matrix(X
)
1624 Yu
= _unembed_quaternion_matrix(Y
)
1625 # The trace need not be real; consider Xu = (i*I) and Yu = I.
1626 # The result will be a quaternion algebra element, which doesn't
1627 # have a "vector" method, but does have coefficient_tuple() method
1628 # that returns the coefficients of 1, i, j, and k -- in that order.
1629 return ((Xu
*Yu
).trace()).coefficient_tuple()[0]
1633 class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra
):
1635 The rank-2 simple EJA consisting of real vectors ``x=(x0, x_bar)``
1636 with the usual inner product and jordan product ``x*y =
1637 (<x_bar,y_bar>, x0*y_bar + y0*x_bar)``. It has dimension `n` over
1642 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1646 This multiplication table can be verified by hand::
1648 sage: J = JordanSpinEJA(4)
1649 sage: e0,e1,e2,e3 = J.gens()
1665 We can change the generator prefix::
1667 sage: JordanSpinEJA(2, prefix='B').gens()
1670 Our inner product satisfies the Jordan axiom::
1672 sage: set_random_seed()
1673 sage: n = ZZ.random_element(1,5)
1674 sage: J = JordanSpinEJA(n)
1675 sage: x = J.random_element()
1676 sage: y = J.random_element()
1677 sage: z = J.random_element()
1678 sage: (x*y).inner_product(z) == y.inner_product(x*z)
1682 def __init__(self
, n
, field
=QQ
, **kwargs
):
1683 V
= VectorSpace(field
, n
)
1684 mult_table
= [[V
.zero() for j
in range(n
)] for i
in range(n
)]
1694 z0
= x
.inner_product(y
)
1695 zbar
= y0
*xbar
+ x0
*ybar
1696 z
= V([z0
] + zbar
.list())
1697 mult_table
[i
][j
] = z
1699 # The rank of the spin algebra is two, unless we're in a
1700 # one-dimensional ambient space (because the rank is bounded by
1701 # the ambient dimension).
1702 fdeja
= super(JordanSpinEJA
, self
)
1703 return fdeja
.__init
__(field
, mult_table
, rank
=min(n
,2), **kwargs
)
1705 def inner_product(self
, x
, y
):
1707 Faster to reimplement than to use natural representations.
1711 sage: from mjo.eja.eja_algebra import JordanSpinEJA
1715 Ensure that this is the usual inner product for the algebras
1718 sage: set_random_seed()
1719 sage: n = ZZ.random_element(1,5)
1720 sage: J = JordanSpinEJA(n)
1721 sage: x = J.random_element()
1722 sage: y = J.random_element()
1723 sage: X = x.natural_representation()
1724 sage: Y = y.natural_representation()
1725 sage: x.inner_product(y) == J.natural_inner_product(X,Y)
1729 return x
.to_vector().inner_product(y
.to_vector())