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
.categories
.magmatic_algebras
import MagmaticAlgebras
9 from sage
.structure
.element
import is_Matrix
10 from sage
.structure
.category_object
import normalize_names
12 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra
import FiniteDimensionalAlgebra
13 from sage
.algebras
.finite_dimensional_algebras
.finite_dimensional_algebra_element
import FiniteDimensionalAlgebraElement
15 class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra
):
17 def __classcall_private__(cls
,
21 assume_associative
=False,
25 mult_table
= [b
.base_extend(field
) for b
in mult_table
]
28 if not (is_Matrix(b
) and b
.dimensions() == (n
, n
)):
29 raise ValueError("input is not a multiplication table")
30 mult_table
= tuple(mult_table
)
32 cat
= MagmaticAlgebras(field
).FiniteDimensional().WithBasis()
33 cat
.or_subcategory(category
)
34 if assume_associative
:
35 cat
= cat
.Associative()
37 names
= normalize_names(n
, names
)
39 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, cls
)
40 return fda
.__classcall
__(cls
,
43 assume_associative
=assume_associative
,
49 def __init__(self
, field
,
52 assume_associative
=False,
56 fda
= super(FiniteDimensionalEuclideanJordanAlgebra
, self
)
65 Return a string representation of ``self``.
67 fmt
= "Euclidean Jordan algebra of degree {} over {}"
68 return fmt
.format(self
.degree(), self
.base_ring())
72 Return the rank of this EJA.
74 if self
._rank
is None:
75 raise ValueError("no rank specified at genesis")
80 class Element(FiniteDimensionalAlgebraElement
):
82 An element of a Euclidean Jordan algebra.
87 Return ``self`` raised to the power ``n``.
89 Jordan algebras are always power-associative; see for
90 example Faraut and Koranyi, Proposition II.1.2 (ii).
94 We have to override this because our superclass uses row vectors
95 instead of column vectors! We, on the other hand, assume column
100 sage: set_random_seed()
102 sage: x = J.random_element()
103 sage: x.matrix()*x.vector() == (x**2).vector()
113 return A
.element_class(A
, (self
.matrix()**(n
-1))*self
.vector())
116 def characteristic_polynomial(self
):
118 Return my characteristic polynomial (if I'm a regular
121 Eventually this should be implemented in terms of the parent
122 algebra's characteristic polynomial that works for ALL
125 if self
.is_regular():
126 return self
.minimal_polynomial()
128 raise NotImplementedError('irregular element')
133 Return my determinant, the product of my eigenvalues.
138 sage: e0,e1 = J.gens()
143 sage: e0,e1,e2 = J.gens()
144 sage: x = e0 + e1 + e2
149 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
152 return cs
[0] * (-1)**r
154 raise ValueError('charpoly had no coefficients')
157 def is_nilpotent(self
):
159 Return whether or not some power of this element is zero.
161 The superclass method won't work unless we're in an
162 associative algebra, and we aren't. However, we generate
163 an assocoative subalgebra and we're nilpotent there if and
164 only if we're nilpotent here (probably).
168 The identity element is never nilpotent::
170 sage: set_random_seed()
171 sage: n = ZZ.random_element(2,10).abs()
173 sage: J.one().is_nilpotent()
176 sage: J.one().is_nilpotent()
179 The additive identity is always nilpotent::
181 sage: set_random_seed()
182 sage: n = ZZ.random_element(2,10).abs()
184 sage: J.zero().is_nilpotent()
187 sage: J.zero().is_nilpotent()
191 # The element we're going to call "is_nilpotent()" on.
192 # Either myself, interpreted as an element of a finite-
193 # dimensional algebra, or an element of an associative
197 if self
.parent().is_associative():
198 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
200 V
= self
.span_of_powers()
201 assoc_subalg
= self
.subalgebra_generated_by()
202 # Mis-design warning: the basis used for span_of_powers()
203 # and subalgebra_generated_by() must be the same, and in
205 elt
= assoc_subalg(V
.coordinates(self
.vector()))
207 # Recursive call, but should work since elt lives in an
208 # associative algebra.
209 return elt
.is_nilpotent()
212 def is_regular(self
):
214 Return whether or not this is a regular element.
218 The identity element always has degree one, but any element
219 linearly-independent from it is regular::
222 sage: J.one().is_regular()
224 sage: e0, e1, e2, e3, e4 = J.gens() # e0 is the identity
225 sage: for x in J.gens():
226 ....: (J.one() + x).is_regular()
234 return self
.degree() == self
.parent().rank()
239 Compute the degree of this element the straightforward way
240 according to the definition; by appending powers to a list
241 and figuring out its dimension (that is, whether or not
242 they're linearly dependent).
247 sage: J.one().degree()
249 sage: e0,e1,e2,e3 = J.gens()
250 sage: (e0 - e1).degree()
253 In the spin factor algebra (of rank two), all elements that
254 aren't multiples of the identity are regular::
256 sage: set_random_seed()
257 sage: n = ZZ.random_element(1,10).abs()
259 sage: x = J.random_element()
260 sage: x == x.coefficient(0)*J.one() or x.degree() == 2
264 return self
.span_of_powers().dimension()
269 Return the matrix that represents left- (or right-)
270 multiplication by this element in the parent algebra.
272 We have to override this because the superclass method
273 returns a matrix that acts on row vectors (that is, on
276 fda_elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
277 return fda_elt
.matrix().transpose()
280 def minimal_polynomial(self
):
284 sage: set_random_seed()
285 sage: n = ZZ.random_element(1,10).abs()
287 sage: x = J.random_element()
288 sage: x.degree() == x.minimal_polynomial().degree()
293 sage: set_random_seed()
294 sage: n = ZZ.random_element(1,10).abs()
296 sage: x = J.random_element()
297 sage: x.degree() == x.minimal_polynomial().degree()
300 The minimal polynomial and the characteristic polynomial coincide
301 and are known (see Alizadeh, Example 11.11) for all elements of
302 the spin factor algebra that aren't scalar multiples of the
305 sage: set_random_seed()
306 sage: n = ZZ.random_element(2,10).abs()
308 sage: y = J.random_element()
309 sage: while y == y.coefficient(0)*J.one():
310 ....: y = J.random_element()
311 sage: y0 = y.vector()[0]
312 sage: y_bar = y.vector()[1:]
313 sage: actual = y.minimal_polynomial()
314 sage: x = SR.symbol('x', domain='real')
315 sage: expected = x^2 - 2*y0*x + (y0^2 - norm(y_bar)^2)
316 sage: bool(actual == expected)
320 # The element we're going to call "minimal_polynomial()" on.
321 # Either myself, interpreted as an element of a finite-
322 # dimensional algebra, or an element of an associative
326 if self
.parent().is_associative():
327 elt
= FiniteDimensionalAlgebraElement(self
.parent(), self
)
329 V
= self
.span_of_powers()
330 assoc_subalg
= self
.subalgebra_generated_by()
331 # Mis-design warning: the basis used for span_of_powers()
332 # and subalgebra_generated_by() must be the same, and in
334 elt
= assoc_subalg(V
.coordinates(self
.vector()))
336 # Recursive call, but should work since elt lives in an
337 # associative algebra.
338 return elt
.minimal_polynomial()
341 def span_of_powers(self
):
343 Return the vector space spanned by successive powers of
346 # The dimension of the subalgebra can't be greater than
347 # the big algebra, so just put everything into a list
348 # and let span() get rid of the excess.
349 V
= self
.vector().parent()
350 return V
.span( (self
**d
).vector() for d
in xrange(V
.dimension()) )
353 def subalgebra_generated_by(self
):
355 Return the associative subalgebra of the parent EJA generated
360 sage: set_random_seed()
361 sage: n = ZZ.random_element(1,10).abs()
363 sage: x = J.random_element()
364 sage: x.subalgebra_generated_by().is_associative()
367 sage: x = J.random_element()
368 sage: x.subalgebra_generated_by().is_associative()
371 Squaring in the subalgebra should be the same thing as
372 squaring in the superalgebra::
374 sage: set_random_seed()
376 sage: x = J.random_element()
377 sage: u = x.subalgebra_generated_by().random_element()
378 sage: u.matrix()*u.vector() == (u**2).vector()
382 # First get the subspace spanned by the powers of myself...
383 V
= self
.span_of_powers()
386 # Now figure out the entries of the right-multiplication
387 # matrix for the successive basis elements b0, b1,... of
390 for b_right
in V
.basis():
391 eja_b_right
= self
.parent()(b_right
)
393 # The first row of the right-multiplication matrix by
394 # b1 is what we get if we apply that matrix to b1. The
395 # second row of the right multiplication matrix by b1
396 # is what we get when we apply that matrix to b2...
398 # IMPORTANT: this assumes that all vectors are COLUMN
399 # vectors, unlike our superclass (which uses row vectors).
400 for b_left
in V
.basis():
401 eja_b_left
= self
.parent()(b_left
)
402 # Multiply in the original EJA, but then get the
403 # coordinates from the subalgebra in terms of its
405 this_row
= V
.coordinates((eja_b_left
*eja_b_right
).vector())
406 b_right_rows
.append(this_row
)
407 b_right_matrix
= matrix(F
, b_right_rows
)
408 mats
.append(b_right_matrix
)
410 # It's an algebra of polynomials in one element, and EJAs
411 # are power-associative.
413 # TODO: choose generator names intelligently.
414 return FiniteDimensionalEuclideanJordanAlgebra(F
, mats
, assume_associative
=True, names
='f')
417 def subalgebra_idempotent(self
):
419 Find an idempotent in the associative subalgebra I generate
420 using Proposition 2.3.5 in Baes.
424 sage: set_random_seed()
426 sage: c = J.random_element().subalgebra_idempotent()
430 sage: c = J.random_element().subalgebra_idempotent()
435 if self
.is_nilpotent():
436 raise ValueError("this only works with non-nilpotent elements!")
438 V
= self
.span_of_powers()
439 J
= self
.subalgebra_generated_by()
440 # Mis-design warning: the basis used for span_of_powers()
441 # and subalgebra_generated_by() must be the same, and in
443 u
= J(V
.coordinates(self
.vector()))
445 # The image of the matrix of left-u^m-multiplication
446 # will be minimal for some natural number s...
448 minimal_dim
= V
.dimension()
449 for i
in xrange(1, V
.dimension()):
450 this_dim
= (u
**i
).matrix().image().dimension()
451 if this_dim
< minimal_dim
:
452 minimal_dim
= this_dim
455 # Now minimal_matrix should correspond to the smallest
456 # non-zero subspace in Baes's (or really, Koecher's)
459 # However, we need to restrict the matrix to work on the
460 # subspace... or do we? Can't we just solve, knowing that
461 # A(c) = u^(s+1) should have a solution in the big space,
464 # Beware, solve_right() means that we're using COLUMN vectors.
465 # Our FiniteDimensionalAlgebraElement superclass uses rows.
468 c_coordinates
= A
.solve_right(u_next
.vector())
470 # Now c_coordinates is the idempotent we want, but it's in
471 # the coordinate system of the subalgebra.
473 # We need the basis for J, but as elements of the parent algebra.
475 basis
= [self
.parent(v
) for v
in V
.basis()]
476 return self
.parent().linear_combination(zip(c_coordinates
, basis
))
481 Return my trace, the sum of my eigenvalues.
486 sage: e0,e1,e2 = J.gens()
487 sage: x = e0 + e1 + e2
492 cs
= self
.characteristic_polynomial().coefficients(sparse
=False)
496 raise ValueError('charpoly had fewer than 2 coefficients')
499 def eja_rn(dimension
, field
=QQ
):
501 Return the Euclidean Jordan Algebra corresponding to the set
502 `R^n` under the Hadamard product.
506 This multiplication table can be verified by hand::
509 sage: e0,e1,e2 = J.gens()
524 # The FiniteDimensionalAlgebra constructor takes a list of
525 # matrices, the ith representing right multiplication by the ith
526 # basis element in the vector space. So if e_1 = (1,0,0), then
527 # right (Hadamard) multiplication of x by e_1 picks out the first
528 # component of x; and likewise for the ith basis element e_i.
529 Qs
= [ matrix(field
, dimension
, dimension
, lambda k
,j
: 1*(k
== j
== i
))
530 for i
in xrange(dimension
) ]
532 return FiniteDimensionalEuclideanJordanAlgebra(field
,Qs
,rank
=dimension
)
535 def eja_ln(dimension
, field
=QQ
):
537 Return the Jordan algebra corresponding to the Lorentz "ice cream"
538 cone of the given ``dimension``.
542 This multiplication table can be verified by hand::
545 sage: e0,e1,e2,e3 = J.gens()
561 In one dimension, this is the reals under multiplication::
570 id_matrix
= identity_matrix(field
,dimension
)
571 for i
in xrange(dimension
):
572 ei
= id_matrix
.column(i
)
573 Qi
= zero_matrix(field
,dimension
)
576 Qi
+= diagonal_matrix(dimension
, [ei
[0]]*dimension
)
577 # The addition of the diagonal matrix adds an extra ei[0] in the
578 # upper-left corner of the matrix.
579 Qi
[0,0] = Qi
[0,0] * ~
field(2)
582 # The rank of the spin factor algebra is two, UNLESS we're in a
583 # one-dimensional ambient space (the rank is bounded by the
584 # ambient dimension).
585 rank
= min(dimension
,2)
586 return FiniteDimensionalEuclideanJordanAlgebra(field
,Qs
,rank
=rank
)
589 def eja_sn(dimension
, field
=QQ
):
591 Return the simple Jordan algebra of ``dimension``-by-``dimension``
592 symmetric matrices over ``field``.
597 sage: e0, e1, e2 = J.gens()
608 # In S^2, for example, we nominally have four coordinates even
609 # though the space is of dimension three only. The vector space V
610 # is supposed to hold the entire long vector, and the subspace W
611 # of V will be spanned by the vectors that arise from symmetric
612 # matrices. Thus for S^2, dim(V) == 4 and dim(W) == 3.
613 V
= VectorSpace(field
, dimension
**2)
615 # The basis of symmetric matrices, as matrices, in their R^(n-by-n)
619 for i
in xrange(dimension
):
620 for j
in xrange(i
+1):
621 Eij
= matrix(field
, dimension
, lambda k
,l
: k
==i
and l
==j
)
625 Sij
= Eij
+ Eij
.transpose()
629 return vector(field
, m
.list())
632 return matrix(field
, dimension
, v
.list())
634 W
= V
.span( mat2vec(s
) for s
in S
)
636 # Taking the span above reorders our basis (thanks, jerk!) so we
637 # need to put our "matrix basis" in the same order as the
638 # (reordered) vector basis.
639 S
= [ vec2mat(b
) for b
in W
.basis() ]
642 # Brute force the multiplication-by-s matrix by looping
643 # through all elements of the basis and doing the computation
644 # to find out what the corresponding row should be. BEWARE:
645 # these multiplication tables won't be symmetric! It therefore
646 # becomes REALLY IMPORTANT that the underlying algebra
647 # constructor uses ROW vectors and not COLUMN vectors. That's
648 # why we're computing rows here and not columns.
651 this_row
= mat2vec((s
*t
+ t
*s
)/2)
652 Q_rows
.append(W
.coordinates(this_row
))
653 Q
= matrix(field
,Q_rows
)
656 return FiniteDimensionalEuclideanJordanAlgebra(field
,Qs
,rank
=dimension
)
661 Return a "random" finite-dimensional Euclidean Jordan Algebra.
665 For now, we choose a random natural number ``n`` (greater than zero)
666 and then give you back one of the following:
668 * The cartesian product of the rational numbers ``n`` times; this is
669 ``QQ^n`` with the Hadamard product.
671 * The Jordan spin algebra on ``QQ^n``.
673 * The ``n``-by-``n`` rational symmetric matrices with the symmetric
676 Later this might be extended to return Cartesian products of the
682 Euclidean Jordan algebra of degree...
685 n
= ZZ
.random_element(1,10).abs()
686 constructor
= choice([eja_rn
, eja_ln
, eja_sn
])
687 return constructor(dimension
=n
, field
=QQ
)