TAYLOR.TEX 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. \documentstyle[11pt,reduce]{article}
  2. \newcommand{\MACSYMA}{{\sf MACSYMA}}
  3. \newcommand{\MAPLE}{{\sf MAPLE}}
  4. \newcommand{\Mathematica}{{\sf Mathematica}}
  5. \newcommand{\PSL}{{\sf PSL}}
  6. \title{A \REDUCE{} package for manipulation of Taylor series}
  7. \date{}
  8. \author{Rainer Sch\"opf\\
  9. Zentrum f\"ur Datenverarbeitung der Universit\"at Mainz\\
  10. Anselm-Franz-von-Bentzel-Weg~12\\
  11. D-55055 Mainz\\
  12. Germany\\
  13. E--mail: {\tt Schoepf@Uni-Mainz.DE}}
  14. \begin{document}
  15. \maketitle
  16. \index{Taylor Series} \index{TAYLOR package}
  17. \index{Laurent series}
  18. This short note describes a package of \REDUCE{} procedures that allow
  19. Taylor expansion in one or several variables, and efficient
  20. manipulation of the resulting Taylor series. Capabilities include
  21. basic operations (addition, subtraction, multiplication and division),
  22. and also application of certain algebraic and transcendental
  23. functions. To a certain extent, Laurent and Puiseux expansions can be
  24. performed as well. In many cases, separable singularities are detected
  25. and factored out.
  26. \section{Introduction}
  27. The Taylor package was written to provide \REDUCE{} with some of
  28. the facilities
  29. that \MACSYMA's \verb+TAYLOR+ function offers,
  30. but most of all I needed it to be faster and
  31. more space-efficient.
  32. Especially I wanted procedures that would return the logarithm or
  33. arc tangent of a Taylor series, again as a Taylor series.
  34. This turned out be more work than expected. The features absolutely
  35. required were (as usual) those that were hardest to implement,
  36. e.g., arc tangent applied to a Taylor expansion in more than
  37. one variable.
  38. This package is still undergoing development.
  39. I'll be happy if it is of any use for you.
  40. Tell me if you think that there is something missing.
  41. I invite everybody to criticize and comment and will eagerly try to
  42. correct any errors found.
  43. \section{How to use it}
  44. The most important operator is `\verb+TAYLOR+'. \index{TAYLOR operator}
  45. It is used as follows:
  46. \noindent {\tt TAYLOR}(EXP:{\em exprn}[,VAR:{\em kernel},
  47. VAR$_0$:{\em exprn},ORDER:{\em integer}]\ldots):{\em exprn}
  48. where EXP is the expression to be expanded. It can be any \REDUCE{}
  49. object, even an expression containing other Taylor kernels. VAR is
  50. the kernel with respect to which EXP is to be expanded. VAR$_0$
  51. denotes the point about which and ORDER the order up to which
  52. expansion is to take place. If more than one (VAR, VAR0, ORDER) triple
  53. is specified {\tt TAYLOR} will expand its first argument independently
  54. with respect to each variable in turn. For example,
  55. \begin{verbatim}
  56. taylor(e^(x^2+y^2),x,0,2,y,0,2);
  57. \end{verbatim}
  58. will calculate the Taylor expansion up to order $X^{2}*Y^{2}$.
  59. Note that once the expansion has been done it is not possible to
  60. calculate higher orders.
  61. Instead of a kernel, VAR may also
  62. be a list of kernels. In this case expansion will take place in a way
  63. so that the {\em sum\/} of the degrees of the kernels does not exceed
  64. ORDER.
  65. If VAR$_0$ evaluates to the special identifier \verb|INFINITY|
  66. {\tt TAYLOR} tries to expand EXP in a series in 1/VAR.
  67. The expansion is performed variable per variable, i.e.\ in the example
  68. above by first expanding $\exp(x^{2}+y^{2})$ with respect to $x$ and
  69. then expanding every coefficient with respect to $y$.
  70. \index{IMPLICIT\_TAYLOR operator}\index{INVERSE\_TAYLOR} There are two
  71. extra operators to compute the Taylor expansions of implicit and
  72. inverse functions:
  73. \noindent {\tt IMPLICIT\_TAYLOR}(F:{\em exprn},VAR1,VAR2:{\em kernel},\\
  74. \hphantom{{\tt IMPLICIT\_TAYLOR}(}VAR1$_0$,VAR2$_0$:{\em exprn},
  75. ORDER:{\em integer}):{\em exprn}
  76. takes a function F depending on two variables VAR1 and VAR2 and
  77. computes the Taylor series of the implicit function VAR2(VAR1)
  78. given by the equation F(VAR1,VAR2) = 0. For example,
  79. \begin{verbatim}
  80. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,5);
  81. \end{verbatim}
  82. \noindent {\tt INVERSE\_TAYLOR}(F:{\em exprn},VAR1,VAR2:{\em kernel},\\
  83. \hphantom{{\tt INVERSE\_TAYLOR}(}VAR1$_0$:{\em exprn},
  84. ORDER:{\em integer}):{\em exprn}
  85. takes a function F depending on VAR1 and computes the Taylor series of
  86. the inverse of F with respect to VAR2. For example,
  87. \begin{verbatim}
  88. inverse_taylor(exp(x)-1,x,y,0,8);
  89. \end{verbatim}
  90. \index{TAYLORPRINTTERMS variable}
  91. When a Taylor kernel is printed, only a certain number of (non-zero)
  92. coefficients are shown. If there are more, an expression of the form
  93. \verb|(|$n$\verb| terms)| is printed to indicate how many non-zero
  94. terms have been suppressed. The number of terms printed is given by
  95. the value of the shared algebraic variable \verb|TAYLORPRINTTERMS|.
  96. Allowed values are integers and the special identifier \verb|ALL|. The
  97. latter setting specifies that all terms are to be printed. The default
  98. setting is $5$.
  99. \index{TAYLORKEEPORIGINAL switch}
  100. If the switch \verb|TAYLORKEEPORIGINAL| is set to \verb|ON| the
  101. original expression EXP is kept for later reference.
  102. It can be recovered by means of the operator
  103. \hspace*{2em} {\tt TAYLORORIGINAL}(EXP:{\em exprn}):{\em exprn}
  104. An error is signalled if EXP is not a Taylor kernel or if the original
  105. expression was not kept, i.e.\ if \verb|TAYLORKEEPORIGINAL| was
  106. \verb|OFF| during expansion. The template of a Taylor kernel, i.e.\
  107. the list of all variables with respect to which expansion took place
  108. together with expansion point and order can be extracted using
  109. \ttindex{TAYLORTEMPLATE}
  110. \hspace*{2em} {\tt TAYLORTEMPLATE}(EXP:{\em exprn}):{\em list}
  111. This returns a list of lists with the three elements (VAR,VAR0,ORDER).
  112. As with \verb|TAYLORORIGINAL|,
  113. an error is signalled if EXP is not a Taylor kernel.
  114. \hspace*{2em} {\tt TAYLORTOSTANDARD}(EXP:{\em exprn}):{\em exprn}
  115. converts all Taylor kernels in EXP into standard form and
  116. \ttindex{TAYLORTOSTANDARD} resimplifies the result.
  117. \hspace*{2em} {\tt TAYLORSERIESP}(EXP:{\em exprn}):{\em boolean}
  118. may be used to determine if EXP is a Taylor kernel.
  119. \ttindex{TAYLORSERIESP} Note that this operator is subject to the same
  120. restrictions as, e.g., ORDP or NUMBERP, i.e.\ it may only be used in
  121. boolean expressions in \verb|IF| or \verb|LET| statements. Finally
  122. there is
  123. \hspace*{2em} {\tt TAYLORCOMBINE}(EXP:{\em exprn}):{\em exprn}
  124. which tries to combine all Taylor kernels found in EXP into one.
  125. \ttindex{TAYLORCOMBINE}
  126. Operations currently possible are:
  127. \index{Taylor series ! arithmetic}
  128. \begin{itemize}
  129. \item Addition, subtraction, multiplication, and division.
  130. \item Roots, exponentials, and logarithms.
  131. \item Trigonometric and hyperbolic functions and their inverses.
  132. \end{itemize}
  133. Application of unary operators like \verb|LOG| and \verb|ATAN| will
  134. nearly always succeed. For binary operations their arguments have to be
  135. Taylor kernels with the same template. This means that the expansion
  136. variable and the expansion point must match. Expansion order is not so
  137. important, different order usually means that one of them is truncated
  138. before doing the operation.
  139. \ttindex{TAYLORKEEPORIGINAL} \ttindex{TAYLORCOMBINE}
  140. If \verb|TAYLORKEEPORIGINAL| is set to \verb|ON| and if all Taylor
  141. kernels in \verb|exp| have their original expressions kept
  142. \verb|TAYLORCOMBINE| will also combine these and store the result
  143. as the original expression of the resulting Taylor kernel.
  144. \index{TAYLORAUTOEXPAND switch}
  145. There is also the switch \verb|TAYLORAUTOEXPAND| (see below).
  146. There are a few restrictions to avoid mathematically undefined
  147. expressions: it is not possible to take the logarithm of a Taylor
  148. kernel which has no terms (i.e. is zero), or to divide by such a
  149. beast. There are some provisions made to detect singularities during
  150. expansion: poles that arise because the denominator has zeros at the
  151. expansion point are detected and properly treated, i.e.\ the Taylor
  152. kernel will start with a negative power. (This is accomplished by
  153. expanding numerator and denominator separately and combining the
  154. results.) Essential singularities of the known functions (see above)
  155. are handled correctly.
  156. \index{Taylor series ! differentiation}
  157. Differentiation of a Taylor expression is possible. If you
  158. differentiate with respect to one of the Taylor variables the order
  159. will decrease by one.
  160. \index{Taylor series ! substitution}
  161. Substitution is a bit restricted: Taylor variables can only be replaced
  162. by other kernels. There is one exception to this rule: you can always
  163. substitute a Taylor variable by an expression that evaluates to a
  164. constant. Note that \REDUCE{} will not always be able to determine
  165. that an expression is constant.
  166. \index{Taylor series ! integration}
  167. Only simple taylor kernels can be integrated. More complicated
  168. expressions that contain Taylor kernels as parts of themselves are
  169. automatically converted into a standard representation by means of the
  170. TAYLORTOSTANDARD operator. In this case a suitable warning is printed.
  171. \index{Taylor series ! reversion} It is possible to revert a Taylor
  172. series of a function $f$, i.e., to compute the first terms of the
  173. expansion of the inverse of $f$ from the expansion of $f$. This is
  174. done by the operator
  175. \hspace*{2em} {\tt TAYLORREVERT}(EXP:{\em exprn},OLDVAR:{\em kernel},
  176. NEWVAR:{\em kernel}):{\em exprn}
  177. EXP must evaluate to a Taylor kernel with OLDVAR being one of its
  178. expansion variables. Example:
  179. \begin{verbatim}
  180. taylor (u - u**2, u, 0, 5);
  181. taylorrevert (ws, u, x);
  182. \end{verbatim}
  183. This package introduces a number of new switches:
  184. \begin{itemize}
  185. \index{TAYLORAUTOCOMBINE switch}
  186. \item If you set \verb|TAYLORAUTOCOMBINE| to \verb|ON| \REDUCE{}
  187. automatically combines Taylor expressions during the simplification
  188. process. This is equivalent to applying \verb|TAYLORCOMBINE| to
  189. every expression that contains Taylor kernels.
  190. Default is \verb|ON|.
  191. \index{TAYLORAUTOEXPAND switch}
  192. \item \verb|TAYLORAUTOEXPAND| makes Taylor expressions ``contagious''
  193. in the sense that \verb|TAYLORCOMBINE| tries to Taylor expand
  194. all non-Taylor subexpressions and to combine the result with the
  195. rest. Default is \verb|OFF|.
  196. \index{TAYLORKEEPORIGINAL switch}
  197. \item \verb|TAYLORKEEPORIGINAL|, if set to \verb|ON|, forces the
  198. package to keep the original expression, i.e.\ the expression
  199. that was Taylor expanded. All operations performed on the
  200. Taylor kernels are also applied to this expression which can
  201. be recovered using the operator \verb|TAYLORORIGINAL|.
  202. Default is \verb|OFF|.
  203. \index{TAYLORPRINTORDER switch}
  204. \item \verb|TAYLORPRINTORDER|, if set to \verb|ON|, causes the
  205. remainder to be printed in big-$O$ notation. Otherwise, three
  206. dots are printed. Default is \verb|ON|.
  207. \index{VERBOSELOAD switch}
  208. \item There is also the switch \verb|VERBOSELOAD|. If it is set to
  209. \verb|ON|
  210. \REDUCE{} will print some information when the Taylor package is
  211. loaded. This switch is already present in \PSL{} systems.
  212. Default is \verb|OFF|.
  213. \end{itemize}
  214. \index{defaults ! TAYLOR package}
  215. \section{Caveats}
  216. \index{caveats ! TAYLOR package}
  217. \verb|TAYLOR| should now always detect non-analytical expressions in
  218. its first argument. As an example, consider the function $xy/(x+y)$
  219. that is not analytical in the neighborhood of $(x,y) = (0,0)$: Trying
  220. to calculate
  221. \begin{verbatim}
  222. taylor(x*y/(x+y),x,0,2,y,0,2);
  223. \end{verbatim}
  224. causes an error
  225. \begin{verbatim}
  226. ***** Not a unit in argument to QUOTTAYLOR
  227. \end{verbatim}
  228. Note that it is not generally possible to apply the standard \REDUCE{}
  229. operators to a Taylor kernel. For example, \verb|PART|, \verb|COEFF|,
  230. or \verb|COEFFN| cannot be used. Instead, the expression at hand has
  231. to be converted to standard form first using the \verb|TAYLORTOSTANDARD|
  232. operator.
  233. \section{Warnings and error messages}
  234. \index{errors ! TAYLOR package}
  235. \begin{itemize}
  236. \item \verb|Branch point detected in ...|\\
  237. This occurs if you take a rational power of a Taylor kernel
  238. and raising the lowest order term of the kernel to this
  239. power yields a non analytical term (i.e.\ a fractional power).
  240. \item \verb|Cannot expand further... truncation done|\\
  241. You will get this warning if you try to expand a Taylor kernel to
  242. a higher order.
  243. \item \verb|Computation loops (recursive definition?): ...|\\
  244. Most probably the expression to be expanded contains an operator
  245. whose derivative involves the operator itself.
  246. \item \verb|Converting Taylor kernels to standard representation|\\
  247. This warning appears if you try to integrate an expression that
  248. contains Taylor kernels.
  249. \item \verb|Error during expansion (possible singularity)|\\
  250. The expression you are trying to expand caused an error.
  251. As far as I know this can only happen if it contains a function
  252. with a pole or an essential singularity at the expansion point.
  253. (But one can never be sure.)
  254. \item \verb|Essential singularity in ...|\\
  255. An essential singularity was detected while applying a
  256. special function to a Taylor kernel.
  257. \item \verb|Expansion point lies on branch cut in ...|\\
  258. The only functions with branch cuts this package knows of are
  259. (natural) logarithm, inverse circular and hyperbolic tangent and
  260. cotangent. The branch cut of the logarithm is assumed to lie on
  261. the negative real axis. Those of the arc tangent and arc
  262. cotangent functions are chosen to be compatible with this: both
  263. have essential singularities at the points $\pm i$. The branch
  264. cut of arc tangent is the straight line along the imaginary axis
  265. connecting $+1$ to $-1$ going through $\infty$ whereas that of arc
  266. cotangent goes through the origin. Consequently, the branch cut
  267. of the inverse hyperbolic tangent resp.\ cotangent lies on the
  268. real axis and goes from $-1$ to $+1$, that of the latter across
  269. $0$, the other across $\infty$.
  270. The error message can currently only appear when you try to
  271. calculate the inverse tangent or cotangent of a Taylor
  272. kernel that starts with a negative degree.
  273. The case of a logarithm of a Taylor kernel whose constant term
  274. is a negative real number is not caught since it is
  275. difficult to detect this in general.
  276. \item \verb|Invalid substitution in Taylor kernel: ...|\\
  277. You tried to substitute a variable that is already present in the
  278. Taylor kernel or on which one of the Taylor variables depend.
  279. \item \verb|Not a unity in ...|\\
  280. This will happen if you try to divide by or take the logarithm of
  281. a Taylor series whose constant term vanishes.
  282. \item \verb|Not implemented yet (...)|\\
  283. Sorry, but I haven't had the time to implement this feature.
  284. Tell me if you really need it, maybe I have already an improved
  285. version of the package.
  286. \item \verb|Reversion of Taylor series not possible: ...|\\
  287. \ttindex{TAYLORREVERT}
  288. You tried to call the \verb|TAYLORREVERT| operator with
  289. inappropriate arguments. The second half of this error message
  290. tells you why this operation is not possible.
  291. \item \verb|Taylor kernel doesn't have an original part|\\
  292. \ttindex{TAYLORORIGINAL} \ttindex{TAYLORKEEPORIGINAL}
  293. The Taylor kernel upon which you try to use \verb|TAYLORORIGINAL|
  294. was created with the switch \verb|TAYLORKEEPORIGINAL|
  295. set to \verb|OFF|
  296. and does therefore not keep the original expression.
  297. \item \verb|Wrong number of arguments to TAYLOR|\\
  298. You try to use the operator \verb|TAYLOR| with a wrong number of
  299. arguments.
  300. \item \verb|Zero divisor in TAYLOREXPAND|\\
  301. A zero divisor was found while an expression was being expanded.
  302. This should not normally occur.
  303. \item \verb|Zero divisor in Taylor substitution|\\
  304. That's exactly what the message says. As an example consider the
  305. case of a Taylor kernel containing the term \verb|1/x| and you try
  306. to substitute \verb|x| by \verb|0|.
  307. \item \verb|... invalid as kernel|\\
  308. You tried to expand with respect to an expression that is not a
  309. kernel.
  310. \item \verb|... invalid as order of Taylor expansion|\\
  311. The order parameter you gave to \verb|TAYLOR| is not an integer.
  312. \item \verb|... invalid as Taylor kernel|\\
  313. \ttindex{TAYLORORIGINAL} \ttindex{TAYLORTEMPLATE}
  314. You tried to apply \verb|TAYLORORIGINAL| or \verb|TAYLORTEMPLATE|
  315. to an expression that is not a Taylor kernel.
  316. \item \verb|... invalid as Taylor variable|\\
  317. You tried to substitute a Taylor variable by an expression that is
  318. not a kernel.
  319. \item \verb|... invalid as value of TaylorPrintTerms|\\
  320. \ttindex{TAYLORPRINTTERMS}
  321. You have assigned an invalid value to \verb|TAYLORPRINTTERMS|.
  322. Allowed values are: an integer or the special identifier
  323. \verb|ALL|.
  324. \item \verb|TAYLOR PACKAGE (...): this can't happen ...|\\
  325. This message shows that an internal inconsistency was detected.
  326. This is not your fault, at least as long as you did not try to
  327. work with the internal data structures of \REDUCE. Send input
  328. and output to me, together with the version information that is
  329. printed out.
  330. \end{itemize}
  331. \section{Comparison to other packages}
  332. At the moment there is only one \REDUCE{} package that I know of:
  333. the truncated power series package by Alan Barnes and Julian Padget.
  334. In my opinion there are two major differences:
  335. \begin{itemize}
  336. \item The interface. They use the domain mechanism for their power
  337. series, I decided to invent a special kind of kernel. Both
  338. approaches have advantages and disadvantages: with domain
  339. modes, it is easier
  340. to do certain things automatically, e.g., conversions.
  341. \item The concept of a truncated series. Their idea is to remember
  342. the original expression and to compute more coefficients when
  343. more of them are needed. My approach is to truncate at a
  344. certain order and forget how the unexpanded expression
  345. looked like. I think that their method is more widely
  346. usable, whereas mine is more efficient when you know in
  347. advance exactly how many terms you need.
  348. \end{itemize}
  349. \end{document}