Rename *ll* and *ul* to ll and ul in poles-in-interval
[maxima.git] / tests / rtest_log.mac
blob85d646789bbd181924aaa4e4f9ab1b024946c6d9
1 /*******************************************************************************
2  *
3  *          Log function
4  *
5  * The examples show what a Maxima user can expect from the log function.
6  * Examples are taken from functions.wolfram.com.
7  *
8  ******************************************************************************/
10 /* ---------- Initialization ------------------------------------------------ */
12 kill(all);
13 done;
15 declare(z,complex, n,integer);
16 done;
18 assume(xp>0, notequal(v,0));
19 [xp>0, notequal(v,0)];
21 (load(functs),done);
22 done;
24 (domain:complex, logexpand:false, done);
25 done;
27 /* ----- Specific values ---------------------------------------------------- */
29 log([exp(1), exp(2), exp(-2), exp(n), exp(n+2)]);
30 [1, 2, -2, n, n+2];
32 limit(log(x),x,0,plus);
33 minf;
35 log([1, 1.0, 1.0b0]);
36 [0, 0.0, 0.0b0];
38 log(-1),lognegint;
39 %i*%pi;
40 log(-1.0)-float(%i*%pi);
41 0.0;
42 log(-1.0b0)-bfloat(%i*%pi);
43 0.0b0;
45 log(%e);
48 /* For the following simplifications Maxima needs help */
50 log(-%e),lognegint, logexpand:all;
51 1+%i*%pi;
52 log(-%e),rectform;
53 1+%i*%pi;
55 log(%i),rectform;
56 %i*%pi/2;
58 log(-%i),rectform;
59 -%i*%pi/2;
61 /* ----- Values at infinities ----------------------------------------------- */
63 /* functions.wolfram.com gives the result infinity for limit(log(minf)) and
64    limit(log(infinity)).
65  */
67 limit(log([inf,minf,infinity]));
68 [inf, infinity, infinity];
70 /* ----- Mirror symmetry ---------------------------------------------------- */
72 conjugate(log(z));
73 '(conjugate(log(z)));
75 conjugate(log(x+%i*y));
76 '(conjugate(log(x+%i*y)));
78 conjugate(log(xp+%i*y));
79 log(xp-%i*y);
81 conjugate(log(10+%i*y));
82 log(10-%i*y);
84 conjugate(log(-10+%i*y));
85 '(conjugate(log(-10+%i*y)));
87 /* ---- Series representations ---------------------------------------------- */
89 taylor(log(x),x,x0,2);
90 log(x0)+(x-x0)/x0-(x-x0)^2/(2*x0^2);
92 taylor(log(f(x)),x,x0,2);
93 log(f(x0))+('at('diff(f(x),x,1),x = x0))*(x-x0)/f(x0)
94           +(f(x0)*('at('diff(f(x),x,2),x = x0))
95            -('at('diff(f(x),x,1),x = x0))^2)
96            *(x-x0)^2
97            /(2*f(x0)^2);
99 taylor(log(x),x,1,3) - (x-1-(x-1)^2/2+(x-1)^3/3), ratsimp;
102 taylor(log(1+x),x,0,3);
103 x-x^2/2+x^3/3;
105 taylor(log(1+x),x,inf,3);
106 +log(x)+1/x-1/(2*x^2)+1/(3*x^3);
108 taylor(log(x),x,0,2);
109 +log(x);
111 /* ----- Differential equations --------------------------------------------- */
113 depends([w,g,h],z);
114 [w(z), g(z), h(z)];
116 ode2(z*'diff(w,z)-1,w,z);
117 w=log(z)+%c;
119 ic1(%,z=1,w=0);
120 w=log(z);
122 ode2(z*'diff(w,z,2)+'diff(w,z),w,z);
123 w = %k1*log(z) + %k2;
125 determinant(wronskian([1,log(z)],z));
126 1/z;
128 ode2('diff(w,z,2)
129      +('diff(g(z),z)/g(z)-'diff(g(z),z,2)/'diff(g(z),z))*'diff(w,z),w,z);
130 w = %k1*log(g(z)) + %k2;
132 determinant(wronskian([log(g(z)),1],z));
133 -'diff(g(z),z,1)/g(z)$
135 /* Maxima can not solve this ode
136 ode2( 'diff(w,z,2)
137      + ('diff(g(z),z)/g(z) - 2*'diff(h(z),z)/h(z) 
138                            - 'diff(g(z),z,2)/'diff(g(z),z)) * 'diff(w,z)
139      +(2*'diff(h(z),z)^2/h(z)^2 + 'diff(g(z),z,2)*'diff(h(z),z)/h(z)/'diff(g(z),z)
140                                 - 'diff(g(z),z)*'diff(h(z),z)/g(z)/h(z)
141                                 - 'diff(h(z),z,2)/h(z)) * w,
142      w,z);
143 w=%k1*h(z)*log(g(z))+%k2*h(z)$
146 determinant(wronskian([h(z)*log(g(z)), h(z)],z)),ratsimp;
147 -h(z)^2*'diff(g(z),z,1)/g(z)$
149 ode2 ('diff(w,z,2)*z^2+(1-2*s)*'diff(w,z,1)*z+s^2*w, w,z)$
150 w = z^s*(%k2*log(z)+%k1)$
152 determinant(wronskian([z^s*log(z),z^s],z)), ratsimp;
153 -z^(2*s-1)$
155 assume(not(equal(log(s),0)));
156 [notequal(log(s),0)];
157 ode2(diff(w,z,2)-2*log(s)*diff(w,z,1)+log(s)^2*w, w,z), radcan;
158 w = %k2*s^z*z+%k1*s^z$
159 forget(notequal(log(s),0));
160 [notequal(log(s),0)];
162 determinant(wronskian([s^z*z, s^z], z)), ratsimp;
163 -s^(2*z)$
165 /* ----- Transformations and argument simplifications ----------------------- */
167 (reset(domain, logexpand), done);
168 done$
170 domain;
171 real$
172 logexpand;
173 true$
175 /* Simplifications with the standard settings of domain and logexpand */
177 (expr1: (x-1)^3, expr2: (2*y-3), done);
178 done$
180 log(a^b);
181 b*log(a)$
183 log(x^a^b);
184 a^b*log(x)$
186 log((x^a)^b);
187 a*b*log(x)$
189 log(1/x);
190 -log(x)$
192 log(1/2);
193 -log(2)$
195 log(1/(x-1)^3);
196 -3*log(x-1)$
198 log(((x-1)^3)^(2*y-3));
199 3*(2*y-3)*log(x-1)$
201 /* Simplification of products with logexpand:all */
203 log(-z), logexpand:all;
204 log(-1)+log(z);
206 log(2/3*a*b), logexpand:all;
207 log(a)+log(b)+log(2/3)$
209 log(2/3*a/b), logexpand:all;
210 log(a)-log(b)+log(2/3)$
212 log(2/3*(x-1)^3*(2*y-3)), logexpand:all;
213 3*log(x-1)+log(2*y-3)+log(2/3)$
215 log(2/3*(x-1)^3/(2*y-3)), logexpand:all;
216 3*log(x-1)-log(2*y-3)+log(2/3)$
218 log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), logexpand:all;
219 3*a*log(x-1)/b + b*log(2*y-3)/a+log(2/3)$
221 /* Simplificaton of products with logexpand:super
222    In addition log(n/d) -> log(n)-log(d), where n/d is a rational number
223  */
225 log(2/3*a*b), logexpand:super;
226 log(a)+log(b)+log(2)-log(3)$
228 log(2/3*a/b), logexpand:super;
229 log(a)-log(b)+log(2)-log(3)$
231 log(2/3*(x-1)^3*(2*y-3)), logexpand:super;
232 3*log(x-1)+log(2*y-3)+log(2)-log(3)$
234 log(2/3*(x-1)^3/(2*y-3)), logexpand:super;
235 3*log(x-1)-log(2*y-3)+log(2)-log(3)$
237 log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), logexpand:super;
238 3*a*log(x-1)/b + b*log(2*y-3)/a+log(2)-log(3)$
240 /* Simplifications with domain:complex */
242 /* The following examples show that the expressions do not simplify
243    with domain:complex or logexand:false
244  */
246 subst(a^b=1,log(a^b)),domain:complex;
248 subst(a^b=1,log(a^b)),logexpand:false;
251 subst(xp^z=1,log(xp^z)),domain:complex;
253 subst(xp^z=1,log(xp^z)),logexpand:false;
256 subst(exp(x+%i*y)=1,log(exp(x+%i*y))),domain:complex;
258 subst(exp(x+%i*y)=1,log(exp(x+%i*y))),logexpand:false;
261 /* These examples simplifies with domain:complex and logexpand:false */
263 log(xp^a), domain:complex, logexpand:false;
264 a*log(xp);
266 log(exp(x)), domain:complex, logexpand:false;
268 log(exp(%i*x)), domain:complex, logexpand:false;
269 %i*x;
271 log(1/2), domain:complex, logexpand:false;
272 -log(2);
274 log(sqrt(z)), domain:complex, logexpand:false;
275 log(z)/2;
277 log(z^(1/3)), domain:complex, logexpand:false;
278 log(z)/3;
280 log(z^(1/(n^2+1))), domain:complex, logexpand:false;
281 log(z)/(n^2+1);
283 /* logexpand:all and logexpand:true overwrites the setting domain:complex */
285 log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), domain:complex, logexpand:all;
286 3*a*log(x-1)/b + b*log(2*y-3)/a+log(2/3)$
288 log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), domain:complex, logexpand:super;
289 3*a*log(x-1)/b + b*log(2*y-3)/a+log(2)-log(3)$
291 /* Bug ID: 3377347 - log(1/(1+%i)) gives error
292  * Check this case.
293  */
294 log(1/(1+%i)),logexpand:false;
295 -log(1+%i);
297 /* Bug 2597: logcontract(42+log[x]) was returning 42+log(x) */
298 is(logcontract(42+log[x]) = 42+log[x]);
299 true$
301 /* ----- Complex characteristics -------------------------------------------- */
303 realpart(log(x+%i*y));
304 log(y^2+x^2)/2;
306 realpart(log(z));
307 log(abs(z));
309 realpart(log(x));
310 log(abs(x));
312 imagpart(log(x+%i*y));
313 atan2(y,x);
315 imagpart(log(z));
316 carg(z);
318 imagpart(log(x));
319 atan2(0,x);
321 cabs(log(x+%i*y));
322 sqrt(log(y^2+x^2)^2/4+atan2(y,x)^2);
324 cabs(log(z));
325 sqrt(log(abs(z))^2+carg(z)^2);
327 carg(log(x+%i*y));
328 atan2(atan2(y,x),log(y^2+x^2)/2);
330 carg(log(z));
331 atan2(carg(z),log(abs(z)));
333 /* ----- Differentiation ---------------------------------------------------- */
335 diff(log(z),z);
336 1/z;
338 diff(log(z),z,2);
339 -1/z^2;
341 /* ----- Indefinite integration --------------------------------------------- */
343 integrate(log(z),z);
344 z*log(z)-z;
346 integrate(z^(v-1)*log(z),z);
347 z^v*log(z)/v-z^v/v^2;
349 integrate(1/z*log((b+a*z)/(d+c*z)),z);
350 log(z)*log((a*z+b)/(c*z+d))-log(c*z+d)*log(1-(c*z+d)/d)
351                            +log(a*z+b)*log(1-(a*z+b)/b)-li[2]((c*z+d)/d)
352                            -log(z)*(log(a*z+b)-log(c*z+d))+li[2]((a*z+b)/b);
354 assume(c>0,d>0);
355 [c>0,d>0];
356 integrate(log(z)/sqrt(c*z^2+d),z);
357 'integrate(log(z)/sqrt(c*z^2+d),z);
358 forget(c>0,d>0);
359 [c>0,d>0];
361 integrate(log(b+a*z)/(d+c*z),z);
362 (log(a*z+b)*log((a*c*z+b*c)/(a*d-b*c)+1)+li[2]((a*c*z+b*c)/(a*d-b*c)/-1))/c;
364 integrate(log(a*z^2+b*z+e)/(d+c*z),z);
365 'integrate(log(a*z^2+b*z+e)/(d+c*z),z);
367 integrate(log(z)^2/(1-z),z);
368 2*(-log(1-z)*log(z)^2/2-li[2](z)*log(z)+li[3](z));
370 integrate(log(1+z)^2/z,z);
371 -2*(-log(-z)*log(z+1)^2/2-li[2](z+1)*log(z+1)+li[3](z+1));
373 integrate(log(a+b*z)^2/(e+f*z),z);
374 -2*(-log(b*z+a)^2*log(1-f*(b*z+a)/(a*f-b*e))/2
375    +li[3](f*(b*z+a)/(a*f-b*e))-log(b*z+a)*li[2](f*(b*z+a)/(a*f-b*e)))/f;
377 integrate(1/z*log((a+b*z)/(c+d*z))^2,z);
378 'integrate(1/z*log((a+b*z)/(c+d*z))^2,z);
380 integrate(log(z)*log(1-z)/z,z);
381 li[3](z)-li[2](z)*log(z);
383 integrate(log(a+b*z)*log(c+d*z)/(e+f*z),z);
384 'integrate(log(a+b*z)*log(c+d*z)/(e+f*z),z);
386 integrate(log(z)*log(z-1)/z,z);
387 log(z-1)*log(z)^2/2-log(1-z)*log(z)^2/2-li[2](z)*log(z)+li[3](z);
389 integrate(log(z)^3/(1-z),z);
390 -6*(log(1-z)*log(z)^3/6+li[2](z)*log(z)^2/2-li[3](z)*log(z)+li[4](z));
392 integrate(log(z)^2*log(1-z)/z,z);
393 log(1-z)*log(z)^3/3-2*(log(1-z)*log(z)^3/6+li[2](z)*log(z)^2/2-li[3](z)*log(z)
394                                           +li[4](z))$
396 integrate(log(z)^2*log(1-z)/(1-z),z);
397 'integrate(log(z)^2*log(1-z)/(1-z),z);
398 /*  'integrate(log(1-z)^2*log(z)/z,z)-log(1-z)^2*log(z)^2/2;  */
400 /* Hier fehlen noch Integrale */
402 /* ----- Definite integration ----------------------------------------------- */
404 integrate(log(t),t,0,1);
407 integrate(log(t^2-2*cos(z)*t+1)/t,t,0,1);
408 'integrate(log(t^2-2*cos(z)*t+1)/t,t,0,1);
410 /* Lisp error in Maxima 5.24
411 integrate(log(t)*log(t+1),t,0,1),expand,lognegint;
412 -2*log(2)-%pi^2/12+2;
415 integrate(log(t+1)*log(1+1/t^2)/t,t,0,inf);
416 'integrate(log(t+1)*log(1+1/t^2)/t,t,0,inf);
418 integrate(log(t+1)*log(1+1/t^2),t,0,inf);
419 'integrate(log(t+1)*log(1+1/t^2),t,0,inf);
421 integrate(log(a*t+1)*log(z/t^2+1)/t,t,0,inf);
422 'integrate(log(a*t+1)*log(z/t^2+1)/t,t,0,inf);
424 integrate(log(t)*log(1-t)^2/t,t,0,1);
425 'integrate(log(t)*log(1-t)^2/t,t,0,1);
427 integrate(log(t*(1-t))^4/(1-t),t,0,1/2);
428 'integrate(log(t*(1-t))^4/(1-t),t,0,1/2);
430 integrate(log(t*(1-t))^5/(1-t),t,0,1/2);
431 'integrate(log(t*(1-t))^5/(1-t),t,0,1/2);
433 integrate(exp(-t)*log(t),t,0,1);
434 'integrate(exp(-t)*log(t),t,0,1);
436 /* Hier fehlen noch Integrale */
438 /* ----- Integral transforms ------------------------------------------------ */
440 laplace(log(t),t,s);
441 (-log(s)-%gamma)/s$
443 /* ----- Representations through more general functions --------------------- */
445 (z-1)*hgfred([1,1],[2],1-z);
446 log(z)$
448 -li[1](1-z);
449 log(z)$
451 /* SF bug #3105: "li[s](1) simplifies to zeta(s), but li[s](1.0) doesn't simplify" */
453 makelist (li[k](1), k, 2, 8);
454 [%pi^2/6,zeta(3),%pi^4/90,zeta(5),%pi^6/945,zeta(7),%pi^8/9450]$
456 makelist (li[k](1.0), k, 2, 8);
457 [1.644934066848226, 1.202056903159594, 1.082323233711138, 
458  1.03692775514337, 1.017343061984449, 1.008349277381923, 1.004077356197944] $
460 makelist (li[k](1b0), k, 2, 8);
461 [1.644934066848226b0, 1.202056903159594b0, 1.082323233711138b0, 
462  1.03692775514337b0, 1.017343061984449b0, 1.008349277381923b0, 1.004077356197944b0] $
464 makelist (li[k](-1), k, 2, 8);
465 [-%pi^2/12,-(3*zeta(3))/4,-(7*%pi^4)/720,-(15*zeta(5))/16,-(31*%pi^6)/30240,
466  -(63*zeta(7))/64,-(127*%pi^8)/1209600]$
468 makelist (li[k](-1.0), k, 2, 8);
469 [- 0.8224670334241131, - 0.9015426773696957, - 0.9470328294972459, 
470 - 0.9721197704469093, - 0.9855510912974348, - 0.9925938199228304, 
471 - 0.9962330018526477] $
473 makelist (li[k](-1b0), k, 2, 8);
474 [- 0.8224670334241131b0, - 0.9015426773696957b0, - 0.9470328294972459b0, 
475 - 0.9721197704469093b0, - 0.9855510912974351b0, - 0.9925938199228304b0, 
476 - 0.9962330018526479b0] $
478 /* SF bug #3422: "li[2] and li[3] numerical evaluation fails for complex not in rectangular form"
479  * SF bug #3636: "XXX-numerical-eval-p in gamma.lisp extremely inefficient"
480  */
482 (reset (fpprec), 0);
485 li[2](rectform((1 + %i)/2e0));
486 0.45398526915029558 + 0.64376733288926875*%i;
488 li[2](rectform((1 + %i)/2b0));
489 0.45398526915029558b0 + 0.64376733288926875b0*%i;
491 li[3](rectform((1 + %i)/2e0));
492 0.48615953708556008 + 0.57007740708876898*%i;
494 li[3](rectform((1 + %i)/2b0));
495 0.48615953708556008b0 + 0.57007740708876898b0*%i;