taylor.tst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. comment
  2. Test and demonstration file for the Taylor expansion package,
  3. by Rainer M. Schoepf. Works with version 2.2 (18-Jun-97);
  4. %%% showtime;
  5. on errcont; % disable interruption on errors
  6. comment Simple Taylor expansion;
  7. xx := taylor (e**x, x, 0, 4);
  8. yy := taylor (e**y, y, 0, 4);
  9. comment Basic operations, i.e. addition, subtraction, multiplication,
  10. and division are possible: this is not done automatically if
  11. the switch TAYLORAUTOCOMBINE is OFF. In this case it is
  12. necessary to use taylorcombine;
  13. taylorcombine (xx**2);
  14. taylorcombine (ws - xx);
  15. taylorcombine (xx**3);
  16. comment The result is again a Taylor kernel;
  17. if taylorseriesp ws then write "OK";
  18. comment It is not possible to combine Taylor kernels that were
  19. expanded with respect to different variables;
  20. taylorcombine (xx**yy);
  21. comment But we can take the exponential or the logarithm
  22. of a Taylor kernel;
  23. taylorcombine (e**xx);
  24. taylorcombine log ws;
  25. comment A more complicated example;
  26. hugo := taylor(log(1/(1-x)),x,0,5);
  27. taylorcombine(exp(hugo/(1+hugo)));
  28. comment We may try to expand about another point;
  29. taylor (xx, x, 1, 2);
  30. comment Arc tangent is one of the functions this package knows of;
  31. xxa := taylorcombine atan ws;
  32. comment The trigonometric functions;
  33. taylor (tan x / x, x, 0, 2);
  34. taylorcombine sin ws;
  35. taylor (cot x / x, x, 0, 4);
  36. comment The poles of these functions are correctly handled;
  37. taylor(tan x,x,pi/2,0);
  38. taylor(tan x,x,pi/2,3);
  39. comment Expansion with respect to more than one kernel is possible;
  40. xy := taylor (e**(x+y), x, 0, 2, y, 0, 2);
  41. taylorcombine (ws**2);
  42. comment We take the inverse and convert back to REDUCE's standard
  43. representation;
  44. taylorcombine (1/ws);
  45. taylortostandard ws;
  46. comment Some examples of Taylor kernel divsion;
  47. xx1 := taylor (sin (x), x, 0, 4);
  48. taylorcombine (xx/xx1);
  49. taylorcombine (1/xx1);
  50. tt1 := taylor (exp (x), x, 0, 3);
  51. tt2 := taylor (sin (x), x, 0, 3);
  52. tt3 := taylor (1 + tt2, x, 0, 3);
  53. taylorcombine(tt1/tt2);
  54. taylorcombine(tt1/tt3);
  55. taylorcombine(tt2/tt1);
  56. taylorcombine(tt3/tt1);
  57. comment Here's what I call homogeneous expansion;
  58. xx := taylor (e**(x*y), {x,y}, 0, 2);
  59. xx1 := taylor (sin (x+y), {x,y}, 0, 2);
  60. xx2 := taylor (cos (x+y), {x,y}, 0, 2);
  61. temp := taylorcombine (xx/xx2);
  62. taylorcombine (ws*xx2);
  63. comment The following shows a principal difficulty:
  64. since xx1 is symmetric in x and y but has no constant term
  65. it is impossible to compute 1/xx1;
  66. taylorcombine (1/xx1);
  67. comment Substitution in Taylor expressions is possible;
  68. sub (x=z, xy);
  69. comment Expression dependency in substitution is detected;
  70. sub (x=y, xy);
  71. comment It is possible to replace a Taylor variable by a constant;
  72. sub (x=4, xy);
  73. sub (x=4, xx1);
  74. sub (y=0, ws);
  75. comment This package has three switches:
  76. TAYLORKEEPORIGINAL, TAYLORAUTOEXPAND, and TAYLORAUTOCOMBINE;
  77. on taylorkeeporiginal;
  78. temp := taylor (e**(x+y), x, 0, 5);
  79. taylorcombine (log (temp));
  80. taylororiginal ws;
  81. taylorcombine (temp * e**x);
  82. on taylorautoexpand;
  83. taylorcombine ws;
  84. taylororiginal ws;
  85. taylorcombine (xx1 / x);
  86. on taylorautocombine;
  87. xx / xx2;
  88. ws * xx2;
  89. comment Another example that shows truncation if Taylor kernels
  90. of different expansion order are combined;
  91. comment First we increase the number of terms to be printed;
  92. taylorprintterms := all;
  93. p := taylor (x**2 + 2, x, 0, 10);
  94. p - x**2;
  95. p - taylor (x**2, x, 0, 5);
  96. taylor (p - x**2, x, 0, 6);
  97. off taylorautocombine;
  98. taylorcombine(p-x**2);
  99. taylorcombine(p - taylor(x**2,x,0,5));
  100. comment Switch back to finite number of terms;
  101. taylorprintterms := 6;
  102. comment Some more examples;
  103. taylor(1/(1+y^4+x^2*y^2+x^4),{x,y},0,6);
  104. taylor ((1 + x)**n, x, 0, 3);
  105. taylor (e**(-a*t) * (1 + sin(t)), t, 0, 4);
  106. operator f;
  107. taylor (1 + f(t), t, 0, 3);
  108. taylor(f(sqrt(x^2+y^2)),x,x0,4,y,y0,4);
  109. clear f;
  110. taylor (sqrt(1 + a*x + sin(x)), x, 0, 3);
  111. taylorcombine (ws**2);
  112. taylor (sqrt(1 + x), x, 0, 5);
  113. taylor ((cos(x) - sec(x))^3, x, 0, 5);
  114. taylor ((cos(x) - sec(x))^-3, x, 0, 5);
  115. taylor (sqrt(1 - k^2*sin(x)^2), x, 0, 6);
  116. taylor (sin(x + y), x, 0, 3, y, 0, 3);
  117. taylor (e^x - 1 - x,x,0,6);
  118. taylorcombine sqrt ws;
  119. taylor(sin(x)/x,x,1,2);
  120. taylor((sqrt(4+h)-2)/h,h,0,5);
  121. taylor((sqrt(x)-2)/(4-x),x,4,2);
  122. taylor((sqrt(y+4)-2)/(-y),y,0,2);
  123. taylor(x*tanh(x)/(sqrt(1-x^2)-1),x,0,3);
  124. taylor((e^(5*x)-2*x)^(1/x),x,0,2);
  125. taylor(sin x/cos x,x,pi/2,3);
  126. taylor(log x*sin(x^2)/(x*sinh x),x,0,2);
  127. taylor(1/x-1/sin x,x,0,2);
  128. taylor(tan x/log cos x,x,pi/2,2);
  129. taylor(log(x^2/(x^2-a)),x,0,3);
  130. comment Three more complicated examples contributed by Stan Kameny;
  131. zz2 := (z*(z-2*pi*i)*(z-pi*i/2)^2)/(sinh z-i);
  132. dz2 := df(zz2,z);
  133. z0 := pi*i/2;
  134. taylor(dz2,z,z0,6);
  135. zz3:=(z*(z-2*pi)*(z-pi/2)^2)/(sin z-1);
  136. dz3 := df(zz3,z);
  137. z1 := pi/2;
  138. taylor(dz3,z,z1,6);
  139. taylor((sin tan x-tan sin x)/(asin atan x-atan asin x),x,0,6);
  140. comment If the expansion point is not constant, it has to be taken
  141. care of in differentation, as the following examples show;
  142. taylor(sin(x+a),x,a,8);
  143. df(ws,a);
  144. taylor(cos(x+a),x,a,7);
  145. comment A problem are non-analytical terms: rational powers and
  146. logarithmic terms can be handled, but other types of essential
  147. singularities cannot;
  148. taylor(sqrt(x),x,0,2);
  149. taylor(asinh(1/x),x,0,5);
  150. taylor(e**(1/x),x,0,2);
  151. comment Another example for non-integer powers;
  152. sub (y = sqrt (x), yy);
  153. comment Expansion about infinity is possible in principle...;
  154. taylor (e**(1/x), x, infinity, 5);
  155. xi := taylor (sin (1/x), x, infinity, 5);
  156. y1 := taylor(x/(x-1), x, infinity, 3);
  157. z := df(y1, x);
  158. comment ...but far from being perfect;
  159. taylor (1 / sin (x), x, infinity, 5);
  160. clear z;
  161. comment You may access the expansion with the PART operator;
  162. part(yy,0);
  163. part(yy,1);
  164. part(yy,4);
  165. part(yy,6);
  166. comment The template of a Taylor kernel can be extracted;
  167. taylortemplate yy;
  168. taylortemplate xxa;
  169. taylortemplate xi;
  170. taylortemplate xy;
  171. taylortemplate xx1;
  172. comment Here is a slightly less trivial example;
  173. exp := (sin (x) * sin (y) / (x * y))**2;
  174. taylor (exp, x, 0, 1, y, 0, 1);
  175. taylor (exp, x, 0, 2, y, 0, 2);
  176. tt := taylor (exp, {x,y}, 0, 2);
  177. comment An example that uses factorization;
  178. on factor;
  179. ff := y**5 - 1;
  180. zz := sub (y = taylor(e**x, x, 0, 3), ff);
  181. on exp;
  182. zz;
  183. comment A simple example of Taylor kernel differentiation;
  184. hugo := taylor(e^x,x,0,5);
  185. df(hugo^2,x);
  186. comment The following shows the (limited) capabilities to integrate
  187. Taylor kernels. Only simple cases are supported, otherwise
  188. a warning is printed and the Taylor kernels are converted to
  189. standard representation;
  190. zz := taylor (sin x, x, 0, 5);
  191. ww := taylor (cos y, y, 0, 5);
  192. int (zz, x);
  193. int (ww, x);
  194. int (zz + ww, x);
  195. comment And here we present Taylor series reversion.
  196. We start with the example given by Knuth for the algorithm;
  197. taylor (t - t**2, t, 0, 5);
  198. taylorrevert (ws, t, x);
  199. tan!-series := taylor (tan x, x, 0, 5);
  200. taylorrevert (tan!-series, x, y);
  201. atan!-series:=taylor (atan y, y, 0, 5);
  202. tmp := taylor (e**x, x, 0, 5);
  203. taylorrevert (tmp, x, y);
  204. taylor (log y, y, 1, 5);
  205. comment The following example calculates the perturbation expansion
  206. of the root x = 20 of the following polynomial in terms of
  207. EPS, in ROUNDED mode;
  208. poly := for r := 1 : 20 product (x - r);
  209. on rounded;
  210. tpoly := taylor (poly, x, 20, 4);
  211. taylorrevert (tpoly, x, eps);
  212. comment Some more examples using rounded mode;
  213. taylor(sin x/x,x,0,4);
  214. taylor(sin x,x,pi/2,4);
  215. taylor(tan x,x,pi/2,4);
  216. off rounded;
  217. comment An example that involves computing limits of type 0/0 if
  218. expansion is done via differentiation;
  219. taylor(sqrt((e^x - 1)/x),x,0,15);
  220. comment An example that involves intermediate non-analytical terms
  221. which cancel entirely;
  222. taylor(x^(5/2)/(log(x+1)*tan(x^(3/2))),x,0,5);
  223. comment Other examples involving non-analytical terms;
  224. taylor(log(e^x-1),x,0,5);
  225. taylor(e^(1/x)*(e^x-1),x,0,5);
  226. taylor(log(x)*x^10,x,0,5);
  227. taylor(log(x)*x^10,x,0,11);
  228. taylor(log(x-a)/((a-b)*(a-c)) + log(2(x-b))/((b-c)*(b-a))
  229. + log(x-c)/((c-a)*(c-b)),x,infinity,2);
  230. ss := (sqrt(x^(2/5) +1) - x^(1/3)-1)/x^(1/3);
  231. taylor(exp ss,x,0,2);
  232. taylor(exp sub(x=x^15,ss),x,0,2);
  233. taylor(dilog(x),x,0,4);
  234. taylor(ei(x),x,0,4);
  235. comment In the following we demonstrate the possibiblity to compute the
  236. expansion of a function which is given by a simple first order
  237. differential equation: the function myexp(x) is exp(-x^2);
  238. operator myexp,myerf;
  239. let {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  240. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  241. taylor(myexp(x),x,0,5);
  242. taylor(myerf(x),x,0,5);
  243. clear {df(myexp(~x),~x) => -2*x*myexp(x), myexp(0) => 1,
  244. df(myerf(~x),~x) => 2/sqrt(pi)*myexp(x), myerf(0) => 0};
  245. clear myexp,erf;
  246. %%% showtime;
  247. comment There are two special operators, implicit_taylor and
  248. inverse_taylor, to compute the Taylor expansion of implicit
  249. or inverse functions;
  250. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,5);
  251. implicit_taylor(x^2 + y^2 - 1,x,y,0,1,20);
  252. implicit_taylor(x+y^3-y,x,y,0,0,8);
  253. implicit_taylor(x+y^3-y,x,y,0,1,5);
  254. implicit_taylor(x+y^3-y,x,y,0,-1,5);
  255. implicit_taylor(y*e^y-x,x,y,0,0,5);
  256. comment This is the function exp(-1/x^2), which has an essential
  257. singularity at the point 0;
  258. implicit_taylor(x^2*log y+1,x,y,0,0,3);
  259. inverse_taylor(exp(x)-1,x,y,0,8);
  260. inverse_taylor(exp(x),x,y,0,5);
  261. inverse_taylor(sqrt(x),x,y,0,5);
  262. inverse_taylor(log(1+x),x,y,0,5);
  263. inverse_taylor((e^x-e^(-x))/2,x,y,0,5);
  264. comment In the next two cases the inverse functions have a branch
  265. point, therefore the computation fails;
  266. inverse_taylor((e^x+e^(-x))/2,x,y,0,5);
  267. inverse_taylor(exp(x^2-1),x,y,0,5);
  268. inverse_taylor(exp(sqrt(x))-1,x,y,0,5);
  269. inverse_taylor(x*exp(x),x,y,0,5);
  270. %%% showtime;
  271. comment An application is the problem posed by Prof. Stanley:
  272. we prove that the finite difference expression below
  273. corresponds to the given derivative expression;
  274. operator diff,a,f,gg; % We use gg to avoid conflict with high energy
  275. % physics operator.
  276. let diff(~f,~arg) => df(f,arg);
  277. derivative_expression :=
  278. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),y),x) +
  279. diff(a(x,y)*diff(gg(x,y),x)*diff(gg(x,y),y)*diff(f(x,y),x),y) ;
  280. finite_difference_expression :=
  281. +a(x+dx,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  282. +a(x+dx,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  283. +a(x,y+dy)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  284. +a(x,y)*f(x+dx,y+dy)*gg(x+dx,y+dy)^2/(32*dx^2*dy^2)
  285. -f(x,y)*a(x+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dy^2)
  453. -f(x,y)*gg(x,y)^2*a(x,y+dy)/(16*dx^2*dy^2)
  454. +f(x,y)*a(x,y-dy)*gg(x,y-dy)^2/(16*dx^2*dy^2)
  455. +a(x,y)*f(x,y)*gg(x,y-dy)^2/(16*dx^2*dy^2)
  456. -f(x,y)*gg(x,y)^2*a(x,y-dy)/(16*dx^2*dy^2)
  457. -a(x,y)*f(x,y)*gg(x,y)^2/(8*dx^2*dy^2)$
  458. comment We define abbreviations for the partial derivatives;
  459. operator ax,ay,fx,fy,gx,gy;
  460. operator axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  461. operator axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  462. operator axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,
  463. gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  464. operator axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  465. operator gxxxxyy,gxxxyyy,gxxyyyy;
  466. operator_diff_rules := {
  467. df(a(~x,~y),~x) => ax(x,y),
  468. df(a(~x,~y),~y) => ay(x,y),
  469. df(f(~x,~y),~x) => fx(x,y),
  470. df(f(~x,~y),~y) => fy(x,y),
  471. df(gg(~x,~y),~x) => gx(x,y),
  472. df(gg(~x,~y),~y) => gy(x,y),
  473. df(ax(~x,~y),~x) => axx(x,y),
  474. df(ax(~x,~y),~y) => axy(x,y),
  475. df(ay(~x,~y),~x) => axy(x,y),
  476. df(ay(~x,~y),~y) => ayy(x,y),
  477. df(fx(~x,~y),~x) => fxx(x,y),
  478. df(fx(~x,~y),~y) => fxy(x,y),
  479. df(fy(~x,~y),~x) => fxy(x,y),
  480. df(fy(~x,~y),~y) => fyy(x,y),
  481. df(gx(~x,~y),~x) => gxx(x,y),
  482. df(gx(~x,~y),~y) => gxy(x,y),
  483. df(gy(~x,~y),~x) => gxy(x,y),
  484. df(gy(~x,~y),~y) => gyy(x,y),
  485. df(axx(~x,~y),~x) => axxx(x,y),
  486. df(axy(~x,~y),~x) => axxy(x,y),
  487. df(ayy(~x,~y),~x) => axyy(x,y),
  488. df(ayy(~x,~y),~y) => ayyy(x,y),
  489. df(fxx(~x,~y),~x) => fxxx(x,y),
  490. df(fxy(~x,~y),~x) => fxxy(x,y),
  491. df(fxy(~x,~y),~y) => fxyy(x,y),
  492. df(fyy(~x,~y),~x) => fxyy(x,y),
  493. df(fyy(~x,~y),~y) => fyyy(x,y),
  494. df(gxx(~x,~y),~x) => gxxx(x,y),
  495. df(gxx(~x,~y),~y) => gxxy(x,y),
  496. df(gxy(~x,~y),~x) => gxxy(x,y),
  497. df(gxy(~x,~y),~y) => gxyy(x,y),
  498. df(gyy(~x,~y),~x) => gxyy(x,y),
  499. df(gyy(~x,~y),~y) => gyyy(x,y),
  500. df(axyy(~x,~y),~x) => axxyy(x,y),
  501. df(axxy(~x,~y),~x) => axxxy(x,y),
  502. df(ayyy(~x,~y),~x) => axyyy(x,y),
  503. df(fxxy(~x,~y),~x) => fxxxy(x,y),
  504. df(fxyy(~x,~y),~x) => fxxyy(x,y),
  505. df(fyyy(~x,~y),~x) => fxyyy(x,y),
  506. df(gxxx(~x,~y),~x) => gxxxx(x,y),
  507. df(gxxy(~x,~y),~x) => gxxxy(x,y),
  508. df(gxyy(~x,~y),~x) => gxxyy(x,y),
  509. df(gyyy(~x,~y),~x) => gxyyy(x,y),
  510. df(gyyy(~x,~y),~y) => gyyyy(x,y),
  511. df(axxyy(~x,~y),~x) => axxxyy(x,y),
  512. df(axyyy(~x,~y),~x) => axxyyy(x,y),
  513. df(fxxyy(~x,~y),~x) => fxxxyy(x,y),
  514. df(fxyyy(~x,~y),~x) => fxxyyy(x,y),
  515. df(gxxxy(~x,~y),~x) => gxxxxy(x,y),
  516. df(gxxyy(~x,~y),~x) => gxxxyy(x,y),
  517. df(gxyyy(~x,~y),~x) => gxxyyy(x,y),
  518. df(gyyyy(~x,~y),~x) => gxyyyy(x,y),
  519. df(gxxxyy(~x,~y),~x) => gxxxxyy(x,y),
  520. df(gxxyyy(~x,~y),~x) => gxxxyyy(x,y),
  521. df(gxyyyy(~x,~y),~x) => gxxyyyy(x,y)
  522. };
  523. let operator_diff_rules;
  524. texp := taylor (finite_difference_expression, dx, 0, 1, dy, 0, 1);
  525. comment You may also try to expand further but this needs a lot
  526. of CPU time. Therefore the following line is commented out;
  527. %texp := taylor (finite_difference_expression, dx, 0, 2, dy, 0, 2);
  528. factor dx,dy;
  529. result := taylortostandard texp;
  530. derivative_expression - result;
  531. clear diff(~f,~arg);
  532. clearrules operator_diff_rules;
  533. clear diff,a,f,gg;
  534. clear ax,ay,fx,fy,gx,gy;
  535. clear axx,axy,ayy,fxx,fxy,fyy,gxx,gxy,gyy;
  536. clear axxx,axxy,axyy,ayyy,fxxx,fxxy,fxyy,fyyy,gxxx,gxxy,gxyy,gyyy;
  537. clear axxxy,axxyy,axyyy,fxxxy,fxxyy,fxyyy,gxxxx,gxxxy,gxxyy,gxyyy,gyyyy;
  538. clear axxxyy,axxyyy,fxxyyy,fxxxyy,gxxxxy,gxxxyy,gxxyyy,gxyyyy;
  539. clear gxxxxyy,gxxxyyy,gxxyyyy;
  540. taylorprintterms := 5;
  541. off taylorautoexpand,taylorkeeporiginal;
  542. %%% showtime;
  543. comment An example provided by Alan Barnes: elliptic functions;
  544. % Jacobi's elliptic functions
  545. % sn(x,k), cn(x,k), dn(x,k).
  546. % The modulus and complementary modulus are denoted by K and K!'
  547. % usually written mathematically as k and k' respectively
  548. %
  549. % epsilon(x,k) is the incomplete elliptic integral of the second kind
  550. % usually written mathematically as E(x,k)
  551. %
  552. % KK(k) is the complete elliptic integral of the first kind
  553. % usually written mathematically as K(k)
  554. % K(k) = arcsn(1,k)
  555. % KK!'(k) is the complementary complete integral
  556. % usually written mathematically as K'(k)
  557. % NB. K'(k) = K(k')
  558. % EE(k) is the complete elliptic integral of the second kind
  559. % usually written mathematically as E(k)
  560. % EE!'(k) is the complementary complete integral
  561. % usually written mathematically as E'(k)
  562. % NB. E'(k) = E(k')
  563. operator sn, cn, dn, epsilon;
  564. elliptic_rules := {
  565. % Differentiation rules for basic functions
  566. df(sn(~x,~k),~x) => cn(x,k)*dn(x,k),
  567. df(cn(~x,~k),~x) => -sn(x,k)*dn(x,k),
  568. df(dn(~x,~k),~x) => -k^2*sn(x,k)*cn(x,k),
  569. df(epsilon(~x,~k),~x)=> dn(x,k)^2,
  570. % k-derivatives
  571. % DF Lawden Elliptic Functions & Applications Springer (1989)
  572. df(sn(~x,~k),~k) => (k*sn(x,k)*cn(x,k)^2
  573. -epsilon(x,k)*cn(x,k)*dn(x,k)/k)/(1-k^2)
  574. + x*cn(x,k)*dn(x,k)/k,
  575. df(cn(~x,~k),~k) => (-k*sn(x,k)^2*cn(x,k)
  576. +epsilon(x,k)*sn(x,k)*dn(x,k)/k)/(1-k^2)
  577. - x*sn(x,k)*dn(x,k)/k,
  578. df(dn(~x,~k),~k) => k*(-sn(x,k)^2*dn(x,k)
  579. +epsilon(x,k)*sn(x,k)*cn(x,k))/(1-k^2)
  580. - k*x*sn(x,k)*cn(x,k),
  581. df(epsilon(~x,~k),~k) => k*(sn(x,k)*cn(x,k)*dn(x,k)
  582. -epsilon(x,k)*cn(x,k)^2)/(1-k^2)
  583. -k*x*sn(x,k)^2,
  584. % parity properties
  585. sn(-~x,~k) => -sn(x,k),
  586. cn(-~x,~k) => cn(x,k),
  587. dn(-~x,~k) => dn(x,k),
  588. epsilon(-~x,~k) => -epsilon(x,k),
  589. sn(~x,-~k) => sn(x,k),
  590. cn(~x,-~k) => cn(x,k),
  591. dn(~x,-~k) => dn(x,k),
  592. epsilon(~x,-~k) => epsilon(x,k),
  593. % behaviour at zero
  594. sn(0,~k) => 0,
  595. cn(0,~k) => 1,
  596. dn(0,~k) => 1,
  597. epsilon(0,~k) => 0,
  598. % degenerate cases of modulus
  599. sn(~x,0) => sin(x),
  600. cn(~x,0) => cos(x),
  601. dn(~x,0) => 1,
  602. epsilon(~x,0) => x,
  603. sn(~x,1) => tanh(x),
  604. cn(~x,1) => 1/cosh(x),
  605. dn(~x,1) => 1/cosh(x),
  606. epsilon(~x,1) => tanh(x)
  607. };
  608. let elliptic_rules;
  609. hugo := taylor(sn(x,k),k,0,6);
  610. otto := taylor(cn(x,k),k,0,6);
  611. taylorcombine(hugo^2 + otto^2);
  612. clearrules elliptic_rules;
  613. clear sn, cn, dn, epsilon;
  614. %%% showtime;
  615. comment That's all, folks;
  616. end;