alg.tst 6.5 KB

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