rataprx.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. \documentstyle[11pt,reduce]{article}
  2. \title{{\bf Rational Approximations Package for REDUCE}}
  3. \author{Lisa Temme\\Wolfram Koepf\\ e-mail: {\tt koepf@zib.de}}
  4. \date{August 1995 : ZIB Berlin}
  5. \begin{document}
  6. \maketitle
  7. \section{Periodic Decimal Representation}
  8. The division of one integer by another often results in
  9. a period in the decimal part. The {\tt rational2periodic}
  10. function in this package can recognise and represent
  11. such an answer in a periodic representation. The inverse
  12. function, {\tt periodic2rational}, can also convert a
  13. periodic representation back to a rational number.\\
  14. \begin{tabbing}
  15. {\bf \underline{Periodic Representation of a Rational Number}}\\ \\
  16. {\bf SYNTAX:} \hspace{3mm}
  17. \= {\tt rational2periodic(n);}\\ \\
  18. {\bf INPUT:}
  19. \> {\tt n} \hspace{3mm} is a rational number\\ \\
  20. {\bf RESULT:}
  21. \> {\tt periodic(\{a,b\} , \{c1,...,cn\})} \\ \\
  22. \> where {\tt a/b} is the non-periodic part\\
  23. \> and {\tt c1,...,cn} are the digits of the periodic part.\\ \\
  24. {\bf EXAMPLE:}
  25. \> $59/70$ written as $0.8\overline{428571}$\\
  26. \> {\tt 1: rational2periodic(59/70);}\\ \\
  27. \> {\tt periodic(\{8,10\},\{4,2,8,5,7,1\})}\\ \\
  28. {\bf \underline{Rational Number of a Periodic Representation}}\\ \\
  29. {\bf SYNTAX:}
  30. \> {\tt periodic2rational(periodic(\{a,b\},\{c1,...,cn\}))}\\
  31. \> {\tt periodic2rational(\{a,b\},\{c1,...,cn\})}\\ \\
  32. {\bf INPUT:}
  33. \> \hspace{15mm} {\tt a} \hspace{3mm}\= is an integer\\
  34. \> \hspace{15mm} {\tt b} \> is $1$, $-1$ or an
  35. integer multiple of $10$\\
  36. \> {\tt c1,...,cn} \> is a list of positive digits\\ \\
  37. {\bf RESULT:}
  38. \> A rational number.\\ \\
  39. {\bf EXAMPLE:}
  40. \> $0.8\overline{428571}$ written as $59/70$ \\
  41. \> {\tt 2: periodic2rational(periodic(\{8,10\},\{4,2,8,5,7,1\}));}
  42. \\ \\
  43. \> \hspace{1mm} {\tt 59}\\
  44. \> {\tt ----}\\
  45. \> \hspace{1mm} {\tt 70}\\ \\
  46. \> {\tt 3: periodic2rational(\{8,10\},\{4,2,8,5,7,1\});}
  47. \\ \\
  48. \> \hspace{1mm} {\tt 59}\\
  49. \> {\tt ----}\\
  50. \> \hspace{1mm} {\tt 70}
  51. \end{tabbing}
  52. Note that if {\tt a} is zero, {\tt b} will indicate how many places
  53. after the decimal point that the period occurs. Note also that if the answer
  54. is negative then this will be indicated by the sign of {\tt a} (unless
  55. {\tt a} is zero in which case it is indicated by the sign of {\tt b}).
  56. \\ \\
  57. {\bf ERROR MESSAGE}\\
  58. {\tt ***** operator to be used in off rounded mode}\\
  59. The periodicity of a function can only be recognised in
  60. the {\tt off rounded} mode. This is also true for the inverse
  61. procedure.\\ \\
  62. {\large\bf EXAMPLES}\\
  63. \begin{verbatim}
  64. 4: rational2periodic(1/3);
  65. periodic({0,1},{3})
  66. 5: periodic2rational(ws);
  67. 1
  68. ---
  69. 3
  70. 6: periodic2rational({0,1},{3});
  71. 1
  72. ---
  73. 3
  74. 7: rational2periodic(-1/6);
  75. periodic({-1,10},{6})
  76. 8: periodic2rational(ws);
  77. - 1
  78. ------
  79. 6
  80. 9: rational2periodic(6/17);
  81. periodic({0,1},{3,5,2,9,4,1,1,7,6,4,7,0,5,8,8,2})
  82. 10: periodic2rational(ws);
  83. 6
  84. ----
  85. 17
  86. 11: rational2periodic(352673/3124);
  87. periodic({11289,100},{1,4,8,5,2,7,5,2,8,8,0,9,2,1,8,9,5,0,0,6,
  88. 4,0,2,0,4,8,6,5,5,5,6,9,7,8,2,3,3,0,3,4,
  89. 5,7,1,0,6,2,7,4,0,0,7,6,8,2,4,5,8,3,8,6,
  90. 6,8,3,7,3,8,7,9,6,4})
  91. 12: periodic2rational(ws);
  92. 352673
  93. --------
  94. 3124
  95. \end{verbatim}
  96. %\newpage
  97. \section{Continued Fractions}
  98. A continued fraction (see ~\cite{PA} \S 4.2) has the general form
  99. {\Large
  100. \[b_0 + \frac{a_1}{b_1 +
  101. \frac{a_2}{b_2+
  102. \frac{a_3}{b_3 + \ldots
  103. }}}
  104. \;.\]
  105. }
  106. A more compact way of writing this is as
  107. \[b_0 + \frac{a_1|}{|b_1} + \frac{a_2|}{|b_2} + \frac{a_3|}{|b_3} + \ldots\,.\]
  108. \\
  109. This is represented in {\small REDUCE} as
  110. \[{\tt
  111. contfrac({\sl Rational\hspace{2mm} approximant},
  112. \{b0, \{a1,b1\}, \{a2,b2\},.....\})
  113. }\]
  114. \begin{tabbing}
  115. \\
  116. {\bf SYNTAX:} \hspace{5mm}
  117. \= {\tt cfrac(number);}\\
  118. \> {\tt cfrac(number,length);}\\
  119. \> {\tt cfrac(f, var);}\\
  120. \> {\tt cfrac(f, var, length);}\\ \\
  121. {\bf INPUT:}
  122. \> {\tt number} \hspace{3mm} \= is any real number\\
  123. \> {\tt f} \> is a function\\
  124. \> {\tt var} \> is the function variable\\
  125. %\> {\tt length} \> is the upper bound of the number\\
  126. %\> \> of \{ai,bi\} returned (optional)\\ \\
  127. \end{tabbing}
  128. {\bf Optional Argument: {\tt length}}\\
  129. The {\tt length} argument is optional.
  130. For an NON-RATIONAL function input the {\tt length} argument specifies
  131. the number of ordered pairs, $\{a_i,b_i\}$, to be
  132. returned. It's default value is five.
  133. For a RATIONAL function input the
  134. {\tt length} argument can only truncate the answer, it cannot
  135. return additional pairs even if the precision is increased.
  136. The default value is the complete continued fraction of the
  137. rational input. For a NUMBER input the default value is
  138. dependent on the precision of the session, and the
  139. {\tt length} argument will only take effect if it has a smaller
  140. value than that of the number of ordered pairs which the default
  141. value would return.\\ \\
  142. %\newpage
  143. \large{{\bf EXAMPLES}}\\ \\
  144. \begin{verbatim}
  145. 13: cfrac(23.696);
  146. 2962
  147. contfrac(------,{23,{1,1},{1,2},{1,3},{1,2},{1,5}})
  148. 125
  149. 14: cfrac(23.696,3);
  150. 237
  151. contfrac(-----,{23,{1,1},{1,2},{1,3}})
  152. 10
  153. 15: cfrac pi;
  154. 1146408
  155. contfrac(---------,
  156. 364913
  157. {3,{1,7},{1,15},{1,1},{1,292},{1,1},{1,1},{1,1},{1,2},{1,1}})
  158. 16: cfrac(pi,3);
  159. 355
  160. contfrac(-----,{3,{1,7},{1,15},{1,1}})
  161. 113
  162. 17: cfrac(pi*e*sqrt(2),4);
  163. 10978
  164. contfrac(-------,{12,{1,12},{1,1},{1,68},{1,1}})
  165. 909
  166. 18: cfrac((x+2/3)^2/(6*x-5),x,1);
  167. 2
  168. 9*x + 12*x + 4 6*x + 13 24*x - 20
  169. contfrac(-----------------,{----------,{1,-----------}})
  170. 54*x - 45 36 9
  171. 19: cfrac((x+2/3)^2/(6*x-5),x,10);
  172. 2
  173. 9*x + 12*x + 4 6*x + 13 24*x - 20
  174. contfrac(-----------------,{----------,{1,-----------}})
  175. 54*x - 45 36 9
  176. 20: cfrac(e^x,x);
  177. 3 2
  178. x + 9*x + 36*x + 60
  179. contfrac(-----------------------,{1,{x,1},{ - x,2},{x,3},{ - x,2},{x,5}})
  180. 2
  181. 3*x - 24*x + 60
  182. 21: cfrac(x^2/(x-1)*e^x,x);
  183. 6 4 2
  184. x + 3*x + x
  185. contfrac(----------------,{0,
  186. 4 2
  187. 3*x - x - 1
  188. 2 2 2 2 2
  189. { - x ,1}, { - 2*x ,1}, {x ,1}, {x ,1}, {x ,1}})
  190. 22: cfrac(x^2/(x-1)*e^x,x,2);
  191. 2
  192. x 2 2
  193. contfrac(----------,{0,{ - x ,1},{ - 2*x ,1}})
  194. 2
  195. 2*x - 1
  196. \end{verbatim}
  197. %\newpage
  198. \section{Pad\'{e} Approximation}
  199. The Pad\'{e} approximant represents a function by the ratio of two
  200. polynomials. The coefficients of the powers occuring in the polynomials
  201. are determined by the coefficients in the Taylor series
  202. expansion of the function (see ~\cite{PA}). Given a power series
  203. \[ f(x) = c_0 + c_1 (x-h) + c_2 (x-h)^2 \ldots \]
  204. and the degree of numerator, $n$, and of the denominator, $d$,
  205. the {\tt pade} function finds the unique coefficients
  206. $a_i,\, b_i$ in the Pad\'{e} approximant
  207. \[ \frac{a_0+a_1 x+ \cdots + a_n x^n}{b_0+b_1 x+ \cdots + b_d x^d} \; .\]
  208. \\ \\
  209. \begin{tabbing}
  210. {\bf SYNTAX:} \hspace{5mm}\= {\tt pade(f, x, h, n, d);}\\ \\
  211. {\bf INPUT:}
  212. \> {\tt f} \hspace{3mm} \= is the funtion to be approximated\\
  213. \> {\tt x} \> is the function variable\\
  214. \> {\tt h} \> is the point at which the approximation is\\
  215. \> \> evaluated\\
  216. \> {\tt n} \> is the (specified) degree of the numerator\\
  217. \> {\tt d} \> is the (specified) degree of the denominator\\ \\
  218. {\bf RESULT:}
  219. \> Pad\a'{e} Approximant, ie. a rational function.\\ \\
  220. \end{tabbing}
  221. {\bf ERROR MESSAGES}\\
  222. {\tt ***** not yet implemented}\\
  223. The Taylor series expansion for the function, f, has not yet
  224. been implemented in the {\small REDUCE} Taylor Package.\\ \\
  225. {\tt ***** no Pade Approximation exists}\\
  226. A Pad\'{e} Approximant of this function does not exist.\\ \\
  227. \newpage
  228. {\tt ***** Pade Approximation of this order does not exist}\\
  229. A Pad\'{e} Approximant of this order (ie. the specified
  230. numerator and denominator orders) does not exist but one
  231. of a different order may exist.\\ \\
  232. \large{{\bf EXAMPLES}}
  233. \begin{verbatim}
  234. 23: pade(sin(x),x,0,3,3);
  235. 2
  236. x*( - 7*x + 60)
  237. ------------------
  238. 2
  239. 3*(x + 20)
  240. 24: pade(tanh(x),x,0,5,5);
  241. 4 2
  242. x*(x + 105*x + 945)
  243. -----------------------
  244. 4 2
  245. 15*(x + 28*x + 63)
  246. 25: pade(atan(x),x,0,5,5);
  247. 4 2
  248. x*(64*x + 735*x + 945)
  249. --------------------------
  250. 4 2
  251. 15*(15*x + 70*x + 63)
  252. 26: pade(exp(1/x),x,0,5,5);
  253. ***** no Pade Approximation exists
  254. 27: pade(factorial(x),x,1,3,3);
  255. ***** not yet implemented
  256. 28: pade(asech(x),x,0,3,3);
  257. 2 2 2
  258. - 3*log(x)*x + 8*log(x) + 3*log(2)*x - 8*log(2) + 2*x
  259. --------------------------------------------------------
  260. 2
  261. 3*x - 8
  262. 29: taylor(ws-asech(x),x,0,10);
  263. 11
  264. log(x)*(0 + O(x ))
  265. 13 6 43 8 1611 10 11
  266. + (-----*x + ------*x + -------*x + O(x ))
  267. 768 2048 81920
  268. 30: pade(sin(x)/x^2,x,0,10,0);
  269. ***** Pade Approximation of this order does not exist
  270. 31: pade(sin(x)/x^2,x,0,10,2);
  271. 10 8 6 4 2
  272. ( - x + 110*x - 7920*x + 332640*x - 6652800*x
  273. + 39916800)/(39916800*x)
  274. 32: pade(exp(x),x,0,10,10);
  275. 10 9 8 7 6
  276. (x + 110*x + 5940*x + 205920*x + 5045040*x
  277. 5 4 3
  278. + 90810720*x + 1210809600*x + 11762150400*x
  279. 2
  280. + 79394515200*x + 335221286400*x + 670442572800)/
  281. 10 9 8 7 6
  282. (x - 110*x + 5940*x - 205920*x + 5045040*x
  283. 5 4
  284. - 90810720*x + 1210809600*x
  285. 3 2
  286. - 11762150400*x + 79394515200*x
  287. - 335221286400*x + 670442572800)
  288. 33: pade(sin(sqrt(x)),x,0,3,3);
  289. (sqrt(x)*
  290. 3 2
  291. (56447*x - 4851504*x + 132113520*x - 885487680))\
  292. 3 2
  293. (7*(179*x - 7200*x - 2209680*x - 126498240))
  294. \end{verbatim}
  295. \begin{thebibliography}{9}
  296. \bibitem{PA} Baker(Jr.), George A. and Graves-Morris, Peter:\\
  297. {\it Pad\'{e} Approximants, Part I: Basic Theory},
  298. (Encyclopedia of mathematics and its applications, Vol 13,
  299. Section: Mathematics of physics),
  300. Addison-Wesley Publishing Company, Reading, Massachusetts, 1981.
  301. \end{thebibliography}
  302. \end{document}