COMPACT.TST 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. % Tests of the COMPACT package.
  2. % Author: Anthony C. Hearn.
  3. % First some simple examples.
  4. aa := {cos(x)^2+sin(x)^2-1};
  5. xx := 2*cos(x)^2+2*sin(x)^2-2;
  6. compact(xx,aa);
  7. xx := (1-cos(x)^2)^4;
  8. compact(xx,aa);
  9. % These examples are from Lars Hornfeldt.
  10. % This should be cos x^10*sin x^10.
  11. compact(((1-(sin x)**2)**5)*((1-(cos x)**2)**5)
  12. *(((sin x)**2+(cos x)**2)**5),
  13. {cos x^2+sin x^2=1});
  14. % This example illustrates the problem in the above. It is cos(x)^6.
  15. compact(-3cos(x)^2*sin(x)^2-sin(x)^6+1,{cos x^2+sin x^2-1});
  16. compact(s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2,
  17. {cos x^2+sin x^2=1});
  18. xx := s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2
  19. *((sin x)**2+(cos x)**2)*(sin x)**499*(cos x)**499;
  20. compact(xx,{cos(x)^2+sin(x)^2=1});
  21. compact((s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2)
  22. *((sin x)**2+(cos x)**2)*(sin x)**499*(cos x)**499,
  23. {cos x^2+sin x^2=1});
  24. compact(df((1-(sin x)**2)**4,x),{cos x^2+sin x^2=1});
  25. % End of Lars Hornfeld examples.
  26. xx := a*(cos(x)+2*sin(x))^3-w*(cos(x)-sin(x))^2;
  27. compact(xx,aa);
  28. xx := (1-cos(x)^2)^2+(1-sin(x)^2)^2;
  29. compact(xx,aa);
  30. xx := (c^2-1)^6+7(s-1)^4+23(c+s)^5;
  31. compact(xx,{c+s=1});
  32. yy := (c+1)^6*s^6+7c^4+23;
  33. compact(yy,{c+s=1});
  34. zz := xx^3+c^6*s^6$
  35. compact(zz,{c+s=1});
  36. xx := (c+s)^5 - 55(1-s)^2 + 77(1-c)^3 + (c+2s)^8;
  37. % This should reduce to something like:
  38. yy := 1 - 55c^2 + 77s^3 + (1+s)^8;
  39. % The result contains the same number but different terms.
  40. compact(xx,{c+s=1});
  41. compact(yy,{c+s=1});
  42. % Test showing order of expressions is important.
  43. d2:= - 4*r3a**2 - 4*r3b**2 - 4*r3c**2 + 3*r3**2$
  44. d1:= 4 * r3a**2 * r3
  45. + 4 * r3b**2 * r3
  46. + 4 * r3c**2 * r3
  47. + 16 * r3a * r3b * r3c
  48. - r3**3$
  49. d0:= 16 * r3a**4
  50. + 16 * r3b**4
  51. + 16 * r3c**4
  52. + r3**4
  53. - 32 * r3a**2 * r3b**2
  54. - 32 * r3a**2 * r3c**2
  55. - 32 * r3b**2 * r3c**2
  56. - 8 * r3a**2 * r3**2
  57. - 8 * r3b**2 * r3**2
  58. - 8 * r3c**2 * r3**2
  59. - 64 * r3a * r3b * r3c * r3$
  60. alist := { c0 = d0, c1 = d1, c2 = d2}$
  61. blist := { c2 = d2, c1 = d1, c0 = d0}$
  62. d:= d2 * l*l + d1 * l + d0;
  63. compact(d,alist); % Works fine.
  64. compact(d,blist); % Only c2=d2 is applied.
  65. % This example illustrates why parallel application of the individual
  66. % side relations is necessary.
  67. lst:={x1=a+b+c, x2=a-b-c, x3=-a+b-c, x4=-a-b+c};
  68. z1:=(a+b+c)*(a-b-c)*(-a+b-c); % This is x1*x2*x3.
  69. z2:=(a+b+c)*(a-b-c)*(-a+b-c)*(-a-b+c); % This is x1*x2*x3*x4.
  70. compact(z1,lst); % Not the best solution but better than nothing.
  71. compact(z2,lst); % Does nothing.
  72. end;