vdpcom.red 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. module vdpcom;
  2. % common routines to all vdp mappings
  3. fluid '(intvdpvars!* vdpvars!* secondvalue!* vdpsortmode!* !*groebrm
  4. !*vdpinteger !*trgroeb !*groebdivide pcount!* !*gsugar
  5. vdpsortextension!* );
  6. global '(vdpprintmax);
  7. flag('(vdpprintmax),'share);
  8. vdpprintmax := 5;
  9. % Repeat of smacros defined in vdp2dip.
  10. smacro procedure vdpPoly u; cadr cddr u;
  11. smacro procedure vdpzero!? u;
  12. null u or null vdpPoly u;
  13. smacro procedure vdpevlmon u; cadr u;
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. %
  16. % manipulating of exponent vectors
  17. %
  18. symbolic procedure vevnth (a,n);
  19. % extract nth element from a
  20. if null a then 0 else if n=1 then car a else vevnth(cdr a,n #- 1);
  21. % unrolled code for zero test (very often called)
  22. smacro procedure vevzero!? u;
  23. null u or (car u = 0 and vevzero!?1 cdr u);
  24. symbolic procedure vevzero!?1 u;
  25. null u or (car u = 0 and vevzero!? cdr u);
  26. symbolic procedure veveq(vev1,vev2);
  27. if null vev1 then vevzero!? vev2
  28. else if null vev2 then vevzero!? vev1
  29. else (car vev1 = car vev2 and vevequal(cdr vev1,vev2));
  30. symbolic procedure vevmaptozero e;
  31. % generate an exponent vector with same length as e and zeros only
  32. vevmaptozero1(e,nil);
  33. symbolic procedure vevmaptozero1(e,vev);
  34. if null e then vev else vevmaptozero1(cdr e, 0 . vev);
  35. symbolic procedure vevmtest!? (e1,e2);
  36. % /* Exponent vector multiple test. e1 and e2 are compatible exponent
  37. % vectors. vevmtest?(e1,e2) returns a boolean expression.
  38. % True if exponent vector e1 is a multiple of exponent
  39. % vector e2, else false. */
  40. if null e2 then t
  41. else if null e1 then if vevzero!? e2 then t else nil
  42. else not(car e1 #<car e2)and vevmtest!?(cdr e1,cdr e2);
  43. symbolic procedure vevlcm (e1,e2);
  44. % /* Exponent vector least common multiple. e1 and e2 are
  45. % exponent vectors. vevlcm(e1,e2) computes the least common
  46. % multiple of the exponent vectors e1 and e2, and returns
  47. % an exponent vector. */
  48. begin scalar x;
  49. while e1 and e2 do
  50. <<x := (if car e1 #> car e2 then car e1 else car e2) . x;
  51. e1 := cdr e1; e2 := cdr e2>>;
  52. x := reversip x;
  53. if e1 then x := nconc(x,e1)
  54. else if e2 then x := nconc(x,e2);
  55. return x;
  56. end;
  57. symbolic procedure vevmin (e1,e2);
  58. % Exponent vector minima
  59. begin scalar x;
  60. while e1 and e2 do
  61. <<x := (if car e1 #< car e2 then car e1 else car e2) . x;
  62. e1 := cdr e1; e2 := cdr e2>>;
  63. while x and 0=car x do x := cdr x; % cut trailing zeros
  64. return reversip x;
  65. end;
  66. symbolic procedure vevsum (e1,e2);
  67. % /* Exponent vector sum. e1 and e2 are exponent vectors.
  68. % vevsum(e1,e2) calculates the sum of the exponent vectors.
  69. % e1 and e2 componentwise and returns an exponent vector. */
  70. begin scalar x;
  71. while e1 and e2 do
  72. <<x := (car e1 #+ car e2) . x;e1 := cdr e1; e2 := cdr e2>>;
  73. x := reversip x;
  74. if e1 then x := nconc(x,e1)
  75. else if e2 then x := nconc(x,e2);
  76. return x;
  77. end;
  78. symbolic procedure vevtdeg u;
  79. % calculate the total degree of u
  80. if null u then 0 else car u #+ vevtdeg cdr u;
  81. symbolic procedure vdptdeg u;
  82. if vdpzero!? u then 0 else
  83. max(vevtdeg vdpevlmon u,vdptdeg vdpred u);
  84. symbolic procedure vevdif (ee1,ee2);
  85. % Exponent vector difference. e1 and e2 are exponent
  86. % vectors. vevdif(e1,e2) calculates the difference of the
  87. % exponent vectors e1 and e2 componentwise and returns an
  88. % exponent vector.
  89. begin scalar x,y,break,e1,e2;
  90. e1 := ee1; e2 := ee2;
  91. while e1 and e2 and not break do
  92. <<y := (car e1 #- car e2); x := y . x;
  93. break := y #< 0;
  94. e1 := cdr e1; e2 := cdr e2>>;
  95. if break or (e2 and not vevzero!? e2) then
  96. <<print ee1; print ee2;
  97. if getd 'backtrace then backtrace();
  98. return rerror(dipoly,5,"Vevdif, difference would be < 0")>>;
  99. return nconc(reversip x,e1);
  100. end;
  101. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  102. %
  103. % numbering of polynomials
  104. %
  105. symbolic procedure vdpEnumerate f;
  106. % f is a temporary result. Prepare it for medium range storage
  107. % and ssign a number
  108. if vdpzero!? f then f else
  109. << f := vdpsave f;
  110. if not vdpGetProp(f,'NUMBER) then
  111. f := vdpPutProp(f,'NUMBER,(pcount!* := pcount!* #+ 1));
  112. f>>;
  113. %smacro procedure vdpNumber f;
  114. % vdpGetProp(f,'NUMBER) ;
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. %
  117. % SUGAR of polynomials
  118. %
  119. symbolic procedure gsugar p;
  120. if !*gsugar then
  121. ((s or
  122. << print list("*** missing sugar",p);
  123. backtrace();
  124. s:=vdptdeg p;
  125. gsetsugar(p,s);
  126. s>>
  127. ) where s= if vdpzero!? p then 0 else vdpgetprop(p,'SUGAR));
  128. symbolic procedure gsetsugar(p,s);
  129. !*gsugar and vdpputprop(p,'SUGAR,s or vdptdeg p) or p;
  130. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  131. %
  132. % operations on sets of polynomials
  133. %
  134. symbolic procedure vdpMember(p1,l);
  135. % test membership of a polynomial in a list of polys
  136. if null l then nil
  137. else
  138. if vdpEqual(p1,car l) then l
  139. else
  140. vdpMember(p1,cdr l);
  141. symbolic procedure vdpUnion (s1,s2);
  142. % s1 and s2 are two sets of polynomials.
  143. % union of the sets using vdpMember as crit
  144. if null s1 then s2
  145. else
  146. if vdpmember(car s1,s2) then vdpUnion(cdr s1,s2)
  147. else car s1 . vdpUnion(cdr s1,s2);
  148. symbolic procedure vdpIntersection (s1,s2);
  149. % s1 and s2 are two sets of polynomials.
  150. % intersection of the sets using vdpMember as crit
  151. if null s1 then NIL
  152. else
  153. if vdpmember(car s1,s2) then car s1 . vdpUnion(cdr s1,s2)
  154. else vdpUnion(cdr s1,s2);
  155. symbolic procedure vdpSetEqual!?(s1,s2);
  156. % tests if s1 and s2 have the same polynomials as members
  157. if not (length s1 = length s2) then nil
  158. else vdpSetEqual!?1(s1,append(s2,nil));
  159. symbolic procedure vdpSetEqual!?1(s1,s2);
  160. % destroys its second parameter (is therefor copied when called)
  161. if null s1 and null s2 then t
  162. else
  163. if null s1 or null s2 then nil
  164. else
  165. (if hugo then vdpSetEqual!?1(cdr s1,groedeletip(car hugo,s2))
  166. else nil) where hugo = vdpMember(car s1,s2);
  167. symbolic procedure vdpSortedSetEqual!?(s1,s2);
  168. % tests if s1 and s2 have the same polynomials as members
  169. % here assuming, that both sets are sorted by the same
  170. % principles
  171. if null s1 and null s2 then t
  172. else
  173. if null s1 or null s2 then nil
  174. else
  175. if vdpequal(car s1,car s2) then
  176. vdpSortedSetEqual!?(cdr s1,cdr s2)
  177. else NIL;
  178. symbolic procedure vdpDisjoint!? (s1,s2);
  179. % s1 and s2 are two sets of polynomials.
  180. % test that there are no common members
  181. if null s1 then T
  182. else
  183. if vdpmember(car s1,s2) then NIL
  184. else vdpDisjoint!?(cdr s1,s2);
  185. symbolic procedure vdpSubset!? (s1,s2);
  186. not(length s1 > length s2) and vdpSubset!?1(s1,s2);
  187. symbolic procedure vdpSubset!?1 (s1,s2);
  188. % s1 and s2 are two sets of polynomials.
  189. % test if s1 is subset of s2
  190. if null s1 then T
  191. else
  192. if vdpmember(car s1,s2) then vdpSubset!?1 (cdr s1,s2)
  193. else NIL;
  194. symbolic procedure vdpDeleteMember(p,l);
  195. % delete polynomial p from list l
  196. if null l then nil
  197. else
  198. if vdpequal(p,car l) then vdpdeletemember(p,cdr l)
  199. else car l . vdpdeletemember(p,cdr l);
  200. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  201. %
  202. % sorting of polynomials
  203. %
  204. symbolic procedure vdplsort pl;
  205. % /* Distributive polynomial list sort. pl is a list of
  206. % distributive polynomials. vdplsort(pl) returns the
  207. % sorted distributive polynomial list of pl.
  208. sort(pl, function vdpvevlcomp);
  209. symbolic procedure vdplsortin (po,pl);
  210. % po is a polynomial, pl is a list of polynomials.
  211. % po is inserted into pl at its place determined by vevlcompless?.
  212. % the result is the updated pl;
  213. if null pl then list po
  214. else if vevcompless!? (vdpevlmon po, vdpevlmon car pl)
  215. then car pl . vdplsortin (po, cdr pl)
  216. else po . pl;
  217. symbolic procedure vdplsortinreplacing (po,pl);
  218. % po is a polynomial, pl is a list of polynomials.
  219. % po is inserted into pl at its place determined by vevlcompless?.
  220. % if there is a multiple of the exponent of pl, this is deleted
  221. % the result is the updated pl;
  222. if null pl then list po
  223. else if vevdivides!? (vdpevlmon po, vdpevlmon car pl)
  224. then vdplsortinreplacing (po, cdr pl)
  225. else if vevcompless!? (vdpevlmon po, vdpevlmon car pl)
  226. then car pl . vdplsortinreplacing (po, cdr pl)
  227. else po . pl;
  228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  229. %
  230. % property lists for polynomials
  231. %
  232. symbolic procedure vdpPutProp (poly,prop,val);
  233. begin scalar c,p;
  234. if not pairp poly or not pairp (c := cdr poly)
  235. or not pairp (c := cdr c)
  236. or not pairp (c := cdr c)
  237. or not pairp (c := cdr c )
  238. then rerror(dipoly,6,
  239. list("vdpPutProp given a non-vdp as 1st parameter",
  240. poly,prop,val));
  241. p := assoc(prop,car c);
  242. if p then rplacd(p,val)
  243. else rplaca(c,(prop . val) . car c);
  244. return poly;
  245. end;
  246. symbolic procedure vdpGetProp (poly,prop);
  247. if null poly then nil % nil is a legal variant of vdp=0
  248. else
  249. if not eqcar(poly,'vdp)
  250. then rerror(dipoly,7,
  251. list("vdpGetProp given a non-vdp as 1st parameter",
  252. poly,prop))
  253. else
  254. (if p then cdr p else nil)
  255. where p=assoc(prop,cadr cdddr poly);
  256. symbolic procedure vdpRemAllProps u;
  257. begin scalar c;
  258. if not pairp u or not pairp (c := cdr u)
  259. or not pairp (c := cdr c)
  260. or not pairp (c := cdr c)
  261. or not pairp (c := cdr c)
  262. then return u;
  263. rplaca(c,NIL); return u;
  264. end;
  265. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  266. %
  267. % Groebner interface to power substitution
  268. fluid '(!*sub2);
  269. symbolic procedure groebsubs2 q;
  270. (subs2 q) where !*sub2=t;
  271. % and a special print
  272. symbolic procedure vdpprintshort u;
  273. begin scalar m;
  274. m := vdpprintmax;
  275. vdpprintmax:= 2;
  276. vdpprint u;
  277. vdpprintmax:=m;
  278. end;
  279. endmodule;
  280. end;