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 ******************************************************************************/ 9 10/* ---------- Initialization ------------------------------------------------ */ 11 12kill(all); 13done; 14 15declare(z,complex, n,integer); 16done; 17 18assume(xp>0, notequal(v,0)); 19[xp>0, notequal(v,0)]; 20 21(load(functs),done); 22done; 23 24(domain:complex, logexpand:false, done); 25done; 26 27/* ----- Specific values ---------------------------------------------------- */ 28 29log([exp(1), exp(2), exp(-2), exp(n), exp(n+2)]); 30[1, 2, -2, n, n+2]; 31 32limit(log(x),x,0,plus); 33minf; 34 35log([1, 1.0, 1.0b0]); 36[0, 0.0, 0.0b0]; 37 38log(-1),lognegint; 39%i*%pi; 40log(-1.0)-float(%i*%pi); 410.0; 42log(-1.0b0)-bfloat(%i*%pi); 430.0b0; 44 45log(%e); 461; 47 48/* For the following simplifications Maxima needs help */ 49 50log(-%e),lognegint, logexpand:all; 511+%i*%pi; 52log(-%e),rectform; 531+%i*%pi; 54 55log(%i),rectform; 56%i*%pi/2; 57 58log(-%i),rectform; 59-%i*%pi/2; 60 61/* ----- Values at infinities ----------------------------------------------- */ 62 63/* functions.wolfram.com gives the result infinity for limit(log(minf)) and 64 limit(log(infinity)). 65 */ 66 67limit(log([inf,minf,infinity])); 68[inf, infinity, infinity]; 69 70/* ----- Mirror symmetry ---------------------------------------------------- */ 71 72conjugate(log(z)); 73'(conjugate(log(z))); 74 75conjugate(log(x+%i*y)); 76'(conjugate(log(x+%i*y))); 77 78conjugate(log(xp+%i*y)); 79log(xp-%i*y); 80 81conjugate(log(10+%i*y)); 82log(10-%i*y); 83 84conjugate(log(-10+%i*y)); 85'(conjugate(log(-10+%i*y))); 86 87/* ---- Series representations ---------------------------------------------- */ 88 89taylor(log(x),x,x0,2); 90log(x0)+(x-x0)/x0-(x-x0)^2/(2*x0^2); 91 92taylor(log(f(x)),x,x0,2); 93log(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); 98 99taylor(log(x),x,1,3) - (x-1-(x-1)^2/2+(x-1)^3/3), ratsimp; 1000; 101 102taylor(log(1+x),x,0,3); 103x-x^2/2+x^3/3; 104 105taylor(log(1+x),x,inf,3); 106+log(x)+1/x-1/(2*x^2)+1/(3*x^3); 107 108taylor(log(x),x,0,2); 109+log(x); 110 111/* ----- Differential equations --------------------------------------------- */ 112 113depends([w,g,h],z); 114[w(z), g(z), h(z)]; 115 116ode2(z*'diff(w,z)-1,w,z); 117w=log(z)+%c; 118 119ic1(%,z=1,w=0); 120w=log(z); 121 122ode2(z*'diff(w,z,2)+'diff(w,z),w,z); 123w = %k1*log(z) + %k2; 124 125determinant(wronskian([1,log(z)],z)); 1261/z; 127 128ode2('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); 130w = %k1*log(g(z)) + %k2; 131 132determinant(wronskian([log(g(z)),1],z)); 133-'diff(g(z),z,1)/g(z)$ 134 135/* Maxima can not solve this ode 136ode2( '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); 143w=%k1*h(z)*log(g(z))+%k2*h(z)$ 144*/ 145 146determinant(wronskian([h(z)*log(g(z)), h(z)],z)),ratsimp; 147-h(z)^2*'diff(g(z),z,1)/g(z)$ 148 149ode2 ('diff(w,z,2)*z^2+(1-2*s)*'diff(w,z,1)*z+s^2*w, w,z)$ 150w = z^s*(%k2*log(z)+%k1)$ 151 152determinant(wronskian([z^s*log(z),z^s],z)), ratsimp; 153-z^(2*s-1)$ 154 155assume(not(equal(log(s),0))); 156[notequal(log(s),0)]; 157ode2(diff(w,z,2)-2*log(s)*diff(w,z,1)+log(s)^2*w, w,z), radcan; 158w = %k2*s^z*z+%k1*s^z$ 159forget(notequal(log(s),0)); 160[notequal(log(s),0)]; 161 162determinant(wronskian([s^z*z, s^z], z)), ratsimp; 163-s^(2*z)$ 164 165/* ----- Transformations and argument simplifications ----------------------- */ 166 167(reset(domain, logexpand), done); 168done$ 169 170domain; 171real$ 172logexpand; 173true$ 174 175/* Simplifications with the standard settings of domain and logexpand */ 176 177(expr1: (x-1)^3, expr2: (2*y-3), done); 178done$ 179 180log(a^b); 181b*log(a)$ 182 183log(x^a^b); 184a^b*log(x)$ 185 186log((x^a)^b); 187a*b*log(x)$ 188 189log(1/x); 190-log(x)$ 191 192log(1/2); 193-log(2)$ 194 195log(1/(x-1)^3); 196-3*log(x-1)$ 197 198log(((x-1)^3)^(2*y-3)); 1993*(2*y-3)*log(x-1)$ 200 201/* Simplification of products with logexpand:all */ 202 203log(-z), logexpand:all; 204log(-1)+log(z); 205 206log(2/3*a*b), logexpand:all; 207log(a)+log(b)+log(2/3)$ 208 209log(2/3*a/b), logexpand:all; 210log(a)-log(b)+log(2/3)$ 211 212log(2/3*(x-1)^3*(2*y-3)), logexpand:all; 2133*log(x-1)+log(2*y-3)+log(2/3)$ 214 215log(2/3*(x-1)^3/(2*y-3)), logexpand:all; 2163*log(x-1)-log(2*y-3)+log(2/3)$ 217 218log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), logexpand:all; 2193*a*log(x-1)/b + b*log(2*y-3)/a+log(2/3)$ 220 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 */ 224 225log(2/3*a*b), logexpand:super; 226log(a)+log(b)+log(2)-log(3)$ 227 228log(2/3*a/b), logexpand:super; 229log(a)-log(b)+log(2)-log(3)$ 230 231log(2/3*(x-1)^3*(2*y-3)), logexpand:super; 2323*log(x-1)+log(2*y-3)+log(2)-log(3)$ 233 234log(2/3*(x-1)^3/(2*y-3)), logexpand:super; 2353*log(x-1)-log(2*y-3)+log(2)-log(3)$ 236 237log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), logexpand:super; 2383*a*log(x-1)/b + b*log(2*y-3)/a+log(2)-log(3)$ 239 240/* Simplifications with domain:complex */ 241 242/* The following examples show that the expressions do not simplify 243 with domain:complex or logexand:false 244 */ 245 246subst(a^b=1,log(a^b)),domain:complex; 2470$ 248subst(a^b=1,log(a^b)),logexpand:false; 2490$ 250 251subst(xp^z=1,log(xp^z)),domain:complex; 2520; 253subst(xp^z=1,log(xp^z)),logexpand:false; 2540; 255 256subst(exp(x+%i*y)=1,log(exp(x+%i*y))),domain:complex; 2570$ 258subst(exp(x+%i*y)=1,log(exp(x+%i*y))),logexpand:false; 2590$ 260 261/* These examples simplifies with domain:complex and logexpand:false */ 262 263log(xp^a), domain:complex, logexpand:false; 264a*log(xp); 265 266log(exp(x)), domain:complex, logexpand:false; 267x; 268log(exp(%i*x)), domain:complex, logexpand:false; 269%i*x; 270 271log(1/2), domain:complex, logexpand:false; 272-log(2); 273 274log(sqrt(z)), domain:complex, logexpand:false; 275log(z)/2; 276 277log(z^(1/3)), domain:complex, logexpand:false; 278log(z)/3; 279 280log(z^(1/(n^2+1))), domain:complex, logexpand:false; 281log(z)/(n^2+1); 282 283/* logexpand:all and logexpand:true overwrites the setting domain:complex */ 284 285log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), domain:complex, logexpand:all; 2863*a*log(x-1)/b + b*log(2*y-3)/a+log(2/3)$ 287 288log(2/3*((x-1)^3)^(a/b)*(2*y-3)^(b/a)), domain:complex, logexpand:super; 2893*a*log(x-1)/b + b*log(2*y-3)/a+log(2)-log(3)$ 290 291/* Bug ID: 3377347 - log(1/(1+%i)) gives error 292 * Check this case. 293 */ 294log(1/(1+%i)),logexpand:false; 295-log(1+%i); 296 297/* Bug 2597: logcontract(42+log[x]) was returning 42+log(x) */ 298is(logcontract(42+log[x]) = 42+log[x]); 299true$ 300 301/* ----- Complex characteristics -------------------------------------------- */ 302 303realpart(log(x+%i*y)); 304log(y^2+x^2)/2; 305 306realpart(log(z)); 307log(abs(z)); 308 309realpart(log(x)); 310log(abs(x)); 311 312imagpart(log(x+%i*y)); 313atan2(y,x); 314 315imagpart(log(z)); 316carg(z); 317 318imagpart(log(x)); 319atan2(0,x); 320 321cabs(log(x+%i*y)); 322sqrt(log(y^2+x^2)^2/4+atan2(y,x)^2); 323 324cabs(log(z)); 325sqrt(log(abs(z))^2+carg(z)^2); 326 327carg(log(x+%i*y)); 328atan2(atan2(y,x),log(y^2+x^2)/2); 329 330carg(log(z)); 331atan2(carg(z),log(abs(z))); 332 333/* ----- Differentiation ---------------------------------------------------- */ 334 335diff(log(z),z); 3361/z; 337 338diff(log(z),z,2); 339-1/z^2; 340 341/* ----- Indefinite integration --------------------------------------------- */ 342 343integrate(log(z),z); 344z*log(z)-z; 345 346integrate(z^(v-1)*log(z),z); 347z^v*log(z)/v-z^v/v^2; 348 349integrate(1/z*log((b+a*z)/(d+c*z)),z); 350log(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); 353 354assume(c>0,d>0); 355[c>0,d>0]; 356integrate(log(z)/sqrt(c*z^2+d),z); 357'integrate(log(z)/sqrt(c*z^2+d),z); 358forget(c>0,d>0); 359[c>0,d>0]; 360 361integrate(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; 363 364integrate(log(a*z^2+b*z+e)/(d+c*z),z); 365'integrate(log(a*z^2+b*z+e)/(d+c*z),z); 366 367integrate(log(z)^2/(1-z),z); 3682*(-log(1-z)*log(z)^2/2-li[2](z)*log(z)+li[3](z)); 369 370integrate(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)); 372 373integrate(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; 376 377integrate(1/z*log((a+b*z)/(c+d*z))^2,z); 378'integrate(1/z*log((a+b*z)/(c+d*z))^2,z); 379 380integrate(log(z)*log(1-z)/z,z); 381li[3](z)-li[2](z)*log(z); 382 383integrate(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); 385 386integrate(log(z)*log(z-1)/z,z); 387log(z-1)*log(z)^2/2-log(1-z)*log(z)^2/2-li[2](z)*log(z)+li[3](z); 388 389integrate(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)); 391 392integrate(log(z)^2*log(1-z)/z,z); 393log(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))$ 395 396integrate(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; */ 399 400/* Hier fehlen noch Integrale */ 401 402/* ----- Definite integration ----------------------------------------------- */ 403 404integrate(log(t),t,0,1); 405-1; 406 407integrate(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); 409 410/* Lisp error in Maxima 5.24 411integrate(log(t)*log(t+1),t,0,1),expand,lognegint; 412-2*log(2)-%pi^2/12+2; 413*/ 414 415integrate(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); 417 418integrate(log(t+1)*log(1+1/t^2),t,0,inf); 419'integrate(log(t+1)*log(1+1/t^2),t,0,inf); 420 421integrate(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); 423 424integrate(log(t)*log(1-t)^2/t,t,0,1); 425'integrate(log(t)*log(1-t)^2/t,t,0,1); 426 427integrate(log(t*(1-t))^4/(1-t),t,0,1/2); 428'integrate(log(t*(1-t))^4/(1-t),t,0,1/2); 429 430integrate(log(t*(1-t))^5/(1-t),t,0,1/2); 431'integrate(log(t*(1-t))^5/(1-t),t,0,1/2); 432 433integrate(exp(-t)*log(t),t,0,1); 434'integrate(exp(-t)*log(t),t,0,1); 435 436/* Hier fehlen noch Integrale */ 437 438/* ----- Integral transforms ------------------------------------------------ */ 439 440laplace(log(t),t,s); 441(-log(s)-%gamma)/s$ 442 443/* ----- Representations through more general functions --------------------- */ 444 445(z-1)*hgfred([1,1],[2],1-z); 446log(z)$ 447 448-li[1](1-z); 449log(z)$ 450 451/* SF bug #3105: "li[s](1) simplifies to zeta(s), but li[s](1.0) doesn't simplify" */ 452 453makelist (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]$ 455 456makelist (li[k](1.0), k, 2, 8); 457[1.644934066848226, 1.202056903159594, 1.082323233711138, 458 1.03692775514337, 1.017343061984449, 1.008349277381923, 1.004077356197944] $ 459 460makelist (li[k](1b0), k, 2, 8); 461[1.644934066848226b0, 1.202056903159594b0, 1.082323233711138b0, 462 1.03692775514337b0, 1.017343061984449b0, 1.008349277381923b0, 1.004077356197944b0] $ 463 464makelist (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]$ 467 468makelist (li[k](-1.0), k, 2, 8); 469[- 0.8224670334241131, - 0.9015426773696957, - 0.9470328294972459, 470- 0.9721197704469093, - 0.9855510912974348, - 0.9925938199228304, 471- 0.9962330018526477] $ 472 473makelist (li[k](-1b0), k, 2, 8); 474[- 0.8224670334241131b0, - 0.9015426773696957b0, - 0.9470328294972459b0, 475- 0.9721197704469093b0, - 0.9855510912974351b0, - 0.9925938199228304b0, 476- 0.9962330018526479b0] $ 477 478/* SF bug #3422: "li[2] and li[3] numerical evaluation fails for complex not in rectangular form" */ 479 480(reset (fpprec), 0); 4810; 482 483li[2]((1 + %i)/2e0); 4840.45398526915029558 + 0.64376733288926875*%i; 485 486li[2]((1 + %i)/2b0); 4870.45398526915029558b0 + 0.64376733288926875b0*%i; 488 489li[3]((1 + %i)/2e0); 4900.48615953708556008 + 0.57007740708876898*%i; 491 492li[3]((1 + %i)/2b0); 4930.48615953708556008b0 + 0.57007740708876898b0*%i; 494