trialdiv.red 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. module trialdiv; % Trial division routines.
  2. % Authors: Mary Ann Moore and Arthur C. Norman.
  3. fluid '(!*trint intvar loglist tanlist);
  4. exports countz,findsqrts,findtrialdivs,trialdiv,simp,mksp;
  5. imports !*multf,printsf,quotf;
  6. symbolic procedure countz dl;
  7. % DL is a list of S.F.s;
  8. begin scalar s,n,rl;
  9. loop2: if null dl then return arrangelistz rl;
  10. n:=1;
  11. loop1: n:=n+1;
  12. s:=car dl;
  13. dl:=cdr dl;
  14. if not null dl and (s eq car dl) then
  15. go to loop1
  16. else rl:=(s.n).rl;
  17. go to loop2
  18. end;
  19. symbolic procedure arrangelistz d;
  20. begin scalar n,s,rl,r;
  21. n:=1;
  22. if null d then return rl;
  23. loopd: if (cdar d)=n then s:=(caar d).s
  24. else r:=(car d).r;
  25. d:=cdr d;
  26. if not null d then go to loopd;
  27. d:=r;
  28. rl:=s.rl;
  29. s:=nil;
  30. r:=nil;
  31. n:=n+1;
  32. if not null d then go to loopd;
  33. return reversip rl
  34. end;
  35. symbolic procedure findtrialdivs zl;
  36. % zl is list of kernels found in integrand. result is a list
  37. % giving things to be treated specially in the integration
  38. % namely, exps and tans.
  39. % Result is list of form ((a . b) ...)
  40. % with a a kernel and car a=expt or tan
  41. % and b a standard form for either expt or (1+tan**2).
  42. begin scalar dlists1,args1;
  43. for each z in zl do
  44. if exportan z
  45. then <<if car z eq 'tan
  46. then <<args1 := (mksp(z,2) .* 1) .+ 1;
  47. tanlist := (args1 ./ 1) . tanlist>>
  48. else args1 := !*kk2f z; % z is not unique here.
  49. dlists1 := (z . args1) . dlists1>>;
  50. return dlists1
  51. end;
  52. symbolic procedure exportan dl;
  53. if atom dl then nil
  54. else begin
  55. % extract exp or tan fns from the z-list.
  56. if eq(car dl,'tan) then return t;
  57. nxt: if not eq(car dl,'expt) then return nil;
  58. dl:=cadr dl;
  59. % if atom dl then return t;
  60. % if atom dl or constant_exprp dl then return t;
  61. if atom dl or not smember(intvar,dl) then return t;
  62. % Make sure we find nested exponentials?
  63. go to nxt
  64. end;
  65. symbolic procedure findsqrts z;
  66. begin scalar r;
  67. while not null z do <<
  68. if eqcar(car z,'sqrt) then r:=(car z) . r;
  69. z:=cdr z >>;
  70. return r
  71. end;
  72. symbolic procedure trialdiv(x,dl);
  73. begin scalar qlist,q;
  74. while not null dl do
  75. if not null(q:=quotf(x,cdar dl)) then <<
  76. if (caaar dl='tan) and not eqcar(qlist,cdar dl) then
  77. loglist:=('iden . simp cadr caar dl) . loglist;
  78. %tan fiddle!
  79. qlist:=(cdar dl).qlist;
  80. x:=q >>
  81. else dl:=cdr dl;
  82. return qlist.x
  83. end;
  84. endmodule;
  85. end;