groebopt.red 2.0 KB

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