decompos.tst 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. % Test for the univariate and multivariate polynomial decomposition.
  2. % Herbert Melenk, ZIB Berlin, 1990.
  3. procedure testdecompose u;
  4. begin scalar r,p,val,nextvar;
  5. write "decomposition of ",u;
  6. r := decompose u;
  7. if length r = 1 then rederr "decomposition failed";
  8. write " leads to ",r;
  9. % test if the result is algebraically correct.
  10. r := reverse r;
  11. nextvar := lhs first r; val := rhs first r;
  12. r := rest r;
  13. while not(r={}) do
  14. << p := first r; r := rest r;
  15. if 'equal = part(p,0) then
  16. <<val := sub(nextvar=val,rhs p); nextvar := lhs p>>
  17. else
  18. val := sub(nextvar=val,p);
  19. >>;
  20. if val = u then write " O.K. "
  21. else
  22. <<write "**** reconstructed polynomial: ";
  23. write val;
  24. rederr "reconstruction leads to different polynomial";
  25. >>;
  26. end;
  27. % univariate decompositions
  28. testdecompose(x**4+x**2+1);
  29. testdecompose(x**6+9x**5+52x**4+177x**3+435x**2+630x+593);
  30. testdecompose(x**6+6x**4+x**3+9x**2+3x-5);
  31. testdecompose(x**8-88*x**7+2924*x**6-43912*x**5+263431*x**4-218900*x**3+
  32. 65690*x**2-7700*x+234);
  33. % multivariate cases
  34. testdecompose(u**2+v**2+2u*v+1);
  35. testdecompose(x**4+2x**3*y + 3x**2*y**2 + 2x*y**3 + y**4 + 2x**2*y
  36. +2x*y**2 + 2y**3 + 5 x**2 + 5*x*y + 6*y**2 + 5y + 9);
  37. testdecompose sub(u=(2 x**2 + 17 x+y + y**3),u**2+2 u + 1);
  38. testdecompose sub(u=(2 x**2 *y + 17 x+y + y**3),u**2+2 u + 1);
  39. % some cases which require a special (internal) mapping
  40. testdecompose ( (x + y)**2);
  41. testdecompose ((x + y**2)**2);
  42. testdecompose ( (x**2 + y)**2);
  43. testdecompose ( (u + v)**2 +10 );
  44. % the decomposition is not unique and might generate quite
  45. % different images:
  46. testdecompose ( (u + v + 10)**2 -100 );
  47. % some special (difficult) cases
  48. testdecompose (X**4 + 88*X**3*Y + 2904*X**2*Y**2 - 10*X**2
  49. + 42592*X*Y**3 - 440*X*Y + 234256*Y**4 - 4840*Y**2);
  50. % a polynomial with complex coefficients
  51. on complex;
  52. testdecompose(X**4 + (88*I)*X**3*Y - 2904*X**2*Y**2 - 10*X**2 -
  53. (42592*I)*X*Y**3 - (440*I)*X*Y + 234256*Y**4 + 4840*Y**2);
  54. off complex;
  55. % Examples given by J. Gutierrez and J.M. Olazabal.
  56. f1:=x**6-2x**5+x**4-3x**3+3x**2+5$
  57. testdecompose(f1);
  58. f2:=x**32-1$
  59. testdecompose(f2);
  60. f3:=x**4-(2/3)*x**3-(26/9)*x**2+x+3$
  61. testdecompose(f3);
  62. f4:=sub(x=x**4-x**3-2x+1,x**3-x**2-1)$
  63. testdecompose(f4);
  64. f5:=sub(x=f4,x**5-5)$
  65. testdecompose(f5);
  66. clear f1,f2,f3,f4,f5;
  67. end;