df2q.red 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module df2q; % Conversion from distributive to standard forms.
  2. % Authors: Mary Ann Moore and Arthur C. Norman.
  3. fluid '(indexlist zlist);
  4. exports df2q;
  5. imports addf,gcdf,mksp,!*multf,quotf;
  6. Comment We assume that results already have reduced powers, so
  7. that no power substitution is necessary;
  8. symbolic procedure df2q p;
  9. % Converts distributed form P to standard quotient.
  10. begin scalar n,d,w;
  11. if null p then return nil ./ 1;
  12. d:=denr lc p;
  13. w:=red p;
  14. while w do
  15. <<n:=gcdf(d,denr lc w); % Get denominator of answer ...
  16. d:=!*multf(d,quotf(denr lc w,n));
  17. % ... as lcm of denoms in input.
  18. w:=red w>>;
  19. n := nil; % Place to build numerator of answer.
  20. while p do
  21. <<w := sqrt2top lc p;
  22. n := addf(n,quotf(!*multf(xl2f(lpow p,zlist,indexlist),
  23. !*multf(numr w,d)),
  24. denr w));
  25. p:=red p>>;
  26. return n ./ d
  27. end;
  28. symbolic procedure xl2f(l,z,il);
  29. % L is an exponent list from a D.F., Z is the Z-list,
  30. % IL is the list of indices.
  31. % Value is L converted to standard form. ;
  32. if null z then 1
  33. else if car l=0 then xl2f(cdr l,cdr z,cdr il)
  34. else if not atom car l then
  35. begin scalar temp;
  36. if caar l=0 then temp:= car il
  37. else temp:=list('plus,car il,caar l);
  38. temp:=mksp(list('expt,car z,temp),1);
  39. return !*multf(((temp .* 1) .+ nil),
  40. xl2f(cdr l,cdr z,cdr il))
  41. end
  42. % else if minusp car l then ;
  43. % multsq(invsq (((mksp(car z,-car l) .* 1) .+ nil)), ;
  44. % xl2f(cdr l,cdr z,cdr il)) ;
  45. else !*multf((mksp(car z,car l) .* 1) .+ nil,
  46. xl2f(cdr l,cdr z,cdr il));
  47. endmodule;
  48. end;