REDUCE.TST 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. Comment This is a standard test file for REDUCE that has been used for
  2. many years. It only tests a limited number of facilities in the
  3. current system. In particular, it does not test floating point
  4. arithmetic, or any of the more advanced packages that have been made
  5. available since REDUCE 3.0 was released. It has been used for a long
  6. time to benchmark the performance of REDUCE. A description of this
  7. benchmarking with statistics for REDUCE 3.2 was reported in Jed B.
  8. Marti and Anthony C. Hearn, "REDUCE as a Lisp Benchmark", SIGSAM Bull.
  9. 19 (1985) 8-16. That paper also gives information on the the parts of
  10. the system exercised by the test file. Updated statistics may be found
  11. in the "timings" file in the REDUCE Network Library;
  12. showtime;
  13. comment some examples of the FOR statement;
  14. comment summing the squares of the even positive integers
  15. through 50;
  16. for i:=2 step 2 until 50 sum i**2;
  17. comment to set w to the factorial of 10;
  18. w := for i:=1:10 product i;
  19. comment alternatively, we could set the elements a(i) of the
  20. array a to the factorial of i by the statements;
  21. array a(10);
  22. a(0):=1$
  23. for i:=1:10 do a(i):=i*a(i-1);
  24. comment the above version of the FOR statement does not return
  25. an algebraic value, but we can now use these array
  26. elements as factorials in expressions, e. g.;
  27. 1+a(5);
  28. comment we could have printed the values of each a(i)
  29. as they were computed by writing the FOR statement as;
  30. for i:=1:10 do write a(i):= i*a(i-1);
  31. comment another way to use factorials would be to introduce an
  32. operator FAC by an integer procedure as follows;
  33. integer procedure fac (n);
  34. begin integer m;
  35. m:=1;
  36. l1: if n=0 then return m;
  37. m:=m*n;
  38. n:=n-1;
  39. go to l1
  40. end;
  41. comment we can now use fac as an operator in expressions, e. g.;
  42. z**2+fac(4)-2*fac 2*y;
  43. comment note in the above example that the parentheses around
  44. the arguments of FAC may be omitted since it is a unary operator;
  45. comment the following examples illustrate the solution of some
  46. complete problems;
  47. comment the f and g series (ref Sconzo, P., Leschack, A. R. and
  48. Tobey, R. G., Astronomical Journal, Vol 70 (May 1965);
  49. deps:= -sigma*(mu+2*epsilon)$
  50. dmu:= -3*mu*sigma$
  51. dsig:= epsilon-2*sigma**2$
  52. f1:= 1$
  53. g1:= 0$
  54. for i:= 1:8 do
  55. <<f2:=-mu*g1 + deps*df(f1,epsilon) + dmu*df(f1,mu) + dsig*df(f1,sigma);
  56. write "F(",i,") := ",f2;
  57. g2:= f1 + deps*df(g1,epsilon) + dmu*df(g1,mu) + dsig*df(g1,sigma);
  58. write "G(",i,") := ",g2;
  59. f1:=f2;
  60. g1:=g2>>;
  61. comment a problem in Fourier analysis;
  62. factor cos,sin;
  63. on list;
  64. (a1*cos(omega*t) + a3*cos(3*omega*t) + b1*sin(omega*t)
  65. + b3*sin(3*omega*t))**3
  66. where {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  67. cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2,
  68. sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2,
  69. cos(~x)**2 => (1+cos(2*x))/2,
  70. sin(~x)**2 => (1-cos(2*x))/2};
  71. remfac cos,sin;
  72. off list;
  73. comment end of Fourier analysis example;
  74. comment the following program, written in collaboration with David
  75. Barton and John Fitch, solves a problem in general relativity. it
  76. will compute the Einstein tensor from any given metric;
  77. on nero;
  78. comment here we introduce the covariant and contravariant metrics;
  79. operator p1,q1,x;
  80. array gg(3,3),h(3,3);
  81. gg(0,0):=e**(q1(x(1)))$
  82. gg(1,1):=-e**(p1(x(1)))$
  83. gg(2,2):=-x(1)**2$
  84. gg(3,3):=-x(1)**2*sin(x(2))**2$
  85. for i:=0:3 do h(i,i):=1/gg(i,i);
  86. comment generate Christoffel symbols and store in arrays cs1 and cs2;
  87. array cs1(3,3,3),cs2(3,3,3);
  88. for i:=0:3 do for j:=i:3 do
  89. <<for k:=0:3 do
  90. cs1(j,i,k) := cs1(i,j,k):=(df(gg(i,k),x(j))+df(gg(j,k),x(i))
  91. -df(gg(i,j),x(k)))/2;
  92. for k:=0:3 do cs2(j,i,k):= cs2(i,j,k) := for p := 0:3
  93. sum h(k,p)*cs1(i,j,p)>>;
  94. comment now compute the Riemann tensor and store in r(i,j,k,l);
  95. array r(3,3,3,3);
  96. for i:=0:3 do for j:=i+1:3 do for k:=i:3 do
  97. for l:=k+1:if k=i then j else 3 do
  98. <<r(j,i,l,k) := r(i,j,k,l) := for q := 0:3
  99. sum gg(i,q)*(df(cs2(k,j,q),x(l))-df(cs2(j,l,q),x(k))
  100. + for p:=0:3 sum (cs2(p,l,q)*cs2(k,j,p)
  101. -cs2(p,k,q)*cs2(l,j,p)));
  102. r(i,j,l,k) := -r(i,j,k,l);
  103. r(j,i,k,l) := -r(i,j,k,l);
  104. if i neq k or j>l
  105. then <<r(k,l,i,j) := r(l,k,j,i) := r(i,j,k,l);
  106. r(l,k,i,j) := -r(i,j,k,l);
  107. r(k,l,j,i) := -r(i,j,k,l)>>>>;
  108. comment now compute and print the Ricci tensor;
  109. array ricci(3,3);
  110. for i:=0:3 do for j:=0:3 do
  111. write ricci(j,i) := ricci(i,j) := for p := 0:3 sum for q := 0:3
  112. sum h(p,q)*r(q,i,p,j);
  113. comment now compute and print the Ricci scalar;
  114. rs := for i:= 0:3 sum for j:= 0:3 sum h(i,j)*ricci(i,j);
  115. comment finally compute and print the Einstein tensor;
  116. array einstein(3,3);
  117. for i:=0:3 do for j:=0:3 do
  118. write einstein(i,j):=ricci(i,j)-rs*gg(i,j)/2;
  119. comment end of Einstein tensor program;
  120. clear gg,h,cs1,cs2,r,ricci,einstein;
  121. comment an example using the matrix facility;
  122. matrix xx,yy,zz;
  123. let xx= mat((a11,a12),(a21,a22)),
  124. yy= mat((y1),(y2));
  125. 2*det xx - 3*w;
  126. zz:= xx**(-1)*yy;
  127. 1/xx**2;
  128. comment end of matrix examples;
  129. comment a physics example;
  130. on div; comment this gives us output in same form as Bjorken and Drell;
  131. mass ki= 0, kf= 0, p1= m, pf= m;
  132. vector eei,ef;
  133. mshell ki,kf,p1,pf;
  134. let p1.eei= 0, p1.ef= 0, p1.pf= m**2+ki.kf, p1.ki= m*k,p1.kf=
  135. m*kp, pf.eei= -kf.eei, pf.ef= ki.ef, pf.ki= m*kp, pf.kf=
  136. m*k, ki.eei= 0, ki.kf= m*(k-kp), kf.ef= 0, eei.eei= -1, ef.ef=
  137. -1;
  138. operator gp;
  139. for all p let gp(p)= g(l,p)+m;
  140. comment this is just to save us a lot of writing;
  141. gp(pf)*(g(l,ef,eei,ki)/(2*ki.p1) + g(l,eei,ef,kf)/(2*kf.p1))
  142. * gp(p1)*(g(l,ki,eei,ef)/(2*ki.p1) + g(l,kf,ef,eei)/(2*kf.p1))$
  143. write "The Compton cross-section is ",ws;
  144. comment end of first physics example;
  145. off div;
  146. comment another physics example;
  147. index ix,iy,iz;
  148. mass p1=mm,p2=mm,p3= mm,p4= mm,k1=0;
  149. mshell p1,p2,p3,p4,k1;
  150. vector qi,q2;
  151. factor mm,p1.p3;
  152. operator ga,gb;
  153. for all p let ga(p)=g(la,p)+mm, gb(p)= g(lb,p)+mm;
  154. ga(-p2)*g(la,ix)*ga(-p4)*g(la,iy)* (gb(p3)*g(lb,ix)*gb(qi)
  155. *g(lb,iz)*gb(p1)*g(lb,iy)*gb(q2)*g(lb,iz) + gb(p3)
  156. *g(lb,iz)*gb(q2)*g(lb,ix)*gb(p1)*g(lb,iz)*gb(qi)*g(lb,iy))$
  157. let qi=p1-k1, q2=p3+k1;
  158. comment it is usually faster to make such substitutions after all the
  159. trace algebra is done;
  160. write "CXN =",ws;
  161. comment end of second physics example;
  162. showtime;
  163. end;