rsltnt.red 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. module resultant;
  2. % Author: Eberhard Schruefer.
  3. %**********************************************************************
  4. % *
  5. % The resultant function defined here has the following properties: *
  6. % *
  7. % degr(p1,x)*degr(p2,x) *
  8. % resultant(p1,p2,x) = (-1) *resultant(p2,p1,x) *
  9. % *
  10. % degr(p2,x) *
  11. % resultant(p1,p2,x) = p1 if p1 free of x *
  12. % *
  13. % resultant(p1,p2,x) = 1 if p1 free of x and p2 free of x *
  14. % *
  15. %**********************************************************************
  16. %exports resultant;
  17. %imports reorder,setkorder,degr,addf,negf,multf,multpf;
  18. fluid '(!*exp kord!*);
  19. symbolic procedure resultant(u,v,w);
  20. %u and v are standard forms. Result is resultant of u and v
  21. %w.r.t. kernel w. Method is Bezout's determinant using exterior
  22. %multiplication for its calculation.
  23. begin scalar ap,ep,uh,ut,vh,vt;
  24. integer n,nm;
  25. if domainp u and domainp v then return 1;
  26. kord!* := w . kord!*;
  27. if null domainp u and null(mvar u eq w) then u := reorder u;
  28. if null domainp v and null(mvar v eq w) then v := reorder v;
  29. if domainp u or null(mvar u eq w)
  30. then <<setkorder cdr kord!*;
  31. return if not domainp v and mvar v eq w
  32. then exptf(u,ldeg v)
  33. else 1>>
  34. else if domainp v or null(mvar v eq w)
  35. then <<setkorder cdr kord!*;
  36. return if mvar u eq w then exptf(v,ldeg u)
  37. else 1>>;
  38. n := ldeg u - ldeg v;
  39. ep := 1;
  40. if n<0 then
  41. <<for j := (-n-1) step -1 until 1 do
  42. ep := b!:extmult(!*sf2exb(multpf(w to j,u),w),ep);
  43. ep := b!:extmult(!*sf2exb(multd((-1)**(-n*ldeg u),u),
  44. w),
  45. ep)>>
  46. else if n>0 then
  47. <<for j := (n-1) step -1 until 1 do
  48. ep := b!:extmult(!*sf2exb(multpf(w to j,v),w),ep);
  49. ep := b!:extmult(!*sf2exb(v,w),ep)>>;
  50. nm := max(ldeg u,ldeg v);
  51. uh := lc u;
  52. vh := lc v;
  53. ut := if n<0 then multpf(w to -n,red u)
  54. else red u;
  55. vt := if n>0 then multpf(w to n,red v)
  56. else red v;
  57. ap := addf(multf(uh,vt),negf multf(vh,ut));
  58. ep := if null ep then !*sf2exb(ap,w)
  59. else b!:extmult(!*sf2exb(ap,w),ep);
  60. for j := (nm - 1) step -1 until (abs n + 1) do
  61. <<if degr(ut,w) = j then
  62. <<uh := addf(lc ut,multf(!*k2f w,uh));
  63. ut := red ut>>
  64. else uh := multf(!*k2f w,uh);
  65. if degr(vt,w) = j then
  66. <<vh := addf(lc vt,multf(!*k2f w,vh));
  67. vt := red vt>>
  68. else vh := multf(!*k2f w,vh);
  69. ep := b!:extmult(!*sf2exb(addf(multf(uh,vt),
  70. negf multf(vh,ut)),w),ep)>>;
  71. setkorder cdr kord!*;
  72. return if null ep then nil else lc ep
  73. end;
  74. put('resultant,'simpfn,'simpresultant);
  75. symbolic procedure simpresultant u;
  76. begin scalar !*exp;
  77. if length u neq 3
  78. then rederr "RESULTANT called with wrong number of arguments";
  79. !*exp := t;
  80. return resultant(!*q2f simp!* car u,
  81. !*q2f simp!* cadr u,
  82. !*a2k caddr u) ./ 1
  83. end;
  84. symbolic procedure !*sf2exb(u,v);
  85. %distributes s.f. u with respect to powers in v.
  86. if degr(u,v)=0 then if null u then nil
  87. else list 0 .* u .+ nil
  88. else list ldeg u .* lc u .+ !*sf2exb(red u,v);
  89. %**** Support for exterior multiplication ****
  90. % Data structure is lpow ::= list of degrees in exterior product
  91. % lc ::= standard form
  92. symbolic procedure b!:extmult(u,v);
  93. %Special exterior multiplication routine. Degree of form v is
  94. %arbitrary, u is a one-form.
  95. if null u or null v then nil
  96. else if v = 1 then u
  97. else (if x then cdr x .* (if car x then negf multf(lc u,lc v)
  98. else multf(lc u,lc v))
  99. .+ b!:extadd(b!:extmult(!*t2f lt u,red v),
  100. b!:extmult(red u,v))
  101. else b!:extadd(b!:extmult(red u,v),
  102. b!:extmult(!*t2f lt u,red v)))
  103. where x = b!:ordexn(car lpow u,lpow v);
  104. symbolic procedure b!:extadd(u,v);
  105. if null u then v
  106. else if null v then u
  107. else if lpow u = lpow v then
  108. (lambda x,y; if null x then y else lpow u .* x .+ y)
  109. (addf(lc u,lc v),b!:extadd(red u,red v))
  110. else if b!:ordexp(lpow u,lpow v) then lt u .+ b!:extadd(red u,v)
  111. else lt v .+ b!:extadd(u,red v);
  112. symbolic procedure b!:ordexp(u,v);
  113. if null u then t
  114. else if car u > car v then t
  115. else if car u = car v then b!:ordexp(cdr u,cdr v)
  116. else nil;
  117. symbolic procedure b!:ordexn(u,v);
  118. %u is a single integer, v a list. Returns nil if u is a member
  119. %of v or a dotted pair of a permutation indicator and the ordered
  120. %list of u merged into v.
  121. begin scalar s,x;
  122. a: if null v then return(s . reverse(u . x))
  123. else if u = car v then return nil
  124. else if u and u > car v then
  125. return(s . append(reverse(u . x),v))
  126. else <<x := car v . x;
  127. v := cdr v;
  128. s := not s>>;
  129. go to a
  130. end;
  131. endmodule;
  132. end;