1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*- ******************/
2 /***************************************************************************
4 *** Copyright (c) 1984 by William Schelter,University of Texas *****
5 *** All rights reserved *****
6 ***************************************************************************/
12 for a from -3 step 7 thru 26 do ldisplay(a);
16 for i while i <= 10 do s:s+i;
25 (term:diff(term,x)/p,series:series+subst(x = 0,term)*x^p);
28 x^7/90-x^6/240-x^5/15-x^4/8+x^2/2+x+1$
31 for i thru 5 do (for j from i step -1 thru 1 do poly:poly+i*x^j);
34 5*x^5+9*x^4+12*x^3+14*x^2+15*x$
38 (guess:subst(guess,x,0.5*(x+10/x)),
39 if abs(guess^2-10) < 5.0e-5 then return(guess));
42 for count from 2 next 3*count thru 20 do ldisplay(count);
46 thru 10 while x # 0 do x:0.5*(x+5/x);
52 newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
53 define(df(x),diff(f(x),x)),
54 do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
55 guess:guess-f(guess)/y,
56 if abs(f(guess)) < 5.0e-6 then return(guess)));
57 newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
58 define(df(x),diff(f(x),x)),
59 do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
60 guess:guess-f(guess)/y,
61 if abs(f(guess)) < 5.0e-6 then return(guess)))$
66 for f in [log,rho,atan] do ldisp(f(1.0));
68 ev(concat(e,linenum-1),numer);
70 kill(functions,values,arrays);
75 x*'diff(f(x),x,1)+f(x)$
104 'integrate(f(x),x,a,b);
105 'integrate(x^2,x,a,b)$
106 for i thru 5 do s:s+i^2;
114 exp:'sum(g(i),i,0,n);
130 declare(integrate,noun);
136 f(y):=diff(y*log(y),y,2);
137 f(y):=diff(y*log(y),y,2)$
152 ev(%e^x*sin(x)^2,exponentialize);
153 -%e^x*(%e^(%i*x)-%e^-(%i*x))^2/4;
155 -((%e^((2*%i+1)*x)/(2*%i+1)+%e^((1-2*%i)*x)/(1-2*%i)-2*%e^x)/4);
157 -((%e^x*(%i*sin(2*x)+cos(2*x))/(2*%i+1)
158 +%e^x*(cos(2*x)-%i*sin(2*x))/(1-2*%i)-2*%e^x)
161 -%e^x*sin(2*x)/5-%e^x*cos(2*x)/10+%e^x/2;
162 ev(ans,x:1,numer)-ev(ans,x:0,numer);
166 ev(ans,x:1,bfloat)-ev(ans,x:0,bfloat);
167 5.7791601820424019599988308251707781b-1;
168 integrate(%e^x*sin(x)^2,x);
169 -(((2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10));
171 -((2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10);
181 sin(%pi/12)+tan(%pi/6);
182 sin(%pi/12)+1/sqrt(3)$
185 /* tops 20 : 0.83616931$ */
194 /* tops 20: 3.67909265$ */
195 diff(atanh(sqrt(x)),x);
200 4.794255386042030002732879b-1$
204 exp:cos(x)^2-sin(x)^2;
211 (sin(2*x)/2+x)/2-(x-sin(2*x)/2)/2$
220 %-exp,trigreduce,ratsimp;
223 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
224 +sech(x)^2*tanh(x)/coth(x)^2;
225 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
226 +sech(x)^2*tanh(x)/coth(x)^2$
228 (sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
229 /* These are from the trgsmp.dem file.
230 * I (rtoy) hand-verified these results (using maxima, of course)
232 (1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2;
233 (1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2$
235 (sin(x)+cos(x)^4)/cos(x)^3$
237 tan(x)^2+sec(x)^2/(1-tan(x)*sec(x));
238 tan(x)^2+sec(x)^2/(1-tan(x)*sec(x))$
240 (sin(x)^4+sin(x)^3-1)/(cos(x)^2*sin(x)-cos(x)^4)$
242 (sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3);
243 (sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3)$
245 (sin(x)+cos(x)^4)/cos(x)^3$
248 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2;
249 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2$
251 (sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
253 -sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16;
254 -sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16$
256 -((sinh(x)^5+sinh(x)^4-2*sinh(x)^3)/cosh(x)^5)$
258 cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x);
259 cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x)$
263 v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x);
264 v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x)$
266 -2*'diff(v,x,1)*sin(x)+'diff(v,x,2)*cos(x)+'diff(v,x,1)$
275 x/(sqrt(1-x)*sqrt(x+1));
281 1/(sqrt(1-x)*sqrt(x+1));
287 sqrt(x-1)*sqrt(x+1)/x;
289 /* A few checks to see that triginverses false disables the above transformations */
299 /* SF bug # 1981518, Calling desolve inside a "for...do" makes it loop endlessly
300 * (protect against endless loop by throw--catch in case bug is triggered)
302 catch (block ([foo:1],
303 for i thru 3 do (ilt (1/s, s, t),
304 if foo > 3 then throw ('i = i) else foo : foo + 1)));
307 /* bug reported to mailing list 2009-05-09
308 * unexpected behavior in for loop with variable step
311 block ([L : []], for r:0 thru 7 step +2 do L : cons (r, L), L);
314 block ([L : []], for r:7 thru 0 step -2 do L : cons (r, L), L);
317 block ([L : [], r0 : 0, r1 : 7, s : +2], for r:r0 thru r1 step s do L : cons (r, L), L);
320 block ([L : [], r0 : 7, r1 : 0, s : -2], for r:r0 thru r1 step s do L : cons (r, L), L);
323 /* step is evaluated once at start of loop, so these loops are defined */
325 block ([L : [], s : +2], for i:1 thru 10 step s do L : cons (s : -s, L), L);
328 block ([L : [], s : -2], for i:10 thru 1 step s do L : cons (s : -s, L), L);
331 /* bug reported to mailing list 2009-05-13 "reset ( radexpand, domain )"
333 * display2d is a resetable option variable. We save the value of display2d
334 * and restore it after the reset. This allows to run the testsuite in both
337 (save:display2d, done);
339 (reset (), [radexpand, domain]);
341 (display2d:save, done);
344 [radexpand, domain] : [all, complex];
347 reset (radexpand, domain);
353 ([foo, bar, baz] : [1, 2, 3],
354 /* should ignore these non-defmvar's */
355 reset (foo, bar, baz));
358 /* verify that ORDFNA can handle CRE.
360 (kill (a, b), [doallmxops, doscmxops] : [false, false], 0);
364 b*matrix([''(rat(a))]);
366 (reset (doallmxops, doscmxops), 0);
369 /* SF bug #2936: stack overflow in integrate */
371 kill (x, A, B, MU, SIGMA);
374 trigsimp (gamma_incomplete (1, log (x)));
375 gamma_incomplete (1, log (x));
377 trigsimp ((%i*gamma_incomplete(1,(1-2*log(x))^2/4)*(1-2*log(x))^2)
379 %i*gamma_incomplete(1,(4*log(x)^2-4*log(x)+1)/4)$
381 trigsimp (integrate (%e^((-log(x)^2)-1)*log(x),x));
382 -(%e^-(3/4)*(2*gamma_incomplete(1,(4*log(x)^2-4*log(x)+1)/4)*abs(2*log(x)-1)
383 +2*gamma_incomplete(1/2,(4*log(x)^2-4*log(x)+1)/4)*log(x)
384 -gamma_incomplete(1/2,(4*log(x)^2-4*log(x)+1)/4)))
385 /(4*abs(2*log(x)-1))$
387 /* throw away results of integrate, just make sure it runs without crashing */
388 block ([foo, bar, ctxt],
389 foo : exp(-(log(x) - MU)*(log(x) - MU)/(2*SIGMA*SIGMA))/(x*SIGMA*sqrt(2*%pi)),
390 bar : (log(B) - log(x*SIGMA) + ((x-A)*(x-A)/(2*B*B) - (log(x) -MU)*(log(x) -MU)/(2*SIGMA*SIGMA))),
391 [foo, bar] : subst ([A=2, MU=3], [foo, bar]),
392 ctxt : newcontext (),
393 assume (SIGMA > 0, B > 0),
394 integrate (expand (foo*bar), x),
395 integrate (expand (foo*bar), x, 2, inf),
400 /* mailing list 2015-09-07: How can I catch this error? "errcatch" doesn't do the trick. */
402 /* result for this test will change if ever "quotient by zero" bug is fixed */
403 errcatch (integrate(ev(ratsimp(1/(x^(5/2)+3*x^(1/3))),algebraic),x));
406 (kill (foo, bar, baz), foo () := bar (), bar () := (errcatch (integrate(ev(ratsimp(1/(x^(5/2)+3*x^(1/3))),algebraic),x)), throw ('baz)), catch (foo ()));
409 /* result for this test will change if ever "quotient by zero" bug is fixed */
410 errcatch (integrate (exp(2^(3/2)*x^2 - sqrt(2)*x^2), x));
413 (kill (quux), bar () := (errcatch (integrate (exp(2^(3/2)*x^2 - sqrt(2)*x^2), x)), throw ('quux)), catch (foo ()));
416 /* result for this test will change if ever "quotient by zero" bug is fixed */
417 errcatch (taylor(coth(x), x, %i*%pi, 0));
420 (kill (mumble), bar () := (errcatch (taylor(coth(x), x, %i*%pi, 0)), throw ('mumble)), catch (foo ()));