compact.tst 2.4 KB

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