1% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
2% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
3\newcommand{\OperatorXmpTitle}{Operator}
4\newcommand{\OperatorXmpNumber}{9.62}
5%
6% =====================================================================
7\begin{page}{OperatorXmpPage}{9.62 Operator}
8% =====================================================================
9\beginscroll
10
11%
12%
13%
14%
15%
16
17
18Given any ring \spad{R}, the ring of the \spadtype{Integer}-linear operators
19over \spad{R} is called \spadtype{Operator(R)}.
20%-% \HDindex{operator}{OperatorXmpPage}{9.62}{Operator}
21To create an operator over \spad{R}, first create a basic operator using the
22operation \spadfun{operator}, and then convert it to \spadtype{Operator(R)}
23for the \spad{R} you want.
24%
25\xtc{
26We choose \spad{R} to be the two by two matrices over the integers.
27}{
28\spadpaste{R := SQMATRIX(2, INT)\bound{r}}
29}
30\xtc{
31Create the operator \spad{tilde} on \spad{R}.
32}{
33\spadpaste{t := operator("tilde") :: OP(R) \free{r}\bound{t}}
34}
35%
36Since \spadtype{Operator} is unexposed we must either package-call operations
37from it, or expose it explicitly.  For convenience we will do the latter.
38%
39\noOutputXtc{
40Expose \spadtype{Operator}.
41}{
42\spadpaste{)set expose add constructor Operator \free{t}\bound{expose}}
43}
44%
45To attach an evaluation function (from \spad{R} to \spad{R}) to an
46operator over \spad{R}, use \spad{evaluate(op, f)} where \spad{op}
47is an operator over \spad{R} and \spad{f} is a function \spad{R -> R}.
48This needs to be done only once when the operator is defined.
49Note that \spad{f} must be \spadtype{Integer}-linear (that is,
50\spad{f(ax+y) = a f(x) + f(y)} for any integer \spad{a}, and any
51\spad{x} and \spad{y} in \spad{R}).
52%
53\xtc{
54We now attach the transpose map to the above operator \spad{t}.
55}{
56\spadpaste{evaluate(t, m +-> transpose m)\free{expose}\free{t}\bound{evt}}
57}
58%
59Operators can be manipulated formally as in any ring: \spadop{+} is the
60pointwise addition and \spadop{*} is composition.
61Any element \spad{x} of \spad{R} can be converted to an operator
62\subscriptText{\tt op}{\tt x}
63over \spad{R}, and the evaluation function of
64\subscriptText{\tt op}{\tt x}
65is left-multiplication by \spad{x}.
66%
67\xtc{
68Multiplying on the
69left by this matrix swaps the two rows.
70}{
71\spadpaste{s : R := matrix [[0, 1], [1, 0]]\bound{s}}
72}
73%
74\xtc{
75Can you guess what is the action of the following operator?
76}{
77\spadpaste{rho := t * s\free{evt s}\bound{rho}}
78}
79%
80%
81\xtc{
82Hint: applying \spad{rho} four times gives the identity, so
83\spad{rho^4-1} should return 0 when applied to any two by two matrix.
84}{
85\spadpaste{z := rho^4 - 1\free{rho}\bound{z}}
86}
87%
88%
89\xtc{
90Now check with this matrix.
91}{
92\spadpaste{m:R := matrix [[1, 2], [3, 4]]\bound{m}}
93}
94\xtc{
95}{
96\spadpaste{z m\free{z m}}
97}
98%
99%
100\xtc{
101As you have probably guessed by now, \spad{rho} acts on matrices
102by rotating the elements clockwise.
103}{
104\spadpaste{rho m\free{rho m}}
105}
106\xtc{
107}{
108\spadpaste{rho rho m\free{rho m}}
109}
110\xtc{
111}{
112\spadpaste{(rho^3) m\free{rho m}}
113}
114%
115%
116\xtc{
117Do the swapping of rows and transposition commute?
118We can check by computing their bracket.
119}{
120\spadpaste{b := t * s - s * t\free{s evt}\bound{b}}
121}
122%
123%
124\xtc{
125Now apply it to \spad{m}.
126}{
127\spadpaste{b m \free{b m}}
128}
129%
130
131Next we demonstrate how to define a differential operator
132on a polynomial ring.
133\xtc{
134This is the recursive definition of the \spad{n}-th Legendre polynomial.
135%-% \HDindex{polynomial!Legendre}{OperatorXmpPage}{9.62}{Operator}
136}{
137\begin{spadsrc}[\bound{l}]
138L n ==
139  n = 0 => 1
140  n = 1 => x
141  (2*n-1)/n * x * L(n-1) - (n-1)/n * L(n-2)
142\end{spadsrc}
143}
144\xtc{
145Create the differential operator \spad{d/dx} on
146polynomials in \spad{x} over the rational numbers.
147}{
148\spadpaste{dx := operator("D") :: OP(POLY FRAC INT) \bound{dx}}
149}
150\xtc{
151Now attach the map to it.
152}{
153\spadpaste{evaluate(dx, p +-> D(p, 'x)) \free{dx}\bound{edx}}
154}
155\xtc{
156This is the differential equation satisfied by the \spad{n}-th
157Legendre polynomial.
158}{
159\spadpaste{E n == (1 - x^2) * dx^2 - 2 * x * dx + n*(n+1) \free{edx}\bound{E}}
160}
161\xtc{
162Now we verify this for \spad{n = 15}.
163Here is the polynomial.
164}{
165\spadpaste{L 15 \free{L}}
166}
167\xtc{
168Here is the operator.
169}{
170\spadpaste{E 15 \free{E}}
171}
172\xtc{
173Here is the evaluation.
174}{
175\spadpaste{(E 15)(L 15) \free{L E}}
176}
177\endscroll
178\autobuttons
179\end{page}
180%
181