taylor.tex 18 KB

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