poly.red 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. module poly; % Header module and low-level support for poly package.
  2. % Author: Anthony C. Hearn.
  3. % Copyright (c) 1991 RAND. All rights reserved.
  4. create!-package('(poly polrep quotf gcd exptf kernel mksp reord dmode
  5. dmodeop rational rnelem gint cpxrn compopr modular
  6. facform homog tdconv primfac specfac kronf conj diff
  7. polyop decompos interpol subs2q subs3q subs4q horner),
  8. nil);
  9. flag('(poly),'core_package);
  10. fluid '(!*mcd !*nosq wtl!*);
  11. % switch nosq;
  12. % Particular infix operators used in standard forms.
  13. newtok '((!. !+) add);
  14. newtok '((!. !*) mult);
  15. newtok '((!. !^) to);
  16. newtok '((!. !* !*) to);
  17. newtok '((!. !/) over);
  18. infix .^,.*,.+,./;
  19. % Constructors and selectors for standard forms.
  20. smacro procedure u.+v; % Standard (polynomial) addition constructor.
  21. u . v;
  22. smacro procedure lc u; % Leading coefficient of standard form.
  23. cdar u;
  24. smacro procedure ldeg u; % Leading degree of standard form.
  25. cdaar u;
  26. smacro procedure lt u; % Leading term of standard form.
  27. car u;
  28. smacro procedure u.*v; % Standard form multiplication constructor.
  29. u . v;
  30. smacro procedure mvar u; % Main variable of standard form.
  31. caaar u;
  32. smacro procedure lpow u; % Leading power of standard form.
  33. caar u;
  34. smacro procedure pdeg u;
  35. % Returns the degree of the power U.
  36. cdr u;
  37. smacro procedure red u; % Reductum of standard form.
  38. cdr u;
  39. smacro procedure tc u; % Coefficient of standard term.
  40. cdr u;
  41. smacro procedure tdeg u; % Degree of standard term.
  42. cdar u;
  43. smacro procedure tpow u; % Power of standard term.
  44. car u;
  45. smacro procedure tvar u; % Main variable of a standard term.
  46. caar u;
  47. smacro procedure numr u; % Numerator of standard quotient.
  48. car u;
  49. smacro procedure denr u; % Denominator of standard quotient.
  50. cdr u;
  51. smacro procedure u ./ v; % Constructor for standard quotient.
  52. u . v;
  53. symbolic smacro procedure domainp u; atom u or atom car u;
  54. % Procedures for converting between parts of standard quotients and
  55. % prefix forms.
  56. symbolic procedure !*a2f u;
  57. % U is an algebraic expression. Value is the equivalent form
  58. % or an error if conversion is not possible;
  59. !*q2f simp!* u;
  60. symbolic procedure !*a2k u;
  61. % U is an algebraic expression. Value is the equivalent kernel
  62. % or an error if conversion is not possible.
  63. % Note: earlier versions used SIMP0.
  64. begin scalar x;
  65. if kernp(x := simp!* u) then return mvar numr x
  66. else typerr(if null u then 0 else u,'kernel)
  67. end;
  68. symbolic procedure !*a2kwoweight u;
  69. % U is an algebraic expression. Value is the equivalent kernel
  70. % neglecting any weights, or an error if conversion is not possible.
  71. (if kernp x then mvar numr x else typerr(u,'kernel))
  72. where x=simp!* u where !*uncached=t,wtl!*=nil;
  73. symbolic procedure !*d2q u;
  74. % Converts domain element U into a standard quotient.
  75. if numberp u
  76. then if zerop u then nil ./ 1
  77. % else if floatp u then mkfloat u ./ 1
  78. else u ./ 1
  79. % The following converts a domain rational to a SQ, which may not
  80. % be desirable.
  81. % else if eqcar(u,'!:rn!:) and !*mcd then cdr u
  82. else if !:zerop u then nil ./ 1 else u ./ 1;
  83. symbolic procedure !*ff2a(u,v);
  84. % Converts ratio of two forms U and V to a prefix form.
  85. (if wtl!* then prepsq x else mk!*sq x) where x = cancel( u ./ v);
  86. smacro procedure !*f2a u; prepf u;
  87. smacro procedure !*f2q u;
  88. % U is a standard form, value is a standard quotient.
  89. u . 1;
  90. smacro procedure !*k2f u;
  91. % U is a kernel, value is a standard form.
  92. list((u .** 1) . 1);
  93. symbolic smacro procedure !*kk2f u;
  94. % U is a non-unique kernel, value is a standard form.
  95. list(mksp(u,1) . 1);
  96. symbolic smacro procedure !*kk2q u;
  97. % U is a non-unique kernel, value is a standard quotient.
  98. list(mksp(u,1) .* 1) ./ 1;
  99. smacro procedure !*k2q u;
  100. % U is a kernel, value is a standard quotient.
  101. list((u .** 1) . 1) . 1;
  102. symbolic procedure !*n2f u;
  103. % U is a number. Value is a standard form.
  104. if zerop u then nil else u;
  105. smacro procedure !*p2f u;
  106. % U is a standard power, value is a standard form.
  107. list(u . 1);
  108. smacro procedure !*p2q u;
  109. % U is a standard power, value is a standard quotient.
  110. list(u . 1) . 1;
  111. symbolic procedure !*q2a u;
  112. % U is a standard quotient, value is an algebraic expression.
  113. !*q2a1(u,!*nosq);
  114. symbolic procedure !*q2a1(u,v);
  115. if null v then mk!*sq u else prepsqxx u;
  116. symbolic procedure !*q2f u;
  117. % U is a standard quotient, value is a standard form.
  118. if denr u=1 then numr u else typerr(prepsq u,'polynomial);
  119. symbolic procedure !*q2k u;
  120. % U is a standard quotient, value is a kernel or an error if
  121. % conversion not possible.
  122. if kernp u then mvar numr u else typerr(prepsq u,'kernel);
  123. smacro procedure !*t2f u;
  124. % U is a standard term, value is a standard form.
  125. list u;
  126. smacro procedure !*t2q u;
  127. % U is a standard term, value is a standard quotient.
  128. list u . 1;
  129. symbolic smacro procedure tvar a; caar a;
  130. endmodule;
  131. end;