kredelw.red 2.5 KB

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