2 A collection of tests to stress $limit and friends
8 Tests to check how limit deals with weird combinations of
9 infinitesimals and infinities. See bug 2563
18 /* Tests from Bug 1036900 */
19 /* These bugs were fixed in limit.lisp rev 1.7, 2004/10/04 */
22 limit(7^(n^2)/8^n,n,inf);
24 limit((10^n+9^n+8^n)^(1/n),n,inf);
26 limit(4^n/2^(2*n),n,inf);
29 /* Test from Bug 1052308 */
30 /* Fixed in limit.lisp rev 1.11 */
33 limit(erf(nn*zz), nn, inf);
35 limit(tanh(nn*zz), nn, inf);
40 /* Bug 1281737, fixed in limit.lisp rev 1.15 */
41 limit(atan(x)/(1/exp(1)-exp(-(1+x)^2)),x,inf,plus);
45 limit(atan2(y,x),y,minf);
49 limit(abs(sqrt(1-1/x)-1),x,0);
53 limit(x*atan(x)/(x+1),x,inf);
55 limit(x*atan(x)-log(x),x,inf);
63 limit(sin(x)/x,x,0,plus);
65 limit(sin(x)/x,x,0,minus);
70 /* #2504 wrong answer for simple limit, limit(sin(x)+1/x, x, inf)=0 */
71 limit(1/x + sin(x), x, inf);
79 limit(t^2*exp(-4*t/3-8*exp(-t)),t,inf);
83 * From bug 535363, but this isn't really fixed. The fix for 1469411
84 * broke this test, so we're adding it to make sure we don't break it.
88 limit(exp(-1/x)/x^4,x,0,'plus);
92 limit(x*(atan(x)-%pi/2),x,inf);
95 limit((atan(x)-(%pi/2))/(sin(10/x)),x,inf);
98 /* [ 1498047 ] limit(a/n,n,inf); */
103 * [ 1646761 ] limit atanh @ -1 / 1 all wrong...
105 /* Limit at 1 is (complex) infinity). But one-sided limit can be inf (real infinity). */
108 limit(atanh(x),x,1,'minus);
110 limit(atanh(x),x,-1);
112 limit(atanh(x),x,-1,'plus);
115 /* There shouldn't be an error message printed out here. Need to look at output to see. */
116 limit(2*atanh(x),x,1);
118 limit(2*atanh(x),x,1,'minus);
121 limit(atanh(a-1)-log(a)/2,a,0,'plus),logarc:true;
124 /* [ 1606731 ] limit of algebraic when algebraic : true */
125 limit(x*(sqrt(1+x^2)-x),x,inf), algebraic : true, gcd : subres;
128 /* [ 1097982 ] limit(x/(x^(log(x)))); returns wrong answer */
129 limit(x/(x^log(x)), x, inf);
132 /* [ 1039965 ] limit(4^n/2^(2*n),n,inf) is wrong */
133 limit(4^n/2^(2*n),n,inf);
136 /* [ 1731127 ] limit((1 + 1/x)*(sqrt(x + 1) + 1), x, inf) => 0 (not inf) */
137 limit((1 + 1/x)*(sqrt(x + 1) + 1), x, inf);
140 /* [ 1593083 ] tlimit(t^2*exp(-4*t/3-8*exp(-t)),t,inf) gives error */
141 tlimit(t^2*exp(-4*t/3-8*exp(-t)),t,inf);
144 /* [ 1786774 ] tlimit((5^x + 3^x)^(1/x), x, inf) => Error */
145 tlimit((5^x + 3^x)^(1/x), x, inf);
148 /* [ 1603900 ] taylor/tlimit (4^n+1)/2^(2*n) internal error */
149 tlimit((4^n+1)/2^(2*n),n,inf);
152 /* [ 1281736 ] limit((x/log(x))*(x^(1/x)-1),x,inf) - wrong result */
153 limit((x/log(x))*(x^(1/x)-1),x,inf);
156 /* [ 1036901 ] tlimit(7^(n^2)/8^n,n,inf); wrong result */
157 tlimit(7^(n^2)/8^n, n, inf);
160 /* [ 1665657 ] limit fails to find easy limit */
161 limit(x/(x-1)-1/log(x),x,1,plus);
164 /* [ 611411 ] limit asks sign of IND */
165 limit(abs(sin(x)),x,inf);
168 /* [ 1629723 ] bug in limit, asks sign of IND, encountered in integrator */
169 limit(abs(sin(x))/x, x, inf);
172 /* [ 782099 ] limit returns expression in IND */
173 limit(sinh(exp(%i*x)),x,inf);
176 /* [ 1528607 ] limit(a^x,x,inf) can't solve for a : abs(a) < 1 */
177 limit((-2/3)^x,x,inf);
180 limit(signum(x), x, 0, plus);
183 limit(signum(x), x, 0, minus);
186 limit((-1/%pi)^x,x,inf);
189 tlimit(exp(%i*t), t, inf);
192 tlimit(exp(-t+%i*t),t,inf);
195 /* [ 1811503 ] computing a wrong result */
196 limit((((1+1/x)^(x^2))+1)^(1/x),x,inf);
199 /* [ 1760232 ] limit(1/n * n!^(1/n), n, inf); */
200 limit(1/n * n!^(1/n), n, inf);
203 /* Apparently wrong limit with factorial - ID: 3198530 */
204 limit(1/(2+1/factorial(n)),n,inf);
207 limit(t*(erf((t))-1),t,inf);
210 limit(exp(x)*(sin(1/x+exp(-x))-sin(1/x+exp(-x^2))), x, inf);
213 /* it would be nice to handle this someday
214 limit(n - exp(psi[0](n)), n, inf);
218 limit(x*gamma(x), x, 0);
221 /* [ 744679 ] limit overflows memory? */
222 (assume(a>1), limit((a^(1/n)+1)^n/2^n, n, inf));
225 /* [ 702512 ] limit(1/(1/a*2^(%i*a)+1),a,inf) => UND */
226 limit(1/(1/a*2^(%i*a)+1),a,inf);
229 /* [ 923407 ] limit(atan(sqrt(x))/sqrt(x),x,0) wrong */
230 limit(atan(sqrt(x))/sqrt(x),x,0);
233 /* [ 1102908 ] limit/atan/exp returns complex expr with wrong principal val */
234 limit(atan(x)/(1/exp(1)-exp(-(1+x)^2)),x,inf,plus);
237 limit( (3^(1/x) + 5^(1/x))^x, x, 0, minus);
240 limit( (3^(1/x) + 5^(1/x))^x, x, 0, plus);
243 limit( (3^(1/x) + 5^(1/x))^x, x, 0);
246 /* [ 1852415 ] limit(sqrt(1-%e^(-x^2)), x, inf) = 0 */
247 limit(sqrt(1-%e^(-x^2)), x, inf);
250 /* [ 1515712 ] tlimit (x*atan(x)/(x+1),x,inf) => 3 %pi/2, etc */
251 tlimit(x*atan(x)/(x+1),x,inf);
254 tlimit(x*(atan(x)-%pi/2),x,inf);
257 tlimit(atan(x^-1), x, 0, minus);
260 /* [ 1973399 ] F(x) := 1/%pi*(atan(x) + %pi/2) */
261 (assume(c>0), limit(((1/%pi)*(atan(n/%pi) + %pi/2))^n, n, inf));
264 /* [ 1103515 ] limit(atan2(x,-1),x,0) wrong */
265 limit(atan2(x,-1), x, 0, minus);
268 limit(atan2(x,-1), x, 0, plus);
271 limit(atan2(x,-1), x, 0);
273 /* ideally should be ind */
275 /* limit of atan2 - ID: 3539699 */
276 limit(atan2(x^2-2,x^3-3*x), x, sqrt(2), minus);
279 limit(atan2(x^2-2,x^3-3*x), x, sqrt(2), plus);
282 limit(atan2((x^2-2), x^3-2*x), x, sqrt(2), minus);
285 limit(atan2((x^2-2), x^3-2*x), x, sqrt(2), plus);
288 limit(atan2(-(x^2-2), x^3-2*x), x, sqrt(2), minus);
291 limit(atan2(-(x^2-2), x^3-2*x), x, sqrt(2), plus);
294 limit(floor(x), x, 5, minus);
297 limit(floor(x), x, 5, plus);
300 /* [ 1587235 ] limit(floor(x),x,1) wrong */
304 /* [ 1885377 ] wrong limit evaluation in 5.14.0 */
305 limit((3/4)^(5*n+1), n, inf);
308 limit(-%e^x/x, x, inf);
311 /* [ 2083561 ] Limit of the Wallis product */
312 limit((%pi*4^N*N!^2)/(2*2^(2*N)*gamma(N+1/2)*gamma(N+3/2)), N, inf);
315 /* wrong limit(log(gamma(x+1))/x,x,0) - ID: 2727078 */
316 limit(log(gamma(x+1))/x, x, 0);
319 /* log has a branch cut on negative real axis */
320 limit(log(-1+x*%i), x, 0, plus);
323 limit(log(-1+x*%i), x, 0, minus);
326 limit((log(y+h)-log(y))/h,h,0,plus);
329 /* limit of incomplete gamma */
330 /* function simplim%gamma_incomplete in gamma.lisp */
332 /* sin(x^2)/(x^2) improper integral incorrect? - ID: 3397562 */
333 limit( gamma_incomplete(-1/2, -%i*x^2), x, inf);
336 /* should be complex infinity */
337 limit( gamma_incomplete(2, -%i*x), x, inf);
338 'limit(gamma_incomplete(2,-%i*x),x,inf);
340 /* Error integrating exp(-x)*sinh(sqrt(x)) with domain: complex - ID: 3529144 */
341 /* need taylor expansion of gamma_incomplete(1/2, x) at x=0 */
342 limit(gamma_incomplete(1/2,(1-2*sqrt(x))^2/4)*(1-2*sqrt(x))
343 /(sqrt((1-2*sqrt(x))^2)), x, 1/4, minus),domain:complex;
346 limit(gamma_incomplete(1/2,(1-2*sqrt(x))^2/4)*(1-2*sqrt(x))
347 /(sqrt((1-2*sqrt(x))^2)), x, 1/4, plus),domain:complex;
350 /* [ 635606 ] limit(abs(log(x))) internal error, UND */
351 limit(abs(log(x)), x, 0);
354 limit(exp(-x)*(x*sin(x)+cos(x)), x, inf);
357 /* tex(t[1]) shouldn't change t to true */
360 "; /* tex output contains embedded newline */
362 /* tex(x[1]^2) shouldn't get confused by debug info in expression CAR */
363 (foo : x[1]^2, tex (foo, false));
365 "; /* tex output contains embedded newline */
367 /* [ 2084910 ] limit bugs */
368 limit((%pi*N^(2*N+1)*2^(2*N))/((2*N-1)^(2*N)*(2*%e*N+%e)), N, inf);
371 /* [ 1977992 ] no limit calculation */
372 limit(abs(sin(x))/sqrt(1-cos(x)), x, 0);
375 /* [ 1973399 ] F(x) := 1/%pi*(atan(x) + %pi/2) */
376 /* only works with taylor_logexpand:true */
377 limit( ((1/%pi)*(atan(n/%pi) + %pi/2))^n, n, inf);
380 /* limit(x*expintegral_ei(x),x,0) --> Error - ID: 2801821 */
381 limit(x*expintegral_ei(x), x, 0);
384 /* Limit of the factorial function - 4 problems - ID: 2841504 */
385 limit(factorial(x),x,-2,plus);
388 /* Calculus mistake: wrong answer: limit - ID: 3534858 */
389 limit((sin(x)-tan(x))/(x*(cos(x)-1)),x,0);
392 /* #2639 limit asks about internal variable */
393 limit(tan(x)/sqrt(tan(x)^2+1),x,%pi/2,plus);
396 limit(1/psi[1](x), x, inf);
399 /* limit of psi[i] - ID: 2843705 */
400 limit(psi[i](x),x,inf);
401 'limit(psi[i](x),x,inf);
403 /* tests for gruntz limit algorithm */
404 gruntz(exp(x), x, inf);
407 gruntz(exp(-x), x, inf);
410 gruntz( (x + 2^x) / 3^x, x, inf);
413 gruntz( x^2/(x + 2*x^2), x, inf);
416 gruntz( x/x^log(x), x, inf);
419 gruntz( (2^x)/(x + exp(x)) , x, 0, plus);
422 gruntz( (erf(x))/sqrt(1-cos(x)) , x, 0, minus);
423 -2*sqrt(2)/sqrt(%pi);
425 gruntz( (erf(x))/sqrt(1-cos(x)) , x, 0, plus);
428 gruntz( x*(x^(1/x)-1)/log(x), x, inf);
431 gruntz( (x*x^(1/x)-x)/log(x), x, inf);
434 gruntz(exp(-1/x)/x^6,x,0,plus);
437 /* limit gives the wrong answer - ID: 3410704 */
438 limit(sqrt(t^2+4)*(((t+2/t^2)^2+4)^(3/2)-(t+2/t^2)^3-4*(t+2/t^2))
439 /(sqrt((t+2/t^2)^2+4)*((t^2+4)^(3/2)-t^3-4*t)), t, inf);
442 /* Inaccurate Limit Evaluation - ID: 3276461 */
443 radcan(limit((-4*x^2-10*x+24)/((4*x+8)^(1/3)+2), x, -4));
446 limit(-(3*n^2 + 1)*(-1)^n/sqrt(n^5 + 8*n^3 + 8),n,inf);
450 * Bug ID: 1315837 limit(?foo)
451 * Bug ID: 1119228 limit(1/zeraoa)
466 * Bug ID: 1797296 - Crazy results when doing limit of 'diff
468 limit('diff(x+1,x),x,2);
469 'limit('diff(x+1,x),x,2);
471 limit('integrate(x+1,x),x,2);
472 'limit('integrate(x+1,x),x,2);
474 limit(integrate(f(t),t,0,x),x,0,plus);
475 'limit(integrate(f(t),t,0,x),x,0,plus);
477 limit(integrate(t,t,0,x)/x,x,inf);
480 (assume(a>2), limit(integrate(t/log(t),t,2,a)/a,a,inf));
483 /* limit(1/inf-1/minf) => 0+0 - ID: 903074 */
488 1-arg limit: limit(a*inf-inf) => minf - ID: 1385306
490 The original fix for this bug sent it to inf, assuming that the two
491 different "inf" occurrences were the same. I disagree: inf - inf
492 probably shouldn't ever be simplified to zero, but we can avoid it
498 /* limit(1 - (-1/2)^inf) --> inf - ID: 2853506 */
499 limit(1 - (-1/2)^inf);
501 /* ideally should be 1 */
503 /* definition of derivative in terms of limit */
504 limit((sin(3*(x+h)) - sin(3*(x)))/h, h, 0, plus);
507 /* limit incorrect for -x/sqrt(1-x^2) - ID: 2869955 */
508 limit(-x/sqrt(1-x^2), x, 1, minus);
511 /* limit(%i*log(a),a,0) nounform (%i*und problem) - ID: 816797 */
512 limit(%i*log(x),x,0);
515 /* limit(sqrt(x),x,minf) not fully evaluated - ID: 2901855 */
516 limit(sqrt(x), x, minf);
519 /* #2847 limits of powers of constants */
520 limit((5+%i)^n,n,inf);
523 /* limit bug - ID: 3101075 */
524 limit((2+cos(x))/(x^3*sin(x))-3/x^4,x,0,plus);
527 /* #2527 exponent too big in limit */
528 limit ((cosh(sqrt(x+1))-cosh(sqrt(x)))^(1/sqrt(x)),x,inf );
531 /* #2561 limit(log(x^2),x,-20) gives 2*log(-20) */
532 limit(log(x^2),x,-20),logexpand:false;
535 /* #2412 Problems with integral (x/(exp(x)+1),x,0,inf) */
536 limit(-x*log(%e^x+1)-li[2](-%e^x)+x^2/2, x, inf);
539 /* The initial problem which triggers this bug */
542 limit ((sin(n*x) - n*x*cos(n*x))/n^2, x, %pi);
545 /* #2503 Declaring x as an integer changes result of limit from 3 to inf */
546 limit((2^n+3^n)^(1/n), n,inf);
549 /* #2624 Erroneous limit result */
550 (assume(n>2), limit(x-x*(1-1/x)^n, x, inf));
556 /* Bug ID: 593351 - limit/sin(inf)etc. should give 0, not IND
558 limit(cos(1/x)*sin(x)-sin(x),x,inf);
560 limit(cos(1/x)*sin(x)-sin(x)+a,x,inf);
563 /* Bug ID: 1376392 - limit(x/(2+sin(1/x)), x, 0); wrong result
565 limit(x/(2+sin(1/x)),x,0);
568 /* Bug ID: 1106912 - limit(x/sin(x)^2,x,inf)
569 I think the limit is not defined because the func is not defined
570 for all x > any constant.
572 limit(x/sin(x)^2,x,inf);
575 /* Bug ID: 811522 - redundant question in limit
576 * b is assumed to be zero. Maxima now can deduce from the database
577 * that b-2 is an even number.
581 limit(r^(b-2)*(x-r)^2,r,0);
582 'limit(r^(b-2)*(x-r)^2,r,0);
586 /* Bug ID: 221642 limit needs %piargs to be true
587 * The implementation of simp-%atan and simpatan2 has been revised.
588 * We get more limits independent of the value of %piargs.
592 limit(atan2(0,y),y,0,plus);
594 limit(atan2(0,y),y,0,minus);
596 limit(atan2(x,0),x,0,plus);
598 limit(atan2(x,0),x,0,minus);
603 /* Bug ID: 3002971 - limit fails where rat+subst works
605 limit(min(x,x+2,sin(x)/x),x,0);
607 limit(max(x,x+2,sin(x)/x),x,0);
610 /* Bug ID: 1969790 - limits and subscripts
612 limit(mu[inf],x,inf);
616 * Bug 3509430: limit of tanh(x) at 0 makes no sense
618 limit(tanh(x), x, 0);
621 /* bug 2535: stack exhausted when computing limit(log(..)) */
623 limit(log(-1/3125*((-1/2*sqrt(5) + 1/2)^n - (1/2*sqrt(5) +
624 1/2)^n)^9*sqrt(5))/log(-1/5*((-1/2*sqrt(5) + 1/2)^(8*n) - (1/2*sqrt(5) +
625 1/2)^(8*n))*((-1/2*sqrt(5) + 1/2)^n - (1/2*sqrt(5) + 1/2)^n) -
626 1/5*((-1/2*sqrt(5) + 1/2)^(9*n) - (1/2*sqrt(5) +
627 1/2)^(9*n))*sqrt(5)),n,inf);
630 /* #2675 maxima will not do the simplest of definite integrals
631 and will not factor otherwise */
632 limit(x^2*exp(-%i*x - x), x, inf);
635 /* bug #2621 gamma limit error */
637 limit(gamma(x+1/2)/(sqrt(x)*gamma(x)), x, inf);
640 /* Triggered by #2849. This result isn't great, but it's better than
641 an error. A more useful result would be und. */
645 limit((a*exp(a*x)*sin(b*x))/(b^2+a^2)-(b*exp(a*x)*cos(b*x))/(b^2+a^2), x, 0, plus);