reduce2.example.s.6 18 KB

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