TAYLOR.LOG 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. comment
  3. Test and demonstration file for the Taylor expansion package,
  4. by Rainer M. Schoepf. Works with version 2.1e (03-May-95);
  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 The template of a Taylor kernel can be extracted;
  526. taylortemplate yy;
  527. {{y,0,4}}
  528. taylortemplate xxa;
  529. {{x,1,2}}
  530. taylortemplate xi;
  531. {{x,infinity,5}}
  532. taylortemplate xy;
  533. {{x,0,2},{y,0,2}}
  534. taylortemplate xx1;
  535. {{{x,y},0,2}}
  536. comment Here is a slightly less trivial example;
  537. exp := (sin (x) * sin (y) / (x * y))**2;
  538. 2 2
  539. sin(x) *sin(y)
  540. exp := -----------------
  541. 2 2
  542. x *y
  543. taylor (exp, x, 0, 1, y, 0, 1);
  544. 2 2
  545. 1 + O(x ,y )
  546. taylor (exp, x, 0, 2, y, 0, 2);
  547. 1 2 1 2 1 2 2 3 3
  548. 1 - ---*x - ---*y + ---*y *x + O(x ,y )
  549. 3 3 9
  550. tt := taylor (exp, {x,y}, 0, 2);
  551. 1 2 1 2 3
  552. tt := 1 - ---*y - ---*x + O({x,y} )
  553. 3 3
  554. comment An example that uses factorization;
  555. on factor;
  556. ff := y**5 - 1;
  557. 4 3 2
  558. ff := (y + y + y + y + 1)*(y - 1)
  559. zz := sub (y = taylor(e**x, x, 0, 3), ff);
  560. 1 2 1 3 4 4 1 2 1 3 4 3
  561. zz := ((1 + x + ---*x + ---*x + O(x )) + (1 + x + ---*x + ---*x + O(x ))
  562. 2 6 2 6
  563. 1 2 1 3 4 2 1 2 1 3 4
  564. + (1 + x + ---*x + ---*x + O(x )) + (1 + x + ---*x + ---*x + O(x ))
  565. 2 6 2 6
  566. 1 2 1 3 4
  567. + 1)*((1 + x + ---*x + ---*x + O(x )) - 1)
  568. 2 6
  569. on exp;
  570. zz;
  571. 1 2 1 3 4 5
  572. (1 + x + ---*x + ---*x + O(x )) - 1
  573. 2 6
  574. comment A simple example of Taylor kernel differentiation;
  575. hugo := taylor(e^x,x,0,5);
  576. 1 2 1 3 1 4 1 5 6
  577. hugo := 1 + x + ---*x + ---*x + ----*x + -----*x + O(x )
  578. 2 6 24 120
  579. df(hugo^2,x);
  580. 2 8 3 4 4 5
  581. 2 + 4*x + 4*x + ---*x + ---*x + O(x )
  582. 3 3
  583. comment The following shows the (limited) capabilities to integrate
  584. Taylor kernels. Only simple cases are supported, otherwise
  585. a warning is printed and the Taylor kernels are converted to
  586. standard representation;
  587. zz := taylor (sin x, x, 0, 5);
  588. 1 3 1 5 6
  589. zz := x - ---*x + -----*x + O(x )
  590. 6 120
  591. ww := taylor (cos y, y, 0, 5);
  592. 1 2 1 4 6
  593. ww := 1 - ---*y + ----*y + O(y )
  594. 2 24
  595. int (zz, x);
  596. 1 2 1 4 1 6 7
  597. ---*x - ----*x + -----*x + O(x )
  598. 2 24 720
  599. int (ww, x);
  600. x 2 x 4 6
  601. x - ---*y + ----*y + O(y )
  602. 2 24
  603. int (zz + ww, x);
  604. 1 2 1 4 1 6 7 x 2 x 4 6
  605. (---*x - ----*x + -----*x + O(x )) + (x - ---*y + ----*y + O(y ))
  606. 2 24 720 2 24
  607. comment And here we present Taylor series reversion.
  608. We start with the example given by Knuth for the algorithm;
  609. taylor (t - t**2, t, 0, 5);
  610. 2 6
  611. t - t + O(t )
  612. taylorrevert (ws, t, x);
  613. 2 3 4 5 6
  614. x + x + 2*x + 5*x + 14*x + O(x )
  615. tan!-series := taylor (tan x, x, 0, 5);
  616. 1 3 2 5 6
  617. tan-series := x + ---*x + ----*x + O(x )
  618. 3 15
  619. taylorrevert (tan!-series, x, y);
  620. 1 3 1 5 6
  621. y - ---*y + ---*y + O(y )
  622. 3 5
  623. atan!-series:=taylor (atan y, y, 0, 5);
  624. 1 3 1 5 6
  625. atan-series := y - ---*y + ---*y + O(y )
  626. 3 5
  627. tmp := taylor (e**x, x, 0, 5);
  628. 1 2 1 3 1 4 1 5 6
  629. tmp := 1 + x + ---*x + ---*x + ----*x + -----*x + O(x )
  630. 2 6 24 120
  631. taylorrevert (tmp, x, y);
  632. 1 2 1 3 1 4 1 5 6
  633. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  634. 2 3 4 5
  635. taylor (log y, y, 1, 5);
  636. 1 2 1 3 1 4 1 5 6
  637. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  638. 2 3 4 5
  639. comment The following example calculates the perturbation expansion
  640. of the root x = 20 of the following polynomial in terms of
  641. EPS, in ROUNDED mode;
  642. poly := for r := 1 : 20 product (x - r);
  643. 20 19 18 17 16 15
  644. poly := x - 210*x + 20615*x - 1256850*x + 53327946*x - 1672280820*x
  645. 14 13 12
  646. + 40171771630*x - 756111184500*x + 11310276995381*x
  647. 11 10 9
  648. - 135585182899530*x + 1307535010540395*x - 10142299865511450*x
  649. 8 7 6
  650. + 63030812099294896*x - 311333643161390640*x + 1206647803780373360*x
  651. 5 4
  652. - 3599979517947607200*x + 8037811822645051776*x
  653. 3 2
  654. - 12870931245150988800*x + 13803759753640704000*x
  655. - 8752948036761600000*x + 2432902008176640000
  656. on rounded;
  657. tpoly := taylor (poly, x, 20, 4);
  658. 2
  659. tpoly := 1.21649393692e+17*(x - 20) + 4.31564847287e+17*(x - 20)
  660. 3 4
  661. + 6.68609351672e+17*(x - 20) + 6.10115975015e+17*(x - 20)
  662. 5
  663. + O((x - 20) )
  664. taylorrevert (tpoly, x, eps);
  665. 2 3
  666. 20 + 8.22034512178e-18*eps - 2.39726594662e-34*eps + 1.09290580232e-50*eps
  667. 4 5
  668. - 5.97114159465e-67*eps + O(eps )
  669. comment Some more examples using rounded mode;
  670. taylor(sin x/x,x,0,4);
  671. 2 4 5
  672. 1 - 0.166666666667*x + 0.00833333333333*x + O(x )
  673. taylor(sin x,x,pi/2,4);
  674. 2
  675. 1 + 6.12303176911e-17*(x - 1.57079632679) - 0.5*(x - 1.57079632679)
  676. 3 4
  677. - 1.02050529485e-17*(x - 1.57079632679) + 0.0416666666667*(x - 1.57079632679)
  678. 5
  679. + O((x - 1.57079632679) )
  680. taylor(tan x,x,pi/2,4);
  681. -1
  682. - (x - 1.57079632679) + 0.333333333333*(x - 1.57079632679)
  683. 3 5
  684. + 0.0222222222222*(x - 1.57079632679) + O((x - 1.57079632679) )
  685. off rounded;
  686. comment An example that involves computing limits of type 0/0 if
  687. expansion is done via differentiation;
  688. taylor(sqrt((e^x - 1)/x),x,0,15);
  689. 1 5 2 1 3 79 4 3 5 16
  690. 1 + ---*x + ----*x + -----*x + -------*x + -------*x + (10 terms) + O(x )
  691. 4 96 128 92160 40960
  692. comment An example that involves intermediate non-analytical terms
  693. which cancel entirely;
  694. taylor(x^(5/2)/(log(x+1)*tan(x^(3/2))),x,0,5);
  695. 1 1 2 7 3 139 4 67 5 6
  696. 1 + ---*x - ----*x - ----*x - -----*x + ------*x + O(x )
  697. 2 12 24 720 1440
  698. comment Other examples involving non-analytical terms;
  699. taylor(log(e^x-1),x,0,5);
  700. 1 1 2 1 4 5
  701. log(x) + (---*x + ----*x - ------*x + O(x ))
  702. 2 24 2880
  703. taylor(e^(1/x)*(e^x-1),x,0,5);
  704. 1/x 1 2 1 3 1 4 1 5 6
  705. e *(x + ---*x + ---*x + ----*x + -----*x + O(x ))
  706. 2 6 24 120
  707. taylor(log(x)*x^10,x,0,5);
  708. 10 11
  709. log(x)*(x + O(x ))
  710. taylor(log(x)*x^10,x,0,11);
  711. 10 12
  712. log(x)*(x + O(x ))
  713. taylor(log(x-a)/((a-b)*(a-c)) + log(2(x-b))/((b-c)*(b-a))
  714. + log(x-c)/((c-a)*(c-b)),x,infinity,2);
  715. log(2) 1 1 1
  716. - ---------------------- - ---*---- + O(----)
  717. 2 2 2 3
  718. a*b - a*c - b + b*c x x
  719. ss := (sqrt(x^(2/5) +1) - x^(1/3)-1)/x^(1/3);
  720. 2/5 1/3
  721. sqrt(x + 1) - x - 1
  722. ss := ---------------------------
  723. 1/3
  724. x
  725. taylor(exp ss,x,0,2);
  726. 1 1 1/15 1 2/15 1 1/5 1 4/15 1 1/3
  727. --- + -----*x + -----*x + ------*x + -------*x + --------*x
  728. e 2*e 8*e 48*e 384*e 3840*e
  729. 31/15
  730. + (25 terms) + O(x )
  731. taylor(exp sub(x=x^15,ss),x,0,2);
  732. 1 1 1 2 3
  733. --- + -----*x + -----*x + O(x )
  734. e 2*e 8*e
  735. taylor(dilog(x),x,0,4);
  736. 1 2 1 3 1 4 5
  737. log(x)*(x + ---*x + ---*x + ---*x + O(x ))
  738. 2 3 4
  739. 2
  740. pi 1 2 1 3 1 4 5
  741. + (----- - x - ---*x - ---*x - ----*x + O(x ))
  742. 6 4 9 16
  743. taylor(ei(x),x,0,4);
  744. 1 2 1 3 1 4 5
  745. log(x) - psi(1) + (x + ---*x + ----*x + ----*x + O(x ))
  746. 4 18 96
  747. comment In the following we demonstrate the possibiblity to compute the
  748. expansion of a function which is given by a simple first order
  749. differential equation: the function myexp(x) is exp(-x^2);
  750. operator myexp,myerf;
  751. let {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  752. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  753. taylor(myexp(x),x,0,5);
  754. 2 1 4 6
  755. 1 - x + ---*x + O(x )
  756. 2
  757. taylor(myerf(x),x,0,5);
  758. 2*sqrt(pi) 2*sqrt(pi) 3 sqrt(pi) 5 6
  759. ------------*x - ------------*x + ----------*x + O(x )
  760. pi 3*pi 5*pi
  761. clear {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  762. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  763. clear myexp,erf;
  764. %%% showtime;
  765. comment There are two special operators, implicit_taylor and
  766. inverse_taylor, to compute the Taylor expansion of implicit
  767. or inverse functions;
  768. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,5);
  769. 1 2 1 4 6
  770. 1 - ---*x - ---*x + O(x )
  771. 2 8
  772. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,20);
  773. 1 2 1 4 1 6 5 8 7 10 21
  774. 1 - ---*x - ---*x - ----*x - -----*x - -----*x + (5 terms) + O(x )
  775. 2 8 16 128 256
  776. implicit_taylor(x+y^3-y,x,y,0,0,8);
  777. 3 5 7 9
  778. x + x + 3*x + 12*x + O(x )
  779. implicit_taylor(x+y^3-y,x,y,0,1,5);
  780. 1 3 2 1 3 105 4 3 5 6
  781. 1 - ---*x - ---*x - ---*x - -----*x - ---*x + O(x )
  782. 2 8 2 128 2
  783. implicit_taylor(x+y^3-y,x,y,0,-1,5);
  784. 1 3 2 1 3 105 4 3 5 6
  785. - 1 - ---*x + ---*x - ---*x + -----*x - ---*x + O(x )
  786. 2 8 2 128 2
  787. implicit_taylor(y*e^y-x,x,y,0,0,5);
  788. 2 3 3 8 4 125 5 6
  789. x - x + ---*x - ---*x + -----*x + O(x )
  790. 2 3 24
  791. comment This is the function exp(-1/x^2), which has an essential
  792. singularity at the point 0;
  793. implicit_taylor(x^2*log y+1,x,y,0,0,3);
  794. ***** Computation of Taylor series of implicit function failed
  795. Input expression non-zero at given point
  796. inverse_taylor(exp(x)-1,x,y,0,8);
  797. 1 2 1 3 1 4 1 5 1 6 9
  798. y - ---*y + ---*y - ---*y + ---*y - ---*y + (2 terms) + O(y )
  799. 2 3 4 5 6
  800. inverse_taylor(exp(x),x,y,0,5);
  801. 1 2 1 3 1 4 1 5 6
  802. y - 1 - ---*(y - 1) + ---*(y - 1) - ---*(y - 1) + ---*(y - 1) + O((y - 1) )
  803. 2 3 4 5
  804. inverse_taylor(sqrt(x),x,y,0,5);
  805. 2 6
  806. y + O(y )
  807. inverse_taylor(log(1+x),x,y,0,5);
  808. 1 2 1 3 1 4 1 5 6
  809. y + ---*y + ---*y + ----*y + -----*y + O(y )
  810. 2 6 24 120
  811. inverse_taylor((e^x-e^(-x))/2,x,y,0,5);
  812. 1 3 3 5 6
  813. y - ---*y + ----*y + O(y )
  814. 6 40
  815. comment In the next two cases the inverse functions have a branch
  816. point, therefore the computation fails;
  817. inverse_taylor((e^x+e^(-x))/2,x,y,0,5);
  818. ***** Computation of Taylor series of inverse function failed
  819. inverse_taylor(exp(x^2-1),x,y,0,5);
  820. ***** Computation of Taylor series of inverse function failed
  821. inverse_taylor(exp(sqrt(x))-1,x,y,0,5);
  822. 2 3 11 4 5 5 6
  823. y - y + ----*y - ---*y + O(y )
  824. 12 6
  825. inverse_taylor(x*exp(x),x,y,0,5);
  826. 2 3 3 8 4 125 5 6
  827. y - y + ---*y - ---*y + -----*y + O(y )
  828. 2 3 24
  829. %%% showtime;
  830. comment An application is the problem posed by Prof. Stanley:
  831. we prove that the finite difference expression below
  832. corresponds to the given derivative expression;
  833. operator diff,a,f,gg;
  834. % We use gg to avoid conflict with high energy
  835. % physics operator.
  836. let diff(~f,~arg) => df(f,arg);
  837. derivative_expression :=
  838. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),y),x) +
  839. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),x),y) ;
  840. derivative_expression := 2*a(x,y)*df(f(x,y),x,y)*df(gg(x,y),x)*df(gg(x,y),y)
  841. + a(x,y)*df(f(x,y),x)*df(gg(x,y),x,y)*df(gg(x,y),y)
  842. + a(x,y)*df(f(x,y),x)*df(gg(x,y),x)*df(gg(x,y),y,2)
  843. + a(x,y)*df(f(x,y),y)*df(gg(x,y),x,y)*df(gg(x,y),x)
  844. + a(x,y)*df(f(x,y),y)*df(gg(x,y),x,2)*df(gg(x,y),y)
  845. + df(a(x,y),x)*df(f(x,y),y)*df(gg(x,y),x)*df(gg(x,y),y)
  846. + df(a(x,y),y)*df(f(x,y),x)*df(gg(x,y),x)*df(gg(x,y),y)
  847. finite_difference_expression :=
  848. +a(x+dx,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  849. +a(x+dx,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  850. +a(x,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  851. +a(x,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  852. -f(x,y)*a(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  853. -f(x,y)*a(x+dx,y)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  854. -f(x,y)*a(x,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  855. -a(x,y)*f(x,y)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  856. -gg(x,y)*a(x+dx,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)/(16*dx^2*dy^2)
  857. -gg(x,y)*a(x+dx,y)*f(x+dx,y+dy)*gg(x+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y)*gg(x-dx,y)^2/(16*dx^2*dy^2)
  1006. +f(x,y)*a(x,y+dy)*gg(x-dx,y)^2/(32*dx^2*dy^2)
  1007. +f(x,y)*a(x,y-dy)*gg(x-dx,y)^2/(32*dx^2*dy^2)
  1008. +a(x,y)*f(x,y)*gg(x-dx,y)^2/(16*dx^2*dy^2)
  1009. -f(x,y)*gg(x,y+dy)*a(x-dx,y)*gg(x-dx,y)/(16*dx^2*dy^2)
  1010. -f(x,y)*gg(x,y-dy)*a(x-dx,y)*gg(x-dx,y)/(16*dx^2*dy^2)
  1011. -f(x,y)*a(x,y+dy)*gg(x,y+dy)*gg(x-dx,y)/(16*dx^2*dy^2)
  1012. -a(x,y)*f(x,y)*gg(x,y+dy)*gg(x-dx,y)/(16*dx^2*dy^2)
  1013. -f(x,y)*a(x,y-dy)*gg(x,y-dy)*gg(x-dx,y)/(16*dx^2*dy^2)
  1014. -a(x,y)*f(x,y)*gg(x,y-dy)*gg(x-dx,y)/(16*dx^2*dy^2)
  1015. +f(x,y)*gg(x,y+dy)^2*a(x-dx,y)/(32*dx^2*dy^2)
  1016. +f(x,y)*gg(x,y-dy)^2*a(x-dx,y)/(32*dx^2*dy^2)
  1017. -f(x,y)*gg(x,y)^2*a(x-dx,y)/(16*dx^2*dy^2)
  1018. +f(x,y)*a(x,y+dy)*gg(x,y+dy)^2/(16*dx^2*dy^2)
  1019. +a(x,y)*f(x,y)*gg(x,y+dy)^2/(16*dx^2*dy^2)
  1020. -f(x,y)*gg(x,y)^2*a(x,y+dy)/(16*dx^2*dy^2)
  1021. +f(x,y)*a(x,y-dy)*gg(x,y-dy)^2/(16*dx^2*dy^2)
  1022. +a(x,y)*f(x,y)*gg(x,y-dy)^2/(16*dx^2*dy^2)
  1023. -f(x,y)*gg(x,y)^2*a(x,y-dy)/(16*dx^2*dy^2)
  1024. -a(x,y)*f(x,y)*gg(x,y)^2/(8*dx^2*dy^2)$
  1025. comment We define abbreviations for the partial derivatives;
  1026. operator ax,ay,fx,fy,gx,gy;
  1027. operator axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  1028. operator axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  1029. operator axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,
  1030. gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  1031. operator axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  1032. operator gxxxxyy,gxxxyyy,gxxyyyy;
  1033. operator_diff_rules := {
  1034. df(a(~x,~y),~x) => ax(x,y),
  1035. df(a(~x,~y),~y) => ay(x,y),
  1036. df(f(~x,~y),~x) => fx(x,y),
  1037. df(f(~x,~y),~y) => fy(x,y),
  1038. df(gg(~x,~y),~x) => gx(x,y),
  1039. df(gg(~x,~y),~y) => gy(x,y),
  1040. df(ax(~x,~y),~x) => axx(x,y),
  1041. df(ax(~x,~y),~y) => axy(x,y),
  1042. df(ay(~x,~y),~x) => axy(x,y),
  1043. df(ay(~x,~y),~y) => ayy(x,y),
  1044. df(fx(~x,~y),~x) => fxx(x,y),
  1045. df(fx(~x,~y),~y) => fxy(x,y),
  1046. df(fy(~x,~y),~x) => fxy(x,y),
  1047. df(fy(~x,~y),~y) => fyy(x,y),
  1048. df(gx(~x,~y),~x) => gxx(x,y),
  1049. df(gx(~x,~y),~y) => gxy(x,y),
  1050. df(gy(~x,~y),~x) => gxy(x,y),
  1051. df(gy(~x,~y),~y) => gyy(x,y),
  1052. df(axx(~x,~y),~x) => axxx(x,y),
  1053. df(axy(~x,~y),~x) => axxy(x,y),
  1054. df(ayy(~x,~y),~x) => axyy(x,y),
  1055. df(ayy(~x,~y),~y) => ayyy(x,y),
  1056. df(fxx(~x,~y),~x) => fxxx(x,y),
  1057. df(fxy(~x,~y),~x) => fxxy(x,y),
  1058. df(fxy(~x,~y),~y) => fxyy(x,y),
  1059. df(fyy(~x,~y),~x) => fxyy(x,y),
  1060. df(fyy(~x,~y),~y) => fyyy(x,y),
  1061. df(gxx(~x,~y),~x) => gxxx(x,y),
  1062. df(gxx(~x,~y),~y) => gxxy(x,y),
  1063. df(gxy(~x,~y),~x) => gxxy(x,y),
  1064. df(gxy(~x,~y),~y) => gxyy(x,y),
  1065. df(gyy(~x,~y),~x) => gxyy(x,y),
  1066. df(gyy(~x,~y),~y) => gyyy(x,y),
  1067. df(axyy(~x,~y),~x) => axxyy(x,y),
  1068. df(axxy(~x,~y),~x) => axxxy(x,y),
  1069. df(ayyy(~x,~y),~x) => axyyy(x,y),
  1070. df(fxxy(~x,~y),~x) => fxxxy(x,y),
  1071. df(fxyy(~x,~y),~x) => fxxyy(x,y),
  1072. df(fyyy(~x,~y),~x) => fxyyy(x,y),
  1073. df(gxxx(~x,~y),~x) => gxxxx(x,y),
  1074. df(gxxy(~x,~y),~x) => gxxxy(x,y),
  1075. df(gxyy(~x,~y),~x) => gxxyy(x,y),
  1076. df(gyyy(~x,~y),~x) => gxyyy(x,y),
  1077. df(gyyy(~x,~y),~y) => gyyyy(x,y),
  1078. df(axxyy(~x,~y),~x) => axxxyy(x,y),
  1079. df(axyyy(~x,~y),~x) => axxyyy(x,y),
  1080. df(fxxyy(~x,~y),~x) => fxxxyy(x,y),
  1081. df(fxyyy(~x,~y),~x) => fxxyyy(x,y),
  1082. df(gxxxy(~x,~y),~x) => gxxxxy(x,y),
  1083. df(gxxyy(~x,~y),~x) => gxxxyy(x,y),
  1084. df(gxyyy(~x,~y),~x) => gxxyyy(x,y),
  1085. df(gyyyy(~x,~y),~x) => gxyyyy(x,y),
  1086. df(gxxxyy(~x,~y),~x) => gxxxxyy(x,y),
  1087. df(gxxyyy(~x,~y),~x) => gxxxyyy(x,y),
  1088. df(gxyyyy(~x,~y),~x) => gxxyyyy(x,y)
  1089. };
  1090. operator_diff_rules := {df(a(~x,~y),~x) => ax(x,y),
  1091. df(a(~x,~y),~y) => ay(x,y),
  1092. df(f(~x,~y),~x) => fx(x,y),
  1093. df(f(~x,~y),~y) => fy(x,y),
  1094. df(gg(~x,~y),~x) => gx(x,y),
  1095. df(gg(~x,~y),~y) => gy(x,y),
  1096. df(ax(~x,~y),~x) => axx(x,y),
  1097. df(ax(~x,~y),~y) => axy(x,y),
  1098. df(ay(~x,~y),~x) => axy(x,y),
  1099. df(ay(~x,~y),~y) => ayy(x,y),
  1100. df(fx(~x,~y),~x) => fxx(x,y),
  1101. df(fx(~x,~y),~y) => fxy(x,y),
  1102. df(fy(~x,~y),~x) => fxy(x,y),
  1103. df(fy(~x,~y),~y) => fyy(x,y),
  1104. df(gx(~x,~y),~x) => gxx(x,y),
  1105. df(gx(~x,~y),~y) => gxy(x,y),
  1106. df(gy(~x,~y),~x) => gxy(x,y),
  1107. df(gy(~x,~y),~y) => gyy(x,y),
  1108. df(axx(~x,~y),~x) => axxx(x,y),
  1109. df(axy(~x,~y),~x) => axxy(x,y),
  1110. df(ayy(~x,~y),~x) => axyy(x,y),
  1111. df(ayy(~x,~y),~y) => ayyy(x,y),
  1112. df(fxx(~x,~y),~x) => fxxx(x,y),
  1113. df(fxy(~x,~y),~x) => fxxy(x,y),
  1114. df(fxy(~x,~y),~y) => fxyy(x,y),
  1115. df(fyy(~x,~y),~x) => fxyy(x,y),
  1116. df(fyy(~x,~y),~y) => fyyy(x,y),
  1117. df(gxx(~x,~y),~x) => gxxx(x,y),
  1118. df(gxx(~x,~y),~y) => gxxy(x,y),
  1119. df(gxy(~x,~y),~x) => gxxy(x,y),
  1120. df(gxy(~x,~y),~y) => gxyy(x,y),
  1121. df(gyy(~x,~y),~x) => gxyy(x,y),
  1122. df(gyy(~x,~y),~y) => gyyy(x,y),
  1123. df(axyy(~x,~y),~x) => axxyy(x,y),
  1124. df(axxy(~x,~y),~x) => axxxy(x,y),
  1125. df(ayyy(~x,~y),~x) => axyyy(x,y),
  1126. df(fxxy(~x,~y),~x) => fxxxy(x,y),
  1127. df(fxyy(~x,~y),~x) => fxxyy(x,y),
  1128. df(fyyy(~x,~y),~x) => fxyyy(x,y),
  1129. df(gxxx(~x,~y),~x) => gxxxx(x,y),
  1130. df(gxxy(~x,~y),~x) => gxxxy(x,y),
  1131. df(gxyy(~x,~y),~x) => gxxyy(x,y),
  1132. df(gyyy(~x,~y),~x) => gxyyy(x,y),
  1133. df(gyyy(~x,~y),~y) => gyyyy(x,y),
  1134. df(axxyy(~x,~y),~x) => axxxyy(x,y),
  1135. df(axyyy(~x,~y),~x) => axxyyy(x,y),
  1136. df(fxxyy(~x,~y),~x) => fxxxyy(x,y),
  1137. df(fxyyy(~x,~y),~x) => fxxyyy(x,y),
  1138. df(gxxxy(~x,~y),~x) => gxxxxy(x,y),
  1139. df(gxxyy(~x,~y),~x) => gxxxyy(x,y),
  1140. df(gxyyy(~x,~y),~x) => gxxyyy(x,y),
  1141. df(gyyyy(~x,~y),~x) => gxyyyy(x,y),
  1142. df(gxxxyy(~x,~y),~x) => gxxxxyy(x,y),
  1143. df(gxxyyy(~x,~y),~x) => gxxxyyy(x,y),
  1144. df(gxyyyy(~x,~y),~x) => gxxyyyy(x,y)}
  1145. let operator_diff_rules;
  1146. texp := taylor (finite_difference_expression, dx, 0, 1, dy, 0, 1);
  1147. 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)
  1148. + 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)
  1149. + a(x,y)*fy(x,y)*gxx(x,y)*gy(x,y) + ax(x,y)*fy(x,y)*gx(x,y)*gy(x,y)
  1150. 2 2
  1151. + ay(x,y)*fx(x,y)*gx(x,y)*gy(x,y) + O(dx ,dy )
  1152. comment You may also try to expand further but this needs a lot
  1153. of CPU time. Therefore the following line is commented out;
  1154. %texp := taylor (finite_difference_expression, dx, 0, 2, dy, 0, 2);
  1155. factor dx,dy;
  1156. result := taylortostandard texp;
  1157. 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)
  1158. + 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)
  1159. + a(x,y)*fy(x,y)*gxx(x,y)*gy(x,y) + ax(x,y)*fy(x,y)*gx(x,y)*gy(x,y)
  1160. + ay(x,y)*fx(x,y)*gx(x,y)*gy(x,y)
  1161. derivative_expression - result;
  1162. 0
  1163. clear diff(~f,~arg);
  1164. clearrules operator_diff_rules;
  1165. clear diff,a,f,gg;
  1166. clear ax,ay,fx,fy,gx,gy;
  1167. clear axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  1168. clear axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  1169. clear axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  1170. clear axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  1171. clear gxxxxyy,gxxxyyy,gxxyyyy;
  1172. taylorprintterms := 5;
  1173. taylorprintterms := 5
  1174. off taylorautoexpand,taylorkeeporiginal;
  1175. %%% showtime;
  1176. comment An example provided by Alan Barnes: elliptic functions;
  1177. % Jacobi's elliptic functions
  1178. % sn(x,k), cn(x,k), dn(x,k).
  1179. % The modulus and complementary modulus are denoted by K and K!'
  1180. % usually written mathematically as k and k' respectively
  1181. %
  1182. % epsilon(x,k) is the incomplete elliptic integral of the second kind
  1183. % usually written mathematically as E(x,k)
  1184. %
  1185. % KK(k) is the complete elliptic integral of the first kind
  1186. % usually written mathematically as K(k)
  1187. % K(k) = arcsn(1,k)
  1188. % KK!'(k) is the complementary complete integral
  1189. % usually written mathematically as K'(k)
  1190. % NB. K'(k) = K(k')
  1191. % EE(k) is the complete elliptic integral of the second kind
  1192. % usually written mathematically as E(k)
  1193. % EE!'(k) is the complementary complete integral
  1194. % usually written mathematically as E'(k)
  1195. % NB. E'(k) = E(k')
  1196. operator sn, cn, dn, epsilon;
  1197. elliptic_rules := {
  1198. % Differentiation rules for basic functions
  1199. df(sn(~x,~k),~x) => cn(x,k)*dn(x,k),
  1200. df(cn(~x,~k),~x) => -sn(x,k)*dn(x,k),
  1201. df(dn(~x,~k),~x) => -k^2*sn(x,k)*cn(x,k),
  1202. df(epsilon(~x,~k),~x)=> dn(x,k)^2,
  1203. % k-derivatives
  1204. % DF Lawden Elliptic Functions & Applications Springer (1989)
  1205. df(sn(~x,~k),~k) => (k*sn(x,k)*cn(x,k)^2
  1206. -epsilon(x,k)*cn(x,k)*dn(x,k)/k)/(1-k^2)
  1207. + x*cn(x,k)*dn(x,k)/k,
  1208. df(cn(~x,~k),~k) => (-k*sn(x,k)^2*cn(x,k)
  1209. +epsilon(x,k)*sn(x,k)*dn(x,k)/k)/(1-k^2)
  1210. - x*sn(x,k)*dn(x,k)/k,
  1211. df(dn(~x,~k),~k) => k*(-sn(x,k)^2*dn(x,k)
  1212. +epsilon(x,k)*sn(x,k)*cn(x,k))/(1-k^2)
  1213. - k*x*sn(x,k)*cn(x,k),
  1214. df(epsilon(~x,~k),~k) => k*(sn(x,k)*cn(x,k)*dn(x,k)
  1215. -epsilon(x,k)*cn(x,k)^2)/(1-k^2)
  1216. -k*x*sn(x,k)^2,
  1217. % parity properties
  1218. sn(-~x,~k) => -sn(x,k),
  1219. cn(-~x,~k) => cn(x,k),
  1220. dn(-~x,~k) => dn(x,k),
  1221. epsilon(-~x,~k) => -epsilon(x,k),
  1222. sn(~x,-~k) => sn(x,k),
  1223. cn(~x,-~k) => cn(x,k),
  1224. dn(~x,-~k) => dn(x,k),
  1225. epsilon(~x,-~k) => epsilon(x,k),
  1226. % behaviour at zero
  1227. sn(0,~k) => 0,
  1228. cn(0,~k) => 1,
  1229. dn(0,~k) => 1,
  1230. epsilon(0,~k) => 0,
  1231. % degenerate cases of modulus
  1232. sn(~x,0) => sin(x),
  1233. cn(~x,0) => cos(x),
  1234. dn(~x,0) => 1,
  1235. epsilon(~x,0) => x,
  1236. sn(~x,1) => tanh(x),
  1237. cn(~x,1) => 1/cosh(x),
  1238. dn(~x,1) => 1/cosh(x),
  1239. epsilon(~x,1) => tanh(x)
  1240. };
  1241. elliptic_rules := {df(sn(~x,~k),~x) => cn(x,k)*dn(x,k),
  1242. df(cn(~x,~k),~x) => - sn(x,k)*dn(x,k),
  1243. 2
  1244. df(dn(~x,~k),~x) => - k *sn(x,k)*cn(x,k),
  1245. 2
  1246. df(epsilon(~x,~k),~x) => dn(x,k) ,
  1247. 2 dn(x,k)
  1248. k*sn(x,k)*cn(x,k) - epsilon(x,k)*cn(x,k)*---------
  1249. k
  1250. df(sn(~x,~k),~k) => -----------------------------------------------------
  1251. 2
  1252. 1 - k
  1253. dn(x,k)
  1254. + x*cn(x,k)*---------,
  1255. k
  1256. 2 dn(x,k)
  1257. - k*sn(x,k) *cn(x,k) + epsilon(x,k)*sn(x,k)*---------
  1258. k
  1259. df(cn(~x,~k),~k) => --------------------------------------------------------
  1260. 2
  1261. 1 - k
  1262. dn(x,k)
  1263. - x*sn(x,k)*---------,
  1264. k
  1265. 2
  1266. - sn(x,k) *dn(x,k) + epsilon(x,k)*sn(x,k)*cn(x,k)
  1267. df(dn(~x,~k),~k) => k*----------------------------------------------------
  1268. 2
  1269. 1 - k
  1270. - k*x*sn(x,k)*cn(x,k),
  1271. df(epsilon(~x,~k),~k)
  1272. 2
  1273. sn(x,k)*cn(x,k)*dn(x,k) - epsilon(x,k)*cn(x,k) 2
  1274. => k*------------------------------------------------- - k*x*sn(x,k) ,
  1275. 2
  1276. 1 - k
  1277. sn( - ~x,~k) => - sn(x,k),
  1278. cn( - ~x,~k) => cn(x,k),
  1279. dn( - ~x,~k) => dn(x,k),
  1280. epsilon( - ~x,~k) => - epsilon(x,k),
  1281. sn(~x, - ~k) => sn(x,k),
  1282. cn(~x, - ~k) => cn(x,k),
  1283. dn(~x, - ~k) => dn(x,k),
  1284. epsilon(~x, - ~k) => epsilon(x,k),
  1285. sn(0,~k) => 0,
  1286. cn(0,~k) => 1,
  1287. dn(0,~k) => 1,
  1288. epsilon(0,~k) => 0,
  1289. sn(~x,0) => sin(x),
  1290. cn(~x,0) => cos(x),
  1291. dn(~x,0) => 1,
  1292. epsilon(~x,0) => x,
  1293. sn(~x,1) => tanh(x),
  1294. 1
  1295. cn(~x,1) => ---------,
  1296. cosh(x)
  1297. 1
  1298. dn(~x,1) => ---------,
  1299. cosh(x)
  1300. epsilon(~x,1) => tanh(x)}
  1301. let elliptic_rules;
  1302. hugo := taylor(sn(x,k),k,0,6);
  1303. 2 2
  1304. cos(x)*(cos(x) *x + cos(x)*sin(x) + sin(x) *x - 2*x) 2
  1305. hugo := sin(x) + ------------------------------------------------------*k + (
  1306. 4
  1307. 5 4 2 4
  1308. cos(x) *x - 2*cos(x) *sin(x)*x + 5*cos(x) *sin(x)
  1309. 3 2 3 2 3 2
  1310. - 10*cos(x) *sin(x) *x + 6*cos(x) *x - 4*cos(x) *sin(x) *x
  1311. 2 3 2 2 2
  1312. + cos(x) *sin(x) + 8*cos(x) *sin(x)*x + 4*cos(x) *sin(x)
  1313. 4 2
  1314. - 11*cos(x)*sin(x) *x + 30*cos(x)*sin(x) *x - 16*cos(x)*x
  1315. 5 2 3 2 2 4
  1316. - 2*sin(x) *x + 8*sin(x) *x - 8*sin(x)*x )/64*k + (
  1317. 7 3 7 6 2
  1318. - 6*cos(x) *x + 17*cos(x) *x - 99*cos(x) *sin(x)*x
  1319. 6 5 2 3 5 2
  1320. + 21*cos(x) *sin(x) - 18*cos(x) *sin(x) *x - 71*cos(x) *sin(x) *x
  1321. 5 3 5 4 3 2
  1322. + 36*cos(x) *x - 18*cos(x) *x - 135*cos(x) *sin(x) *x
  1323. 4 3 4 2 4
  1324. - 133*cos(x) *sin(x) + 324*cos(x) *sin(x)*x + 172*cos(x) *sin(x)
  1325. 3 4 3 3 4
  1326. - 18*cos(x) *sin(x) *x - 13*cos(x) *sin(x) *x
  1327. 3 2 3 3 2 3 3
  1328. + 72*cos(x) *sin(x) *x - 156*cos(x) *sin(x) *x - 72*cos(x) *x
  1329. 3 2 5 2 2 5
  1330. + 160*cos(x) *x + 27*cos(x) *sin(x) *x - 118*cos(x) *sin(x)
  1331. 2 3 2 2 2
  1332. + 176*cos(x) *sin(x) - 108*cos(x) *sin(x)*x + 32*cos(x) *sin(x)
  1333. 6 3 6 4 3
  1334. - 6*cos(x)*sin(x) *x + 75*cos(x)*sin(x) *x + 36*cos(x)*sin(x) *x
  1335. 4 2 3 2
  1336. - 498*cos(x)*sin(x) *x - 72*cos(x)*sin(x) *x + 888*cos(x)*sin(x) *x
  1337. 3 7 2 5 2
  1338. + 48*cos(x)*x - 384*cos(x)*x + 63*sin(x) *x - 324*sin(x) *x
  1339. 3 2 2 6 7
  1340. + 540*sin(x) *x - 288*sin(x)*x )/2304*k + O(k )
  1341. otto := taylor(cn(x,k),k,0,6);
  1342. 2 2
  1343. sin(x)*( - cos(x) *x - cos(x)*sin(x) - sin(x) *x + 2*x) 2
  1344. otto := cos(x) + ---------------------------------------------------------*k +
  1345. 4
  1346. 5 2 4 3 2 2
  1347. ( - 2*cos(x) *x - 5*cos(x) *sin(x)*x - 4*cos(x) *sin(x) *x
  1348. 3 2 3 2 2 3
  1349. - 7*cos(x) *sin(x) + 8*cos(x) *x + 2*cos(x) *sin(x) *x
  1350. 2 4 2 4
  1351. + 2*cos(x) *sin(x)*x - 2*cos(x)*sin(x) *x - 3*cos(x)*sin(x)
  1352. 2 2 2 2 5
  1353. + 8*cos(x)*sin(x) *x - 4*cos(x)*sin(x) - 8*cos(x)*x + 7*sin(x) *x
  1354. 3 4 7 2
  1355. - 22*sin(x) *x + 16*sin(x)*x)/64*k + ( - 9*cos(x) *x
  1356. 6 3 6 5 2 2
  1357. + 6*cos(x) *sin(x)*x - 71*cos(x) *sin(x)*x + 135*cos(x) *sin(x) *x
  1358. 5 2 5 2 4 3 3
  1359. - 66*cos(x) *sin(x) - 36*cos(x) *x + 18*cos(x) *sin(x) *x
  1360. 4 3 4 3 4
  1361. - cos(x) *sin(x) *x - 36*cos(x) *sin(x)*x + 18*cos(x) *sin(x)*x
  1362. 3 4 2 3 4
  1363. + 297*cos(x) *sin(x) *x + 61*cos(x) *sin(x)
  1364. 3 2 2 3 2 3 2
  1365. - 720*cos(x) *sin(x) *x - 208*cos(x) *sin(x) + 252*cos(x) *x
  1366. 2 5 3 2 5
  1367. + 18*cos(x) *sin(x) *x + 31*cos(x) *sin(x) *x
  1368. 2 3 3 2 3
  1369. - 72*cos(x) *sin(x) *x - 24*cos(x) *sin(x) *x
  1370. 2 3 2 6 2
  1371. + 72*cos(x) *sin(x)*x + 56*cos(x) *sin(x)*x + 153*cos(x)*sin(x) *x
  1372. 6 4 2 4
  1373. + 91*cos(x)*sin(x) - 684*cos(x)*sin(x) *x - 212*cos(x)*sin(x)
  1374. 2 2 2 2
  1375. + 900*cos(x)*sin(x) *x - 32*cos(x)*sin(x) - 288*cos(x)*x
  1376. 7 3 7 5 3 5
  1377. + 6*sin(x) *x - 39*sin(x) *x - 36*sin(x) *x + 318*sin(x) *x
  1378. 3 3 3 3
  1379. + 72*sin(x) *x - 672*sin(x) *x - 48*sin(x)*x + 384*sin(x)*x)/2304
  1380. 6 7
  1381. *k + O(k )
  1382. taylorcombine(hugo^2 + otto^2);
  1383. 2 2 7
  1384. cos(x) + sin(x) + O(k )
  1385. clearrules elliptic_rules;
  1386. clear sn, cn, dn, epsilon;
  1387. %%% showtime;
  1388. comment That's all, folks;
  1389. end;
  1390. (TIME: taylor 14199 15009)