polyop.red 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. module polyop; % Functions for algebraic mode operations on polynomials.
  2. % Author: Anthony C. Hearn.
  3. % Modified by: F. Kako, F.J. Wright.
  4. % Copyright (c) 1995 RAND. All rights reserved.
  5. % This code has been modified to be consistent with the rules
  6. % lterm(f,x) = lcof(f,x)*lpower(f,x)
  7. % f = lterm(f,x) + reduct(f,x)
  8. fluid '(!*ratarg gdmode!*);
  9. symbolic procedure deg(u,kern);
  10. <<u := simp!* u; tstpolyarg(denr u,u); numrdeg(numr u,kern)>>
  11. where dmode!* = gdmode!*;
  12. symbolic procedure numrdeg(u,kern);
  13. begin scalar x;
  14. kern := !*a2k kern;
  15. if domainp u then return 0
  16. else if mvar u eq kern then return !*f2a ldeg u;
  17. x := updkorder kern;
  18. u := reorder u;
  19. if not(mvar u eq kern) then u := 0 else u := ldeg u;
  20. setkorder x;
  21. % return !*f2a u
  22. return u
  23. end;
  24. symbolic procedure lcofeval u;
  25. begin scalar kern,x,y;
  26. if null u or null cdr u or not null cddr u
  27. then rerror(poly,280,
  28. "LCOF called with wrong number of arguments");
  29. kern := !*a2k cadr u;
  30. u := simp!* car u;
  31. y := denr u;
  32. tstpolyarg(y,u);
  33. u := numr u;
  34. if domainp u then return if null u then 0 else mk!*sq (u . 1)
  35. else if mvar u eq kern then return !*ff2a(lc u,y);
  36. x := updkorder kern;
  37. u := reorder u;
  38. if mvar u eq kern then u := lc u;
  39. setkorder x;
  40. return if null u then 0 else !*ff2a(u,y)
  41. end;
  42. put('lcof,'psopfn,'lcofeval);
  43. % Note. This is an older definition still used by some packages.
  44. symbolic procedure lcof(u,kern);
  45. begin scalar x,y;
  46. u := simp!* u;
  47. y := denr u;
  48. tstpolyarg(y,u);
  49. u := numr u;
  50. kern := !*a2k kern;
  51. if domainp u then return 0
  52. else if mvar u eq kern then return !*ff2a(lc u,y);
  53. x := updkorder kern;
  54. u := reorder u;
  55. if mvar u eq kern then u := lc u;
  56. setkorder x;
  57. return if null u then 0 else !*ff2a(u,y)
  58. end;
  59. symbolic procedure lpower(u,kern);
  60. begin scalar x,y;
  61. u := simp!* u;
  62. y := denr u;
  63. tstpolyarg(y,u);
  64. u := numr u;
  65. kern := !*a2k kern;
  66. if domainp u then return 1
  67. else if mvar u eq kern then return !*ff2a(lpow u.*1 .+ nil,y);
  68. x := updkorder kern;
  69. u := reorder u;
  70. if mvar u eq kern then u := lpow u.*1 .+ nil else u := 1;
  71. setkorder x;
  72. return !*ff2a(u,y)
  73. end;
  74. symbolic procedure lterm(u,kern);
  75. begin scalar x,y;
  76. u := simp!* u;
  77. y := denr u;
  78. tstpolyarg(y,u);
  79. u := numr u;
  80. kern := !*a2k kern;
  81. if domainp u then return if null u then 0 else u
  82. else if mvar u eq kern then return !*ff2a(lt u .+ nil,y);
  83. x := updkorder kern;
  84. u := reorder u;
  85. % if mvar u eq kern then u := lt u .+ nil else u := nil;
  86. if mvar u eq kern then u := lt u .+ nil;
  87. setkorder x;
  88. u := reorder u;
  89. return !*ff2a(u,y)
  90. end;
  91. % symbolic procedure !*lterm u; lt u .+ nil;
  92. symbolic procedure mainvar u;
  93. if domainp(u := numr simp!* u) then 0
  94. else sfchk(u := mvar u);
  95. symbolic procedure sfchk u; if sfp u then prepf u else u;
  96. symbolic procedure reduct(u,kern);
  97. begin scalar x,y;
  98. u := simp!* u;
  99. y := denr u;
  100. tstpolyarg(y,u);
  101. u := numr u;
  102. kern := !*a2k kern;
  103. % if domainp u then return !*ff2a(u,y)
  104. if domainp u then return 0
  105. else if mvar u eq kern then return !*ff2a(cdr u,y);
  106. x := updkorder kern;
  107. u := reorder u;
  108. % if mvar u eq kern then u := cdr u;
  109. if mvar u eq kern then u := cdr u else u := nil;
  110. setkorder x;
  111. u := reorder u;
  112. return !*ff2a(u,y)
  113. end;
  114. symbolic procedure tstpolyarg(y,u);
  115. null !*ratarg and y neq 1 and typerr(prepsq u,"polynomial");
  116. % symbolic operator deg,lpower,lterm,mainvar,reduct;
  117. flag('(deg lpower lterm mainvar reduct),'opfn); % This way for booting.
  118. endmodule;
  119. end;