reduce.tst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. SHOWTIME$
  2. COMMENT SOME EXAMPLES OF THE F O R STATEMENT;
  3. COMMENT SUMMING THE SQUARES OF THE EVEN POSITIVE INTEGERS
  4. THROUGH 50;
  5. FOR I:=2 STEP 2 UNTIL 50 SUM I**2;
  6. COMMENT TO SET W TO THE FACTORIAL OF 10;
  7. W := FOR I:=1:10 PRODUCT I;
  8. COMMENT ALTERNATIVELY, WE COULD SET THE ELEMENTS A(I) OF THE
  9. ARRAY A TO THE FACTORIAL OF I BY THE STATEMENTS;
  10. ARRAY A(10);
  11. A(0):=1$
  12. FOR I:=1:10 DO A(I):=I*A(I-1);
  13. COMMENT THE ABOVE VERSION OF THE F O R STATEMENT DOES NOT RETURN
  14. AN ALGEBRAIC VALUE, BUT WE CAN NOW USE THESE ARRAY
  15. ELEMENTS AS FACTORIALS IN EXPRESSIONS, E. G.;
  16. 1+A(5);
  17. COMMENT WE COULD HAVE PRINTED THE VALUES OF EACH A(I)
  18. AS THEY WERE COMPUTED BY REPLACING THE F O R STATEMENT BY;
  19. FOR I:=1:10 DO WRITE A(I):= I*A(I-1);
  20. COMMENT ANOTHER WAY TO USE FACTORIALS WOULD BE TO INTRODUCE AN
  21. OPERATOR FAC BY AN INTEGER PROCEDURE AS FOLLOWS;
  22. INTEGER PROCEDURE FAC (N);
  23. BEGIN INTEGER M;
  24. M:=1;
  25. L1: IF N=0 THEN RETURN M;
  26. M:=M*N;
  27. N:=N-1;
  28. GO TO L1
  29. END;
  30. COMMENT WE CAN NOW USE FAC AS AN OPERATOR IN EXPRESSIONS,
  31. E. G.;
  32. Z**2+FAC(4)-2*FAC 2*Y;
  33. COMMENT NOTE IN THE ABOVE EXAMPLE THAT THE PARENTHESES AROUND
  34. THE ARGUMENTS OF FAC MAY BE OMITTED SINCE IT IS A UNARY OPERATOR;
  35. COMMENT THE FOLLOWING EXAMPLES ILLUSTRATE THE SOLUTION OF SOME
  36. COMPLETE PROBLEMS;
  37. COMMENT THE F AND G SERIES (REF SCONZO, P., LESCHACK, A. R. AND
  38. TOBEY, R. G., ASTRONOMICAL JOURNAL, VOL 70 (MAY 1965);
  39. DEPS:= -SIG*(MU+2*EPS)$
  40. DMU:= -3*MU*SIG$
  41. DSIG:= EPS-2*SIG**2$
  42. F1:= 1$
  43. G1:= 0$
  44. FOR I:= 1:8 DO
  45. BEGIN
  46. F2:= -MU*G1 + DEPS*DF(F1,EPS) + DMU*DF(F1,MU) + DSIG*DF(F1,SIG)$
  47. WRITE "F(",I,") := ",F2;
  48. G2:= F1 + DEPS*DF(G1,EPS) + DMU*DF(G1,MU) + DSIG*DF(G1,SIG)$
  49. WRITE "G(",I,") := ",G2;
  50. F1:=F2$
  51. G1:=G2
  52. END;
  53. COMMENT A PROBLEM IN FOURIER ANALYSIS;
  54. FOR ALL X,Y LET COS(X)*COS(Y)= (COS(X+Y)+COS(X-Y))/2,
  55. COS(X)*SIN(Y)= (SIN(X+Y)-SIN(X-Y))/2,
  56. SIN(X)*SIN(Y)= (COS(X-Y)-COS(X+Y))/2,
  57. COS(X)**2= (1+COS(2*X))/2,
  58. SIN(X)**2= (1-COS(2*X))/2;
  59. FACTOR COS,SIN;
  60. ON LIST;
  61. (A1*COS(WT)+ A3*COS(3*WT)+ B1*SIN(WT)+ B3*SIN(3*WT))**3;
  62. COMMENT END OF FOURIER ANALYSIS EXAMPLE;
  63. OFF LIST;
  64. FOR ALL X,Y CLEAR COS X*COS Y, COS X*SIN Y, SIN X*SIN Y,
  65. COS(X)**2,SIN(X)**2;
  66. COMMENT LEAVING SUCH REPLACEMENTS ACTIVE WOULD SLOW DOWN SUBSEQUENT
  67. COMPUTATION;
  68. COMMENT THE FOLLOWING PROGRAM, WRITTEN IN COLLABORATION WITH DAVID
  69. BARTON AND JOHN FITCH, SOLVES A PROBLEM IN GENERAL RELATIVITY. IT
  70. WILL COMPUTE THE EINSTEIN TENSOR FROM ANY GIVEN METRIC;
  71. ON NERO;
  72. COMMENT HERE WE INTRODUCE THE COVARIANT AND CONTRAVARIANT METRICS;
  73. OPERATOR P1,Q1,X;
  74. ARRAY GG(3,3),H(3,3)$
  75. GG(0,0):=E**(Q1(X(1)))$
  76. GG(1,1):=-E**(P1(X(1)))$
  77. GG(2,2):=-X(1)**2$
  78. GG(3,3):=-X(1)**2*SIN(X(2))**2$
  79. FOR I:=0:3 DO H(I,I):=1/GG(I,I)$
  80. COMMENT GENERATE CHRISTOFFEL SYMBOLS AND STORE IN ARRAYS CS1 AND CS2;
  81. ARRAY CS1(3,3,3),CS2(3,3,3)$
  82. FOR I:=0:3 DO FOR J:=I:3 DO BEGIN
  83. FOR K:=0:3 DO
  84. CS1(J,I,K) := CS1(I,J,K):=(DF(GG(I,K),X(J))+DF(GG(J,K),X(I))
  85. -DF(GG(I,J),X(K)))/2;
  86. FOR K:=0:3 DO CS2(J,I,K):= CS2(I,J,K) := FOR P := 0:3
  87. SUM H(K,P)*CS1(I,J,P) END;
  88. COMMENT NOW COMPUTE THE RIEMANN TENSOR AND STORE IN R(I,J,K,L);
  89. ARRAY R(3,3,3,3)$
  90. FOR I:=0:3 DO FOR J:=I+1:3 DO FOR K:=I:3 DO
  91. FOR L:=K+1:IF K=I THEN J ELSE 3 DO BEGIN
  92. R(J,I,L,K) := R(I,J,K,L) := FOR Q := 0:3
  93. SUM GG(I,Q)*(DF(CS2(K,J,Q),X(L))-DF(CS2(J,L,Q),X(K))
  94. + FOR P:=0:3 SUM (CS2(P,L,Q)*CS2(K,J,P)
  95. -CS2(P,K,Q)*CS2(L,J,P)))$
  96. LET R(I,J,L,K) = -R(I,J,K,L), R(J,I,K,L)= -R(I,J,K,L);
  97. IF I=K AND J<=L THEN GO TO A$
  98. R(K,L,I,J) := R(L,K,J,I) := R(I,J,K,L)$
  99. LET R(L,K,I,J) = -R(I,J,K,L), R(K,L,J,I)= -R(I,J,K,L);
  100. A: END$
  101. COMMENT NOW COMPUTE AND PRINT THE RICCI TENSOR;
  102. ARRAY RICCI(3,3)$
  103. FOR I:=0:3 DO FOR J:=0:3 DO
  104. WRITE RICCI(J,I) := RICCI(I,J) := FOR P := 0:3 SUM FOR Q := 0:3
  105. SUM H(P,Q)*R(Q,I,P,J);
  106. COMMENT NOW COMPUTE AND PRINT THE RICCI SCALAR;
  107. RS := FOR I:= 0:3 SUM FOR J:= 0:3 SUM H(I,J)*RICCI(I,J);
  108. COMMENT FINALLY COMPUTE AND PRINT THE EINSTEIN TENSOR;
  109. ARRAY EINSTEIN(3,3);
  110. FOR I:=0:3 DO FOR J:=0:3 DO
  111. WRITE EINSTEIN(I,J):=RICCI(I,J)-RS*GG(I,J)/2;
  112. COMMENT END OF EINSTEIN TENSOR PROGRAM;
  113. CLEAR GG,H,CS1,CS2,R,RICCI,EINSTEIN;
  114. COMMENT AN EXAMPLE USING THE MATRIX FACILITY;
  115. MATRIX XX,YY;
  116. LET XX= MAT((A11,A12),(A21,A22)),
  117. YY= MAT((Y1),(Y2));
  118. 2*DET XX - 3*W;
  119. ZZ:= XX**(-1)*YY;
  120. 1/XX**2;
  121. COMMENT END OF MATRIX EXAMPLES;
  122. COMMENT THE FOLLOWING EXAMPLES WILL FAIL UNLESS THE FUNCTIONS
  123. NEEDED FOR PROBLEMS IN HIGH ENERGY PHYSICS HAVE BEEN LOADED;
  124. COMMENT A PHYSICS EXAMPLE;
  125. ON DIV; COMMENT THIS GIVES US OUTPUT IN SAME FORM AS BJORKEN AND DRELL;
  126. MASS KI= 0, KF= 0, PI= M, PF= M;
  127. VECTOR EI,EF;
  128. MSHELL KI,KF,PI,PF;
  129. LET PI.EI= 0, PI.EF= 0, PI.PF= M**2+KI.KF, PI.KI= M*K,PI.KF=
  130. M*KP, PF.EI= -KF.EI, PF.EF= KI.EF, PF.KI= M*KP, PF.KF=
  131. M*K, KI.EI= 0, KI.KF= M*(K-KP), KF.EF= 0, EI.EI= -1, EF.EF=
  132. -1;
  133. OPERATOR GP;
  134. FOR ALL P LET GP(P)= G(L,P)+M;
  135. COMMENT THIS IS JUST TO SAVE US A LOT OF WRITING;
  136. GP(PF)*(G(L,EF,EI,KI)/(2*KI.PI) + G(L,EI,EF,KF)/(2*KF.PI))
  137. * GP(PI)*(G(L,KI,EI,EF)/(2*KI.PI) + G(L,KF,EF,EI)/(2*KF.PI)) $
  138. WRITE "THE COMPTON CROSS-SECTION IS ",WS;
  139. COMMENT END OF FIRST PHYSICS EXAMPLE;
  140. OFF DIV;
  141. COMMENT ANOTHER PHYSICS EXAMPLE;
  142. FACTOR MM,P1.P3;
  143. INDEX X1,Y1,Z;
  144. MASS P1=MM,P2=MM,P3= MM,P4= MM,K1=0;
  145. MSHELL P1,P2,P3,P4,K1;
  146. VECTOR Q1,Q2;
  147. OPERATOR GA,GB;
  148. FOR ALL P LET GA(P)=G(LA,P)+MM, GB(P)= G(LB,P)+MM;
  149. GA(-P2)*G(LA,X1)*GA(-P4)*G(LA,Y1)* (GB(P3)*G(LB,X1)*GB(Q1)
  150. *G(LB,Z)*GB(P1)*G(LB,Y1)*GB(Q2)*G(LB,Z) + GB(P3)
  151. *G(LB,Z)*GB(Q2)*G(LB,X1)*GB(P1)*G(LB,Z)*GB(Q1)*G(LB,Y1))$
  152. LET Q1=P1-K1, Q2=P3+K1;
  153. COMMENT IT IS USUALLY FASTER TO MAKE SUCH SUBSTITUTIONS AFTER ALL THE
  154. TRACE ALGEBRA IS DONE;
  155. WRITE "CXN =",WS;
  156. COMMENT END OF SECOND PHYSICS EXAMPLE;
  157. SHOWTIME$
  158. END;