]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/euclidean_jordan_algebra.py
eja: add eja_ln() for the rank-two algebra.
[sage.d.git] / mjo / eja / euclidean_jordan_algebra.py
1 """
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.
6 """
7
8 from sage.all import *
9
10 def eja_rn(dimension, field=QQ):
11 """
12 Return the Euclidean Jordan Algebra corresponding to the set
13 `R^n` under the Hadamard product.
14
15 EXAMPLES:
16
17 This multiplication table can be verified by hand::
18
19 sage: J = eja_rn(3)
20 sage: e0,e1,e2 = J.gens()
21 sage: e0*e0
22 e0
23 sage: e0*e1
24 0
25 sage: e0*e2
26 0
27 sage: e1*e1
28 e1
29 sage: e1*e2
30 0
31 sage: e2*e2
32 e2
33
34 """
35 # The FiniteDimensionalAlgebra constructor takes a list of
36 # matrices, the ith representing right multiplication by the ith
37 # basis element in the vector space. So if e_1 = (1,0,0), then
38 # right (Hadamard) multiplication of x by e_1 picks out the first
39 # component of x; and likewise for the ith basis element e_i.
40 Qs = [ matrix(field, dimension, dimension, lambda k,j: 1*(k == j == i))
41 for i in xrange(dimension) ]
42 A = FiniteDimensionalAlgebra(QQ,Qs,assume_associative=True)
43 return JordanAlgebra(A)
44
45
46 def eja_ln(dimension, field=QQ):
47 """
48 Return the Jordan algebra corresponding to the Lorenzt "ice cream"
49 cone of the given ``dimension``.
50
51 EXAMPLES:
52
53 This multiplication table can be verified by hand::
54
55 sage: J = eja_ln(4)
56 sage: e0,e1,e2,e3 = J.gens()
57 sage: e0*e0
58 e0
59 sage: e0*e1
60 e1
61 sage: e0*e2
62 e2
63 sage: e0*e3
64 e3
65 sage: e1*e2
66 0
67 sage: e1*e3
68 0
69 sage: e2*e3
70 0
71
72 In one dimension, this is the reals under multiplication::
73
74 sage: J1 = eja_ln(1)
75 sage: J2 = eja_rn(1)
76 sage: J1 == J2
77 True
78
79 """
80 Qs = []
81 id_matrix = identity_matrix(field,dimension)
82 for i in xrange(dimension):
83 ei = id_matrix.column(i)
84 Qi = zero_matrix(field,dimension)
85 Qi.set_row(0, ei)
86 Qi.set_column(0, ei)
87 Qi += diagonal_matrix(dimension, [ei[0]]*dimension)
88 # The addition of the diagonal matrix adds an extra ei[0] in the
89 # upper-left corner of the matrix.
90 Qi[0,0] = Qi[0,0] * ~field(2)
91 Qs.append(Qi)
92
93 A = FiniteDimensionalAlgebra(QQ,Qs,assume_associative=True)
94 return JordanAlgebra(A)