dfpart.tex 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. \documentstyle[11pt,reduce]{article}
  2. \title{DFPART: A Package for Calculating with Derivatives of
  3. Generic Functions}
  4. \date{}
  5. \author{
  6. H. Melenk \\[0.05in]
  7. Konrad--Zuse--Zentrum \\
  8. f\"ur Informationstechnik Berlin \\
  9. Takustra\"se 7 \\
  10. D--14195 Berlin--Dahlem \\
  11. Federal Republic of Germany \\[0.05in]
  12. Email: melenk@zib.de}
  13. \begin{document}
  14. \maketitle
  15. \index{derivatives}
  16. \index{partial derivatives}
  17. \index{generic function}
  18. The package {\tt DFPART} supports computations with total and partial
  19. derivatives of formal function objects. Such computations can
  20. be useful in the context of differential equations or
  21. power series expansions.
  22. \section{Generic Functions}
  23. A generic function is a symbol which represents a mathematical
  24. function. The minimal information about a generic function
  25. function is the number of its arguments. In order to facilitate
  26. the programming and for a better readable output this package
  27. assumes that the arguments of a generic function have default
  28. names such as $f(x,y)$,$q(rho,phi)$.
  29. A generic function is declared by prototype form in a statement
  30. \vspace{.1in}
  31. {\tt GENERIC\_FUNCTION} $fname(arg_1,arg_2\cdots arg_n)$;
  32. \vspace{.1in}
  33. \noindent
  34. where $fname$ is the (new) name of a function and $arg_i$ are
  35. symbols for its formal arguments.
  36. In the following $fname$ is referred to as ``generic function",
  37. $arg_1,arg_2\cdots arg_n$ as ``generic arguments" and
  38. $fname(arg_1,arg_2\cdots arg_n)$ as ``generic form".
  39. Examples:
  40. \begin{verbatim}
  41. generic_function f(x,y);
  42. generic_function g(z);
  43. \end{verbatim}
  44. After this declaration {\REDUCE} knows that
  45. \begin{itemize}
  46. \item there are formal partial derivatives $\frac{\partial f}{\partial x}$,
  47. $\frac{\partial f}{\partial y}$ $\frac{\partial g}{\partial z}$
  48. and higher ones, while partial derivatives of $f$ and $g$
  49. with respect to other variables are assumed as zero,
  50. \item expressions of the type $f()$, $g()$ are abbreviations for
  51. $f(x,y)$, $g(z)$,
  52. \item expressions of the type $f(u,v)$ are abbreviations for\\
  53. $sub(x=u,y=v,f(x,y))$
  54. \item a total derivative $\frac{d f(u,v)}{d w}$ has to be computed
  55. as $\frac{\partial f}{\partial x} \frac{d u}{d w} +
  56. \frac{\partial f}{\partial y} \frac{d v}{d w}$
  57. \end{itemize}
  58. \section{Partial Derivatives}
  59. The operator {\tt DFP} represents a partial derivative:
  60. \vspace{.1in}
  61. {\tt DFP}($expr,{dfarg_1,dfarg_2\cdots dfarg_n}$);
  62. \vspace{.1in}
  63. \noindent
  64. where $expr$ is a function expression and $dfarg_i$ are
  65. the differentiation variables. Examples:
  66. \begin{verbatim}
  67. dfp(f(),{x,y});
  68. \end{verbatim}
  69. means $\frac{\partial ^2 f}{\partial x \partial y}$ and
  70. \begin{verbatim}
  71. dfp(f(u,v),{x,y});
  72. \end{verbatim}
  73. stands for $\frac{\partial ^2 f}{\partial x \partial y} (u,v)$.
  74. For compatibility with the $DF$ operator the differentiation
  75. variables need not be entered in list form; instead the syntax
  76. of {\tt DF} can be used, where the function expression is followed
  77. by the differentiation variables, eventually with repetition
  78. numbers. Such forms are interenally converted to the above
  79. form with a list as second parameter.
  80. The expression $expr$ can be a generic function
  81. with or without arguments, or an arithmetic expression built
  82. from generic functions and other algebraic parts. In the
  83. second case the standard differentiation rules are applied
  84. in order to reduce each derivative expressions to a minimal
  85. form.
  86. When the switch {\tt NAT} is on partial derivatives of generic
  87. functions are printed in standard index notation, that is
  88. $f_{xy}$ for $\frac{\partial ^2 f}{\partial x \partial y}$
  89. and $f_{xy}(u,v)$ for $\frac{\partial ^2 f}{\partial x \partial y}(u,v)$.
  90. Therefore single characters should be used for the arguments
  91. whenever possible. Examples:
  92. \begin{verbatim}
  93. generic_function f(x,y);
  94. generic_function g(y);
  95. dfp(f(),x,2);
  96. F
  97. XX
  98. dfp(f()*g(),x,2);
  99. F *G()
  100. XX
  101. dfp(f()*g(),x,y);
  102. F *G() + F *G
  103. XY X Y
  104. \end{verbatim}
  105. The difference between partial and total derivatives is
  106. illustrated by the following example:
  107. \begin{verbatim}
  108. generic_function h(x);
  109. dfp(f(x,h(x))*g(h(x)),x);
  110. F (X,H(X))*G(H(X))
  111. X
  112. df(f(x,h(x))*g(h(x)),x);
  113. F (X,H(X))*G(H(X)) + F (X,H(X))*H (X)*G(H(X))
  114. X Y X
  115. + G (H(X))*H (X)*F(X,H(X))
  116. Y X
  117. \end{verbatim}
  118. Cooperation of partial derivatives and Taylor series under
  119. a differential side relation $\frac{dq}{dx}=f(x,q)$:
  120. \begin{verbatim}
  121. load_package taylor;
  122. operator q;
  123. let df(q(~x),x) => f(x,q(x));
  124. taylor(q(x0+h),h,0,3);
  125. F (X0,Q(X0)) + F (X0,Q(X0))*F(X0,Q(X0))
  126. X Y 2
  127. Q(X0) + F(X0,Q(X0))*H + -----------------------------------------*H
  128. 2
  129. + (F (X0,Q(X0)) + F (X0,Q(X0))*F(X0,Q(X0))
  130. XX XY
  131. + F (X0,Q(X0))*F (X0,Q(X0)) + F (X0,Q(X0))*F(X0,Q(X0))
  132. X Y YX
  133. 2 2 3
  134. + F (X0,Q(X0))*F(X0,Q(X0)) + F (X0,Q(X0)) *F(X0,Q(X0)))/6*H
  135. YY Y
  136. 4
  137. + O(H )
  138. \end{verbatim}
  139. Normally partial differentials are assumed as non-commutative
  140. \begin{verbatim}
  141. dfp(f(),x,y)-dfp(f(),y,x);
  142. F - F
  143. XY YX
  144. \end{verbatim}
  145. However, a generic function can be declared to have globally
  146. interchangeable partial derivatives using the declaration
  147. {\tt DFP\_COMMUTE}
  148. which takes the name of a generic function or a generic function
  149. form as argument. For such a function differentiation variables are
  150. rearranged corresponding to the sequence of the generic variables.
  151. \begin{verbatim}
  152. generic_function q(x,y);
  153. dfp_commute q(x,y);
  154. dfp(q(),{x,y,y}) + dfp(q(),{y,x,y}) + dfp(q(),{y,y,x});
  155. 3*Q
  156. XYY
  157. \end{verbatim}
  158. If only a part of the derivatives commute, this has to be
  159. declared using the standard {\REDUCE} rule mechanism. Please
  160. note that then the derivative variables must be written as
  161. list.
  162. \section{Substitutions}
  163. When a generic form or a {\tt DFP} expression takes part in a
  164. substitution the following steps are performed:
  165. \begin{enumerate}
  166. \item The substitutions are performed for the arguments. If the
  167. argument list is empty the substitution is applied to the
  168. generic arguments of the function; if these change, the resulting
  169. forms are used as new actual arguments.
  170. If the generic function itself is not affected by the substitution,
  171. the process stops here.
  172. \item If the function name or the generic function
  173. form occurs as a left hand side in the substitution list,
  174. it is replaced by the corresponding right hand side.
  175. \item The new form is partially differentiated according to the
  176. list of partial derivative variables.
  177. \item The (eventually modified) actual parameters are substituted
  178. into the form for their corresponding generic variables.
  179. This substitution is done by name.
  180. \end{enumerate}
  181. Examples:
  182. \begin{verbatim}
  183. generic_function f(x,y);
  184. sub(y=10,f());
  185. F(X,10)
  186. sub(y=10,dfp(f(),x,2));
  187. F (X,10)
  188. XX
  189. sub(y=10,dfp(f(y,y),x,2));
  190. F (10,10)
  191. XX
  192. sub(f=x**3*y**3,dfp(f(),x,2));
  193. 3
  194. 6*X*Y
  195. generic_function ff(y,z);
  196. sub(f=ff,f(a,b));
  197. FF(B,Z)
  198. \end{verbatim}
  199. The dataset $dfpart.tst$ contains more examples,
  200. including a complete application for computing the coefficient
  201. equations for Runge-Kutta ODE solvers.
  202. \end{document}