RANDPOLY.LOG 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. % randpoly.tst
  3. % F.J.Wright@Maths.QMW.ac.uk, 14 July 1994
  4. off allfac;
  5. on div, errcont;
  6. % Univariate:
  7. % ----------
  8. randpoly x;
  9. 5 4 3 2
  10. - 68*x + 45*x - 13*x + 27*x + 54*x - 15
  11. % Equivalent to above:
  12. randpoly {x};
  13. 5 4 3 2
  14. 23*x - 83*x + 75*x - 89*x - 24*x + 54
  15. randpoly(x, dense);
  16. 5 4 3 2
  17. 4*x + 17*x - 53*x + 53*x + 88*x - 12
  18. % univariate default already dense
  19. randpoly(x, degree=10, ord=5);
  20. 10 9 8 7 6 5
  21. - 83*x + 28*x - 13*x - 65*x + 55*x - 26*x
  22. % Bivariate:
  23. % ---------
  24. % Default is sparse
  25. randpoly {x,y};
  26. 3 2 3 2 2
  27. 29*x *y + 12*x *y - 33*x *y - 64*x*y - 19*x - 13
  28. randpoly({x,y}, dense);
  29. 5 4 4 3 2 3 3 2 3 2 2
  30. - 12*x + 11*x *y - 26*x + 2*x *y + 69*x *y - 93*x + x *y - 93*x *y
  31. 2 2 4 3 2 5 4
  32. + 19*x *y + 95*x + 51*x*y + 68*x*y + 77*x*y + 25*x*y - 27*x + 63*y + 37*y
  33. 3 2
  34. - 89*y - 76*y + 28*y - 67
  35. randpoly({x,y}, degree=10);
  36. 10 7 6 2 8 2 5 9
  37. 19*x + 16*x + 86*x + 82*x *y - 62*x *y + 41*x*y
  38. % Lots of terms:
  39. randpoly({x,y}, dense, degree=10);
  40. 9 9 8 2 8 8 7 3 7 2 7
  41. 43*x *y + 67*x - 6*x *y - 11*x *y - 88*x - 87*x *y - 36*x *y + 27*x *y
  42. 7 6 4 6 3 6 2 6 6 5 5
  43. - 56*x + 41*x *y + 52*x *y + 15*x *y + 84*x *y - 76*x - 59*x *y
  44. 5 4 5 3 5 2 5 5 4 6 4 5
  45. + 74*x *y + 90*x *y - 50*x *y - 35*x *y - 90*x - 51*x *y + 73*x *y
  46. 4 4 4 3 4 2 4 4 3 7 3 6
  47. - 5*x *y + 34*x *y + 88*x *y + 87*x *y - 33*x - 41*x *y - 12*x *y
  48. 3 5 3 4 3 3 3 2 3 3 2 8
  49. + 29*x *y - 14*x *y - 35*x *y - 77*x *y + 21*x *y + 43*x - 73*x *y
  50. 2 7 2 6 2 5 2 4 2 3 2 2 2
  51. - 55*x *y + 27*x *y - 41*x *y + 45*x *y - 25*x *y + 46*x *y - 95*x *y
  52. 2 9 8 7 6 5 4 3
  53. + 71*x - 70*x*y - 50*x*y + 93*x*y + 77*x*y + 98*x*y - 72*x*y - 84*x*y
  54. 2 10 9 8 7 6 5 4
  55. - 39*x*y - 86*x*y - 22*x - 66*y + 31*y - 58*y + 60*y - 65*y - y - 71*y
  56. 3 2
  57. + 49*y + 91*y - 34*y + 49
  58. randpoly({x,y}, dense, degree=10, ord=5);
  59. 10 9 9 8 2 8 8 7 3 7 2 7
  60. 55*x - 23*x *y - 33*x - 22*x *y - 94*x *y + x + 14*x *y + 85*x *y - 60*x
  61. 6 4 6 3 6 2 6 6 5 5 5 4
  62. + 60*x *y + 9*x *y - 27*x *y + 44*x *y + 43*x + 75*x *y + 10*x *y
  63. 5 3 5 2 5 5 4 6 4 5 4 4
  64. + 30*x *y - 48*x *y + 63*x *y - 65*x - 60*x *y - 75*x *y - 39*x *y
  65. 4 3 4 2 4 3 7 3 6 3 5 3 4
  66. + 34*x *y - 52*x *y - 41*x *y + 86*x *y - 65*x *y - 44*x *y + 40*x *y
  67. 3 3 3 2 2 8 2 7 2 6 2 5 2 4
  68. + 67*x *y - 84*x *y + 45*x *y - 36*x *y + 32*x *y - 85*x *y - 53*x *y
  69. 2 3 9 7 6 5 10 9 8
  70. + 7*x *y - 10*x*y + 19*x*y + 22*x*y + 32*x*y - 38*y - 24*y - 93*y
  71. 7 6 5
  72. + 25*y + 53*y + 83*y
  73. % Sparse:
  74. randpoly({x,y}, deg=10, ord=5);
  75. 8 7 2 3 4 3 3 2 8 9
  76. - 68*x *y - 31*x *y + x *y + 8*x *y + 72*x *y - 3*y
  77. % Dense again:
  78. randpoly({x,y}, terms=1000, maxdeg=10, mindeg=5);
  79. 10 9 9 8 2 8 8 7 3 7 2
  80. 41*x + 31*x *y + 59*x - 83*x *y - 30*x *y + 21*x + 82*x *y + 74*x *y
  81. 7 7 6 4 6 3 6 2 6 6 5 5
  82. - 21*x *y - 74*x - 80*x *y + 61*x *y + 4*x *y - 81*x *y + 14*x - 91*x *y
  83. 5 4 5 3 5 2 5 5 4 5 4 4
  84. + 61*x *y - 61*x *y + 21*x *y - 60*x *y + 26*x + 73*x *y - 41*x *y
  85. 4 3 4 2 4 3 7 3 6 3 5 3 4
  86. + 26*x *y - x *y - 28*x *y + 42*x *y + 20*x *y - 50*x *y - 41*x *y
  87. 3 3 3 2 2 8 2 7 2 6 2 5 2 4
  88. + 91*x *y - 39*x *y - 36*x *y - 24*x *y + 85*x *y + 39*x *y - 48*x *y
  89. 2 3 9 8 7 6 5 4 10
  90. + 3*x *y - 50*x*y + 87*x*y - 78*x*y + 64*x*y - 87*x*y - 65*x*y - 52*y
  91. 9 8 7 6 5
  92. - 30*y - 88*y + 24*y + 7*y - 54*y
  93. % Exponent and coefficient functions:
  94. % ----------------------------------
  95. randpoly({x,y}, expons = rand(-10 .. 10));
  96. 4 -7 -1 -2 -4 3 -4 -5
  97. - 70*x *y - 61*x*y - 87*x *y + 26*x + 9*x *y + 16*x *y
  98. % Trivial example:
  99. randpoly({x,y}, expons = proc 5);
  100. 5 5
  101. 69*x *y
  102. randpoly({x,y}, expons = proc(2*random(0 .. 5)));
  103. 10 10 6 6 6 4 4 10 4
  104. 21*x *y + 77*x *y + 50*x *y + 123*x *y + 73*x
  105. randpoly({x,y}, coeffs = rand(-999 .. 999));
  106. 3 2 2 4 2 3
  107. 58*x *y - 723*x *y + 113*x - 200*x*y + 61*x*y + 311*y
  108. procedure coe; randpoly(a, terms=2)$
  109. randpoly({x,y}, coeffs = coe);
  110. 4 3 2 4 3 4 2 4 2 4 5 4 4
  111. 97*a *x *y + 97*a *x *y + 97*a *x *y + 97*a *x*y + 97*a *y + 97*a *y
  112. 2 3 2 2 3 2 2 2 2 2 5 2 4
  113. - 85*a *x *y - 85*a *x *y - 85*a *x *y - 85*a *x*y - 85*a *y - 85*a *y
  114. randpoly({x,y}, coeffs = coe, degree = 10);
  115. 5 6 2 5 5 5 5 5 2 5 4 6 5 4 5 6
  116. - 44*a *x *y - 44*a *x *y - 44*a *x *y - 44*a *x *y - 44*a *x - 44*a *y
  117. 3 6 2 3 5 5 3 5 2 3 4 6 3 4 3 6
  118. + 33*a *x *y + 33*a *x *y + 33*a *x *y + 33*a *x *y + 33*a *x + 33*a *y
  119. % Polynomials composed with general expressions:
  120. % ---------------------------------------------
  121. randpoly({x,y^2});
  122. 4 2 4 2 6 4 2 2
  123. 43*x *y - 45*x + 83*x *y - 24*x*y + 73*x*y + 36*y
  124. randpoly(x^2 - y^2);
  125. 10 8 2 8 6 4 6 2 6 4 6
  126. - 44*x + 220*x *y + 92*x - 440*x *y - 368*x *y - 48*x + 440*x *y
  127. 4 4 4 2 4 2 8 2 6 2 4 2 2
  128. + 552*x *y + 144*x *y + 42*x - 220*x *y - 368*x *y - 144*x *y - 84*x *y
  129. 2 10 8 6 4 2
  130. + 52*x + 44*y + 92*y + 48*y + 42*y - 52*y + 30
  131. % This should give the constant term:
  132. sub(x=y, ws);
  133. 30
  134. randpoly({x^2 - a^2, y - b});
  135. 6 6 4 2 4 2 4 4 2 4 2
  136. 63*a *b - 63*a *y + 4*a *b - 189*a *b*x - 8*a *b*y + 189*a *x *y + 4*a *y
  137. 4 2 4 2 3 2 2 2 2 2 2 2 4
  138. + 50*a + 48*a *b - 192*a *b *y - 8*a *b *x + 288*a *b *y + 189*a *b*x
  139. 2 2 2 3 2 2 4 2 2 2 2 2
  140. + 16*a *b*x *y - 192*a *b*y + 59*a *b - 189*a *x *y - 8*a *x *y - 100*a *x
  141. 2 4 2 4 2 3 2 3 2 4 2 2 2
  142. + 48*a *y - 59*a *y - 48*b *x + 192*b *x *y - 42*b + 4*b *x - 288*b *x *y
  143. 2 6 4 2 3 2 2 6
  144. + 126*b *y - 63*b*x - 8*b*x *y + 192*b*x *y - 59*b*x - 126*b*y + 63*x *y
  145. 4 2 4 2 4 2 3
  146. + 4*x *y + 50*x - 48*x *y + 59*x *y + 42*y
  147. % This should give the constant term:
  148. sub(x=a, y=b, ws);
  149. 0
  150. % Polynomials with specified zeros:
  151. % --------------------------------
  152. randpoly(x = a);
  153. 5 4 4 3 2 3 3 2 3 2 2
  154. 32*a - 160*a *x - 12*a + 320*a *x + 48*a *x - 31*a - 320*a *x - 72*a *x
  155. 2 2 4 3 2 5
  156. + 93*a *x + 87*a + 160*a*x + 48*a*x - 93*a*x - 174*a*x - 31*a - 32*x
  157. 4 3 2
  158. - 12*x + 31*x + 87*x + 31*x
  159. % This should give 0:
  160. sub(x=a, ws);
  161. 0
  162. randpoly({x = a, y = b});
  163. 3 2 3 3 2 3 2 3 2 2 2 2
  164. - 24*a *b + 48*a *b*y - 24*a *y - 26*a + 92*a *b + 72*a *b *x - 276*a *b *y
  165. 2 2 2 2 2 2 2 3 2 4
  166. - 144*a *b*x*y + 276*a *b*y + 72*a *x*y + 78*a *x - 92*a *y - 43*a - a*b
  167. 3 3 2 2 2 2 2 2
  168. - 184*a*b *x + 4*a*b *y - 72*a*b *x + 552*a*b *x*y - 6*a*b *y + 144*a*b*x *y
  169. 2 3 2 2 2 3 4
  170. - 552*a*b*x*y + 4*a*b*y - 72*a*x *y - 78*a*x + 184*a*x*y + 86*a*x - a*y
  171. 4 3 2 3 2 3 2 2 2 2
  172. + 24*a + b *x + 92*b *x - 4*b *x*y + 24*b *x - 276*b *x *y + 6*b *x*y
  173. 3 2 2 3 3 2 3 2 3 2
  174. - 48*b*x *y + 276*b*x *y - 4*b*x*y + 24*x *y + 26*x - 92*x *y - 43*x
  175. 4
  176. + x*y - 24*x
  177. % This should give 0:
  178. sub(x=a, y=b, ws);
  179. 0
  180. % Invalid input detection:
  181. % -----------------------
  182. randpoly({x,y}, degree=foo);
  183. ***** degree=foo invalid as optional randpoly argument
  184. randpoly({x,y}, foo);
  185. ***** foo invalid as optional randpoly argument
  186. randpoly({x,y}, degree=-5);
  187. ***** degree=-5 invalid as optional randpoly argument
  188. on allfac;
  189. off div, errcont;
  190. end;
  191. (TIME: randpoly 300 300)