places.red 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. MODULE PLACES;
  2. % Author: James H. Davenport.
  3. FLUID '(BASIC!-LISTOFALLSQRTS
  4. BASIC!-LISTOFNEWSQRTS
  5. INTVAR
  6. LISTOFALLSQRTS
  7. LISTOFNEWSQRTS
  8. SQRT!-INTVAR
  9. SQRT!-PLACES!-ALIST
  10. SQRTS!-IN!-INTEGRAND);
  11. EXPORTS GETSQRTSFROMPLACES,SQRTSINPLACES,GET!-CORRECT!-SQRTS,BASICPLACE,
  12. EXTENPLACE,EQUALPLACE,PRINTPLACE;
  13. % Function to manipulate places
  14. % a place is stored as a list of substitutions
  15. % substitutions (x.f(x)) define the algrbraic number
  16. % of which this place is an extension,
  17. % while places (f(x).g(x)) define the extension.
  18. % currently g(x( is list ('minus,f(x))
  19. % or similar,e.g. (sqrt(sqrt x)).(sqrt(-sqrt x)).
  20. % Given a list of places, produces a list of all
  21. % the SQRTs in it that depend on INTVAR.
  22. SYMBOLIC PROCEDURE GETSQRTSFROMPLACES PLACES;
  23. % The following loop finds all the SQRTs for a basis,
  24. % taking account of BASICPLACEs.
  25. BEGIN
  26. SCALAR BASIS,V,B,C,VV;
  27. FOR EACH U IN PLACES DO <<
  28. V:=ANTISUBS(BASICPLACE U,INTVAR);
  29. VV:=SQRTSINSQ (SUBSTITUTESQ(!*KK2Q INTVAR,V),INTVAR);
  30. % We must go via SUBSTITUTESQ to get parallel
  31. % substitutions performed correctly.
  32. IF VV
  33. THEN VV:=SIMP ARGOF CAR VV;
  34. FOR EACH W IN EXTENPLACE U DO <<
  35. B:=SUBSTITUTESQ(SIMP LSUBS W,V);
  36. B:=DELETE(SQRT!-INTVAR,SQRTSINSQ(B,INTVAR));
  37. FOR EACH U IN B DO
  38. FOR EACH V IN DELETE(U,B) DO
  39. IF DEPENDSP(V,U)
  40. THEN B:=DELETE(U,B);
  41. % remove all the "inner" items, since they will
  42. % be accounted for anyway.
  43. IF LENGTH B IEQUAL 1
  44. THEN B:=CAR B
  45. ELSE B:=MVAR NUMR SIMPSQRTSQ MAPPLY(FUNCTION !*MULTSQ,
  46. FOR EACH U IN B COLLECT SIMP ARGOF U);
  47. IF VV AND NOT (B MEMBER SQRTS!-IN!-INTEGRAND)
  48. THEN <<
  49. C:=NUMR MULTSQ(SIMP ARGOF B,VV);
  50. C:=CAR SQRTSINSF(SIMPSQRT2 C,NIL,INTVAR);
  51. IF C MEMBER SQRTS!-IN!-INTEGRAND
  52. THEN B:=C >>;
  53. IF NOT (B MEMBER BASIS)
  54. THEN BASIS:=B.BASIS >> >>;
  55. % The following loop deals with the annoying case of, say,
  56. % (X DIFFERENCE X 1) (X EXPT X 2) which should give rise to
  57. % SQRT(X-1).
  58. FOR EACH U IN PLACES DO BEGIN
  59. V:=CDR U;
  60. IF NULL V OR (CAR RFIRSTSUBS V NEQ 'EXPT)
  61. THEN RETURN;
  62. U:=SIMP!* SUBST(LIST('MINUS,INTVAR),INTVAR,RFIRSTSUBS U);
  63. WHILE V AND (CAR RFIRSTSUBS V EQ 'EXPT) DO <<
  64. U:=SIMPSQRTSQ U;
  65. V:=CDR V;
  66. BASIS:=UNION(BASIS,DELETE(SQRT!-INTVAR,SQRTSINSQ(U,INTVAR))) >>
  67. END;
  68. RETURN REMOVE!-EXTRA!-SQRTS BASIS
  69. END;
  70. SYMBOLIC PROCEDURE SQRTSINPLACES U;
  71. % Note the difference between this procedure and
  72. % the previous one: this one does not take account
  73. % of the BASICPLACE component (& is pretty useless).
  74. IF NULL U
  75. THEN NIL
  76. ELSE SQRTSINTREE(FOR EACH V IN CAR U COLLECT LSUBS V,
  77. INTVAR,
  78. SQRTSINPLACES CDR U);
  79. %symbolic procedure placesindiv places;
  80. % Given a list of places (i.e. a divisor),
  81. % produces a list of all the SQRTs on which the places
  82. % explicitly depend.
  83. %begin scalar v;
  84. % for each u in places do
  85. % for each uu in u do
  86. % if not (lsubs uu member v)
  87. % then v:=(lsubs uu) . v;
  88. % return v
  89. % end;
  90. SYMBOLIC PROCEDURE GET!-CORRECT!-SQRTS U;
  91. % u is a basicplace.
  92. BEGIN
  93. SCALAR V;
  94. V:=ASSOC(U,SQRT!-PLACES!-ALIST);
  95. IF V
  96. THEN <<
  97. V:=CDR V;
  98. LISTOFALLSQRTS:=CDR V;
  99. LISTOFNEWSQRTS:=CAR V
  100. >>
  101. ELSE <<
  102. LISTOFNEWSQRTS:=BASIC!-LISTOFNEWSQRTS;
  103. LISTOFALLSQRTS:=BASIC!-LISTOFALLSQRTS
  104. >>;
  105. RETURN NIL
  106. END;
  107. %symbolic procedure change!-place(old,new);
  108. %% old and new are basicplaces;
  109. %begin
  110. % scalar v;
  111. % v:=assoc(new,sqrt!-places!-alist);
  112. % if v
  113. % then sqrtsave(cddr v,cadr v,old)
  114. % else <<
  115. % listofnewsqrts:=basic!-listofnewsqrts;
  116. % listofallsqrts:=basic!-listofallsqrts
  117. % >>;
  118. % return nil
  119. % end;
  120. SYMBOLIC PROCEDURE BASICPLACE(U);
  121. % Returns the basic part of a place.
  122. IF NULL U
  123. THEN NIL
  124. ELSE IF ATOM CAAR U
  125. THEN (CAR U).BASICPLACE CDR U
  126. ELSE NIL;
  127. SYMBOLIC PROCEDURE EXTENPLACE(U);
  128. % Returns the extension part of a place.
  129. IF U AND ATOM CAAR U
  130. THEN EXTENPLACE CDR U
  131. ELSE U;
  132. SYMBOLIC PROCEDURE EQUALPLACE(A,B);
  133. % Sees if two extension places represent the same place or not.
  134. IF NULL A
  135. THEN IF NULL B
  136. THEN T
  137. ELSE NIL
  138. ELSE IF NULL B
  139. THEN NIL
  140. ELSE IF MEMBER(CAR A,B)
  141. THEN EQUALPLACE(CDR A,DELETE(CAR A,B))
  142. ELSE NIL;
  143. SYMBOLIC PROCEDURE REMOVE!-EXTRA!-SQRTS BASIS;
  144. BEGIN
  145. SCALAR BASIS2,SAVE;
  146. SAVE:=BASIS2:=FOR EACH U IN BASIS COLLECT !*Q2F SIMP ARGOF U;
  147. FOR EACH U IN BASIS2 DO
  148. FOR EACH V IN DELETE(U,BASIS2) DO
  149. IF QUOTF(V,U)
  150. THEN BASIS2:=DELETE(V,BASIS2);
  151. IF BASIS2 EQ SAVE
  152. THEN RETURN BASIS
  153. ELSE RETURN FOR EACH U IN BASIS2 COLLECT LIST('SQRT,PREPF U)
  154. END;
  155. SYMBOLIC PROCEDURE PRINTPLACE U;
  156. BEGIN
  157. SCALAR A,N,V;
  158. A:=RFIRSTSUBS U;
  159. PRINC (V:=LFIRSTSUBS U);
  160. PRINC "=";
  161. IF ATOM A
  162. THEN PRINC "0"
  163. ELSE IF (CAR A EQ 'QUOTIENT) AND (CADR A=1)
  164. THEN PRINC "infinity"
  165. ELSE <<
  166. N:=NEGSQ ADDSQ(!*KK2Q V,NEGSQ SIMP!* A);
  167. % NEGSQ added JHD 22.3.87 - the previous value was wrong.
  168. % If the substitution is (X-v) then this takes -v to 0,
  169. % so the place was at -v.
  170. IF (NUMBERP NUMR N) AND (NUMBERP DENR N)
  171. THEN <<
  172. PRINC NUMR N;
  173. IF NOT ONEP DENR N
  174. THEN <<
  175. PRINC " / ";
  176. PRINC DENR N >> >>
  177. ELSE <<
  178. IF DEGREEIN(NUMR N,INTVAR) > 1
  179. THEN PRINTC "Any root of:";
  180. PRINTSQ N;
  181. IF CDR U
  182. THEN PRINC "at the place " >> >>;
  183. U:=CDR U;
  184. IF NULL U
  185. THEN GOTO NL!-RETURN;
  186. N:=1;
  187. WHILE U AND (CAR RFIRSTSUBS U EQ 'EXPT) DO <<
  188. N:=N * CADDR RFIRSTSUBS U;
  189. U:=CDR U >>;
  190. IF N NEQ 1 THEN <<
  191. TERPRI!* NIL;
  192. prin2 " ";
  193. PRINC V;
  194. PRINC "=>";
  195. PRINC V;
  196. PRINC "**";
  197. PRINC N >>;
  198. WHILE U DO <<
  199. IF CAR RFIRSTSUBS U EQ 'MINUS
  200. THEN PRINC "-"
  201. ELSE PRINC "+";
  202. U:=CDR U >>;
  203. NL!-RETURN:
  204. TERPRI();
  205. RETURN
  206. END;
  207. SYMBOLIC PROCEDURE DEGREEIN(SF,VAR);
  208. IF ATOM SF
  209. THEN 0
  210. ELSE IF MVAR SF EQ VAR
  211. THEN LDEG SF
  212. ELSE MAX(DEGREEIN(LC SF,VAR),DEGREEIN(RED SF,VAR));
  213. ENDMODULE;
  214. END;