oper2.tex 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. \section{Even and Odd Operators}\index{Even operator}\index{Odd operator}
  2. An operator can be declared to be {\em even\/} or {\em odd\/} in its first
  3. argument by the declarations {\tt EVEN}\ttindex{EVEN} and
  4. {\tt ODD}\ttindex{ODD} respectively. Expressions involving an operator
  5. declared in this manner are transformed if the first argument contains a
  6. minus sign. Any other arguments are not affected. In addition, if say
  7. {\tt F} is declared odd, then {\tt f(0)} is replaced by zero unless
  8. {\tt F} is also declared {\em non zero\/} by the declaration
  9. {\tt NONZERO}\ttindex{NONZERO}. For example, the declarations
  10. \begin{verbatim}
  11. even f1; odd f2;
  12. \end{verbatim}
  13. mean that
  14. \begin{verbatim}
  15. f1(-a) -> F1(A)
  16. f2(-a) -> -F2(A)
  17. f1(-a,-b) -> F1(A,-B)
  18. f2(0) -> 0.
  19. \end{verbatim}
  20. To inhibit the last transformation, say {\tt nonzero f2;}.
  21. \section{Linear Operators}\index{Linear operator}
  22. An operator can be declared to be linear in its first argument over powers
  23. of its second argument. If an operator {\tt F} is so declared, {\tt F} of
  24. any sum is broken up into sums of {\tt F}s, and any factors that are not
  25. powers of the variable are taken outside. This means that {\tt F} must
  26. have (at least) two arguments. In addition, the second argument must be
  27. an identifier (or more generally a kernel), not an expression.
  28. {\it Example:}
  29. If {\tt F} were declared linear, then
  30. \begin{verbatim}
  31. 5
  32. f(a*x^5+b*x+c,x) -> F(X ,X)*A + F(X,X)*B + F(1,X)*C
  33. \end{verbatim}
  34. More precisely, not only will the variable and its powers remain within the
  35. scope of the {\tt F} operator, but so will any variable and its powers that
  36. had been declared to {\tt DEPEND} on the prescribed variable; and so would
  37. any expression that contains that variable or a dependent variable on any
  38. level, e.g. {\tt cos(sin(x))}.
  39. To declare operators {\tt F} and {\tt G} to be linear operators,
  40. use:\ttindex{LINEAR}
  41. \begin{verbatim}
  42. linear f,g;
  43. \end{verbatim}
  44. The analysis is done of the first argument with respect to the second; any
  45. other arguments are ignored. It uses the following rules of evaluation:
  46. \begin{quote}
  47. \begin{tabbing}
  48. {\tt f(0) -> 0} \\
  49. {\tt f(-y,x) -> -F(Y,X)} \\
  50. {\tt f(y+z,x) -> F(Y,X)+F(Z,X)} \\
  51. {\tt f(y*z,x) -> Z*F(Y,X)} \hspace{0.5in}\= if Z does not depend on X \\
  52. {\tt f(y/z,x) -> F(Y,X)/Z} \> if Z does not depend on X
  53. \end{tabbing}
  54. \end{quote}
  55. To summarize, {\tt Y} ``depends'' on the indeterminate {\tt X} in the above
  56. if either of the following hold:
  57. \begin{enumerate}
  58. \item {\tt Y} is an expression that contains {\tt X} at any level as a
  59. variable, e.g.: {\tt cos(sin(x))}
  60. \item Any variable in the expression {\tt Y} has been declared dependent on
  61. {\tt X} by use of the declaration {\tt DEPEND}.
  62. \end{enumerate}
  63. The use of such linear operators\index{Linear operator} can be seen in the
  64. paper Fox, J.A. and A. C. Hearn, ``Analytic Computation of Some Integrals
  65. in Fourth Order Quantum Electrodynamics'' Journ. Comp. Phys. 14 (1974)
  66. 301-317, which contains a complete listing of a program for definite
  67. integration\index{Integration} of some expressions that arise in fourth
  68. order quantum electrodynamics.
  69. \section{Non-Commuting Operators}\index{Non-commuting operator}
  70. An operator can be declared to be non-commutative under multiplication by
  71. the declaration {\tt NONCOM}.\ttindex{NONCOM}
  72. {\it Example:}
  73. After the declaration \\
  74. {\tt noncom u,v;}\\
  75. the expressions {\tt
  76. u(x)*u(y)-u(y)*u(x)} and {\tt u(x)*v(y)-v(y)*u(x)} will remain unchanged
  77. on simplification, and in particular will not simplify to zero.
  78. Note that it is the operator ({\tt U} and {\tt V} in the above example)
  79. and not the variable that has the non-commutative property.
  80. The {\tt LET}\ttindex{LET} statement may be used to introduce rules of
  81. evaluation for such operators. In particular, the boolean operator
  82. {\tt ORDP}\ttindex{ORDP} is useful for introducing an ordering on such
  83. expressions.
  84. {\it Example:}
  85. The rule
  86. \begin{verbatim}
  87. for all x,y such that x neq y and ordp(x,y)
  88. let u(x)*u(y)= u(y)*u(x)+comm(x,y);
  89. \end{verbatim}
  90. would introduce the commutator of {\tt u(x)} and {\tt u(y)} for all
  91. {\tt X} and {\tt Y}. Note that since {\tt ordp(x,x)} is {\em true}, the
  92. equality check is necessary in the degenerate case to avoid a circular
  93. loop in the rule.
  94. \section{Symmetric and Antisymmetric Operators}
  95. An operator can be declared to be symmetric with respect to its arguments
  96. by the declaration {\tt SYMMETRIC}.\ttindex{SYMMETRIC} For example
  97. \begin{verbatim}
  98. symmetric u,v;
  99. \end{verbatim}
  100. means that any expression involving the top level operators {\tt U} or
  101. {\tt V} will have its arguments reordered to conform to the internal order
  102. used by {\REDUCE}. The user can change this order for kernels by the
  103. command {\tt KORDER}.
  104. For example, {\tt u(x,v(1,2))} would become {\tt u(v(2,1),x)}, since
  105. numbers are ordered in decreasing order, and expressions are ordered in
  106. decreasing order of complexity.
  107. Similarly the declaration {\tt ANTISYMMETRIC}\ttindex{ANTISYMMETRIC}
  108. declares an operator antisymmetric. For example,
  109. \begin{verbatim}
  110. antisymmetric l,m;
  111. \end{verbatim}
  112. means that any expression involving the top level operators {\tt L} or
  113. {\tt M} will have its arguments reordered to conform to the internal order
  114. of the system, and the sign of the expression changed if there are an odd
  115. number of argument interchanges necessary to bring about the new order.
  116. For example, {\tt l(x,m(1,2))} would become {\tt -l(-m(2,1),x)} since one
  117. interchange occurs with each operator. An expression like {\tt l(x,x)}
  118. would also be replaced by 0.
  119. \section{Declaring New Prefix Operators}
  120. The user may add new prefix\index{Prefix} operators to the system by
  121. using the declaration {\tt OPERATOR}. For example:
  122. \begin{verbatim}
  123. operator h,g1,arctan;
  124. \end{verbatim}
  125. adds the prefix operators {\tt H}, {\tt G1} and {\tt ARCTAN} to the system.
  126. This allows symbols like {\tt h(w), h(x,y,z), g1(p+q), arctan(u/v)} to be
  127. used in expressions, but no meaning or properties of the operator are
  128. implied. The same operator symbol can be used equally well as a 0-, 1-, 2-,
  129. 3-, etc.-place operator.
  130. To give a meaning to an operator symbol, or express some of its
  131. properties, {\tt LET}\ttindex{LET} statements can be used, or the operator
  132. can be given a definition as a procedure.
  133. If the user forgets to declare an identifier as an operator, the system
  134. will prompt the user to do so in interactive mode, or do it automatically
  135. in non-interactive mode. A diagnostic message will also be printed if an
  136. identifier is declared {\tt OPERATOR} more than once.
  137. Operators once declared are global in scope, and so can then be referenced
  138. anywhere in the program. In other words, a declaration within a block (or
  139. a procedure) does not limit the scope of the operator to that block, nor
  140. does the operator go away on exiting the block (use {\tt CLEAR} instead
  141. for this purpose).
  142. \section{Declaring New Infix Operators}
  143. Users can add new infix operators by using the declarations
  144. {\tt INFIX}\ttindex{INFIX} and {\tt PRECEDENCE}.\ttindex{PRECEDENCE}
  145. For example,
  146. \begin{verbatim}
  147. infix mm;
  148. precedence mm,-;
  149. \end{verbatim}
  150. The declaration {\tt infix mm;} would allow one to use the symbol
  151. {\tt MM} as an infix operator:
  152. \begin{quote}
  153. \hspace{0.2in} {\tt a mm b} \hspace{0.3in} instead of \hspace{0.3in}
  154. {\tt mm(a,b)}.
  155. \end{quote}
  156. The declaration {\tt precedence mm,-;} says that {\tt MM} should be
  157. inserted into the infix operator precedence list just {\em after\/}
  158. the $-$ operator. This gives it higher precedence than $-$ and lower
  159. precedence than * . Thus
  160. \begin{quote}
  161. \hspace{0.2in}{\tt a - b mm c - d}\hspace{.3in} means \hspace{.3in}
  162. {\tt a - (b mm c) - d},
  163. \end{quote}
  164. while
  165. \begin{quote}
  166. \hspace{0.2in}{\tt a * b mm c * d}\hspace{.3in} means \hspace{.3in}
  167. {\tt (a * b) mm (c * d)}.
  168. \end{quote}
  169. Both infix and prefix\index{Prefix} operators have no transformation
  170. properties unless {\tt LET}\ttindex{LET} statements or procedure
  171. declarations are used to assign a meaning.
  172. We should note here that infix operators so defined are always binary:
  173. \begin{quote}
  174. \hspace{0.2in}{\tt a mm b mm c}\hspace{.3in} means \hspace{.3in}
  175. {\tt (a mm b) mm c}.
  176. \end{quote}
  177. \section{Creating/Removing Variable Dependency}
  178. There are several facilities in {\REDUCE}, such as the differentiation
  179. \index{Differentiation}
  180. operator and the linear operator\index{Linear operator} facility, that
  181. can utilize knowledge of the dependency between various variables, or
  182. kernels. Such dependency may be expressed by the command {\tt
  183. DEPEND}.\ttindex{DEPEND} This takes an arbitrary number of arguments and
  184. sets up a dependency of the first argument on the remaining arguments.
  185. For example,
  186. \begin{verbatim}
  187. depend x,y,z;
  188. \end{verbatim}
  189. says that {\tt X} is dependent on both {\tt Y} and {\tt Z}.
  190. \begin{verbatim}
  191. depend z,cos(x),y;
  192. \end{verbatim}
  193. says that {\tt Z} is dependent on {\tt COS(X)} and {\tt Y}.
  194. Dependencies introduced by {\tt DEPEND} can be removed by {\tt NODEPEND}.
  195. \ttindex{NODEPEND} The arguments of this are the same as for {\tt DEPEND}.
  196. For example, given the above dependencies,
  197. \begin{verbatim}
  198. nodepend z,cos(x);
  199. \end{verbatim}
  200. says that {\tt Z} is no longer dependent on {\tt COS(X)}, although it remains
  201. dependent on {\tt Y}.