taylor.rlg 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497
  1. Tue Feb 10 12:29:11 2004 run on Linux
  2. comment
  3. Test and demonstration file for the Taylor expansion package,
  4. by Rainer M. Schoepf. Works with version 2.2a (01-Apr-2000);
  5. %%% showtime;
  6. on errcont;
  7. % disable interruption on errors
  8. comment Simple Taylor expansion;
  9. xx := taylor (e**x, x, 0, 4);
  10. 1 2 1 3 1 4 5
  11. xx := 1 + x + ---*x + ---*x + ----*x + O(x )
  12. 2 6 24
  13. yy := taylor (e**y, y, 0, 4);
  14. 1 2 1 3 1 4 5
  15. yy := 1 + y + ---*y + ---*y + ----*y + O(y )
  16. 2 6 24
  17. comment Basic operations, i.e. addition, subtraction, multiplication,
  18. and division are possible: this is not done automatically if
  19. the switch TAYLORAUTOCOMBINE is OFF. In this case it is
  20. necessary to use taylorcombine;
  21. taylorcombine (xx**2);
  22. 2 4 3 2 4 5
  23. 1 + 2*x + 2*x + ---*x + ---*x + O(x )
  24. 3 3
  25. taylorcombine (ws - xx);
  26. 3 2 7 3 5 4 5
  27. x + ---*x + ---*x + ---*x + O(x )
  28. 2 6 8
  29. taylorcombine (xx**3);
  30. 9 2 9 3 27 4 5
  31. 1 + 3*x + ---*x + ---*x + ----*x + O(x )
  32. 2 2 8
  33. comment The result is again a Taylor kernel;
  34. if taylorseriesp ws then write "OK";
  35. OK
  36. comment It is not possible to combine Taylor kernels that were
  37. expanded with respect to different variables;
  38. taylorcombine (xx**yy);
  39. 1 2 1 3 1 4 5
  40. (1 + x + ---*x + ---*x + ----*x + O(x ))
  41. 2 6 24
  42. 1 2 1 3 1 4 5
  43. **(1 + y + ---*y + ---*y + ----*y + O(y ))
  44. 2 6 24
  45. comment But we can take the exponential or the logarithm
  46. of a Taylor kernel;
  47. taylorcombine (e**xx);
  48. 2 5*e 3 5*e 4 5
  49. e + e*x + e*x + -----*x + -----*x + O(x )
  50. 6 8
  51. taylorcombine log ws;
  52. 1 2 1 3 1 4 5
  53. 1 + x + ---*x + ---*x + ----*x + O(x )
  54. 2 6 24
  55. comment A more complicated example;
  56. hugo := taylor(log(1/(1-x)),x,0,5);
  57. 1 2 1 3 1 4 1 5 6
  58. hugo := x + ---*x + ---*x + ---*x + ---*x + O(x )
  59. 2 3 4 5
  60. taylorcombine(exp(hugo/(1+hugo)));
  61. 1 4 6
  62. 1 + x + ----*x + O(x )
  63. 12
  64. comment We may try to expand about another point;
  65. taylor (xx, x, 1, 2);
  66. 65 8 5 2 3
  67. ---- + ---*(x - 1) + ---*(x - 1) + O((x - 1) )
  68. 24 3 4
  69. comment Arc tangent is one of the functions this package knows of;
  70. xxa := taylorcombine atan ws;
  71. 65 1536 2933040 2 3
  72. xxa := atan(----) + ------*(x - 1) - ----------*(x - 1) + O((x - 1) )
  73. 24 4801 23049601
  74. comment The trigonometric functions;
  75. taylor (tan x / x, x, 0, 2);
  76. 1 2 3
  77. 1 + ---*x + O(x )
  78. 3
  79. taylorcombine sin ws;
  80. cos(1) 2 3
  81. sin(1) + --------*x + O(x )
  82. 3
  83. taylor (cot x / x, x, 0, 4);
  84. -2 1 1 2 2 4 5
  85. x - --- - ----*x - -----*x + O(x )
  86. 3 45 945
  87. comment The poles of these functions are correctly handled;
  88. taylor(tan x,x,pi/2,0);
  89. pi -1 pi
  90. - (x - ----) + O(x - ----)
  91. 2 2
  92. taylor(tan x,x,pi/2,3);
  93. pi -1 1 pi 1 pi 3 pi 4
  94. - (x - ----) + ---*(x - ----) + ----*(x - ----) + O((x - ----) )
  95. 2 3 2 45 2 2
  96. comment Expansion with respect to more than one kernel is possible;
  97. xy := taylor (e**(x+y), x, 0, 2, y, 0, 2);
  98. 1 2 3 3
  99. xy := 1 + y + ---*y + x + y*x + (4 terms) + O(x ,y )
  100. 2
  101. taylorcombine (ws**2);
  102. 2 3 3
  103. 1 + 2*y + 2*y + 2*x + 4*y*x + (4 terms) + O(x ,y )
  104. comment We take the inverse and convert back to REDUCE's standard
  105. representation;
  106. taylorcombine (1/ws);
  107. 2 3 3
  108. 1 - 2*x + 2*x - 2*y + 4*y*x + (4 terms) + O(x ,y )
  109. taylortostandard ws;
  110. 2 2 2 2 2 2
  111. 4*x *y - 4*x *y + 2*x - 4*x*y + 4*x*y - 2*x + 2*y - 2*y + 1
  112. comment Some examples of Taylor kernel divsion;
  113. xx1 := taylor (sin (x), x, 0, 4);
  114. 1 3 5
  115. xx1 := x - ---*x + O(x )
  116. 6
  117. taylorcombine (xx/xx1);
  118. -1 2 1 2 3
  119. x + 1 + ---*x + ---*x + O(x )
  120. 3 3
  121. taylorcombine (1/xx1);
  122. -1 1 3
  123. x + ---*x + O(x )
  124. 6
  125. tt1 := taylor (exp (x), x, 0, 3);
  126. 1 2 1 3 4
  127. tt1 := 1 + x + ---*x + ---*x + O(x )
  128. 2 6
  129. tt2 := taylor (sin (x), x, 0, 3);
  130. 1 3 4
  131. tt2 := x - ---*x + O(x )
  132. 6
  133. tt3 := taylor (1 + tt2, x, 0, 3);
  134. 1 3 4
  135. tt3 := 1 + x - ---*x + O(x )
  136. 6
  137. taylorcombine(tt1/tt2);
  138. -1 2 2
  139. x + 1 + ---*x + O(x )
  140. 3
  141. taylorcombine(tt1/tt3);
  142. 1 2 1 3 4
  143. 1 + ---*x - ---*x + O(x )
  144. 2 6
  145. taylorcombine(tt2/tt1);
  146. 2 1 3 4
  147. x - x + ---*x + O(x )
  148. 3
  149. taylorcombine(tt3/tt1);
  150. 1 2 1 3 4
  151. 1 - ---*x + ---*x + O(x )
  152. 2 6
  153. comment Here's what I call homogeneous expansion;
  154. xx := taylor (e**(x*y), {x,y}, 0, 2);
  155. 3
  156. xx := 1 + y*x + O({x,y} )
  157. xx1 := taylor (sin (x+y), {x,y}, 0, 2);
  158. 3
  159. xx1 := y + x + O({x,y} )
  160. xx2 := taylor (cos (x+y), {x,y}, 0, 2);
  161. 1 2 1 2 3
  162. xx2 := 1 - ---*y - y*x - ---*x + O({x,y} )
  163. 2 2
  164. temp := taylorcombine (xx/xx2);
  165. 1 2 1 2 3
  166. temp := 1 + ---*y + 2*y*x + ---*x + O({x,y} )
  167. 2 2
  168. taylorcombine (ws*xx2);
  169. 3
  170. 1 + y*x + O({x,y} )
  171. comment The following shows a principal difficulty:
  172. since xx1 is symmetric in x and y but has no constant term
  173. it is impossible to compute 1/xx1;
  174. taylorcombine (1/xx1);
  175. ***** Not a unit in argument to invtaylor
  176. comment Substitution in Taylor expressions is possible;
  177. sub (x=z, xy);
  178. 1 2 3 3
  179. 1 + y + ---*y + z + y*z + (4 terms) + O(z ,y )
  180. 2
  181. comment Expression dependency in substitution is detected;
  182. sub (x=y, xy);
  183. ***** Invalid substitution in Taylor kernel: dependent variables y y
  184. comment It is possible to replace a Taylor variable by a constant;
  185. sub (x=4, xy);
  186. 13 2 3
  187. 13 + 13*y + ----*y + O(y )
  188. 2
  189. sub (x=4, xx1);
  190. 3
  191. 4 + y + O(y )
  192. sub (y=0, ws);
  193. 4
  194. comment This package has three switches:
  195. TAYLORKEEPORIGINAL, TAYLORAUTOEXPAND, and TAYLORAUTOCOMBINE;
  196. on taylorkeeporiginal;
  197. temp := taylor (e**(x+y), x, 0, 5);
  198. y y y
  199. y y e 2 e 3 e 4 6
  200. temp := e + e *x + ----*x + ----*x + ----*x + (1 term) + O(x )
  201. 2 6 24
  202. taylorcombine (log (temp));
  203. 6
  204. y + x + O(x )
  205. taylororiginal ws;
  206. x + y
  207. taylorcombine (temp * e**x);
  208. y y y
  209. x y y e 2 e 3 e 4 6
  210. e *(e + e *x + ----*x + ----*x + ----*x + (1 term) + O(x ))
  211. 2 6 24
  212. on taylorautoexpand;
  213. taylorcombine ws;
  214. y y
  215. y y y 2 4*e 3 2*e 4 6
  216. e + 2*e *x + 2*e *x + ------*x + ------*x + (1 term) + O(x )
  217. 3 3
  218. taylororiginal ws;
  219. 2*x + y
  220. e
  221. taylorcombine (xx1 / x);
  222. -1 2
  223. y*x + 1 + O({x,y} )
  224. on taylorautocombine;
  225. xx / xx2;
  226. 1 2 1 2 3
  227. 1 + ---*y + 2*y*x + ---*x + O({x,y} )
  228. 2 2
  229. ws * xx2;
  230. 3
  231. 1 + y*x + O({x,y} )
  232. comment Another example that shows truncation if Taylor kernels
  233. of different expansion order are combined;
  234. comment First we increase the number of terms to be printed;
  235. taylorprintterms := all;
  236. taylorprintterms := all
  237. p := taylor (x**2 + 2, x, 0, 10);
  238. 2 11
  239. p := 2 + x + O(x )
  240. p - x**2;
  241. 2 11 2
  242. (2 + x + O(x )) - x
  243. p - taylor (x**2, x, 0, 5);
  244. 6
  245. 2 + O(x )
  246. taylor (p - x**2, x, 0, 6);
  247. 7
  248. 2 + O(x )
  249. off taylorautocombine;
  250. taylorcombine(p-x**2);
  251. 11
  252. 2 + O(x )
  253. taylorcombine(p - taylor(x**2,x,0,5));
  254. 6
  255. 2 + O(x )
  256. comment Switch back to finite number of terms;
  257. taylorprintterms := 6;
  258. taylorprintterms := 6
  259. comment Some more examples;
  260. taylor(1/(1+y^4+x^2*y^2+x^4),{x,y},0,6);
  261. 4 2 2 4 7
  262. 1 - y - y *x - x + O({x,y} )
  263. taylor ((1 + x)**n, x, 0, 3);
  264. 2
  265. n*(n - 1) 2 n*(n - 3*n + 2) 3 4
  266. 1 + n*x + -----------*x + ------------------*x + O(x )
  267. 2 6
  268. taylor (e**(-a*t) * (1 + sin(t)), t, 0, 4);
  269. 3 2
  270. a*(a - 2) 2 - a + 3*a - 1 3
  271. 1 + ( - a + 1)*t + -----------*t + ------------------*t
  272. 2 6
  273. 3 2
  274. a*(a - 4*a + 4) 4 5
  275. + -------------------*t + O(t )
  276. 24
  277. operator f;
  278. taylor (1 + f(t), t, 0, 3);
  279. sub(t=0,df(f(t),t,2)) 2
  280. f(0) + 1 + sub(t=0,df(f(t),t))*t + -----------------------*t
  281. 2
  282. sub(t=0,df(f(t),t,3)) 3 4
  283. + -----------------------*t + O(t )
  284. 6
  285. taylor(f(sqrt(x^2+y^2)),x,x0,4,y,y0,4);
  286. 2 2 2 2
  287. f(sqrt(x0 + y0 )) + sub(y=y0,df(f(sqrt(x0 + y )),y))*(y - y0)
  288. 2 2
  289. sub(y=y0,df(f(sqrt(x0 + y )),y,2)) 2
  290. + -------------------------------------*(y - y0)
  291. 2
  292. 2 2
  293. sub(y=y0,df(f(sqrt(x0 + y )),y,3)) 3
  294. + -------------------------------------*(y - y0)
  295. 6
  296. 2 2
  297. sub(y=y0,df(f(sqrt(x0 + y )),y,4)) 4
  298. + -------------------------------------*(y - y0)
  299. 24
  300. 2 2
  301. + sub(x=x0,df(f(sqrt(x + y0 )),x))*(x - x0) + (19 terms)
  302. 5 5
  303. + O((x - x0) ,(y - y0) )
  304. clear f;
  305. taylor (sqrt(1 + a*x + sin(x)), x, 0, 3);
  306. 2 3 2
  307. a + 1 - a - 2*a - 1 2 3*a + 9*a + 9*a - 1 3 4
  308. 1 + -------*x + -----------------*x + -----------------------*x + O(x )
  309. 2 8 48
  310. taylorcombine (ws**2);
  311. 1 3 4
  312. 1 + (a + 1)*x - ---*x + O(x )
  313. 6
  314. taylor (sqrt(1 + x), x, 0, 5);
  315. 1 1 2 1 3 5 4 7 5 6
  316. 1 + ---*x - ---*x + ----*x - -----*x + -----*x + O(x )
  317. 2 8 16 128 256
  318. taylor ((cos(x) - sec(x))^3, x, 0, 5);
  319. 6
  320. 0 + O(x )
  321. taylor ((cos(x) - sec(x))^-3, x, 0, 5);
  322. -6 1 -4 11 -2 347 6767 2 15377 4 6
  323. - x + ---*x + -----*x - ------- - --------*x - ---------*x + O(x )
  324. 2 120 15120 604800 7983360
  325. taylor (sqrt(1 - k^2*sin(x)^2), x, 0, 6);
  326. 2 2 2 2 4 2
  327. k 2 k *( - 3*k + 4) 4 k *( - 45*k + 60*k - 16) 6 7
  328. 1 - ----*x + ------------------*x + ----------------------------*x + O(x )
  329. 2 24 720
  330. taylor (sin(x + y), x, 0, 3, y, 0, 3);
  331. 1 3 1 2 1 2 1 2 3 4 4
  332. x - ---*x + y - ---*y*x - ---*y *x + ----*y *x + (2 terms) + O(x ,y )
  333. 6 2 2 12
  334. taylor (e^x - 1 - x,x,0,6);
  335. 1 2 1 3 1 4 1 5 1 6 7
  336. ---*x + ---*x + ----*x + -----*x + -----*x + O(x )
  337. 2 6 24 120 720
  338. taylorcombine sqrt ws;
  339. 1 1 2 1 3 1 4
  340. ---------*x + -----------*x + ------------*x + -------------*x
  341. sqrt(2) 6*sqrt(2) 36*sqrt(2) 270*sqrt(2)
  342. 1 5 6
  343. + --------------*x + O(x )
  344. 2592*sqrt(2)
  345. taylor(sin(x)/x,x,1,2);
  346. - 2*cos(1) + sin(1) 2
  347. sin(1) + (cos(1) - sin(1))*(x - 1) + ----------------------*(x - 1)
  348. 2
  349. 3
  350. + O((x - 1) )
  351. taylor((sqrt(4+h)-2)/h,h,0,5);
  352. 1 1 1 2 5 3 7 4 21 5 6
  353. --- - ----*h + -----*h - -------*h + --------*h - ---------*h + O(h )
  354. 4 64 512 16384 131072 2097152
  355. taylor((sqrt(x)-2)/(4-x),x,4,2);
  356. 1 1 1 2 3
  357. - --- + ----*(x - 4) - -----*(x - 4) + O((x - 4) )
  358. 4 64 512
  359. taylor((sqrt(y+4)-2)/(-y),y,0,2);
  360. 1 1 1 2 3
  361. - --- + ----*y - -----*y + O(y )
  362. 4 64 512
  363. taylor(x*tanh(x)/(sqrt(1-x^2)-1),x,0,3);
  364. 7 2 4
  365. - 2 + ---*x + O(x )
  366. 6
  367. taylor((e^(5*x)-2*x)^(1/x),x,0,2);
  368. 3
  369. 3 3 73*e 2 3
  370. e + 8*e *x + -------*x + O(x )
  371. 3
  372. taylor(sin x/cos x,x,pi/2,3);
  373. pi -1 1 pi 1 pi 3 pi 4
  374. - (x - ----) + ---*(x - ----) + ----*(x - ----) + O((x - ----) )
  375. 2 3 2 45 2 2
  376. taylor(log x*sin(x^2)/(x*sinh x),x,0,2);
  377. 1 2 3
  378. log(x)*(1 - ---*x + O(x ))
  379. 6
  380. taylor(1/x-1/sin x,x,0,2);
  381. 1 3
  382. - ---*x + O(x )
  383. 6
  384. taylor(tan x/log cos x,x,pi/2,2);
  385. pi -1 pi
  386. - (x - ----) + O(x - ----)
  387. 2 2
  388. -------------------------------
  389. log(pi - 2*x) - log(2)
  390. taylor(log(x^2/(x^2-a)),x,0,3);
  391. 2
  392. - x
  393. taylor(log(--------),x,0,3)
  394. 2
  395. a - x
  396. comment Three more complicated examples contributed by Stan Kameny;
  397. zz2 := (z*(z-2*pi*i)*(z-pi*i/2)^2)/(sinh z-i);
  398. 3 2 2 3
  399. z*(2*i*pi - 12*i*pi*z - 9*pi *z + 4*z )
  400. zz2 := -------------------------------------------
  401. 4*(sinh(z) - i)
  402. dz2 := df(zz2,z);
  403. 3 3 2 2
  404. dz2 := ( - 2*cosh(z)*i*pi *z + 12*cosh(z)*i*pi*z + 9*cosh(z)*pi *z
  405. 4 3 2
  406. - 4*cosh(z)*z + 2*sinh(z)*i*pi - 36*sinh(z)*i*pi*z
  407. 2 3 2 3 3
  408. - 18*sinh(z)*pi *z + 16*sinh(z)*z + 18*i*pi *z - 16*i*z + 2*pi
  409. 2 2
  410. - 36*pi*z )/(4*(sinh(z) - 2*sinh(z)*i - 1))
  411. z0 := pi*i/2;
  412. i*pi
  413. z0 := ------
  414. 2
  415. taylor(dz2,z,z0,6);
  416. 2
  417. i*(pi - 16) i*pi pi i*pi 2
  418. - 2*pi + --------------*(z - ------) + ----*(z - ------)
  419. 4 2 2 2
  420. 2
  421. i*( - 3*pi + 80) i*pi 3 pi i*pi 4
  422. + -------------------*(z - ------) - ----*(z - ------)
  423. 120 2 24 2
  424. 2
  425. i*(5*pi - 168) i*pi 5 i*pi 7
  426. + -----------------*(z - ------) + (1 term) + O((z - ------) )
  427. 3360 2 2
  428. zz3:=(z*(z-2*pi)*(z-pi/2)^2)/(sin z-1);
  429. 3 2 2 3
  430. z*( - 2*pi + 9*pi *z - 12*pi*z + 4*z )
  431. zz3 := ------------------------------------------
  432. 4*(sin(z) - 1)
  433. dz3 := df(zz3,z);
  434. 3 2 2 3 4
  435. dz3 := (2*cos(z)*pi *z - 9*cos(z)*pi *z + 12*cos(z)*pi*z - 4*cos(z)*z
  436. 3 2 2 3
  437. - 2*sin(z)*pi + 18*sin(z)*pi *z - 36*sin(z)*pi*z + 16*sin(z)*z
  438. 3 2 2 3 2
  439. + 2*pi - 18*pi *z + 36*pi*z - 16*z )/(4*(sin(z) - 2*sin(z) + 1))
  440. z1 := pi/2;
  441. pi
  442. z1 := ----
  443. 2
  444. taylor(dz3,z,z1,6);
  445. 2 2
  446. pi - 16 pi pi pi 2 3*pi - 80 pi 3
  447. 2*pi + ----------*(z - ----) + ----*(z - ----) + ------------*(z - ----)
  448. 4 2 2 2 120 2
  449. 2
  450. pi pi 4 5*pi - 168 pi 5 pi 7
  451. + ----*(z - ----) + -------------*(z - ----) + (1 term) + O((z - ----) )
  452. 24 2 3360 2 2
  453. taylor((sin tan x-tan sin x)/(asin atan x-atan asin x),x,0,6);
  454. 5 2 1313 4 2773 6 7
  455. 1 + ---*x + ------*x - -------*x + O(x )
  456. 3 1890 11907
  457. comment If the expansion point is not constant, it has to be taken
  458. care of in differentation, as the following examples show;
  459. taylor(sin(x+a),x,a,8);
  460. sin(2*a) 2 cos(2*a) 3
  461. sin(2*a) + cos(2*a)*(x - a) - ----------*(x - a) - ----------*(x - a)
  462. 2 6
  463. sin(2*a) 4 cos(2*a) 5 9
  464. + ----------*(x - a) + ----------*(x - a) + (3 terms) + O((x - a) )
  465. 24 120
  466. df(ws,a);
  467. cos(2*a) 2 sin(2*a) 3
  468. cos(2*a) - sin(2*a)*(x - a) - ----------*(x - a) + ----------*(x - a)
  469. 2 6
  470. cos(2*a) 4 sin(2*a) 5 8
  471. + ----------*(x - a) - ----------*(x - a) + (2 terms) + O((x - a) )
  472. 24 120
  473. taylor(cos(x+a),x,a,7);
  474. cos(2*a) 2 sin(2*a) 3
  475. cos(2*a) - sin(2*a)*(x - a) - ----------*(x - a) + ----------*(x - a)
  476. 2 6
  477. cos(2*a) 4 sin(2*a) 5 8
  478. + ----------*(x - a) - ----------*(x - a) + (2 terms) + O((x - a) )
  479. 24 120
  480. comment A problem are non-analytical terms: rational powers and
  481. logarithmic terms can be handled, but other types of essential
  482. singularities cannot;
  483. taylor(sqrt(x),x,0,2);
  484. 1/2 3
  485. x + O(x )
  486. taylor(asinh(1/x),x,0,5);
  487. 1 2 3 4 5 6 7
  488. - log(x) + (log(2) + ---*x - ----*x + ----*x + O(x ))
  489. 4 32 96
  490. taylor(e**(1/x),x,0,2);
  491. 1/x
  492. taylor(e ,x,0,2)
  493. comment Another example for non-integer powers;
  494. sub (y = sqrt (x), yy);
  495. 1/2 1 1 3/2 1 2 5/2
  496. 1 + x + ---*x + ---*x + ----*x + O(x )
  497. 2 6 24
  498. comment Expansion about infinity is possible in principle...;
  499. taylor (e**(1/x), x, infinity, 5);
  500. 1 1 1 1 1 1 1 1 1 1
  501. 1 + --- + ---*---- + ---*---- + ----*---- + -----*---- + O(----)
  502. x 2 2 6 3 24 4 120 5 6
  503. x x x x x
  504. xi := taylor (sin (1/x), x, infinity, 5);
  505. 1 1 1 1 1 1
  506. xi := --- - ---*---- + -----*---- + O(----)
  507. x 6 3 120 5 6
  508. x x x
  509. y1 := taylor(x/(x-1), x, infinity, 3);
  510. 1 1 1 1
  511. y1 := 1 + --- + ---- + ---- + O(----)
  512. x 2 3 4
  513. x x x
  514. z := df(y1, x);
  515. 1 1 1 1
  516. z := - ---- - 2*---- - 3*---- + O(----)
  517. 2 3 4 5
  518. x x x x
  519. comment ...but far from being perfect;
  520. taylor (1 / sin (x), x, infinity, 5);
  521. 1
  522. taylor(--------,x,infinity,5)
  523. sin(x)
  524. clear z;
  525. comment You may access the expansion with the PART operator;
  526. part(yy,0);
  527. plus
  528. part(yy,1);
  529. 1
  530. part(yy,4);
  531. 3
  532. y
  533. ----
  534. 6
  535. part(yy,6);
  536. ***** Expression taylor(1 + y + 1/2*y**2 + 1/6*y**3 + 1/24*y**4,y,0,4)
  537. does not have part 6
  538. comment The template of a Taylor kernel can be extracted;
  539. taylortemplate yy;
  540. {{y,0,4}}
  541. taylortemplate xxa;
  542. {{x,1,2}}
  543. taylortemplate xi;
  544. {{x,infinity,5}}
  545. taylortemplate xy;
  546. {{x,0,2},{y,0,2}}
  547. taylortemplate xx1;
  548. {{{x,y},0,2}}
  549. comment Here is a slightly less trivial example;
  550. exp := (sin (x) * sin (y) / (x * y))**2;
  551. 2 2
  552. sin(x) *sin(y)
  553. exp := -----------------
  554. 2 2
  555. x *y
  556. taylor (exp, x, 0, 1, y, 0, 1);
  557. 2 2
  558. 1 + O(x ,y )
  559. taylor (exp, x, 0, 2, y, 0, 2);
  560. 1 2 1 2 1 2 2 3 3
  561. 1 - ---*x - ---*y + ---*y *x + O(x ,y )
  562. 3 3 9
  563. tt := taylor (exp, {x,y}, 0, 2);
  564. 1 2 1 2 3
  565. tt := 1 - ---*y - ---*x + O({x,y} )
  566. 3 3
  567. comment An example that uses factorization;
  568. on factor;
  569. ff := y**5 - 1;
  570. 4 3 2
  571. ff := (y + y + y + y + 1)*(y - 1)
  572. zz := sub (y = taylor(e**x, x, 0, 3), ff);
  573. 1 2 1 3 4 4 1 2 1 3 4 3
  574. zz := ((1 + x + ---*x + ---*x + O(x )) + (1 + x + ---*x + ---*x + O(x ))
  575. 2 6 2 6
  576. 1 2 1 3 4 2 1 2 1 3 4
  577. + (1 + x + ---*x + ---*x + O(x )) + (1 + x + ---*x + ---*x + O(x ))
  578. 2 6 2 6
  579. 1 2 1 3 4
  580. + 1)*((1 + x + ---*x + ---*x + O(x )) - 1)
  581. 2 6
  582. on exp;
  583. zz;
  584. 1 2 1 3 4 5
  585. (1 + x + ---*x + ---*x + O(x )) - 1
  586. 2 6
  587. comment A simple example of Taylor kernel differentiation;
  588. hugo := taylor(e^x,x,0,5);
  589. 1 2 1 3 1 4 1 5 6
  590. hugo := 1 + x + ---*x + ---*x + ----*x + -----*x + O(x )
  591. 2 6 24 120
  592. df(hugo^2,x);
  593. 2 8 3 4 4 5
  594. 2 + 4*x + 4*x + ---*x + ---*x + O(x )
  595. 3 3
  596. comment The following shows the (limited) capabilities to integrate
  597. Taylor kernels. Only simple cases are supported, otherwise
  598. a warning is printed and the Taylor kernels are converted to
  599. standard representation;
  600. zz := taylor (sin x, x, 0, 5);
  601. 1 3 1 5 6
  602. zz := x - ---*x + -----*x + O(x )
  603. 6 120
  604. ww := taylor (cos y, y, 0, 5);
  605. 1 2 1 4 6
  606. ww := 1 - ---*y + ----*y + O(y )
  607. 2 24
  608. int (zz, x);
  609. 1 2 1 4 1 6 7
  610. ---*x - ----*x + -----*x + O(x )
  611. 2 24 720
  612. int (ww, x);
  613. x 2 x 4 6
  614. x - ---*y + ----*y + O(y )
  615. 2 24
  616. int (zz + ww, x);
  617. 1 2 1 4 1 6 7 x 2 x 4 6
  618. (---*x - ----*x + -----*x + O(x )) + (x - ---*y + ----*y + O(y ))
  619. 2 24 720 2 24
  620. comment And here we present Taylor series reversion.
  621. We start with the example given by Knuth for the algorithm;
  622. taylor (t - t**2, t, 0, 5);
  623. 2 6
  624. t - t + O(t )
  625. taylorrevert (ws, t, x);
  626. 2 3 4 5 6
  627. x + x + 2*x + 5*x + 14*x + O(x )
  628. tan!-series := taylor (tan x, x, 0, 5);
  629. 1 3 2 5 6
  630. tan-series := x + ---*x + ----*x + O(x )
  631. 3 15
  632. taylorrevert (tan!-series, x, y);
  633. 1 3 1 5 6
  634. y - ---*y + ---*y + O(y )
  635. 3 5
  636. atan!-series:=taylor (atan y, y, 0, 5);
  637. 1 3 1 5 6
  638. atan-series := y - ---*y + ---*y + O(y )
  639. 3 5
  640. tmp := taylor (e**x, x, 0, 5);
  641. 1 2 1 3 1 4 1 5 6
  642. tmp := 1 + x + ---*x + ---*x + ----*x + -----*x + O(x )
  643. 2 6 24 120
  644. taylorrevert (tmp, x, y);
  645. 1 2 1 3 1 4 1 5 6
  646. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  647. 2 3 4 5
  648. taylor (log y, y, 1, 5);
  649. 1 2 1 3 1 4 1 5 6
  650. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  651. 2 3 4 5
  652. comment The following example calculates the perturbation expansion
  653. of the root x = 20 of the following polynomial in terms of
  654. EPS, in ROUNDED mode;
  655. poly := for r := 1 : 20 product (x - r);
  656. 20 19 18 17 16 15
  657. poly := x - 210*x + 20615*x - 1256850*x + 53327946*x - 1672280820*x
  658. 14 13 12
  659. + 40171771630*x - 756111184500*x + 11310276995381*x
  660. 11 10 9
  661. - 135585182899530*x + 1307535010540395*x - 10142299865511450*x
  662. 8 7 6
  663. + 63030812099294896*x - 311333643161390640*x + 1206647803780373360*x
  664. 5 4
  665. - 3599979517947607200*x + 8037811822645051776*x
  666. 3 2
  667. - 12870931245150988800*x + 13803759753640704000*x
  668. - 8752948036761600000*x + 2432902008176640000
  669. on rounded;
  670. tpoly := taylor (poly, x, 20, 4);
  671. 2
  672. tpoly := 1.21649393692e+17*(x - 20) + 4.31564847287e+17*(x - 20)
  673. 3 4
  674. + 6.68609351672e+17*(x - 20) + 6.10115975015e+17*(x - 20)
  675. 5
  676. + O((x - 20) )
  677. taylorrevert (tpoly, x, eps);
  678. 2 3
  679. 20 + 8.22034512178e-18*eps - 2.39726594662e-34*eps + 1.09290580232e-50*eps
  680. 4 5
  681. - 5.97114159465e-67*eps + O(eps )
  682. comment Some more examples using rounded mode;
  683. taylor(sin x/x,x,0,4);
  684. 2 4 5
  685. 1 - 0.166666666667*x + 0.00833333333333*x + O(x )
  686. taylor(sin x,x,pi/2,4);
  687. 2
  688. 1 + 6.12323399574e-17*(x - 1.57079632679) - 0.5*(x - 1.57079632679)
  689. 3 4
  690. - 1.02053899929e-17*(x - 1.57079632679) + 0.0416666666667*(x - 1.57079632679)
  691. 5
  692. + O((x - 1.57079632679) )
  693. taylor(tan x,x,pi/2,4);
  694. -1
  695. - (x - 1.57079632679) + 0.333333333333*(x - 1.57079632679)
  696. 3 5
  697. + 0.0222222222222*(x - 1.57079632679) + O((x - 1.57079632679) )
  698. off rounded;
  699. comment An example that involves computing limits of type 0/0 if
  700. expansion is done via differentiation;
  701. taylor(sqrt((e^x - 1)/x),x,0,15);
  702. 1 5 2 1 3 79 4 3 5 16
  703. 1 + ---*x + ----*x + -----*x + -------*x + -------*x + (10 terms) + O(x )
  704. 4 96 128 92160 40960
  705. comment An example that involves intermediate non-analytical terms
  706. which cancel entirely;
  707. taylor(x^(5/2)/(log(x+1)*tan(x^(3/2))),x,0,5);
  708. 1 1 2 7 3 139 4 67 5 6
  709. 1 + ---*x - ----*x - ----*x - -----*x + ------*x + O(x )
  710. 2 12 24 720 1440
  711. comment Other examples involving non-analytical terms;
  712. taylor(log(e^x-1),x,0,5);
  713. 1 1 2 1 4 5
  714. log(x) + (---*x + ----*x - ------*x + O(x ))
  715. 2 24 2880
  716. taylor(e^(1/x)*(e^x-1),x,0,5);
  717. 1/x 1 2 1 3 1 4 1 5 6
  718. e *(x + ---*x + ---*x + ----*x + -----*x + O(x ))
  719. 2 6 24 120
  720. taylor(log(x)*x^10,x,0,5);
  721. 10 11
  722. log(x)*(x + O(x ))
  723. taylor(log(x)*x^10,x,0,11);
  724. 10 12
  725. log(x)*(x + O(x ))
  726. taylor(log(x-a)/((a-b)*(a-c)) + log(2(x-b))/((b-c)*(b-a))
  727. + log(x-c)/((c-a)*(c-b)),x,infinity,2);
  728. log(2) 1 1 1
  729. - ---------------------- - ---*---- + O(----)
  730. 2 2 2 3
  731. a*b - a*c - b + b*c x x
  732. ss := (sqrt(x^(2/5) +1) - x^(1/3)-1)/x^(1/3);
  733. 2/5 1/3
  734. sqrt(x + 1) - x - 1
  735. ss := ---------------------------
  736. 1/3
  737. x
  738. taylor(exp ss,x,0,2);
  739. 1 1 1/15 1 2/15 1 1/5 1 4/15 1 1/3
  740. --- + -----*x + -----*x + ------*x + -------*x + --------*x
  741. e 2*e 8*e 48*e 384*e 3840*e
  742. 31/15
  743. + (25 terms) + O(x )
  744. taylor(exp sub(x=x^15,ss),x,0,2);
  745. 1 1 1 2 3
  746. --- + -----*x + -----*x + O(x )
  747. e 2*e 8*e
  748. taylor(dilog(x),x,0,4);
  749. 1 2 1 3 1 4 5
  750. log(x)*(x + ---*x + ---*x + ---*x + O(x ))
  751. 2 3 4
  752. 2
  753. pi 1 2 1 3 1 4 5
  754. + (----- - x - ---*x - ---*x - ----*x + O(x ))
  755. 6 4 9 16
  756. taylor(ei(x),x,0,4);
  757. 1 2 1 3 1 4 5
  758. log(x) - psi(1) + (x + ---*x + ----*x + ----*x + O(x ))
  759. 4 18 96
  760. comment In the following we demonstrate the possibiblity to compute the
  761. expansion of a function which is given by a simple first order
  762. differential equation: the function myexp(x) is exp(-x^2);
  763. operator myexp,myerf;
  764. let {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  765. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  766. taylor(myexp(x),x,0,5);
  767. 2 1 4 6
  768. 1 - x + ---*x + O(x )
  769. 2
  770. taylor(myerf(x),x,0,5);
  771. 2 2 3 1 5 6
  772. ----------*x - ------------*x + ------------*x + O(x )
  773. sqrt(pi) 3*sqrt(pi) 5*sqrt(pi)
  774. clear {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  775. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  776. clear myexp,erf;
  777. %%% showtime;
  778. comment There are two special operators, implicit_taylor and
  779. inverse_taylor, to compute the Taylor expansion of implicit
  780. or inverse functions;
  781. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,5);
  782. 1 2 1 4 6
  783. 1 - ---*x - ---*x + O(x )
  784. 2 8
  785. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,20);
  786. 1 2 1 4 1 6 5 8 7 10 21
  787. 1 - ---*x - ---*x - ----*x - -----*x - -----*x + (5 terms) + O(x )
  788. 2 8 16 128 256
  789. implicit_taylor(x+y^3-y,x,y,0,0,8);
  790. 3 5 7 9
  791. x + x + 3*x + 12*x + O(x )
  792. implicit_taylor(x+y^3-y,x,y,0,1,5);
  793. 1 3 2 1 3 105 4 3 5 6
  794. 1 - ---*x - ---*x - ---*x - -----*x - ---*x + O(x )
  795. 2 8 2 128 2
  796. implicit_taylor(x+y^3-y,x,y,0,-1,5);
  797. 1 3 2 1 3 105 4 3 5 6
  798. - 1 - ---*x + ---*x - ---*x + -----*x - ---*x + O(x )
  799. 2 8 2 128 2
  800. implicit_taylor(y*e^y-x,x,y,0,0,5);
  801. 2 3 3 8 4 125 5 6
  802. x - x + ---*x - ---*x + -----*x + O(x )
  803. 2 3 24
  804. comment This is the function exp(-1/x^2), which has an essential
  805. singularity at the point 0;
  806. implicit_taylor(x^2*log y+1,x,y,0,0,3);
  807. ***** Computation of Taylor series of implicit function failed
  808. Input expression non-zero at given point
  809. inverse_taylor(exp(x)-1,x,y,0,8);
  810. 1 2 1 3 1 4 1 5 1 6 9
  811. y - ---*y + ---*y - ---*y + ---*y - ---*y + (2 terms) + O(y )
  812. 2 3 4 5 6
  813. inverse_taylor(exp(x),x,y,0,5);
  814. 1 2 1 3 1 4 1 5 6
  815. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  816. 2 3 4 5
  817. inverse_taylor(sqrt(x),x,y,0,5);
  818. 2 6
  819. y + O(y )
  820. inverse_taylor(log(1+x),x,y,0,5);
  821. 1 2 1 3 1 4 1 5 6
  822. y + ---*y + ---*y + ----*y + -----*y + O(y )
  823. 2 6 24 120
  824. inverse_taylor((e^x-e^(-x))/2,x,y,0,5);
  825. 1 3 3 5 6
  826. y - ---*y + ----*y + O(y )
  827. 6 40
  828. comment In the next two cases the inverse functions have a branch
  829. point, therefore the computation fails;
  830. inverse_taylor((e^x+e^(-x))/2,x,y,0,5);
  831. ***** Computation of Taylor series of inverse function failed
  832. inverse_taylor(exp(x^2-1),x,y,0,5);
  833. ***** Computation of Taylor series of inverse function failed
  834. inverse_taylor(exp(sqrt(x))-1,x,y,0,5);
  835. 2 3 11 4 5 5 6
  836. y - y + ----*y - ---*y + O(y )
  837. 12 6
  838. inverse_taylor(x*exp(x),x,y,0,5);
  839. 2 3 3 8 4 125 5 6
  840. y - y + ---*y - ---*y + -----*y + O(y )
  841. 2 3 24
  842. %%% showtime;
  843. comment An application is the problem posed by Prof. Stanley:
  844. we prove that the finite difference expression below
  845. corresponds to the given derivative expression;
  846. operator diff,a,f,gg;
  847. % We use gg to avoid conflict with high energy
  848. % physics operator.
  849. let diff(~f,~arg) => df(f,arg);
  850. derivative_expression :=
  851. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),y),x) +
  852. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),x),y) ;
  853. derivative_expression := 2*a(x,y)*df(f(x,y),x,y)*df(gg(x,y),x)*df(gg(x,y),y)
  854. + a(x,y)*df(f(x,y),x)*df(gg(x,y),x,y)*df(gg(x,y),y)
  855. + a(x,y)*df(f(x,y),x)*df(gg(x,y),x)*df(gg(x,y),y,2)
  856. + a(x,y)*df(f(x,y),y)*df(gg(x,y),x,y)*df(gg(x,y),x)
  857. + a(x,y)*df(f(x,y),y)*df(gg(x,y),x,2)*df(gg(x,y),y)
  858. + df(a(x,y),x)*df(f(x,y),y)*df(gg(x,y),x)*df(gg(x,y),y)
  859. + df(a(x,y),y)*df(f(x,y),x)*df(gg(x,y),x)*df(gg(x,y),y)
  860. finite_difference_expression :=
  861. +a(x+dx,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  862. +a(x+dx,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  863. +a(x,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  864. +a(x,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  865. -f(x,y)*a(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  866. -f(x,y)*a(x+dx,y)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  867. -f(x,y)*a(x,y+dy)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x,y-dy)^2/(16*dx^2*dy^2)
  1035. +a(x,y)*f(x,y)*gg(x,y-dy)^2/(16*dx^2*dy^2)
  1036. -f(x,y)*gg(x,y)^2*a(x,y-dy)/(16*dx^2*dy^2)
  1037. -a(x,y)*f(x,y)*gg(x,y)^2/(8*dx^2*dy^2)$
  1038. comment We define abbreviations for the partial derivatives;
  1039. operator ax,ay,fx,fy,gx,gy;
  1040. operator axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  1041. operator axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  1042. operator axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,
  1043. gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  1044. operator axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  1045. operator gxxxxyy,gxxxyyy,gxxyyyy;
  1046. operator_diff_rules := {
  1047. df(a(~x,~y),~x) => ax(x,y),
  1048. df(a(~x,~y),~y) => ay(x,y),
  1049. df(f(~x,~y),~x) => fx(x,y),
  1050. df(f(~x,~y),~y) => fy(x,y),
  1051. df(gg(~x,~y),~x) => gx(x,y),
  1052. df(gg(~x,~y),~y) => gy(x,y),
  1053. df(ax(~x,~y),~x) => axx(x,y),
  1054. df(ax(~x,~y),~y) => axy(x,y),
  1055. df(ay(~x,~y),~x) => axy(x,y),
  1056. df(ay(~x,~y),~y) => ayy(x,y),
  1057. df(fx(~x,~y),~x) => fxx(x,y),
  1058. df(fx(~x,~y),~y) => fxy(x,y),
  1059. df(fy(~x,~y),~x) => fxy(x,y),
  1060. df(fy(~x,~y),~y) => fyy(x,y),
  1061. df(gx(~x,~y),~x) => gxx(x,y),
  1062. df(gx(~x,~y),~y) => gxy(x,y),
  1063. df(gy(~x,~y),~x) => gxy(x,y),
  1064. df(gy(~x,~y),~y) => gyy(x,y),
  1065. df(axx(~x,~y),~x) => axxx(x,y),
  1066. df(axy(~x,~y),~x) => axxy(x,y),
  1067. df(ayy(~x,~y),~x) => axyy(x,y),
  1068. df(ayy(~x,~y),~y) => ayyy(x,y),
  1069. df(fxx(~x,~y),~x) => fxxx(x,y),
  1070. df(fxy(~x,~y),~x) => fxxy(x,y),
  1071. df(fxy(~x,~y),~y) => fxyy(x,y),
  1072. df(fyy(~x,~y),~x) => fxyy(x,y),
  1073. df(fyy(~x,~y),~y) => fyyy(x,y),
  1074. df(gxx(~x,~y),~x) => gxxx(x,y),
  1075. df(gxx(~x,~y),~y) => gxxy(x,y),
  1076. df(gxy(~x,~y),~x) => gxxy(x,y),
  1077. df(gxy(~x,~y),~y) => gxyy(x,y),
  1078. df(gyy(~x,~y),~x) => gxyy(x,y),
  1079. df(gyy(~x,~y),~y) => gyyy(x,y),
  1080. df(axyy(~x,~y),~x) => axxyy(x,y),
  1081. df(axxy(~x,~y),~x) => axxxy(x,y),
  1082. df(ayyy(~x,~y),~x) => axyyy(x,y),
  1083. df(fxxy(~x,~y),~x) => fxxxy(x,y),
  1084. df(fxyy(~x,~y),~x) => fxxyy(x,y),
  1085. df(fyyy(~x,~y),~x) => fxyyy(x,y),
  1086. df(gxxx(~x,~y),~x) => gxxxx(x,y),
  1087. df(gxxy(~x,~y),~x) => gxxxy(x,y),
  1088. df(gxyy(~x,~y),~x) => gxxyy(x,y),
  1089. df(gyyy(~x,~y),~x) => gxyyy(x,y),
  1090. df(gyyy(~x,~y),~y) => gyyyy(x,y),
  1091. df(axxyy(~x,~y),~x) => axxxyy(x,y),
  1092. df(axyyy(~x,~y),~x) => axxyyy(x,y),
  1093. df(fxxyy(~x,~y),~x) => fxxxyy(x,y),
  1094. df(fxyyy(~x,~y),~x) => fxxyyy(x,y),
  1095. df(gxxxy(~x,~y),~x) => gxxxxy(x,y),
  1096. df(gxxyy(~x,~y),~x) => gxxxyy(x,y),
  1097. df(gxyyy(~x,~y),~x) => gxxyyy(x,y),
  1098. df(gyyyy(~x,~y),~x) => gxyyyy(x,y),
  1099. df(gxxxyy(~x,~y),~x) => gxxxxyy(x,y),
  1100. df(gxxyyy(~x,~y),~x) => gxxxyyy(x,y),
  1101. df(gxyyyy(~x,~y),~x) => gxxyyyy(x,y)
  1102. };
  1103. operator_diff_rules := {df(a(~x,~y),~x) => ax(x,y),
  1104. df(a(~x,~y),~y) => ay(x,y),
  1105. df(f(~x,~y),~x) => fx(x,y),
  1106. df(f(~x,~y),~y) => fy(x,y),
  1107. df(gg(~x,~y),~x) => gx(x,y),
  1108. df(gg(~x,~y),~y) => gy(x,y),
  1109. df(ax(~x,~y),~x) => axx(x,y),
  1110. df(ax(~x,~y),~y) => axy(x,y),
  1111. df(ay(~x,~y),~x) => axy(x,y),
  1112. df(ay(~x,~y),~y) => ayy(x,y),
  1113. df(fx(~x,~y),~x) => fxx(x,y),
  1114. df(fx(~x,~y),~y) => fxy(x,y),
  1115. df(fy(~x,~y),~x) => fxy(x,y),
  1116. df(fy(~x,~y),~y) => fyy(x,y),
  1117. df(gx(~x,~y),~x) => gxx(x,y),
  1118. df(gx(~x,~y),~y) => gxy(x,y),
  1119. df(gy(~x,~y),~x) => gxy(x,y),
  1120. df(gy(~x,~y),~y) => gyy(x,y),
  1121. df(axx(~x,~y),~x) => axxx(x,y),
  1122. df(axy(~x,~y),~x) => axxy(x,y),
  1123. df(ayy(~x,~y),~x) => axyy(x,y),
  1124. df(ayy(~x,~y),~y) => ayyy(x,y),
  1125. df(fxx(~x,~y),~x) => fxxx(x,y),
  1126. df(fxy(~x,~y),~x) => fxxy(x,y),
  1127. df(fxy(~x,~y),~y) => fxyy(x,y),
  1128. df(fyy(~x,~y),~x) => fxyy(x,y),
  1129. df(fyy(~x,~y),~y) => fyyy(x,y),
  1130. df(gxx(~x,~y),~x) => gxxx(x,y),
  1131. df(gxx(~x,~y),~y) => gxxy(x,y),
  1132. df(gxy(~x,~y),~x) => gxxy(x,y),
  1133. df(gxy(~x,~y),~y) => gxyy(x,y),
  1134. df(gyy(~x,~y),~x) => gxyy(x,y),
  1135. df(gyy(~x,~y),~y) => gyyy(x,y),
  1136. df(axyy(~x,~y),~x) => axxyy(x,y),
  1137. df(axxy(~x,~y),~x) => axxxy(x,y),
  1138. df(ayyy(~x,~y),~x) => axyyy(x,y),
  1139. df(fxxy(~x,~y),~x) => fxxxy(x,y),
  1140. df(fxyy(~x,~y),~x) => fxxyy(x,y),
  1141. df(fyyy(~x,~y),~x) => fxyyy(x,y),
  1142. df(gxxx(~x,~y),~x) => gxxxx(x,y),
  1143. df(gxxy(~x,~y),~x) => gxxxy(x,y),
  1144. df(gxyy(~x,~y),~x) => gxxyy(x,y),
  1145. df(gyyy(~x,~y),~x) => gxyyy(x,y),
  1146. df(gyyy(~x,~y),~y) => gyyyy(x,y),
  1147. df(axxyy(~x,~y),~x) => axxxyy(x,y),
  1148. df(axyyy(~x,~y),~x) => axxyyy(x,y),
  1149. df(fxxyy(~x,~y),~x) => fxxxyy(x,y),
  1150. df(fxyyy(~x,~y),~x) => fxxyyy(x,y),
  1151. df(gxxxy(~x,~y),~x) => gxxxxy(x,y),
  1152. df(gxxyy(~x,~y),~x) => gxxxyy(x,y),
  1153. df(gxyyy(~x,~y),~x) => gxxyyy(x,y),
  1154. df(gyyyy(~x,~y),~x) => gxyyyy(x,y),
  1155. df(gxxxyy(~x,~y),~x) => gxxxxyy(x,y),
  1156. df(gxxyyy(~x,~y),~x) => gxxxyyy(x,y),
  1157. df(gxyyyy(~x,~y),~x) => gxxyyyy(x,y)}
  1158. let operator_diff_rules;
  1159. texp := taylor (finite_difference_expression, dx, 0, 1, dy, 0, 1);
  1160. texp := a(x,y)*fx(x,y)*gx(x,y)*gyy(x,y) + a(x,y)*fx(x,y)*gxy(x,y)*gy(x,y)
  1161. + 2*a(x,y)*fxy(x,y)*gx(x,y)*gy(x,y) + a(x,y)*fy(x,y)*gx(x,y)*gxy(x,y)
  1162. + a(x,y)*fy(x,y)*gxx(x,y)*gy(x,y) + ax(x,y)*fy(x,y)*gx(x,y)*gy(x,y)
  1163. 2 2
  1164. + ay(x,y)*fx(x,y)*gx(x,y)*gy(x,y) + O(dx ,dy )
  1165. comment You may also try to expand further but this needs a lot
  1166. of CPU time. Therefore the following line is commented out;
  1167. %texp := taylor (finite_difference_expression, dx, 0, 2, dy, 0, 2);
  1168. factor dx,dy;
  1169. result := taylortostandard texp;
  1170. result := a(x,y)*fx(x,y)*gx(x,y)*gyy(x,y) + a(x,y)*fx(x,y)*gxy(x,y)*gy(x,y)
  1171. + 2*a(x,y)*fxy(x,y)*gx(x,y)*gy(x,y) + a(x,y)*fy(x,y)*gx(x,y)*gxy(x,y)
  1172. + a(x,y)*fy(x,y)*gxx(x,y)*gy(x,y) + ax(x,y)*fy(x,y)*gx(x,y)*gy(x,y)
  1173. + ay(x,y)*fx(x,y)*gx(x,y)*gy(x,y)
  1174. derivative_expression - result;
  1175. 0
  1176. clear diff(~f,~arg);
  1177. clearrules operator_diff_rules;
  1178. clear diff,a,f,gg;
  1179. clear ax,ay,fx,fy,gx,gy;
  1180. clear axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  1181. clear axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  1182. clear axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  1183. clear axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  1184. clear gxxxxyy,gxxxyyy,gxxyyyy;
  1185. taylorprintterms := 5;
  1186. taylorprintterms := 5
  1187. off taylorautoexpand,taylorkeeporiginal;
  1188. %%% showtime;
  1189. comment An example provided by Alan Barnes: elliptic functions;
  1190. % Jacobi's elliptic functions
  1191. % sn(x,k), cn(x,k), dn(x,k).
  1192. % The modulus and complementary modulus are denoted by K and K!'
  1193. % usually written mathematically as k and k' respectively
  1194. %
  1195. % epsilon(x,k) is the incomplete elliptic integral of the second kind
  1196. % usually written mathematically as E(x,k)
  1197. %
  1198. % KK(k) is the complete elliptic integral of the first kind
  1199. % usually written mathematically as K(k)
  1200. % K(k) = arcsn(1,k)
  1201. % KK!'(k) is the complementary complete integral
  1202. % usually written mathematically as K'(k)
  1203. % NB. K'(k) = K(k')
  1204. % EE(k) is the complete elliptic integral of the second kind
  1205. % usually written mathematically as E(k)
  1206. % EE!'(k) is the complementary complete integral
  1207. % usually written mathematically as E'(k)
  1208. % NB. E'(k) = E(k')
  1209. operator sn, cn, dn, epsilon;
  1210. elliptic_rules := {
  1211. % Differentiation rules for basic functions
  1212. df(sn(~x,~k),~x) => cn(x,k)*dn(x,k),
  1213. df(cn(~x,~k),~x) => -sn(x,k)*dn(x,k),
  1214. df(dn(~x,~k),~x) => -k^2*sn(x,k)*cn(x,k),
  1215. df(epsilon(~x,~k),~x)=> dn(x,k)^2,
  1216. % k-derivatives
  1217. % DF Lawden Elliptic Functions & Applications Springer (1989)
  1218. df(sn(~x,~k),~k) => (k*sn(x,k)*cn(x,k)^2
  1219. -epsilon(x,k)*cn(x,k)*dn(x,k)/k)/(1-k^2)
  1220. + x*cn(x,k)*dn(x,k)/k,
  1221. df(cn(~x,~k),~k) => (-k*sn(x,k)^2*cn(x,k)
  1222. +epsilon(x,k)*sn(x,k)*dn(x,k)/k)/(1-k^2)
  1223. - x*sn(x,k)*dn(x,k)/k,
  1224. df(dn(~x,~k),~k) => k*(-sn(x,k)^2*dn(x,k)
  1225. +epsilon(x,k)*sn(x,k)*cn(x,k))/(1-k^2)
  1226. - k*x*sn(x,k)*cn(x,k),
  1227. df(epsilon(~x,~k),~k) => k*(sn(x,k)*cn(x,k)*dn(x,k)
  1228. -epsilon(x,k)*cn(x,k)^2)/(1-k^2)
  1229. -k*x*sn(x,k)^2,
  1230. % parity properties
  1231. sn(-~x,~k) => -sn(x,k),
  1232. cn(-~x,~k) => cn(x,k),
  1233. dn(-~x,~k) => dn(x,k),
  1234. epsilon(-~x,~k) => -epsilon(x,k),
  1235. sn(~x,-~k) => sn(x,k),
  1236. cn(~x,-~k) => cn(x,k),
  1237. dn(~x,-~k) => dn(x,k),
  1238. epsilon(~x,-~k) => epsilon(x,k),
  1239. % behaviour at zero
  1240. sn(0,~k) => 0,
  1241. cn(0,~k) => 1,
  1242. dn(0,~k) => 1,
  1243. epsilon(0,~k) => 0,
  1244. % degenerate cases of modulus
  1245. sn(~x,0) => sin(x),
  1246. cn(~x,0) => cos(x),
  1247. dn(~x,0) => 1,
  1248. epsilon(~x,0) => x,
  1249. sn(~x,1) => tanh(x),
  1250. cn(~x,1) => 1/cosh(x),
  1251. dn(~x,1) => 1/cosh(x),
  1252. epsilon(~x,1) => tanh(x)
  1253. };
  1254. elliptic_rules := {df(sn(~x,~k),~x) => cn(x,k)*dn(x,k),
  1255. df(cn(~x,~k),~x) => - sn(x,k)*dn(x,k),
  1256. 2
  1257. df(dn(~x,~k),~x) => - k *sn(x,k)*cn(x,k),
  1258. 2
  1259. df(epsilon(~x,~k),~x) => dn(x,k) ,
  1260. 2 dn(x,k)
  1261. k*sn(x,k)*cn(x,k) - epsilon(x,k)*cn(x,k)*---------
  1262. k
  1263. df(sn(~x,~k),~k) => -----------------------------------------------------
  1264. 2
  1265. 1 - k
  1266. dn(x,k)
  1267. + x*cn(x,k)*---------,
  1268. k
  1269. 2 dn(x,k)
  1270. - k*sn(x,k) *cn(x,k) + epsilon(x,k)*sn(x,k)*---------
  1271. k
  1272. df(cn(~x,~k),~k) => --------------------------------------------------------
  1273. 2
  1274. 1 - k
  1275. dn(x,k)
  1276. - x*sn(x,k)*---------,
  1277. k
  1278. 2
  1279. - sn(x,k) *dn(x,k) + epsilon(x,k)*sn(x,k)*cn(x,k)
  1280. df(dn(~x,~k),~k) => k*----------------------------------------------------
  1281. 2
  1282. 1 - k
  1283. - k*x*sn(x,k)*cn(x,k),
  1284. df(epsilon(~x,~k),~k)
  1285. 2
  1286. sn(x,k)*cn(x,k)*dn(x,k) - epsilon(x,k)*cn(x,k) 2
  1287. => k*------------------------------------------------- - k*x*sn(x,k) ,
  1288. 2
  1289. 1 - k
  1290. sn( - ~x,~k) => - sn(x,k),
  1291. cn( - ~x,~k) => cn(x,k),
  1292. dn( - ~x,~k) => dn(x,k),
  1293. epsilon( - ~x,~k) => - epsilon(x,k),
  1294. sn(~x, - ~k) => sn(x,k),
  1295. cn(~x, - ~k) => cn(x,k),
  1296. dn(~x, - ~k) => dn(x,k),
  1297. epsilon(~x, - ~k) => epsilon(x,k),
  1298. sn(0,~k) => 0,
  1299. cn(0,~k) => 1,
  1300. dn(0,~k) => 1,
  1301. epsilon(0,~k) => 0,
  1302. sn(~x,0) => sin(x),
  1303. cn(~x,0) => cos(x),
  1304. dn(~x,0) => 1,
  1305. epsilon(~x,0) => x,
  1306. sn(~x,1) => tanh(x),
  1307. 1
  1308. cn(~x,1) => ---------,
  1309. cosh(x)
  1310. 1
  1311. dn(~x,1) => ---------,
  1312. cosh(x)
  1313. epsilon(~x,1) => tanh(x)}
  1314. let elliptic_rules;
  1315. hugo := taylor(sn(x,k),k,0,6);
  1316. 2 2
  1317. cos(x)*(cos(x) *x + cos(x)*sin(x) + sin(x) *x - 2*x) 2
  1318. hugo := sin(x) + ------------------------------------------------------*k + (
  1319. 4
  1320. 5 4 2 4
  1321. cos(x) *x - 2*cos(x) *sin(x)*x + 5*cos(x) *sin(x)
  1322. 3 2 3 2 3 2
  1323. - 10*cos(x) *sin(x) *x + 6*cos(x) *x - 4*cos(x) *sin(x) *x
  1324. 2 3 2 2 2
  1325. + cos(x) *sin(x) + 8*cos(x) *sin(x)*x + 4*cos(x) *sin(x)
  1326. 4 2
  1327. - 11*cos(x)*sin(x) *x + 30*cos(x)*sin(x) *x - 16*cos(x)*x
  1328. 5 2 3 2 2 4
  1329. - 2*sin(x) *x + 8*sin(x) *x - 8*sin(x)*x )/64*k + (
  1330. 7 3 7 6 2
  1331. - 6*cos(x) *x + 17*cos(x) *x - 99*cos(x) *sin(x)*x
  1332. 6 5 2 3 5 2
  1333. + 21*cos(x) *sin(x) - 18*cos(x) *sin(x) *x - 71*cos(x) *sin(x) *x
  1334. 5 3 5 4 3 2
  1335. + 36*cos(x) *x - 18*cos(x) *x - 135*cos(x) *sin(x) *x
  1336. 4 3 4 2 4
  1337. - 133*cos(x) *sin(x) + 324*cos(x) *sin(x)*x + 172*cos(x) *sin(x)
  1338. 3 4 3 3 4
  1339. - 18*cos(x) *sin(x) *x - 13*cos(x) *sin(x) *x
  1340. 3 2 3 3 2 3 3
  1341. + 72*cos(x) *sin(x) *x - 156*cos(x) *sin(x) *x - 72*cos(x) *x
  1342. 3 2 5 2 2 5
  1343. + 160*cos(x) *x + 27*cos(x) *sin(x) *x - 118*cos(x) *sin(x)
  1344. 2 3 2 2 2
  1345. + 176*cos(x) *sin(x) - 108*cos(x) *sin(x)*x + 32*cos(x) *sin(x)
  1346. 6 3 6 4 3
  1347. - 6*cos(x)*sin(x) *x + 75*cos(x)*sin(x) *x + 36*cos(x)*sin(x) *x
  1348. 4 2 3 2
  1349. - 498*cos(x)*sin(x) *x - 72*cos(x)*sin(x) *x + 888*cos(x)*sin(x) *x
  1350. 3 7 2 5 2
  1351. + 48*cos(x)*x - 384*cos(x)*x + 63*sin(x) *x - 324*sin(x) *x
  1352. 3 2 2 6 7
  1353. + 540*sin(x) *x - 288*sin(x)*x )/2304*k + O(k )
  1354. otto := taylor(cn(x,k),k,0,6);
  1355. 2 2
  1356. sin(x)*( - cos(x) *x - cos(x)*sin(x) - sin(x) *x + 2*x) 2
  1357. otto := cos(x) + ---------------------------------------------------------*k +
  1358. 4
  1359. 5 2 4 3 2 2
  1360. ( - 2*cos(x) *x - 5*cos(x) *sin(x)*x - 4*cos(x) *sin(x) *x
  1361. 3 2 3 2 2 3
  1362. - 7*cos(x) *sin(x) + 8*cos(x) *x + 2*cos(x) *sin(x) *x
  1363. 2 4 2 4
  1364. + 2*cos(x) *sin(x)*x - 2*cos(x)*sin(x) *x - 3*cos(x)*sin(x)
  1365. 2 2 2 2 5
  1366. + 8*cos(x)*sin(x) *x - 4*cos(x)*sin(x) - 8*cos(x)*x + 7*sin(x) *x
  1367. 3 4 7 2
  1368. - 22*sin(x) *x + 16*sin(x)*x)/64*k + ( - 9*cos(x) *x
  1369. 6 3 6 5 2 2
  1370. + 6*cos(x) *sin(x)*x - 71*cos(x) *sin(x)*x + 135*cos(x) *sin(x) *x
  1371. 5 2 5 2 4 3 3
  1372. - 66*cos(x) *sin(x) - 36*cos(x) *x + 18*cos(x) *sin(x) *x
  1373. 4 3 4 3 4
  1374. - cos(x) *sin(x) *x - 36*cos(x) *sin(x)*x + 18*cos(x) *sin(x)*x
  1375. 3 4 2 3 4
  1376. + 297*cos(x) *sin(x) *x + 61*cos(x) *sin(x)
  1377. 3 2 2 3 2 3 2
  1378. - 720*cos(x) *sin(x) *x - 208*cos(x) *sin(x) + 252*cos(x) *x
  1379. 2 5 3 2 5
  1380. + 18*cos(x) *sin(x) *x + 31*cos(x) *sin(x) *x
  1381. 2 3 3 2 3
  1382. - 72*cos(x) *sin(x) *x - 24*cos(x) *sin(x) *x
  1383. 2 3 2 6 2
  1384. + 72*cos(x) *sin(x)*x + 56*cos(x) *sin(x)*x + 153*cos(x)*sin(x) *x
  1385. 6 4 2 4
  1386. + 91*cos(x)*sin(x) - 684*cos(x)*sin(x) *x - 212*cos(x)*sin(x)
  1387. 2 2 2 2
  1388. + 900*cos(x)*sin(x) *x - 32*cos(x)*sin(x) - 288*cos(x)*x
  1389. 7 3 7 5 3 5
  1390. + 6*sin(x) *x - 39*sin(x) *x - 36*sin(x) *x + 318*sin(x) *x
  1391. 3 3 3 3
  1392. + 72*sin(x) *x - 672*sin(x) *x - 48*sin(x)*x + 384*sin(x)*x)/2304
  1393. 6 7
  1394. *k + O(k )
  1395. taylorcombine(hugo^2 + otto^2);
  1396. 2 2 7
  1397. cos(x) + sin(x) + O(k )
  1398. clearrules elliptic_rules;
  1399. clear sn, cn, dn, epsilon;
  1400. %%% showtime;
  1401. comment That's all, folks;
  1402. end;
  1403. Time for test: 580 ms, plus GC time: 10 ms