REDUCE.LOG 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. Comment This is a standard test file for REDUCE that has been used for
  3. many years. It only tests a limited number of facilities in the
  4. current system. In particular, it does not test floating point
  5. arithmetic, or any of the more advanced packages that have been made
  6. available since REDUCE 3.0 was released. It has been used for a long
  7. time to benchmark the performance of REDUCE. A description of this
  8. benchmarking with statistics for REDUCE 3.2 was reported in Jed B.
  9. Marti and Anthony C. Hearn, "REDUCE as a Lisp Benchmark", SIGSAM Bull.
  10. 19 (1985) 8-16. That paper also gives information on the the parts of
  11. the system exercised by the test file. Updated statistics may be found
  12. in the "timings" file in the REDUCE Network Library;
  13. showtime;
  14. Time: 20 ms
  15. comment some examples of the FOR statement;
  16. comment summing the squares of the even positive integers
  17. through 50;
  18. for i:=2 step 2 until 50 sum i**2;
  19. 22100
  20. comment to set w to the factorial of 10;
  21. w := for i:=1:10 product i;
  22. w := 3628800
  23. comment alternatively, we could set the elements a(i) of the
  24. array a to the factorial of i by the statements;
  25. array a(10);
  26. a(0):=1$
  27. for i:=1:10 do a(i):=i*a(i-1);
  28. comment the above version of the FOR statement does not return
  29. an algebraic value, but we can now use these array
  30. elements as factorials in expressions, e. g.;
  31. 1+a(5);
  32. 121
  33. comment we could have printed the values of each a(i)
  34. as they were computed by writing the FOR statement as;
  35. for i:=1:10 do write a(i):= i*a(i-1);
  36. a(1) := 1
  37. a(2) := 2
  38. a(3) := 6
  39. a(4) := 24
  40. a(5) := 120
  41. a(6) := 720
  42. a(7) := 5040
  43. a(8) := 40320
  44. a(9) := 362880
  45. a(10) := 3628800
  46. comment another way to use factorials would be to introduce an
  47. operator FAC by an integer procedure as follows;
  48. integer procedure fac (n);
  49. begin integer m;
  50. m:=1;
  51. l1: if n=0 then return m;
  52. m:=m*n;
  53. n:=n-1;
  54. go to l1
  55. end;
  56. fac
  57. comment we can now use fac as an operator in expressions, e. g.;
  58. z**2+fac(4)-2*fac 2*y;
  59. 2
  60. - 4*y + z + 24
  61. comment note in the above example that the parentheses around
  62. the arguments of FAC may be omitted since it is a unary operator;
  63. comment the following examples illustrate the solution of some
  64. complete problems;
  65. comment the f and g series (ref Sconzo, P., Leschack, A. R. and
  66. Tobey, R. G., Astronomical Journal, Vol 70 (May 1965);
  67. deps:= -sigma*(mu+2*epsilon)$
  68. dmu:= -3*mu*sigma$
  69. dsig:= epsilon-2*sigma**2$
  70. f1:= 1$
  71. g1:= 0$
  72. for i:= 1:8 do
  73. <<f2:=-mu*g1 + deps*df(f1,epsilon) + dmu*df(f1,mu) + dsig*df(f1,sigma);
  74. write "F(",i,") := ",f2;
  75. g2:= f1 + deps*df(g1,epsilon) + dmu*df(g1,mu) + dsig*df(g1,sigma);
  76. write "G(",i,") := ",g2;
  77. f1:=f2;
  78. g1:=g2>>;
  79. F(1) := 0
  80. G(1) := 1
  81. F(2) := - mu
  82. G(2) := 0
  83. F(3) := 3*mu*sigma
  84. G(3) := - mu
  85. 2
  86. F(4) := mu*(3*epsilon + mu - 15*sigma )
  87. G(4) := 6*mu*sigma
  88. 2
  89. F(5) := 15*mu*sigma*( - 3*epsilon - mu + 7*sigma )
  90. 2
  91. G(5) := mu*(9*epsilon + mu - 45*sigma )
  92. 2 2 2
  93. F(6) := mu*( - 45*epsilon - 24*epsilon*mu + 630*epsilon*sigma - mu
  94. 2 4
  95. + 210*mu*sigma - 945*sigma )
  96. 2
  97. G(6) := 30*mu*sigma*( - 6*epsilon - mu + 14*sigma )
  98. 2 2 2
  99. F(7) := 63*mu*sigma*(25*epsilon + 14*epsilon*mu - 150*epsilon*sigma + mu
  100. 2 4
  101. - 50*mu*sigma + 165*sigma )
  102. 2 2 2
  103. G(7) := mu*( - 225*epsilon - 54*epsilon*mu + 3150*epsilon*sigma - mu
  104. 2 4
  105. + 630*mu*sigma - 4725*sigma )
  106. 3 2 2 2
  107. F(8) := mu*(1575*epsilon + 1107*epsilon *mu - 42525*epsilon *sigma
  108. 2 2 4
  109. + 117*epsilon*mu - 24570*epsilon*mu*sigma + 155925*epsilon*sigma
  110. 3 2 2 4 6
  111. + mu - 2205*mu *sigma + 51975*mu*sigma - 135135*sigma )
  112. 2 2 2
  113. G(8) := 126*mu*sigma*(75*epsilon + 24*epsilon*mu - 450*epsilon*sigma + mu
  114. 2 4
  115. - 100*mu*sigma + 495*sigma )
  116. comment a problem in Fourier analysis;
  117. factor cos,sin;
  118. on list;
  119. (a1*cos(omega*t) + a3*cos(3*omega*t) + b1*sin(omega*t)
  120. + b3*sin(3*omega*t))**3
  121. where {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  122. cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2,
  123. sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2,
  124. cos(~x)**2 => (1+cos(2*x))/2,
  125. sin(~x)**2 => (1-cos(2*x))/2};
  126. 3
  127. (3*cos(omega*t)*(a1
  128. 2
  129. +a1 *a3
  130. 2
  131. +2*a1*a3
  132. 2
  133. +a1*b1
  134. +2*a1*b1*b3
  135. 2
  136. +2*a1*b3
  137. 2
  138. -a3*b1 )
  139. 2
  140. +cos(9*omega*t)*a3*(a3
  141. 2
  142. -3*b3 )
  143. 2
  144. +3*cos(7*omega*t)*(a1*a3
  145. 2
  146. -a1*b3
  147. -2*a3*b1*b3)
  148. 2
  149. +3*cos(5*omega*t)*(a1 *a3
  150. 2
  151. +a1*a3
  152. -2*a1*b1*b3
  153. 2
  154. -a1*b3
  155. 2
  156. -a3*b1
  157. +2*a3*b1*b3)
  158. 3
  159. +cos(3*omega*t)*(a1
  160. 2
  161. +6*a1 *a3
  162. 2
  163. -3*a1*b1
  164. 3
  165. +3*a3
  166. 2
  167. +6*a3*b1
  168. 2
  169. +3*a3*b3 )
  170. 2
  171. +3*sin(omega*t)*(a1 *b1
  172. 2
  173. +a1 *b3
  174. -2*a1*a3*b1
  175. 2
  176. +2*a3 *b1
  177. 3
  178. +b1
  179. 2
  180. -b1 *b3
  181. 2
  182. +2*b1*b3 )
  183. 2
  184. +sin(9*omega*t)*b3*(3*a3
  185. 2
  186. -b3 )
  187. +3*sin(7*omega*t)*(2*a1*a3*b3
  188. 2
  189. +a3 *b1
  190. 2
  191. -b1*b3 )
  192. 2
  193. +3*sin(5*omega*t)*(a1 *b3
  194. +2*a1*a3*b1
  195. +2*a1*a3*b3
  196. 2
  197. -a3 *b1
  198. 2
  199. -b1 *b3
  200. 2
  201. +b1*b3 )
  202. 2
  203. +sin(3*omega*t)*(3*a1 *b1
  204. 2
  205. +6*a1 *b3
  206. 2
  207. +3*a3 *b3
  208. 3
  209. -b1
  210. 2
  211. +6*b1 *b3
  212. 3
  213. +3*b3 ))/4
  214. remfac cos,sin;
  215. off list;
  216. comment end of Fourier analysis example;
  217. comment the following program, written in collaboration with David
  218. Barton and John Fitch, solves a problem in general relativity. it
  219. will compute the Einstein tensor from any given metric;
  220. on nero;
  221. comment here we introduce the covariant and contravariant metrics;
  222. operator p1,q1,x;
  223. array gg(3,3),h(3,3);
  224. gg(0,0):=e**(q1(x(1)))$
  225. gg(1,1):=-e**(p1(x(1)))$
  226. gg(2,2):=-x(1)**2$
  227. gg(3,3):=-x(1)**2*sin(x(2))**2$
  228. for i:=0:3 do h(i,i):=1/gg(i,i);
  229. comment generate Christoffel symbols and store in arrays cs1 and cs2;
  230. array cs1(3,3,3),cs2(3,3,3);
  231. for i:=0:3 do for j:=i:3 do
  232. <<for k:=0:3 do
  233. cs1(j,i,k) := cs1(i,j,k):=(df(gg(i,k),x(j))+df(gg(j,k),x(i))
  234. -df(gg(i,j),x(k)))/2;
  235. for k:=0:3 do cs2(j,i,k):= cs2(i,j,k) := for p := 0:3
  236. sum h(k,p)*cs1(i,j,p)>>;
  237. comment now compute the Riemann tensor and store in r(i,j,k,l);
  238. array r(3,3,3,3);
  239. for i:=0:3 do for j:=i+1:3 do for k:=i:3 do
  240. for l:=k+1:if k=i then j else 3 do
  241. <<r(j,i,l,k) := r(i,j,k,l) := for q := 0:3
  242. sum gg(i,q)*(df(cs2(k,j,q),x(l))-df(cs2(j,l,q),x(k))
  243. + for p:=0:3 sum (cs2(p,l,q)*cs2(k,j,p)
  244. -cs2(p,k,q)*cs2(l,j,p)));
  245. r(i,j,l,k) := -r(i,j,k,l);
  246. r(j,i,k,l) := -r(i,j,k,l);
  247. if i neq k or j>l
  248. then <<r(k,l,i,j) := r(l,k,j,i) := r(i,j,k,l);
  249. r(l,k,i,j) := -r(i,j,k,l);
  250. r(k,l,j,i) := -r(i,j,k,l)>>>>;
  251. comment now compute and print the Ricci tensor;
  252. array ricci(3,3);
  253. for i:=0:3 do for j:=0:3 do
  254. write ricci(j,i) := ricci(i,j) := for p := 0:3 sum for q := 0:3
  255. sum h(p,q)*r(q,i,p,j);
  256. q1(x(1))
  257. ricci(0,0) := ricci(0,0) := (e *(df(p1(x(1)),x(1))*df(q1(x(1)),x(1))*x(1)
  258. 2
  259. - 2*df(q1(x(1)),x(1),2)*x(1) - df(q1(x(1)),x(1)) *x(1)
  260. p1(x(1))
  261. - 4*df(q1(x(1)),x(1))))/(4*e *x(1))
  262. ricci(1,1) := ricci(1,1) := ( - df(p1(x(1)),x(1))*df(q1(x(1)),x(1))*x(1)
  263. 2
  264. - 4*df(p1(x(1)),x(1)) + 2*df(q1(x(1)),x(1),2)*x(1) + df(q1(x(1)),x(1)) *x(1)
  265. )/(4*x(1))
  266. ricci(2,2) := ricci(2,2) :=
  267. p1(x(1))
  268. - df(p1(x(1)),x(1))*x(1) + df(q1(x(1)),x(1))*x(1) - 2*e + 2
  269. ----------------------------------------------------------------------
  270. p1(x(1))
  271. 2*e
  272. 2
  273. ricci(3,3) := ricci(3,3) := (sin(x(2))
  274. p1(x(1))
  275. *( - df(p1(x(1)),x(1))*x(1) + df(q1(x(1)),x(1))*x(1) - 2*e + 2))/(2
  276. p1(x(1))
  277. *e )
  278. comment now compute and print the Ricci scalar;
  279. rs := for i:= 0:3 sum for j:= 0:3 sum h(i,j)*ricci(i,j);
  280. 2
  281. rs := (df(p1(x(1)),x(1))*df(q1(x(1)),x(1))*x(1) + 4*df(p1(x(1)),x(1))*x(1)
  282. 2 2 2
  283. - 2*df(q1(x(1)),x(1),2)*x(1) - df(q1(x(1)),x(1)) *x(1)
  284. p1(x(1)) p1(x(1)) 2
  285. - 4*df(q1(x(1)),x(1))*x(1) + 4*e - 4)/(2*e *x(1) )
  286. comment finally compute and print the Einstein tensor;
  287. array einstein(3,3);
  288. for i:=0:3 do for j:=0:3 do
  289. write einstein(i,j):=ricci(i,j)-rs*gg(i,j)/2;
  290. q1(x(1)) p1(x(1))
  291. e *( - df(p1(x(1)),x(1))*x(1) - e + 1)
  292. einstein(0,0) := -------------------------------------------------------
  293. p1(x(1)) 2
  294. e *x(1)
  295. p1(x(1))
  296. - df(q1(x(1)),x(1))*x(1) + e - 1
  297. einstein(1,1) := -------------------------------------------
  298. 2
  299. x(1)
  300. einstein(2,2) := (x(1)*(df(p1(x(1)),x(1))*df(q1(x(1)),x(1))*x(1)
  301. + 2*df(p1(x(1)),x(1)) - 2*df(q1(x(1)),x(1),2)*x(1)
  302. 2
  303. - df(q1(x(1)),x(1)) *x(1) - 2*df(q1(x(1)),x(1))))/(4
  304. p1(x(1))
  305. *e )
  306. 2
  307. einstein(3,3) := (sin(x(2)) *x(1)*(df(p1(x(1)),x(1))*df(q1(x(1)),x(1))*x(1)
  308. + 2*df(p1(x(1)),x(1)) - 2*df(q1(x(1)),x(1),2)*x(1)
  309. 2
  310. - df(q1(x(1)),x(1)) *x(1) - 2*df(q1(x(1)),x(1))))/(4
  311. p1(x(1))
  312. *e )
  313. comment end of Einstein tensor program;
  314. clear gg,h,cs1,cs2,r,ricci,einstein;
  315. comment an example using the matrix facility;
  316. matrix xx,yy,zz;
  317. let xx= mat((a11,a12),(a21,a22)),
  318. yy= mat((y1),(y2));
  319. 2*det xx - 3*w;
  320. 2*(a11*a22 - a12*a21 - 5443200)
  321. zz:= xx**(-1)*yy;
  322. [ - a12*y2 + a22*y1 ]
  323. [--------------------]
  324. [ a11*a22 - a12*a21 ]
  325. zz := [ ]
  326. [ a11*y2 - a21*y1 ]
  327. [------------------- ]
  328. [ a11*a22 - a12*a21 ]
  329. 1/xx**2;
  330. 2
  331. a12*a21 + a22
  332. mat((-------------------------------------------,
  333. 2 2 2 2
  334. a11 *a22 - 2*a11*a12*a21*a22 + a12 *a21
  335. - a12*(a11 + a22)
  336. -------------------------------------------),
  337. 2 2 2 2
  338. a11 *a22 - 2*a11*a12*a21*a22 + a12 *a21
  339. - a21*(a11 + a22)
  340. (-------------------------------------------,
  341. 2 2 2 2
  342. a11 *a22 - 2*a11*a12*a21*a22 + a12 *a21
  343. 2
  344. a11 + a12*a21
  345. -------------------------------------------))
  346. 2 2 2 2
  347. a11 *a22 - 2*a11*a12*a21*a22 + a12 *a21
  348. comment end of matrix examples;
  349. comment a physics example;
  350. on div;
  351. comment this gives us output in same form as Bjorken and Drell;
  352. mass ki= 0, kf= 0, p1= m, pf= m;
  353. vector eei,ef;
  354. mshell ki,kf,p1,pf;
  355. let p1.eei= 0, p1.ef= 0, p1.pf= m**2+ki.kf, p1.ki= m*k,p1.kf=
  356. m*kp, pf.eei= -kf.eei, pf.ef= ki.ef, pf.ki= m*kp, pf.kf=
  357. m*k, ki.eei= 0, ki.kf= m*(k-kp), kf.ef= 0, eei.eei= -1, ef.ef=
  358. -1;
  359. operator gp;
  360. for all p let gp(p)= g(l,p)+m;
  361. comment this is just to save us a lot of writing;
  362. gp(pf)*(g(l,ef,eei,ki)/(2*ki.p1) + g(l,eei,ef,kf)/(2*kf.p1))
  363. * gp(p1)*(g(l,ki,eei,ef)/(2*ki.p1) + g(l,kf,ef,eei)/(2*kf.p1))$
  364. write "The Compton cross-section is ",ws;
  365. 2 1 -1 1 -1
  366. The Compton cross-section is 2*eei.ef + ---*k*kp + ---*k *kp - 1
  367. 2 2
  368. comment end of first physics example;
  369. off div;
  370. comment another physics example;
  371. index ix,iy,iz;
  372. mass p1=mm,p2=mm,p3= mm,p4= mm,k1=0;
  373. mshell p1,p2,p3,p4,k1;
  374. vector qi,q2;
  375. factor mm,p1.p3;
  376. operator ga,gb;
  377. for all p let ga(p)=g(la,p)+mm, gb(p)= g(lb,p)+mm;
  378. ga(-p2)*g(la,ix)*ga(-p4)*g(la,iy)* (gb(p3)*g(lb,ix)*gb(qi)
  379. *g(lb,iz)*gb(p1)*g(lb,iy)*gb(q2)*g(lb,iz) + gb(p3)
  380. *g(lb,iz)*gb(q2)*g(lb,ix)*gb(p1)*g(lb,iz)*gb(qi)*g(lb,iy))$
  381. let qi=p1-k1, q2=p3+k1;
  382. comment it is usually faster to make such substitutions after all the
  383. trace algebra is done;
  384. write "CXN =",ws;
  385. 4 4 2 2
  386. CXN =32*mm *p1.p3 + 8*mm *(k1.p1 - k1.p3) - 16*mm *p1.p3
  387. 2
  388. + 16*mm *p1.p3*( - k1.p1 + k1.p3 - p2.p4)
  389. 2
  390. + 8*mm *( - k1.p1*p2.p4 - 2*k1.p2*k1.p4 + k1.p3*p2.p4) + 8*p1.p3*(
  391. k1.p2*p1.p4 - k1.p2*p3.p4 + k1.p4*p1.p2 - k1.p4*p2.p3 + 2*p1.p2*p3.p4
  392. + 2*p1.p4*p2.p3) + 8*(k1.p1*p1.p2*p3.p4 + k1.p1*p1.p4*p2.p3
  393. + 2*k1.p1*p2.p3*p3.p4 - 2*k1.p3*p1.p2*p1.p4 - k1.p3*p1.p2*p3.p4
  394. - k1.p3*p1.p4*p2.p3)
  395. comment end of second physics example;
  396. showtime;
  397. Time: 1030 ms plus GC time: 10 ms
  398. end;
  399. (TIME: reduce 1050 1060)