groebfac.red 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. module groebfac; % Factorization of polynomials during Groebner calc'n.
  2. imports factor;
  3. symbolic procedure groebfactorize (h,abort1,g,g99);
  4. begin scalar r,tim,gctim,h1,groebactualg99!*,groebfabort!*,test;
  5. scalar s;
  6. s:=!*gsugar and gsugar h;
  7. groebactualg99!* := g99; groebactualg!* := g;
  8. groebfabort!* := abort1;
  9. if vdpgetprop(h,'irreducible) then return groebfactorize3 h;
  10. tim := time();
  11. gctim := gctime();
  12. !*trgroeb and groebmess7 h;
  13. r := if r := vdpgetprop(h,'factors) then r
  14. else if !*groebrm then groebfactorize1 h
  15. else if not !*vdpmodular then groebfactorize2 h
  16. else nil;
  17. factortime!* := factortime!* + time() - tim -(gctime()-gctim);
  18. if null r then <<vdpputprop(h,'irreducible,t);
  19. return groebfactorize3 h>>;
  20. if cdr r then !*trgroeb and groebmess14 (h,r);
  21. vdpputprop(h,'factors,r);
  22. for each p in r do
  23. if vdpmember(car p,g) then test:= car p;
  24. if test then
  25. <<!*trgroeb and groebmess27a(h,test); return 'zero>>;
  26. h1 := car r;
  27. for each p in r do
  28. if vdpmember(car p,abort1) then
  29. <<r := delete(p,r); !*trgroeb and groebmess27 car p >>
  30. else vdpputprop(car p,'irreducible,t);
  31. if null r then r := list h1; % at least one
  32. if null cdr r then groebfactorize3 caar r;
  33. % inherit sugar if no substantial factor.
  34. if !*gsugar then
  35. if null cdr r then gsetsugar(caar r,s) else
  36. for each p in r do gsetsugar(car p,vdptdeg car p);
  37. return 'factor . r end;
  38. symbolic procedure groebfactorize1 h;
  39. % factorize: separate monomial factors which were detected already;
  40. begin scalar monf,vp,n,e,h1,h2,vp2;
  41. monf := vdpgetprop(h,'monfac);
  42. if null monf then
  43. return if not !*vdpmodular then groebfactorize2 h
  44. else nil; % no factor
  45. h2 := vdpdivmon (h,vbcfi 1,monf);
  46. if groebmonfac neq 0 then
  47. << % now build a polynomial from
  48. n := 0; % each variable in MONFAC
  49. for each x in monf do
  50. <<n := n#+1;
  51. if x neq 0 then
  52. <<e := list x;
  53. for i:=2:n do e := 0 . e; % prefix with n-1 zeros.
  54. vp := vdpfmon(a2vbc 1,e) . vp >> >> >>
  55. else
  56. !*trgroeb and groebmess15 monf;
  57. % append body of orig. poly, factorized
  58. if not vdpzero!? h2 and
  59. not vevzero!? vdpevlmon h2 then
  60. <<if not !*vdpmodular then vp2 := groebfactorize2 h2;
  61. vp2 := if not vp2 then list h2
  62. else for each v in vp2 collect car v;
  63. vp := nconc(vp,vp2)>>;
  64. % ascending sorting
  65. % if length vp = 1 then return nil;
  66. h1 := vp;
  67. return reverse for each x in h1 collect list vdpenumerate x end;
  68. symbolic procedure groebfactorize2 h;
  69. % tries to factorize a h-polynomial via REDUCE factorizer
  70. begin scalar h1,h2,!*factor; !*factor := t;
  71. h1 := groefctrf vdp2f h;
  72. if null cdr h1 then return nil;
  73. if null cddr h1 % only one element in factorization list
  74. and cdr cadr h1 = 1 % and multiplicity = 1
  75. then return nil;
  76. h2 := for each l in cdr h1 join
  77. for i:=1:cdr l collect car l;
  78. h2 := vdplsort for each p in h2 collect vdpsimpcont f2vdp p;
  79. return for each x in h2 collect list vdpenumerate x end;
  80. symbolic procedure groefctrf p;
  81. (fctrf p) where !*factor=t,current!-modulus = current!-modulus;
  82. symbolic procedure groebfactorize3 h;
  83. % additional efforts to factor something.
  84. <<h := nil; nil>>;
  85. endmodule;;end ;