groebopt.red 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module groebopt;
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % optimization of the sequence of variables
  4. %
  5. % Optimization of variable sequence;
  6. % the theoretical background can be found
  7. % in Boege/Gebauer/Kredel , J.Symb.Comp(1986)I,83-98
  8. % Techniques modfied to the following algorithm
  9. %
  10. % x > y if
  11. % x appears in a higher power than y
  12. % or
  13. % the highest powers are equal, but x appears more often with
  14. % that power.
  15. %
  16. % An explicit dependency DEPENDS X,Y will supersede the optimality.
  17. fluid '(vdpvars!* % list of intersting variables (and korder)
  18. intvdpvars!*
  19. !*trgroeb % control of print messages
  20. );
  21. symbolic procedure vdpvordopt (w,vars);
  22. % w : list of polynomials (standard forms)
  23. % vars: list of variables
  24. % returns (w . vars), both reorderdered
  25. begin; scalar c;
  26. vars := sort(vars,'ordop);
  27. c := for each x in vars collect x . 0 . 0;
  28. for each poly in w do vdpvordopt1 (poly,vars,c);
  29. c := sort(c,function vdpvordopt2);
  30. intvdpvars!* := for each v in c collect car v;
  31. vars := vdpvordopt31 intvdpvars!*;
  32. if !*trgroeb then
  33. <<prin2 "optimized sequence of kernels: "; prin2t vars>>;
  34. return (for each poly in w collect reorder poly) . vars;
  35. end;
  36. symbolic procedure vdpvordopt1 (p,vl,c);
  37. if null p then 0
  38. else
  39. if domainp p or null vl then 1
  40. else
  41. if mvar p neq car vl then vdpvordopt1(p,cdr vl,c)
  42. else
  43. begin scalar var,pow,slot; integer n;
  44. n := vdpvordopt1 (lc p,cdr vl,c);
  45. var := mvar p;
  46. pow := ldeg p;
  47. slot := assoc(var,c);
  48. if pow #> cadr slot then
  49. <<rplaca(cdr slot,pow); rplacd(cdr slot,n)>>
  50. else
  51. rplacd(cdr slot,n #+ cddr slot);
  52. return n #+ vdpvordopt1 (red p,vl,c);
  53. end;
  54. symbolic procedure vdpvordopt2(sl1,sl2);
  55. % compare two slots from the power table
  56. <<sl1 := cdr sl1;
  57. sl2 := cdr sl2;
  58. car sl1 #< car sl2 or car sl1 = car sl2 and cdr sl1 #< cdr sl2
  59. >>;
  60. symbolic procedure vdpvordopt31 u;
  61. % u : list of variables
  62. % returns u reordered to respect dependency ordering
  63. begin scalar v,y;
  64. if null u then return nil;
  65. v := foreach x in u join
  66. << y := assoc(x,depl!*);
  67. if null y or null xnp(cdr y,u) then {x} >>;
  68. return nconc(vdpvordopt31 setdiff(u,v),v);
  69. end;
  70. % symbolic procedure vdpvordopt3(x,y);
  71. % % two level compare: 1. dependency, 2. optimal order.
  72. % depends(x,y) or member(y,member(x,intvdpvars!*));
  73. endmodule;
  74. end;