coeff.red 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module coeff; % Routines for finding coefficients of forms.
  2. % Author: Anthony C. Hearn.
  3. % Modifications by: F. Kako (including introduction of COEFFN).
  4. % Copyright (c) 1991 RAND. All rights reserved.
  5. fluid '(!*ratarg);
  6. global '(hipow!* lowpow!*);
  7. switch ratarg;
  8. flag ('(hipow!* lowpow!*),'share);
  9. symbolic procedure coeffeval u;
  10. begin integer n;
  11. n := length u;
  12. if n<2 or n>3
  13. then rerror(alg,28,
  14. "COEFF called with wrong number of arguments")
  15. else return coeff1(car u,cadr u,
  16. if null cddr u then nil else caddr u)
  17. end;
  18. put('coeff,'psopfn,'coeffeval);
  19. symbolic procedure coeff1(u,v,w);
  20. % Finds the coefficients of V in U and returns results in W.
  21. % We turn EXP on and FACTOR off to make sure powers of V separate.
  22. (begin scalar !*factor,bool,x,y,z;
  23. if eqcar(u,'!*sq) and null !*exp
  24. then <<!*exp := t; u := resimp cadr u>>
  25. else <<!*exp := t; u := simp!* u>>;
  26. v := !*a2kwoweight v;
  27. bool := !*ratarg or freeof(prepf denr u,v);
  28. if null bool then u := !*q2f u;
  29. x := updkorder v;
  30. if null bool then <<y := reorder u; u := 1>>
  31. else <<y := reorder numr u; u := denr u>>;
  32. setkorder x;
  33. if null y then go to a;
  34. while not domainp y and mvar y=v
  35. do <<z := (ldeg y . !*ff2a(lc y,u)) . z; y := red y>>;
  36. if null y then go to b;
  37. a: z := (0 . !*ff2a(y,u)) . z;
  38. b: lowpow!* := caar z;
  39. z := reverse z;
  40. hipow!* := caar z;
  41. z := multiple!-result(z,w);
  42. return if null w then z else hipow!*
  43. end) where !*exp = !*exp;
  44. symbolic procedure coeffn(u,v,n);
  45. % Returns n-th coefficient of U.
  46. % We turn EXP on and FACTOR off to make sure powers of V separate.
  47. begin scalar !*exp,!*factor,bool,x,y;
  48. !*exp := t;
  49. n := reval n;
  50. if not fixp n or minusp n then typerr(n,"COEFFN index");
  51. v := !*a2kwoweight v;
  52. u := simp!* u;
  53. bool := !*ratarg or freeof(prepf denr u,v);
  54. if null bool then u := !*q2f u;
  55. x := updkorder v;
  56. if null bool then <<y := reorder u; u := 1>>
  57. else <<y := reorder numr u; u := denr u>>;
  58. setkorder x;
  59. if null y then return 0; % changed by JHD for consistency
  60. b: if domainp y or mvar y neq v
  61. then return if n=0 then !*ff2a(y,u) else 0
  62. else if n=ldeg y then return !*ff2a(lc y,u)
  63. else if n>ldeg y then return 0
  64. else <<y := red y; go to b>>
  65. end;
  66. flag('(coeffn),'opfn);
  67. flag('(coeffn),'noval);
  68. endmodule;
  69. end;