taylor.tex 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. \documentstyle[11pt]{article}
  2. \newcommand{\REDUCE}{{\sf REDUCE}}
  3. \newcommand{\MACSYMA}{{\sf MACSYMA}}
  4. \newcommand{\MAPLE}{{\sf MAPLE}}
  5. \newcommand{\Mathematica}{{\sf Mathematica}}
  6. \newcommand{\PSL}{{\sf PSL}}
  7. \renewcommand{\today}{October 5, 1990}
  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. %
  10. % Warning: an overfull \hbox is produced in the first
  11. % verbatim environment.
  12. %
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. \begin{document}
  15. \title{A \REDUCE{} package\\
  16. for manipulation of Taylor series}
  17. \author{Rainer Sch\"opf\\
  18. Konrad-Zuse-Zentrum f\"ur Informationstechnik Berlin\\
  19. Heilbronner Str.\ 10\\
  20. 1000 Berlin 31\\
  21. Federal Republic of Germany\\
  22. Email: \verb|<SCHOEPF@SC.ZIB-Berlin.DE>|}
  23. \maketitle
  24. \begin{abstract}
  25. This short note describes a package of \REDUCE{} procedures
  26. that allow Taylor expansion in one or more variables and efficient
  27. manipulation of the resulting Taylor series. Capabilities include
  28. basic operations (addition, subtraction, multiplication
  29. and division) and also application of certain algebraic and
  30. transcendental functions.
  31. \end{abstract}
  32. \section{Introduction}
  33. The Taylor package was written to provide \REDUCE{} with some of
  34. the facilities
  35. that \MACSYMA's \verb+TAYLOR+ function offers,
  36. but most of all I needed it to be faster and
  37. more space-efficient.
  38. Especially I wanted procedures that would return the logarithm or
  39. arc tangent of a Taylor series, again as a Taylor series.
  40. This turned out be more work than expected. The features absolutely
  41. required were (as usual) those that were hardest to implement,
  42. e.g., arc tangent applied to a Taylor expansion in more than
  43. one variable.
  44. This package is still undergoing development.
  45. I'll be happy if it is of any use for you.
  46. Tell me if you think that there is something missing.
  47. I invite everybody to criticize and comment and will eagerly try to
  48. correct any errors found.
  49. \section{How to use it}
  50. The most important operator is `\verb+TAYLOR+'.
  51. It is used as follows:
  52. \begin{verbatim}
  53. TAYLOR(exp:exprn[,var:kernel,var0:exprn,order:integer]...):exprn
  54. \end{verbatim}
  55. where \verb|exp| is the expression to be expanded. It can be any
  56. \REDUCE{} object, even an expression containing other Taylor kernels.
  57. \verb|var| is the kernel with respect to
  58. which \verb|exp| is to be expanded. \verb|var0| denotes the point
  59. about
  60. which and \verb|order| the order up to which expansion is to take
  61. place.
  62. If more than one (\verb|var|,\verb|var0|,\verb|order|) triple is
  63. specified \verb|TAYLOR| will expand its first argument independently
  64. with respect to all the variables.
  65. For example,
  66. \begin{verbatim}
  67. TAYLOR(E^(X^2+Y^2),X,0,2,Y,0,2);
  68. \end{verbatim}
  69. will calculate the Taylor expansion up to order $X^{2}*Y^{2}$.
  70. Note that once the expansion has been done it is not possible to
  71. calculate higher orders.
  72. Instead of a kernel, \verb|var| may also
  73. be a list of kernels. In this case expansion will take place in a way
  74. so that the {\em sum\/} of the degrees of the kernels does not exceed
  75. \verb|order|.
  76. If \verb|var0| evaluates to the special identifier \verb|INFINITY|
  77. \verb|TAYLOR| tries to expand \verb|exp| in a series in \verb|1/var|.
  78. The expansion is performed variable per variable, i.e.\ in the example
  79. above by first expanding $\exp(x^{2}+y^{2})$ with respect to $x$ and
  80. then expanding every coefficient with respect to $y$.
  81. If the switch \verb|TAYLORKEEPORIGINAL| is set to \verb|ON| the
  82. original expression \verb|exp| is kept for later reference.
  83. It can be recovered by means of the operator
  84. \begin{verbatim}
  85. TAYLORORIGINAL(exp:exprn):exprn
  86. \end{verbatim}
  87. An error is signalled if \verb|exp| is not a Taylor kernel or
  88. if the original expression was not kept, i.e.\ if
  89. \verb|TAYLORKEEPORIGINAL| was \verb|OFF| during expansion.
  90. The template of a Taylor kernel, i.e.\ the list of all
  91. variables with respect to which expansion took place together with
  92. expansion point and order can be extracted using
  93. \begin{verbatim}
  94. TAYLORTEMPLATE(exp:exprn):list
  95. \end{verbatim}
  96. This returns a list of lists with the three elements
  97. \verb|{var,var0,order}|.
  98. As with \verb|TAYLORORIGINAL|,
  99. an error is signalled if \verb|exp| is not a Taylor kernel.
  100. \begin{verbatim}
  101. TAYLORTOSTANDARD(exp:exprn):exprn
  102. \end{verbatim}
  103. converts all Taylor kernels in \verb|exp| into standard form and
  104. resimplifies the result.
  105. \begin{verbatim}
  106. TAYLORSERIESP(exp:exprn):boolean
  107. \end{verbatim}
  108. may be used to determine if \verb|exp| is a Taylor kernel.
  109. Note that this operator is subject to the same restrictions as,
  110. e.g., \verb|ORDP| or \verb|NUMBERP|, i.e.\ it may only be
  111. used in boolean expressions in \verb|IF| or \verb|LET| statements.
  112. Finally there is
  113. \begin{verbatim}
  114. TAYLORCOMBINE(exp:exprn):exprn
  115. \end{verbatim}
  116. which tries to combine all Taylor kernels found in \verb|exp| into one.
  117. Operations currently possible are:
  118. \begin{itemize}
  119. \item Addition, subtraction, multiplication, and division.
  120. \item Roots, exponentials, and logarithms.
  121. \item Trigonometric and hyperbolic functions and their inverses.
  122. \end{itemize}
  123. Application of unary operators like \verb|LOG| and \verb|ATAN| will
  124. nearly always succeed. For binary operations their arguments have to be
  125. Taylor kernels with the same template. This means that the expansion
  126. variable and the expansion point must match. Expansion order is not so
  127. important, different order usually means that one of them is truncated
  128. before doing the operation.
  129. If \verb|TAYLORKEEPORIGINAL| is set to \verb|ON| and if all Taylor
  130. kernels in \verb|exp| have their original expressions kept
  131. \verb|TAYLORCOMBINE| will also combine these and store the result
  132. as the original expression of the resulting Taylor kernel.
  133. There is also the switch \verb|TAYLORAUTOEXPAND| (see below).
  134. There are a few restrictions to avoid mathematically undefined
  135. expressions:
  136. it is not possible to take the logarithm of a Taylor kernel whose
  137. constant
  138. term is zero, or to divide by a Taylor kernel that consists only
  139. of the constant zero.
  140. There are, however, some provisions made to detect singularities during
  141. expansion: poles that arise because the denominator has zeros at
  142. the expansion point are
  143. detected and properly treated, i.e.\ the Taylor kernel will
  144. start with a negative power. (This is accomplished by expanding
  145. numerator and denominator separately and combining the results.)
  146. It has been observed, however, that this does {\em not\/} work if the
  147. \verb|MCD| switch is set to \verb|OFF|. This seems to be a
  148. limitation of \REDUCE{} version 3.3.
  149. Essential singularities are not handled at all which means that usually
  150. some sort of error will be signalled. Maybe I can improve this later.
  151. \verb|TAYLOR| does not always detect non-analytical expressions in
  152. its first argument.
  153. In this case a wrong result will be given that depends on the order
  154. of Taylor variables in the call to \verb|TAYLOR|.
  155. An example for this behaviour is given by the function $xy/(x+y)$ that is
  156. not analytical in the neighborhood of $(x,y) = (0,0)$:
  157. Trying to calculate
  158. \begin{verbatim}
  159. TAYLOR(X*Y/(X+Y),X,0,2,Y,0,2);
  160. \end{verbatim}
  161. we get as result $X-X^{2}/Y$.
  162. The reason for this is as follows:
  163. \verb|TAYLOR| first expands it with respect to $X$ about $0$
  164. up to order $2$ giving $X - X^{2}/Y$.
  165. This has only a simple pole in $Y$ at $0$ and is therefore returned as
  166. result.
  167. If we interchange \verb|X| and \verb|Y| in the call to \verb|TAYLOR|
  168. they are also interchanged in the result.
  169. At the moment I don't know a general method to detect non-analytical
  170. expressions in the argument to \verb|TAYLOR|.
  171. Differentiation of a Taylor expression is possible. If you
  172. differentiate with respect to one of the Taylor variables the order
  173. will decrease by one.
  174. Substitution is a bit restricted: Taylor variables can only be replaced
  175. by other kernels. There is one exception to this rule: you can always
  176. substitute a Taylor variable by an expression that evaluates to a
  177. constant. Note that \REDUCE{} will not always be able to determine
  178. that an expression is constant: an example is \verb|SIN(ACOS(4))|.
  179. This packages introduces a number of new switches:
  180. \begin{itemize}
  181. \item If you set \verb|TAYLORAUTOCOMBINE| to \verb|ON| \REDUCE{}
  182. automatically combines Taylor expressions during the simplification
  183. process. This is equivalent to applying \verb|TAYLORCOMBINE| to
  184. every expression that contains Taylor kernels.
  185. \item \verb|TAYLORAUTOEXPAND| makes Taylor expressions ``contagious''
  186. in the sense that \verb|TAYLORCOMBINE| tries to Taylor expand
  187. all non-Taylor subexpressions and to combine the result with the
  188. rest.
  189. \item \verb|TAYLORKEEPORIGINAL|, if set to \verb|ON|, forces the
  190. package to keep the original expression, i.e.\ the expression
  191. that was Taylor expanded. All operations performed on the
  192. Taylor kernels are also applied to this expression which can
  193. be recovered using the operator \verb|TAYLORORIGINAL|.
  194. \item \verb|TAYLORPRINTORDER|, if set to \verb|ON|, causes the
  195. remainder to be printed in big-$O$ notation. Otherwise, three
  196. dots are printed.
  197. \item There is also the switch \verb|VERBOSELOAD|. If it is set to
  198. \verb|ON|
  199. \REDUCE{} will print some information when the Taylor package is
  200. loaded. This switch is already present in \PSL{} systems.
  201. \end{itemize}
  202. All switches are normally off.
  203. \section{Warnings and error messages}
  204. \begin{itemize}
  205. \item \verb|Branch point detected in ...|\\
  206. This occurs if you take a rational power of a Taylor kernel
  207. and raising the lowest order term of the kernel to this
  208. power yields a non analytical term (i.e.\ a fractional power).
  209. \item \verb|Cannot expand further... truncation done|\\
  210. You will get this warning if you try to expand a Taylor kernel to
  211. a higher order.
  212. \item \verb|Error during expansion (possible singularity)|\\
  213. The expression you are trying to expand caused an error.
  214. As far as I know this can only happen if it contains a function
  215. with a pole or an essential singularity at the expansion point.
  216. (But one can never be sure.)
  217. \item \verb|Essential singularity in ...|\\
  218. An essential singularity was detected while applying a
  219. special function to a Taylor kernel.
  220. This error occurs, for example, if you try to take
  221. the logarithm of a Taylor kernel that starts with a negative
  222. power in one of its variables, i.e.\ that has a pole
  223. at the expansion point.
  224. \item \verb|Expansion point lies on branch cut in ...|\\
  225. The only functions with branch cuts this package knows of
  226. are (natural) logarithm, inverse circular and hyperbolic
  227. tangent and cotangent.
  228. The branch cut of the logarithm is assumed to lie on the negative
  229. real axis. Those of the arc tangent and arc cotangent
  230. functions are chosen to be compatible with this:
  231. both have essential singularities at the points $\pm i$.
  232. The branch cut of arc tangent is the straight line along the
  233. imaginary axis connecting $+1$ to $-1$ going through $\infty$ whereas
  234. that of arc cotangent goes through the origin.
  235. Consequently, the branch cut of the inverse hyperbolic
  236. tangent resp.\ cotangent lies on the real axis and goes from
  237. $-1$ to $+1$, that of the latter across
  238. $0$, the other across $\infty$.
  239. The error message can currently only appear when you try to
  240. calculate the inverse tangent or cotangent of a Taylor
  241. kernel that starts with a negative degree.
  242. The case of a logarithm of a Taylor kernel whose constant term
  243. is a negative real number is not caught since it is
  244. difficult to detect this in general.
  245. \item \verb|Not a unity in ...|\\
  246. This will happen if you try to divide by or take the logarithm of
  247. a Taylor series whose constant term vanishes.
  248. \item \verb|Not implemented yet (...)|\\
  249. Sorry, but I haven't had the time to implement this feature.
  250. Tell me if you really need it, maybe I have already an improved
  251. version of the package.
  252. \item \verb|Substitution of dependent variables ...|\\
  253. You tried to substitute a variable that is already present in the
  254. Taylor kernel or on which one of the Taylor variables depend.
  255. \item \verb|Taylor kernel doesn't have an original part|\\
  256. The Taylor kernel upon which you try to use \verb|TAYLORORIGINAL|
  257. was created with the switch \verb|TAYLORKEEPORIGINAL|
  258. set to \verb|OFF|
  259. and does therefore not keep the original expression.
  260. \item \verb|Wrong number of arguments (TAYLOR)|\\
  261. You try to use the operator \verb|TAYLOR| with a wrong number of
  262. arguments.
  263. \item \verb|Zero denominator in Taylor substitution|\\
  264. That's exactly what the message says. As an example consider the
  265. case of a Taylor kernel containing the term \verb|1/x| and you try
  266. to substitute \verb|x| by \verb|0|.
  267. \item \verb|... invalid as kernel|\\
  268. You tried to expand with respect to an expression that is not a
  269. kernel.
  270. \item \verb|... invalid as order of expansion|\\
  271. The order parameter you gave to \verb|TAYLOR| is not an integer.
  272. \item \verb|... invalid as Taylor kernel|\\
  273. You tried to apply \verb|TAYLORORIGINAL| or \verb|TAYLORTEMPLATE|
  274. to an expression that is not a Taylor kernel.
  275. \item \verb|... invalid as Taylor variable|\\
  276. You tried to substitute a Taylor variable by an expression that is
  277. not a kernel.
  278. \item \verb|TAYLOR PACKAGE (...): this can't happen ...|\\
  279. This message shows that an internal inconsistency was detected.
  280. This is not your fault, at least as long as you did not try to
  281. work with the internal data structures of \REDUCE. Send input
  282. and output to me, together with the version information that is
  283. printed out.
  284. \end{itemize}
  285. \section{Comparison to other packages}
  286. At the moment there is only one \REDUCE{} package that I know of:
  287. the truncated power series package by Alan Barnes and Julian Padget.
  288. In my opinion there are two major differences:
  289. \begin{itemize}
  290. \item The interface. They use the domain mechanism for their power
  291. series, I decided to invent a special kind of kernel. Both
  292. approaches have advantages and disadvantages: with domain
  293. modes, it is easier
  294. to do certain things automatically, e.g., conversions.
  295. \item The concept of a truncated series. Their idea is to remember
  296. the original expression and to compute more coefficients when
  297. more of them are needed. My approach is to truncate at a
  298. certain order and forget how the unexpanded expression
  299. looked like. I think that their method is more widely
  300. usable, whereas mine is more efficient when you know in
  301. advance exactly how many terms you need.
  302. \end{itemize}
  303. \MACSYMA{} has Taylor and power series packages. I don't know much
  304. about the general power series package but the Taylor package has some
  305. features that are still lacking here, e.g., correct treatment of
  306. known essential singularities. In \MACSYMA{} a Taylor series is a
  307. special object, a sort of extended rational expression recognized by
  308. all simplification functions. They also have a better user interface.
  309. E.g., you may define the Taylor expansion of an unknown function.
  310. \Mathematica's \verb|series| function can only handle power series of
  311. one variable. However, it is better in its handling of singularities.
  312. (I should add a comparison to \MAPLE.)
  313. \end{document}