kredelw.red 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module kredelw;% Kredel Weispfenning algorithm .
  2. % Author: H . Melenk(ZIB Berlin).
  3. symbolic procedure gdimension_eval u;
  4. begin integer n,m;
  5. for each s in cdr gindependent_seteval u
  6. do if(m:=length cdr s) > n then n:=m;
  7. return n end;
  8. put('gdimension,'psopfn,'gdimension_eval);
  9. symbolic procedure gindependent_seteval pars;
  10. % Independent set algorithm(Kredel/Weispfenning).
  11. % Parameters:
  12. % 1 Groebner basis
  13. % 2 optional: list of variables.
  14. begin scalar a,u,v,vars,w,oldorder,!*factor,!*exp,!*gsugar,!*groebopt;!*exp:=t;
  15. u:=reval car pars;
  16. v:=if cdr pars then reval cadr pars else nil;
  17. w:=for each j in groerevlist u collect if eqexpr j then !*eqn2a j else j;
  18. if null w then rerror(groebnr2,3,"empty list");
  19. a:=if global!-dipvars!* and cdr global!-dipvars!* then cdr global!-dipvars!*
  20. else gvarlis w;
  21. vars:=if null v then for each j in a collect !*a2k j else groerevlist v;
  22. if not vars then return'(list);
  23. oldorder:=vdpinit vars;
  24. w:=for each j in w collect vdpevlmon a2vdp j;
  25. vars:=for each y in vars collect y.vdpevlmon a2vdp y;
  26. w:=groebkwprec(vars,nil,w,nil);
  27. return 'list.for each s in w collect
  28. 'list.reversip for each x in s collect car x end;
  29. put('gindependent_sets,'psopfn,'gindependent_seteval);
  30. symbolic procedure groebkwprec(vars,s,lt,m);
  31. % Recursive Kredel Weispfennig algorithm.
  32. % vars: unprocessed variables,
  33. % s: current subset of s,
  34. % lt: leading term basis,
  35. % m: collection of independent sets so far.
  36. % Returns : updated m .
  37. begin scalar x,s1,bool;
  38. s1:=for each y in s collect cdr y;
  39. while vars do
  40. <<x:=car vars;vars:= cdr vars;
  41. if groebkwprec1(cdr x.s1,lt) then m:=groebkwprec(vars,x.s,lt,m)>>;
  42. bool:=t;
  43. for each y in m do % bool and not subsetp(s,y);
  44. bool:=bool and not(length s=length intersection(s,y));
  45. return if bool then s.m else m end;
  46. symbolic procedure groebkwprec1(s,lt);
  47. % t if intersection of T(s) and lt is empty.
  48. if null lt then t else groebkwprec2(s,car lt)and groebkwprec1(s,cdr lt);
  49. symbolic procedure groebkwprec2(s,mon);
  50. % t if monomial not in T(s).
  51. <<for each m in s do mon:=vevcan0(m,mon);not vevzero!? mon>>;
  52. symbolic procedure vevcan0(m,mon);
  53. % Divide multiples of m1 out of mon.
  54. if vevzero!? m then mon else
  55. if vevzero!? mon then nil else
  56. (if car m neq 0 then 0 else car mon).vevcan0(cdr m,cdr mon);
  57. endmodule;;end;