groebfac.red 4.2 KB

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