FACTOR.TST 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. comment factorizer test file;
  2. array a(20);
  3. factorize(x**2-1); % To make sure factorizer is loaded.
  4. algebraic procedure test(prob,nfac);
  5. begin
  6. scalar basetime;
  7. p := for i:=1:nfac product a(i);
  8. Write "Problem number ",prob;
  9. symbolic (basetime := time());
  10. m := factorize p;
  11. symbolic (basetime := time() - basetime);
  12. q := for each j in m product j;
  13. if (length m=nfac) and (p=q) then return ok;
  14. write "This example failed:";
  15. write m;
  16. return failed
  17. end;
  18. % Wang test case 1;
  19. a(1) := x*y+z+10$
  20. a(2) := x*z+y+30$
  21. a(3) := x+y*z+20$
  22. test(1,3);
  23. % Wang test case 2;
  24. a(1) := x**3*z+x**3*y+z-11$
  25. a(2) := x**2*z**2+x**2*y**2+y+90$
  26. test(2,2);
  27. % Wang test case 3;
  28. a(1) := x**3*y**2+x*z**4+x+z$
  29. a(2) := x**3+x*y*z+y**2+y*z**3$
  30. test(3,2);
  31. % Wang test case 4;
  32. a(1) := x**2*z+y**4*z**2+5$
  33. a(2) := x*y**3+z**2$
  34. a(3) := -x**3*y+z**2+3$
  35. a(4) := x**3*y**4+z**2$
  36. test(4,4);
  37. % Wang test case 5;
  38. a(1) := 3*u**2*x**3*y**4*z+x*z**2+y**2*z**2+19*y**2$
  39. a(2) := u**2*y**4*z**2+x**2*z+5$
  40. a(3) := u**2+x**3*y**4+z**2$
  41. test(5,3);
  42. % Wang test case 6;
  43. a(1) := w**4*x**5*y**6-w**4*z**3+w**2*x**3*y+x*y**2*z**2$
  44. a(2) := w**4*z**6-w**3*x**3*y-w**2*x**2*y**2*z**2+x**5*z
  45. -x**4*y**2+y**2*z**3$
  46. a(3) := -x**5*z**3+x**2*y**3+y*z$
  47. test(6,3);
  48. % Wang test case 7;
  49. a(1) := x+y+z-2$
  50. a(2) := x+y+z-2$
  51. a(3) := x+y+z-3$
  52. a(4) := x+y+z-3$
  53. a(5) := x+y+z-3$
  54. test(7,5);
  55. % Wang test case 8;
  56. a(1) := -z**31-w**12*z**20+y**18-y**14+x**2*y**2+x**21+w**2$
  57. a(2) := -15*y**2*z**16+29*w**4*x**12*z**3+21*x**3*z**2+3*w**15*y**20$
  58. % Commented out, since it can take a long time.
  59. % TEST(8,2);
  60. % Wang test case 9;
  61. a(1) := 18*u**2*w**3*x*z**2+10*u**2*w*x*y**3+15*u*z**2+6*w**2*y**3*z**2$
  62. a(2) := x$
  63. a(3) := 25*u**2*w**3*y*z**4+32*u**2*w**4*y**4*z**3-
  64. 48*u**2*x**2*y**3*z**3-2*u**2*w*x**2*y**2+44*u*w*x*y**4*z**4-
  65. 8*u*w*x**3*z**4+4*w**2*x+11*w**2*x**3*y+12*y**3*z**2$
  66. a(4) := z$
  67. a(5) := z$
  68. a(6) := u$
  69. a(7) := u$
  70. a(8) := u$
  71. a(9) := u$
  72. test(9,9);
  73. % Wang test case 10;
  74. a(1) := 31*u**2*x*z+35*w**2*y**2+40*w*x**2+6*x*y$
  75. a(2) := 42*u**2*w**2*y**2+47*u**2*w**2*z+22*u**2*w**2+9*u**2*w*x**2+21
  76. *u**2*w*x*y*z+37*u**2*y**2*z+u**2*w**2*x*y**2*z**2+8*u**2*w**2
  77. *z**2+24*u**2*w*x*y**2*z**2+24*u**2*x**2*y*z**2+12*u**2*x*y**2
  78. *z**2+13*u*w**2*x**2*y**2+27*u*w**2*x**2*y+39*u*w*x*z+43*u*
  79. x**2*y+44*u*w**2* z**2+37*w**2*x*y+29*w**2*y**2+31*w**2*y*z**2
  80. +12*w*x**2*y*z+43*w*x*y*z**2+22*x*y**2+23*x*y*z+24*x*y+41*y**2
  81. *z$
  82. test(10,2);
  83. % Wang test case 11;
  84. a(1) := -36*u**2*w**3*x*y*z**3-31*u**2*w**3*y**2+20*u**2*w**2*x**2*y**2
  85. *z**2-36*u**2*w*x*y**3*z+46*u**2*w*x+9*u**2*y**2-36*u*w**2*y**3
  86. +9*u*w*y**3-5*u*w*x**2*y**3+48*u*w*x**3*y**2*z+23*u*w*x**3*y**2
  87. -43*u*x**3*y**3*z**3-46*u*x**3*y**2+29*w**3*x*y**3*z**2-
  88. 14*w**3*x**3*y**3*z**2-45*x**3-8*x*y**2$
  89. a(2) := 13*u**3*w**2*x*y*z**3-4*u*x*y**2-w**3*z**3-47*x*y$
  90. a(3) := x$
  91. a(4) := y$
  92. test(11,4);
  93. % Wang test case 12;
  94. a(1) := x+y+z-3$
  95. a(2) := x+y+z-3$
  96. a(3) := x+y+z-3$
  97. test(12,3);
  98. % Wang test case 13;
  99. a(1) := 2*w*z+45*x**3-9*y**3-y**2+3*z**3$
  100. a(2) := w**2*z**3-w**2+47*x*y$
  101. test(13,2);
  102. % Wang test case 14;
  103. a(1) := 18*x**4*y**5+41*x**4*y**2-37*x**4+26*x**3*y**4+38*x**2*y**4-29*
  104. x**2*y**3-22*y**5$
  105. a(2) := 33*x**5*y**6-22*x**4+35*x**3*y+11*y**2$
  106. test(14,2);
  107. % Wang test case 15;
  108. a(1) := 12*w**2*x*y*z**3-w**2*z**3+w**2-29*x-3*x*y**2$
  109. a(2) := 14*w**2*y**2+2*w*z+18*x**3*y-8*x*y**2-y**2+3*z**3$
  110. a(3) := z$
  111. a(4) := z$
  112. a(5) := y$
  113. a(6) := y$
  114. a(7) := y$
  115. a(8) := x$
  116. a(9) := x$
  117. a(10) := x$
  118. a(11) := x$
  119. a(12) := x$
  120. a(13) := x$
  121. test(15,13);
  122. % Test 16 - the 40th degree polynomial that comes from
  123. % SIGSAM problem number 7;
  124. a(1) := 8192*y**10+20480*y**9+58368*y**8-161792*y**7+198656*y**6+
  125. 199680*y**5-414848*y**4-4160*y**3+171816*y**2-48556*y+469$
  126. a(2) := 8192*y**10+12288*y**9+66560*y**8-22528*y**7-138240*y**6+
  127. 572928*y**5-90496*y**4-356032*y**3+113032*y**2+23420*y-8179$
  128. a(3) := 4096*y**10+8192*y**9+1600*y**8-20608*y**7+20032*y**6+87360*y**5-
  129. 105904*y**4+18544*y**3+11888*y**2-3416*y+1$
  130. a(4) := 4096*y**10+8192*y**9-3008*y**8-30848*y**7+21056*y**6+146496*
  131. y**5-221360*y**4+1232*y**3+144464*y**2-78488*y+11993$
  132. test(16,4);
  133. % Test 17 - taken from Erich Kaltofen's thesis. This polynomial
  134. % splits mod all possible primes p;
  135. a(1) := x**25-25*x**20-3500*x**15-57500*x**10+21875*x**5-3125$
  136. test(17,1);
  137. % Test 18 - another 'hard-to-factorize' univariate;
  138. a(1) := x**18+9*x**17+45*x**16+126*x**15+189*x**14+27*x**13-
  139. 540*x**12-1215*x**11+1377*x**10+15444*x**9+46899*x**8+
  140. 90153*x**7+133893*x**6+125388*x**5+29160*x**4-
  141. 32076*x**3+26244*x**2-8748*x+2916$
  142. test(18,1);
  143. % Test 19 - another example chosen to lead to false splits mod p;
  144. a(1) := x**16+4*x**12-16*x**11+80*x**9+2*x**8+160*x**7+
  145. 128*x**6-160*x**5+28*x**4-48*x**3+128*x**2-16*x+1$
  146. a(2) := x**16+4*x**12+16*x**11-80*x**9+2*x**8-160*x**7+
  147. 128*x**6+160*x**5+28*x**4+48*x**3+128*x**2+16*x+1$
  148. test(19,2);
  149. % End of all tests;
  150. end;