]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_operator.py
eja: normalize the real symmetric matrix basis.
[sage.d.git] / mjo / eja / eja_operator.py
1 from sage.matrix.constructor import matrix
2 from sage.categories.all import FreeModules
3 from sage.categories.map import Map
4
5 class FiniteDimensionalEuclideanJordanAlgebraOperator(Map):
6 def __init__(self, domain_eja, codomain_eja, mat):
7 # if not (
8 # isinstance(domain_eja, FiniteDimensionalEuclideanJordanAlgebra) and
9 # isinstance(codomain_eja, FiniteDimensionalEuclideanJordanAlgebra) ):
10 # raise ValueError('(co)domains must be finite-dimensional Euclidean '
11 # 'Jordan algebras')
12
13 F = domain_eja.base_ring()
14 if not (F == codomain_eja.base_ring()):
15 raise ValueError("domain and codomain must have the same base ring")
16
17 # We need to supply something here to avoid getting the
18 # default Homset of the parent FiniteDimensionalAlgebra class,
19 # which messes up e.g. equality testing. We use FreeModules(F)
20 # instead of VectorSpaces(F) because our characteristic polynomial
21 # algorithm will need to F to be a polynomial ring at some point.
22 # When F is a field, FreeModules(F) returns VectorSpaces(F) anyway.
23 parent = domain_eja.Hom(codomain_eja, FreeModules(F))
24
25 # The Map initializer will set our parent to a homset, which
26 # is explicitly NOT what we want, because these ain't algebra
27 # homomorphisms.
28 super(FiniteDimensionalEuclideanJordanAlgebraOperator,self).__init__(parent)
29
30 # Keep a matrix around to do all of the real work. It would
31 # be nice if we could use a VectorSpaceMorphism instead, but
32 # those use row vectors that we don't want to accidentally
33 # expose to our users.
34 self._matrix = mat
35
36
37 def _call_(self, x):
38 """
39 Allow this operator to be called only on elements of an EJA.
40
41 SETUP::
42
43 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
44 sage: from mjo.eja.eja_algebra import JordanSpinEJA
45
46 EXAMPLES::
47
48 sage: J = JordanSpinEJA(3)
49 sage: x = J.linear_combination(zip(J.gens(),range(len(J.gens()))))
50 sage: id = identity_matrix(J.base_ring(), J.dimension())
51 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
52 sage: f(x) == x
53 True
54
55 """
56 return self.codomain().from_vector(self.matrix()*x.to_vector())
57
58
59 def _add_(self, other):
60 """
61 Add the ``other`` EJA operator to this one.
62
63 SETUP::
64
65 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
66 sage: from mjo.eja.eja_algebra import (
67 ....: JordanSpinEJA,
68 ....: RealSymmetricEJA )
69
70 EXAMPLES:
71
72 When we add two EJA operators, we get another one back::
73
74 sage: J = RealSymmetricEJA(2)
75 sage: id = identity_matrix(J.base_ring(), J.dimension())
76 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
77 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
78 sage: f + g
79 Linear operator between finite-dimensional Euclidean Jordan
80 algebras represented by the matrix:
81 [2 0 0]
82 [0 2 0]
83 [0 0 2]
84 Domain: Euclidean Jordan algebra of dimension 3 over...
85 Codomain: Euclidean Jordan algebra of dimension 3 over...
86
87 If you try to add two identical vector space operators but on
88 different EJAs, that should blow up::
89
90 sage: J1 = RealSymmetricEJA(2)
91 sage: J2 = JordanSpinEJA(3)
92 sage: id = identity_matrix(QQ, 3)
93 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J1,J1,id)
94 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J2,J2,id)
95 sage: f + g
96 Traceback (most recent call last):
97 ...
98 TypeError: unsupported operand parent(s) for +: ...
99
100 """
101 return FiniteDimensionalEuclideanJordanAlgebraOperator(
102 self.domain(),
103 self.codomain(),
104 self.matrix() + other.matrix())
105
106
107 def _composition_(self, other, homset):
108 """
109 Compose two EJA operators to get another one (and NOT a formal
110 composite object) back.
111
112 SETUP::
113
114 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
115 sage: from mjo.eja.eja_algebra import (
116 ....: JordanSpinEJA,
117 ....: RealCartesianProductEJA,
118 ....: RealSymmetricEJA)
119
120 EXAMPLES::
121
122 sage: J1 = JordanSpinEJA(3)
123 sage: J2 = RealCartesianProductEJA(2)
124 sage: J3 = RealSymmetricEJA(1)
125 sage: mat1 = matrix(QQ, [[1,2,3],
126 ....: [4,5,6]])
127 sage: mat2 = matrix(QQ, [[7,8]])
128 sage: g = FiniteDimensionalEuclideanJordanAlgebraOperator(J1,
129 ....: J2,
130 ....: mat1)
131 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J2,
132 ....: J3,
133 ....: mat2)
134 sage: f*g
135 Linear operator between finite-dimensional Euclidean Jordan
136 algebras represented by the matrix:
137 [39 54 69]
138 Domain: Euclidean Jordan algebra of dimension 3 over
139 Rational Field
140 Codomain: Euclidean Jordan algebra of dimension 1 over
141 Rational Field
142
143 """
144 return FiniteDimensionalEuclideanJordanAlgebraOperator(
145 other.domain(),
146 self.codomain(),
147 self.matrix()*other.matrix())
148
149
150 def __eq__(self, other):
151 if self.domain() != other.domain():
152 return False
153 if self.codomain() != other.codomain():
154 return False
155 if self.matrix() != other.matrix():
156 return False
157 return True
158
159
160 def __invert__(self):
161 """
162 Invert this EJA operator.
163
164 SETUP::
165
166 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
167 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
168
169 EXAMPLES::
170
171 sage: J = RealSymmetricEJA(2)
172 sage: id = identity_matrix(J.base_ring(), J.dimension())
173 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
174 sage: ~f
175 Linear operator between finite-dimensional Euclidean Jordan
176 algebras represented by the matrix:
177 [1 0 0]
178 [0 1 0]
179 [0 0 1]
180 Domain: Euclidean Jordan algebra of dimension 3 over...
181 Codomain: Euclidean Jordan algebra of dimension 3 over...
182
183 """
184 return FiniteDimensionalEuclideanJordanAlgebraOperator(
185 self.codomain(),
186 self.domain(),
187 ~self.matrix())
188
189
190 def __mul__(self, other):
191 """
192 Compose two EJA operators, or scale myself by an element of the
193 ambient vector space.
194
195 We need to override the real ``__mul__`` function to prevent the
196 coercion framework from throwing an error when it fails to convert
197 a base ring element into a morphism.
198
199 SETUP::
200
201 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
202 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
203
204 EXAMPLES:
205
206 We can scale an operator on a rational algebra by a rational number::
207
208 sage: J = RealSymmetricEJA(2)
209 sage: e0,e1,e2 = J.gens()
210 sage: x = 2*e0 + 4*e1 + 16*e2
211 sage: x.operator()
212 Linear operator between finite-dimensional Euclidean Jordan algebras
213 represented by the matrix:
214 [ 2 2 0]
215 [ 2 9 2]
216 [ 0 2 16]
217 Domain: Euclidean Jordan algebra of dimension 3 over...
218 Codomain: Euclidean Jordan algebra of dimension 3 over...
219 sage: x.operator()*(1/2)
220 Linear operator between finite-dimensional Euclidean Jordan algebras
221 represented by the matrix:
222 [ 1 1 0]
223 [ 1 9/2 1]
224 [ 0 1 8]
225 Domain: Euclidean Jordan algebra of dimension 3 over...
226 Codomain: Euclidean Jordan algebra of dimension 3 over...
227
228 """
229 try:
230 if other in self.codomain().base_ring():
231 return FiniteDimensionalEuclideanJordanAlgebraOperator(
232 self.domain(),
233 self.codomain(),
234 self.matrix()*other)
235 except NotImplementedError:
236 # This can happen with certain arguments if the base_ring()
237 # is weird and doesn't know how to test membership.
238 pass
239
240 # This should eventually delegate to _composition_ after performing
241 # some sanity checks for us.
242 mor = super(FiniteDimensionalEuclideanJordanAlgebraOperator,self)
243 return mor.__mul__(other)
244
245
246 def _neg_(self):
247 """
248 Negate this EJA operator.
249
250 SETUP::
251
252 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
253 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
254
255 EXAMPLES::
256
257 sage: J = RealSymmetricEJA(2)
258 sage: id = identity_matrix(J.base_ring(), J.dimension())
259 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
260 sage: -f
261 Linear operator between finite-dimensional Euclidean Jordan
262 algebras represented by the matrix:
263 [-1 0 0]
264 [ 0 -1 0]
265 [ 0 0 -1]
266 Domain: Euclidean Jordan algebra of dimension 3 over...
267 Codomain: Euclidean Jordan algebra of dimension 3 over...
268
269 """
270 return FiniteDimensionalEuclideanJordanAlgebraOperator(
271 self.domain(),
272 self.codomain(),
273 -self.matrix())
274
275
276 def __pow__(self, n):
277 """
278 Raise this EJA operator to the power ``n``.
279
280 SETUP::
281
282 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
283 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
284
285 TESTS:
286
287 Ensure that we get back another EJA operator that can be added,
288 subtracted, et cetera::
289
290 sage: J = RealSymmetricEJA(2)
291 sage: id = identity_matrix(J.base_ring(), J.dimension())
292 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
293 sage: f^0 + f^1 + f^2
294 Linear operator between finite-dimensional Euclidean Jordan
295 algebras represented by the matrix:
296 [3 0 0]
297 [0 3 0]
298 [0 0 3]
299 Domain: Euclidean Jordan algebra of dimension 3 over...
300 Codomain: Euclidean Jordan algebra of dimension 3 over...
301
302 """
303 if (n == 1):
304 return self
305 elif (n == 0):
306 # Raising a vector space morphism to the zero power gives
307 # you back a special IdentityMorphism that is useless to us.
308 rows = self.codomain().dimension()
309 cols = self.domain().dimension()
310 mat = matrix.identity(self.base_ring(), rows, cols)
311 else:
312 mat = self.matrix()**n
313
314 return FiniteDimensionalEuclideanJordanAlgebraOperator(
315 self.domain(),
316 self.codomain(),
317 mat)
318
319
320 def _repr_(self):
321 r"""
322
323 A text representation of this linear operator on a Euclidean
324 Jordan Algebra.
325
326 SETUP::
327
328 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
329 sage: from mjo.eja.eja_algebra import JordanSpinEJA
330
331 EXAMPLES::
332
333 sage: J = JordanSpinEJA(2)
334 sage: id = identity_matrix(J.base_ring(), J.dimension())
335 sage: FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
336 Linear operator between finite-dimensional Euclidean Jordan
337 algebras represented by the matrix:
338 [1 0]
339 [0 1]
340 Domain: Euclidean Jordan algebra of dimension 2 over
341 Rational Field
342 Codomain: Euclidean Jordan algebra of dimension 2 over
343 Rational Field
344
345 """
346 msg = ("Linear operator between finite-dimensional Euclidean Jordan "
347 "algebras represented by the matrix:\n",
348 "{!r}\n",
349 "Domain: {}\n",
350 "Codomain: {}")
351 return ''.join(msg).format(self.matrix(),
352 self.domain(),
353 self.codomain())
354
355
356 def _sub_(self, other):
357 """
358 Subtract ``other`` from this EJA operator.
359
360 SETUP::
361
362 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
363 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
364
365 EXAMPLES::
366
367 sage: J = RealSymmetricEJA(2)
368 sage: id = identity_matrix(J.base_ring(),J.dimension())
369 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,id)
370 sage: f - (f*2)
371 Linear operator between finite-dimensional Euclidean Jordan
372 algebras represented by the matrix:
373 [-1 0 0]
374 [ 0 -1 0]
375 [ 0 0 -1]
376 Domain: Euclidean Jordan algebra of dimension 3 over...
377 Codomain: Euclidean Jordan algebra of dimension 3 over...
378
379 """
380 return (self + (-other))
381
382
383 def matrix(self):
384 """
385 Return the matrix representation of this operator with respect
386 to the default bases of its (co)domain.
387
388 SETUP::
389
390 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
391 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
392
393 EXAMPLES::
394
395 sage: J = RealSymmetricEJA(2)
396 sage: mat = matrix(J.base_ring(), J.dimension(), range(9))
397 sage: f = FiniteDimensionalEuclideanJordanAlgebraOperator(J,J,mat)
398 sage: f.matrix()
399 [0 1 2]
400 [3 4 5]
401 [6 7 8]
402
403 """
404 return self._matrix
405
406
407 def minimal_polynomial(self):
408 """
409 Return the minimal polynomial of this linear operator,
410 in the variable ``t``.
411
412 SETUP::
413
414 sage: from mjo.eja.eja_operator import FiniteDimensionalEuclideanJordanAlgebraOperator
415 sage: from mjo.eja.eja_algebra import RealSymmetricEJA
416
417 EXAMPLES::
418
419 sage: J = RealSymmetricEJA(3)
420 sage: J.one().operator().minimal_polynomial()
421 t - 1
422
423 """
424 # The matrix method returns a polynomial in 'x' but want one in 't'.
425 return self.matrix().minimal_polynomial().change_variable_name('t')