compact.log 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. Sat Jun 29 14:15:42 PDT 1991
  2. REDUCE 3.4, 15-Jul-91 ...
  3. 1: 1:
  4. 2: 2:
  5. 3: 3: % Tests of the COMPACT package.
  6. % Author: Anthony C. Hearn.
  7. % First some simple examples.
  8. aa := {cos(x)^2+sin(x)^2-1};
  9. 2 2
  10. AA := {SIN(X) + COS(X) - 1}
  11. xx := 2*cos(x)^2+2*sin(x)^2-2;
  12. 2 2
  13. XX := 2*(SIN(X) + COS(X) - 1)
  14. compact(xx,aa);
  15. 0
  16. xx := (1-cos(x)^2)^4;
  17. 8 6 4 2
  18. XX := COS(X) - 4*COS(X) + 6*COS(X) - 4*COS(X) + 1
  19. compact(xx,aa);
  20. 8
  21. SIN(X)
  22. % These examples are from Lars Hornfeldt.
  23. compact(((1-(sin x)**2)**5)*((1-(cos x)**2)**5)
  24. *(((sin x)**2+(cos x)**2)**5),
  25. {cos x^2+sin x^2=1});
  26. 10 10
  27. SIN(X) *COS(X)
  28. compact(s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2,
  29. {cos x^2+sin x^2=1});
  30. 2 2
  31. SIN(X) *C + COS(X) *S + 1
  32. xx := s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2
  33. *((sin x)**2+(cos x)**2)*(sin x)**499*(cos x)**499;
  34. 501 501 499 503 2 2
  35. XX := SIN(X) *COS(X) + SIN(X) *COS(X) - SIN(X) *S + SIN(X)
  36. 2
  37. - COS(X) *C + C + S
  38. compact(xx,{cos(x)^2+sin(x)^2=1});
  39. 499 501 2 2 2
  40. SIN(X) *COS(X) + SIN(X) *C + SIN(X) + COS(X) *S
  41. compact((s*(1-(sin x**2))+c*(1-(cos x)**2)+(sin x)**2+(cos x)**2)
  42. *((sin x)**2+(cos x)**2)*(sin x)**499*(cos x)**499,
  43. {cos x^2+sin x^2=1});
  44. 499 499 2 2
  45. SIN(X) *COS(X) *(SIN(X) *C + COS(X) *S + 1)
  46. compact(df((1-(sin x)**2)**4,x),{cos x^2+sin x^2=1});
  47. 7
  48. - 8*SIN(X)*COS(X)
  49. % End of Lars Hornfeld examples.
  50. xx := a*(cos(x)+2*sin(x))^3-w*(cos(x)-sin(x))^2;
  51. 3 2 2
  52. XX := 8*SIN(X) *A + 12*SIN(X) *COS(X)*A - SIN(X) *W
  53. 2 3
  54. + 6*SIN(X)*COS(X) *A + 2*SIN(X)*COS(X)*W + COS(X) *A
  55. 2
  56. - COS(X) *W
  57. compact(xx,aa);
  58. 2 3
  59. - 2*SIN(X)*COS(X) *A + 2*SIN(X)*COS(X)*W + 8*SIN(X)*A - 11*COS(X) *A
  60. + 12*COS(X)*A - W
  61. xx := (1-cos(x)^2)^2+(1-sin(x)^2)^2;
  62. 4 2 4 2
  63. XX := SIN(X) - 2*SIN(X) + COS(X) - 2*COS(X) + 2
  64. compact(xx,aa);
  65. 2 2
  66. - 2*SIN(X) *COS(X) + 1
  67. xx := (c^2-1)^6+7(s-1)^4+23(c+s)^5;
  68. 12 10 8 6 5 4 4
  69. XX := C - 6*C + 15*C - 20*C + 23*C + 115*C *S + 15*C
  70. 3 2 2 3 2 4 5 4
  71. + 230*C *S + 230*C *S - 6*C + 115*C*S + 23*S + 7*S
  72. 3 2
  73. - 28*S + 42*S - 28*S + 8
  74. compact(xx,{c+s=1});
  75. 12 10 8 6 4 2
  76. C - 6*C + 15*C - 20*C + 22*C - 6*C + 24
  77. yy := (c+1)^6*s^6+7c^4+23;
  78. 6 6 5 6 4 6 4 3 6 2 6
  79. YY := C *S + 6*C *S + 15*C *S + 7*C + 20*C *S + 15*C *S
  80. 6 6
  81. + 6*C*S + S + 23
  82. compact(yy,{c+s=1});
  83. 6 6 5 6 4 6 4 3 6 2 6 6 6
  84. C *S + 6*C *S + 15*C *S + 7*C + 20*C *S + 15*C *S + 6*C*S + S
  85. + 23
  86. zz := xx^3+c^6*s^6$
  87. compact(zz,{c+s=1});
  88. 36 34 32 30 28 26 24
  89. C - 18*C + 153*C - 816*C + 3081*C - 8820*C + 20019*C
  90. 22 20 18 16 14
  91. - 37272*C + 58854*C - 81314*C + 100488*C - 111840*C
  92. 12 11 10 9 8 7
  93. + 111341*C - 6*C - 97545*C - 20*C + 80439*C - 6*C
  94. 6 4 2
  95. - 53783*C + 40608*C - 10368*C + 13824
  96. xx := (c+s)^5 - 55(1-s)^2 + 77(1-c)^3 + (c+2s)^8;
  97. 8 7 6 2 5 3 5 4 4 4
  98. XX := C + 16*C *S + 112*C *S + 448*C *S + C + 1120*C *S + 5*C *S
  99. 3 5 3 2 3 2 6 2 3
  100. + 1792*C *S + 10*C *S - 77*C + 1792*C *S + 10*C *S
  101. 2 7 4 8 5 2
  102. + 231*C + 1024*C*S + 5*C*S - 231*C + 256*S + S - 55*S
  103. + 110*S + 22
  104. % This should reduce to something like:
  105. yy := 1 - 55c^2 + 77s^3 + (1+s)^8;
  106. 2 8 7 6 5 4 3 2
  107. YY := - 55*C + S + 8*S + 28*S + 56*S + 70*S + 133*S + 28*S
  108. + 8*S + 2
  109. % The result contains the same number but different terms.
  110. compact(xx,{c+s=1});
  111. 8 7 6 5 4 3 2
  112. S + 8*S + 28*S + 56*S + 70*S + 133*S - 27*S + 118*S - 53
  113. compact(yy,{c+s=1});
  114. 8 7 6 5 4 3 2
  115. S + 8*S + 28*S + 56*S + 70*S + 133*S - 27*S + 118*S - 53
  116. % Test showing order of expressions is important.
  117. d2:= - 4*r3a**2 - 4*r3b**2 - 4*r3c**2 + 3*r3**2$
  118. d1:= 4 * r3a**2 * r3
  119. + 4 * r3b**2 * r3
  120. + 4 * r3c**2 * r3
  121. + 16 * r3a * r3b * r3c
  122. - r3**3$
  123. d0:= 16 * r3a**4
  124. + 16 * r3b**4
  125. + 16 * r3c**4
  126. + r3**4
  127. - 32 * r3a**2 * r3b**2
  128. - 32 * r3a**2 * r3c**2
  129. - 32 * r3b**2 * r3c**2
  130. - 8 * r3a**2 * r3**2
  131. - 8 * r3b**2 * r3**2
  132. - 8 * r3c**2 * r3**2
  133. - 64 * r3a * r3b * r3c * r3$
  134. alist := { c0 = d0, c1 = d1, c2 = d2}$
  135. blist := { c2 = d2, c1 = d1, c0 = d0}$
  136. d:= d2 * l*l + d1 * l + d0;
  137. 2 2 2 2 2 2 2 2 2
  138. D := - 4*L *R3A - 4*L *R3B - 4*L *R3C + 3*L *R3 + 4*L*R3A *R3
  139. 2 2 3
  140. + 16*L*R3A*R3B*R3C + 4*L*R3B *R3 + 4*L*R3C *R3 - L*R3
  141. 4 2 2 2 2 2 2
  142. + 16*R3A - 32*R3A *R3B - 32*R3A *R3C - 8*R3A *R3
  143. 4 2 2 2 2
  144. - 64*R3A*R3B*R3C*R3 + 16*R3B - 32*R3B *R3C - 8*R3B *R3
  145. 4 2 2 4
  146. + 16*R3C - 8*R3C *R3 + R3
  147. compact(d,alist);
  148. 2
  149. L *C2 + L*C1 + C0
  150. % Works fine.
  151. compact(d,blist);
  152. 2 3 2 2
  153. L *C2 + 16*L*R3A*R3B*R3C + 2*L*R3 - L*R3*C2 - 64*R3A *R3B
  154. 2 2 2 2 4 2
  155. - 64*R3A *R3C - 64*R3A*R3B*R3C*R3 - 64*R3B *R3C + 4*R3 - 4*R3 *C2
  156. 2
  157. + C2
  158. % Only c2=d2 is applied.
  159. % This example illustrates why parallel application of the individual
  160. % side relations is necessary.
  161. lst:={x1=a+b+c, x2=a-b-c, x3=-a+b-c, x4=-a-b+c};
  162. LST := {X1=A + B + C,
  163. X2=A - B - C,
  164. X3= - A + B - C,
  165. X4= - A - B + C}
  166. z1:=(a+b+c)*(a-b-c)*(-a+b-c);
  167. Z1 :=
  168. 3 2 2 2 2 3 2 2 3
  169. - A + A *B - A *C + A*B + 2*A*B*C + A*C - B - B *C + B*C + C
  170. % This is x1*x2*x3.
  171. z2:=(a+b+c)*(a-b-c)*(-a+b-c)*(-a-b+c);
  172. 4 2 2 2 2 4 2 2 4
  173. Z2 := A - 2*A *B - 2*A *C + B - 2*B *C + C
  174. % This is x1*x2*x3*x4.
  175. compact(z1,lst);
  176. 2
  177. X1*(4*A*B + 2*C*X1 - X1 )
  178. % Not the best solution but better than nothing.
  179. compact(z2,lst);
  180. 4 2 2 2 2 4 2 2 4
  181. A - 2*A *B - 2*A *C + B - 2*B *C + C
  182. % Does nothing.
  183. end;
  184. 4: 4:
  185. Quitting
  186. Sat Jun 29 14:15:50 PDT 1991