bcsf.red 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. module bcsf;
  2. COMMENT
  3. #######################
  4. # #
  5. # BASE COEFFICIENTS #
  6. # #
  7. #######################
  8. These base coefficients are standard forms.
  9. A list of REPLACEBY rules may be supplied with the setrules command
  10. that will be applied in an additional simplification process.
  11. This rules list is a list of s.f. pairs, where car should replace cdr.
  12. END COMMENT;
  13. % Standard is :
  14. !*hardzerotest:=nil;
  15. symbolic operator setrules;
  16. symbolic procedure setrules m; setrules!* cdr reval m;
  17. symbolic procedure setrules!* m;
  18. begin scalar r; r:=ring_names cali!=basering;
  19. m:=for each x in m collect
  20. if not eqcar(x,'replaceby) then
  21. typerr(makelist m,"rules list")
  22. else (numr simp second x . numr simp third x);
  23. for each x in m do
  24. if domainp car x or member(mvar car x,r) then
  25. rederr"no substitution for ring variables allowed";
  26. put('cali,'rules,m);
  27. return getrules();
  28. end;
  29. symbolic operator getrules;
  30. symbolic procedure getrules();
  31. makelist for each x in get('cali,'rules) collect
  32. list('replaceby,prepf car x,prepf cdr x);
  33. symbolic procedure bc!=simp u;
  34. (if r0 then
  35. begin scalar r,c; integer i;
  36. i:=0; r:=r0;
  37. while r and (i<1000) do
  38. << c:=qremf(u,caar r);
  39. if null car c then r:=cdr r
  40. else
  41. << u:=addf(multf(car c,cdar r),cdr c);
  42. i:=i+1; r:=r0;
  43. >>;
  44. >>;
  45. if (i<1000) then return u
  46. else rederr"recursion depth of bc!=simp too high"
  47. end
  48. else u) where r0:=get('cali,'rules);
  49. symbolic procedure bc_minus!? u; minusf u;
  50. symbolic procedure bc_zero!? u;
  51. if (null u or u=0) then t
  52. else if !*hardzerotest and pairp u then
  53. null bc!=simp numr simp prepf u
  54. else nil;
  55. symbolic procedure bc_fi a; if a=0 then nil else a;
  56. symbolic procedure bc_one!? u; (u = 1);
  57. symbolic procedure bc_inv u;
  58. % Test, whether u is invertible. Return the inverse of u or nil.
  59. if (u=1) or (u=-1) then u
  60. else begin scalar v; v:=qremf(1,u);
  61. if cdr v then return nil else return car v;
  62. end;
  63. symbolic procedure bc_neg u; negf u;
  64. symbolic procedure bc_prod (u,v); bc!=simp multf(u,v);
  65. symbolic procedure bc_quot (u,v);
  66. (if null cdr w then bc!=simp car w else typerr(v,"denominator"))
  67. where w=qremf(u,v);
  68. symbolic procedure bc_sum (u,v); addf(u,v);
  69. symbolic procedure bc_diff(u,v); addf(u,negf v);
  70. symbolic procedure bc_power(u,n); bc!=simp exptf(u,n);
  71. symbolic procedure bc_from_a u; bc!=simp numr simp!* u;
  72. symbolic procedure bc_2a u; prepf u;
  73. symbolic procedure bc_prin u;
  74. % Prints a base coefficient in infix form
  75. ( if domainp u then
  76. if dmode!*='!:mod!: then prin2 prepf u
  77. else printsf u
  78. else << write"("; printsf u; write")" >>) where !*nat=nil;
  79. symbolic procedure bc_divmod(u,v); % Returns quot . rem.
  80. qremf(u,v);
  81. symbolic procedure bc_gcd(u,v); gcdf!*(u,v);
  82. symbolic procedure bc_lcm(u,v);
  83. car bc_divmod(bc_prod(u,v),bc_gcd(u,v));
  84. endmodule; % bcsf
  85. end;