Remove some code duplication in TRANSLATE-PREDICATE
[maxima.git] / tests / rtest12.mac
bloba3c5851b254fd148e1ada1e611cf8e99845c6d40
1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*-  ******************/
2 /***************************************************************************
3 ***                                                                    *****
4 ***     Copyright (c) 1984 by William Schelter,University of Texas     *****
5 ***     All rights reserved                                            *****
6 ***************************************************************************/
9 (kill(all),matchdeclare(a,true));
10 done$
11 (\^rule1_retval : tellsimp(sin(a)^2,1-cos(a)^2), 0);
13 sin(y)^2;
14 1-cos(y)^2$
15 kill(rules);
16 done$
17 nonzeroandfreeof(x,e):=is(e # 0 and freeof(x,e));
18 nonzeroandfreeof(x,e):=is(e # 0 and freeof(x,e))$
19 matchdeclare(a,nonzeroandfreeof(x),b,freeof(x));
20 done$
21 defmatch(linear,a*x+b,x);
22 linear$
23 linear(3*z+(y+1)*z+y^2,z);
24 [b = y^2,a = y+4,x = z]$
25 matchdeclare([a,f],true);
26 done$
27 constinterval(l,h):=constantp(h-l);
28 constinterval(l,h):=constantp(h-l)$
29 matchdeclare(b,constinterval(a));
30 done$
31 matchdeclare(x,atom);
32 done$
33 block(remove(integrate,outative),defmatch(checklimits,'integrate(f,x,a,b)),
34       declare(integrate,outative));
35 done$
36 'integrate(sin(t),t,x+%pi,x+2*%pi);
37 'integrate(sin(t),t,x+%pi,x+2*%pi)$
38 checklimits(%);
39 [b = x+2*%pi,a = x+%pi,x = t,f = sin(t)]$
40 'integrate(sin(t),t,0,x);
41 'integrate(sin(t),t,0,t)$
42 checklimits(%);
43 false$
44 (kill(all),matchdeclare(x,freeof(%i)));
45 done$
46 %iargs:false;
47 false$
48 (sinrule_retval : tellsimp(sin(%i*x),%i*sinh(x)), 0);
50 trigexpand(sin(x+%i*y));
51 sin(x)*cos(%i*y)+%i*cos(x)*sinh(y)$
52 %iargs:true;
53 true$
54 errcatch(0^0);
55 []$
56 ev((\^rule2_retval : tellsimp(0^0,1), 0),simp:false);
58 0^0;
60 remrule ("^", first (\^rule2_retval));
61 "^"$
62 (\^rule3_retval : tellsimp(sin(x)^2,1-cos(x)^2), 0);
64 (sin(x)+1)^2;
65 (sin(x)+1)^2$
66 expand(%);
67 2*sin(x)-cos(x)^2+2$
68 sin(x)^2;
69 1-cos(x)^2$
70 kill(rules);
71 done$
72 matchdeclare(a,true);
73 done$
74 (\^rule4_retval : tellsimp(sin(a)^2,1-cos(a)^2), 0);
76 sin(y)^2;
77 1-cos(y)^2$
78 kill(rules);
79 done$
80 (kill(all),nonzeroandfreeof(x,e):=is(e # 0 and freeof(x,e)));
81 nonzeroandfreeof(x,e):=is(e # 0 and freeof(x,e))$
82 matchdeclare(a,nonzeroandfreeof(x),b,freeof(x));
83 done$
84 defmatch(linear,a*x+b,x);
85 linear$
86 linear(3*z+(y+1)*z+y^2,z);
87 [b = y^2,a = y+4,x = z]$
88 matchdeclare([a,f],true);
89 done$
90 constinterval(l,h):=constantp(h-l);
91 constinterval(l,h):=constantp(h-l)$
92 matchdeclare(b,constinterval(a));
93 done$
94 matchdeclare(x,atom);
95 done$
96 block(remove(integrate,outative),defmatch(checklimits,'integrate(f,x,a,b)),
97       declare(integrate,outative));
98 done$
99 'integrate(sin(t),t,x+%pi,x+2*%pi);
100 'integrate(sin(t),t,x+%pi,x+2*%pi)$
101 checklimits(%);
102 [b = x+2*%pi,a = x+%pi,x = t,f = sin(t)]$
103 'integrate(sin(t),t,0,x);
104 'integrate(sin(t),t,0,t)$
105 checklimits(%);
106 false$
107 remvalue(a,b,f,x);
108 [a,b,f,x]$
109 (kill(all),matchdeclare([a,a1,a2],true));
110 done$
111 oneless(x,y):=is(x = y-1);
112 oneless(x,y):=is(x = y-1)$
113 let(a1*a2!,a1!,oneless,a2,a1);
114 ?mtext(a1*a2!,?\ \-\-\>\ ,a1!,?\ where\ ,oneless(a2,a1))$
115 ev(let(a1!/a1,(a1-1)!),letrat);
116 ?mtext(a1!/a1,?\ \-\-\>\ ,(a1-1)!)$
117 ev(letsimp(n*m!*(n-1)!/m),letrat);
118 (m-1)!*n!$
119 let(sin(a)^2,1-cos(a)^2);
120 ?mtext(sin(a)^2,?\ \-\-\>\ ,1-cos(a)^2)$
121 sin(x)^4;
122 sin(x)^4$
123 letsimp(%);
124 cos(x)^4-2*cos(x)^2+1$
125 matchdeclare([a,a1,a2],true);
126 done$
127 oneless(x,y):=is(x = y-1);
128 oneless(x,y):=is(x = y-1)$
129 let(a1*a2!,a1!,oneless,a2,a1);
130 ?mtext(a1*a2!,?\ \-\-\>\ ,a1!,?\ where\ ,oneless(a2,a1))$
131 ev(let(a1!/a1,(a1-1)!),letrat);
132 ?mtext(a1!/a1,?\ \-\-\>\ ,(a1-1)!)$
133 ev(letsimp(n*m!*(n-1)!/m),letrat);
134 (m-1)!*n!$
135 let(sin(a)^2,1-cos(a)^2);
136 ?mtext(sin(a)^2,?\ \-\-\>\ ,1-cos(a)^2)$
137 sin(x)^4;
138 sin(x)^4$
139 letsimp(%);
140 cos(x)^4-2*cos(x)^2+1$
141 pfeformat:true;
142 true$
143 poissimp(sin(x)^2);
144 1/2-1/2*cos(2*x)$
145 (2*a^2-b)*cos(x+2*y)-(a*b+5)*sin(u-4*x);
146 (2*a^2-b)*cos(2*y+x)+(a*b+5)*sin(4*x-u)$
147 exp1:outofpois(poisexpt(%,2));
148 1/2*(2*a^2-b)^2*cos(4*y+2*x)-(2*a^2-b)*(-a*b-5)*sin(2*y+5*x-u)
149                             +(2*a^2-b)*(-a*b-5)*sin(2*y-3*x+u)
150                             -1/2*(-a*b-5)^2*cos(8*x-2*u)+1/2*(-a*b-5)^2
151                             +1/2*(2*a^2-b)^2$
152 printpois(%);
153 done$
155 ratsimp(outofpois(poisint(exp1,y)));
156 ''(ratsimp(((-1)*(2*a^2-b)*(-5-a*b)*cos(u-3*x+2*y))/2+((2*a^2-b)*(-5-a*b)*cos(-u+5*x+2*y))/2+((2*a^2-b)^2*sin(2*x+4*y))/8))$
158 ratsimp(outofpois(poissimp(%)));
159 ''(ratsimp(1/8*(2*a^2-b)^2*sin(4*y+2*x)+1/2*(2*a^2-b)*(-a*b-5)*cos(2*y+5*x-u)
160                             -1/2*(2*a^2-b)*(-a*b-5)*cos(2*y-3*x+u)))$
162 poissimp(sin(x)^5+cos(x)^5);
163 1/16*sin(5*x)+1/16*cos(5*x)-5/16*sin(3*x)+5/16*cos(3*x)+5/8*sin(x)+5/8*cos(x)$
165 pfeformat:false;
166 false$
168 /* test for bug [ 1648352 ] rules and pattern bug */
170 (kill (foo, bar),
171  matchdeclare (aa, true, gg, lambda([yy], evenp(yy) and (yy > 1))),
172  let (foo(aa)^gg, (1 - bar(aa)^2)^(gg/2)),
173  0);
176 letsimp (foo(x)^2);
177 1 - bar(x)^2;
179 letsimp (foo(x)^3);
180 foo(x)^3;
182 letsimp (foo(x)^4);
183 bar(x)^4 - 2*bar(x)^2 + 1;
185 /* letsimp confused by debug stuff in expression car
186  * mailing list 2012-12-23: "let(simp) behaves different when loaded from batch file"
187  */
188 (kill (test),
189  test() := block([expr],
190    local (F),
191    expr : diff(f(x), x),
192    F(xx) := at(expr, [x = xx]),
193    let(at(diff(f(x),x),[x=0]),5),
194    letsimp(F(0))),
195  test ());