1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*- ******************/
2 /***************************************************************************
4 *** Copyright (c) 1984 by William Schelter,University of Texas *****
5 *** All rights reserved *****
6 ***************************************************************************/
9 (kill(all),matchdeclare(a,true));
11 (\^rule1_retval : tellsimp(sin(a)^2,1-cos(a)^2), 0);
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));
21 defmatch(linear,a*x+b,x);
23 linear(3*z+(y+1)*z+y^2,z);
24 [b = y^2,a = y+4,x = z]$
25 matchdeclare([a,f],true);
27 constinterval(l,h):=constantp(h-l);
28 constinterval(l,h):=constantp(h-l)$
29 matchdeclare(b,constinterval(a));
33 block(remove(integrate,outative),defmatch(checklimits,'integrate(f,x,a,b)),
34 declare(integrate,outative));
36 'integrate(sin(t),t,x+%pi,x+2*%pi);
37 'integrate(sin(t),t,x+%pi,x+2*%pi)$
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)$
44 (kill(all),matchdeclare(x,freeof(%i)));
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)$
56 ev((\^rule2_retval : tellsimp(0^0,1), 0),simp:false);
60 remrule ("^", first (\^rule2_retval));
62 (\^rule3_retval : tellsimp(sin(x)^2,1-cos(x)^2), 0);
74 (\^rule4_retval : tellsimp(sin(a)^2,1-cos(a)^2), 0);
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));
84 defmatch(linear,a*x+b,x);
86 linear(3*z+(y+1)*z+y^2,z);
87 [b = y^2,a = y+4,x = z]$
88 matchdeclare([a,f],true);
90 constinterval(l,h):=constantp(h-l);
91 constinterval(l,h):=constantp(h-l)$
92 matchdeclare(b,constinterval(a));
96 block(remove(integrate,outative),defmatch(checklimits,'integrate(f,x,a,b)),
97 declare(integrate,outative));
99 'integrate(sin(t),t,x+%pi,x+2*%pi);
100 'integrate(sin(t),t,x+%pi,x+2*%pi)$
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)$
109 (kill(all),matchdeclare([a,a1,a2],true));
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);
119 let(sin(a)^2,1-cos(a)^2);
120 ?mtext(sin(a)^2,?\ \-\-\>\ ,1-cos(a)^2)$
124 cos(x)^4-2*cos(x)^2+1$
125 matchdeclare([a,a1,a2],true);
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);
135 let(sin(a)^2,1-cos(a)^2);
136 ?mtext(sin(a)^2,?\ \-\-\>\ ,1-cos(a)^2)$
140 cos(x)^4-2*cos(x)^2+1$
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
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)$
168 /* test for bug #1097: rules and pattern bug */
171 matchdeclare (aa, true, gg, lambda([yy], evenp(yy) and (yy > 1))),
172 let (foo(aa)^gg, (1 - bar(aa)^2)^(gg/2)),
183 bar(x)^4 - 2*bar(x)^2 + 1;
185 /* More tests for bug #1097: pattern variable appears in letsimp result */
188 matchdeclare ([arg1, arg2, exp], true),
189 let (f(arg1, arg2)^exp, g(arg2, arg1)^exp), 0);
192 letsimp (f(x, y)); /* This used to yield g(arg2,arg1) */
195 letsimp (f(x, y)^2); /* This used to yield g(arg2,arg1)^2 */
198 letsimp (f(x, y)^q); /* This used to yield g(arg2,arg1)^q */
201 (remlet (f(arg1, arg2)^exp),
202 remove ([arg1, arg2, exp], matchdeclare),
206 /* letsimp confused by debug stuff in expression car
207 * mailing list 2012-12-23: "let(simp) behaves different when loaded from batch file"
210 test() := block([expr],
212 expr : diff(f(x), x),
213 F(xx) := at(expr, [x = xx]),
214 let(at(diff(f(x),x),[x=0]),5),
219 /* Bug #2709: `letsimp' is wrong if `ratexpand' is called */
227 ratexpand (a * b * c);
230 letsimp (U / n); /* This used to yield 1 */
236 /* Some basic letsimp tests, based on bug #3950 */
250 letsimp (f (1, 2, 3));
256 (let (f (1), g (1)), 0);
268 letsimp (f (1, 2, 3));
274 (let (f (1, 2, 3), g (1, 2, 3)), 0);
286 letsimp (f (1, 2, 3));
289 (remlet (f (1, 2, 3)), 0);
292 /* Bug #3950: letsimp confuses symbols and nullary applications */
294 (let (f (), g ()), 0);
297 /* This used to yield g() */
301 /* This used to yield f() */
308 letsimp (f (1, 2, 3));
314 (matchdeclare (foo, true), 0);
317 (let (foo (), bar ()), 0);
320 /* This used to cause a stack overflow */
324 /* This also used to cause a stack overflow */
328 (remove (foo, matchdeclare),