Re: Integrate (a curious result)

*To*: mathgroup at smc.vnet.net*Subject*: [mg74679] Re: Integrate (a curious result)*From*: "dimitris" <dimmechan at yahoo.com>*Date*: Sat, 31 Mar 2007 01:29:18 -0500 (EST)*References*: <esls78$q0v$1@smc.vnet.net><etb5a5$k14$1@smc.vnet.net>

This is from an old post of Peter Pein and has been covered completely by me in this thread. Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}] (*wrong*) Integrate::idiv: Integral of Log[Sin[x]^2]*Tan[x] does not converge on \ {x,0,Pi}. Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}] (*correct*) Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi/2, Pi}] 0 Trying to figure out why the default setting for the iterator of Integrate gives the warning message I take the antidrivative of the integrand: F[x_] = Integrate[Log[Sin[x]^2]*Tan[x], x] Plot[Re[F[x]], {x, 0, Pi}] Plot[Im[F[x]], {x, 0, Pi}] Log[Sec[x/2]^2]^2 + 2*Log[Sec[x/2]^2]*Log[(1/2)*Cos[x]*Sec[x/2]^2] + Log[Sec[x/2]^2]*Log[Sin[x]^2] - 2*Log[Sec[x/2]^2]*Log[-1 + Tan[x/2]^2] - Log[Sin[x]^2]*Log[-1 + Tan[x/2]^2] + Log[Tan[x/2]^2]*Log[-1 + Tan[x/2]^2] + 2*PolyLog[2, (1/2)*Sec[x/2]^2] + PolyLog[2, Cos[x]*Sec[x/2]^2] + PolyLog[2, -Tan[x/ 2]^2] Due to the jump discontinuity at x=Pi/2, the correct application of the Newton-Leibniz formula in [0,Pi] is FullSimplify[(Limit[F[x], x -> Pi, Direction -> 1] - Limit[F[x], x -> Pi/2, Direction -> -1]) + (Limit[F[x], x -> Pi/2, Direction -> 1] - Limit[F[x], x -> 0, Direction -> -1])] 0 and of course give the correct result. If Mathematica will not detect the jump discontinuity he may return FullSimplify[Limit[F[x], x -> Pi, Direction -> 1] - Limit[F[x], x -> 0, Direction -> -1]] 4*I*Pi*Log[2] which it doesn't. So something other happen. Does anyone has any ideas? Note also that strangely Block[{Message}, Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}]] Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}] I said "strangely" because I was waiting Infinity as below for a really divergent integral Integrate::idiv: Integral of BesselJ[0, x]*Csc[x] does not converge on \ {0,Infinity}. Integrate[BesselJ[0, x]*Csc[x], {x, 0, Infinity}] Block[{Message}, Integrate[BesselJ[0, x]/Sin[x], {x, 0, Infinity}]] Infinity Any comments? Thanks Dimitris =CF/=C7 dimitris =DD=E3=F1=E1=F8=E5: > > Dimitris, this is a marvelous solution to my problem. I really apprec= ia= > te > > your help. I will now see if I can solve all my other (similar) integra= ls= > using the same trick. > > It gives me great pleasure that you found so helpful my response. > > > Timing is not really the big issue if I get results in a reasonable amo= un= > t of time. > > Note that you must clarify to your mind what is actually a "reasonable > amount of time". > For example on my machine I do believe that the almost 17 seconds for > evaluating the > integral with my trick is more than just reasonable time. > > Note e.g. a very interesting example > > Integrate[BesselJ[0, x]/Sqrt[1 + x^2], {x, 0, Infinity}]//Timing > N@%[[2]] > NIntegrate[BesselJ[0, x]/Sqrt[1 + x^2], {x, 0, Infinity}, Method -> \ > Oscillatory] > > {4.186999999999999*Second, BesselI[0, 1/2]*BesselK[0, 1/2]} > 0=2E9831043098467616 > 0=2E9831043098470272 > > Quit > > Integrate[BesselJ[0, x]/Sqrt[1 + x^2], {x, 0, Infinity}, > GenerateConditions -> False]//Timing > {0.31299999999999994*Second, BesselI[0, 1/2]*BesselK[0, 1/2]} > > If you know indepently that the integral converges why leave > Mathematica to do the "dirty job" > causing waste of your invaluable time? > > > Also the references you cited are quite interesting, because they give = so= > me insight > > what might go on inside Mathematica concerning integration. > > Here is a more complete list. > Note that following the moderator's advice I will avoid the use of > link references. > > "Indefinite and Definite Integration" by Kelly Roach (1992) > "The evaluation of Bessel functions via G-function identities" by > Victor Adamchik (1995) > "Definite Integration in Mathematica 3.0" by the same author > "Symbolic Definite Integration" by Daniel Lichtblau > > Check also > > Manuel Bronstein's Symbolic Integration 1 and some references therein. > > > I also agree with you that it is my task as a programmer to "help" Math= em= > atica > > and guide it into the direction I want it to go. Sometimes this is an "= ar= > t"... > > It is an a combination of art, experience, reading, thinking (and > guessing sometimes!). > > Let look an integral appeared in an old post Peter Pein. > > $Version > 5=2E2 for Microsoft Windows (June 20, 2005) > > Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}] > Integrate::idiv: Integral of Log[Sin[x]^2]*Tan[x] does not converge on > \ > {x,0,Pi}. > Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi}] > > Of course the integral is zero as you can figure out from the plot of > the integrand > in integration range or noticing that f[x]+f[Pi-x]=0 where > > f[x_] := Log[Sin[x]^2]*Tan[x] > > Also a direct numerical integration verify our statement. > > Tr@(NIntegrate[Log[Sin[x]^2]*Tan[x], > {x,#[[1]],#[[2]]},WorkingPrecision-> > 50,PrecisionGoal->40] &/@Partition[Range[0,Pi,Pi/2],2,1]) > 0``39.9568146932663 > > It is interesting to see what I got from another CAS (due to the > policy > of the forum I can't mention its name). > > int(log(sin(x)^2)*tan(x),x=0..Pi); > undefined > > int(log(sin(x)^2)*tan(x),x=0..Pi/2); > -Infinity > > int(log(sin(x)^2)*tan(x),x=Pi/2..Pi); > Infinity > > On the contrary Mathematica may give a wrong value for the > definite integral in the whole range (0,Pi) but > > Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi/2}] > -(Pi^2/12) > > Integrate[Log[Sin[x]^2]*Tan[x], {x, Pi/2, Pi}] > Pi^2/12 > > Their sum give zero as it should be! > > What is happening here? I will try to figure out (I am not quite sure > and as you may notice > I have a recent post mentioning this integral). > > Note first that Mathematica evaluates correctly an indefinite integral > of Log[Sin[x]^2]*Tan[x] > > F[x_] = Integrate[f[x], x] > Log[Sec[x/2]^2]^2 + 2*Log[Sec[x/2]^2]*Log[(1/2)*Cos[x]*Sec[x/2]^2] + > Log[Sec[x/2]^2]*Log[Sin[x]^2] - > 2*Log[Sec[x/2]^2]*Log[-1 + Tan[x/2]^2] - Log[Sin[x]^2]*Log[-1 + > Tan[x/2]^2] + Log[Tan[x/2]^2]*Log[-1 + Tan[x/2]^2] + 2*PolyLog[2, > (1/2)*Sec[x/2]^2] + PolyLog[2, Cos[x]*Sec[x/2]^2] + PolyLog[2, -Tan[x/ > 2]^2] > > Simplify[D[F[x], x] == f[x]] > True > > The obtained antiderivative has real and imaginary part > > Plot[Re@F[x], {x, 0, Pi}] > Plot[Im@F[x], {x, 0, Pi}] > > Helping now Mathematica we can take the correct answer > > FullSimplify[(Limit[F[x], x -> Pi, Direction -> 1] - Limit[F[x], x -> > Pi/2, Direction -> -1]) + > (Limit[F[x], x -> Pi/2, Direction -> 1] - Limit[F[x], x -> 0, > Direction -> -1])] > 0 > > The problem is the vanishing of the integrand at Pi/2. > > Indeed using the following undocumentated setting of Integrate (which > is well documentated for NIntegrate) Mathematica gives again the > correct > answer with less effort > > Integrate[Log[Sin[x]^2]*Tan[x], {x, 0, Pi/2, Pi}] > 0 > > Note that if we didn't take notice of Pi/2 and applied blindly the > fundamental > theorem of calculus we would get incorrectly > > FullSimplify[Limit[F[x], x -> Pi, Direction -> 1] - Limit[F[x], x -> > 0, Direction -> -1]] > 4*I*Pi*Log[2] > > That is a complex value for an integral whose integrand is real in the > integration range. > If Mathematica would simply return this complex value, I would say > that it failed > to detect the discontinuity of the antiderivative at Pi/2. But it > returns a warning > message for divergence, so...I GIVE UP! > > Note also that Integrate has been already from version 3.0 very > powerful. > But since version 5.0 symbolic integration has become one of the most > important advantages of Mathematica over other CAS. > > But as Daniel Lichtblau pointed out in his article: The powerfulness > has the price > of slower speed (usually) and some level of platform dependent > behavior (less usually) > than in the past. > > Indeed in the original thread regarding this integral there was the > following response > from Bob Hanlon: > > >>Works in my version: > > >>$Version > >>5.2 for Mac OS X (June 20, 2005) > > >>f[x_]:=Log[Sin[x]^2]Tan[x]; > > >>Integrate[f[x],{x,0,Pi}] > >>0 > > Anyway other possible ways of working under Mathematica 5.2 for > Windows include > > Tr @( Integrate[f[x], {x, #1[[1]], #1[[2]]}] & /@ > Partition[Range[0, Pi, Pi/2], 2, 1] ) > 0 > > Integrate[f[x], {x, 0, z}, Assumptions -> Inequality[Pi/2, Less, z, > LessEqual, Pi]] > Limit[%, z -> Pi, Direction -> 1] > -(Pi^2/3) - 2*I*Pi*Log[2] + Log[2]^2 + 4*I*Pi*Log[Sec[z/2]] + 4*Log[- > (Cos[z]/(1 + Cos[z]))]*Log[Sec[z/2]] + 4*Log[Sec[z/2]]^2 - > 4*Log[Sec[z/2]]*Log[(-Cos[z])*Sec[z/2]^2] + 4*Log[Sec[z/ > 2]]*Log[Sin[z]] - 2*Log[(-Cos[z])*Sec[z/2]^2]*Log[Sin[z]] + > 2*Log[(-Cos[z])*Sec[z/2]^2]*Log[Tan[z/2]] + 2*PolyLog[2, 1/(1 + > Cos[z])] + PolyLog[2, Cos[z]*Sec[z/2]^2] + > PolyLog[2, -Tan[z/2]^2] > 0 > > Assuming[a >= 1, Integrate[f[a*x], {x, 0, Pi}]] > Limit[%, a -> 1] > > (1/(3*a))*(-Pi^2 - 6*I*Pi*Log[2] + 3*Log[2]^2 + 6*Log[Cos[a*Pi]/(1 + > Cos[a*Pi])]*Log[Sec[(a*Pi)/2]^2] + > 3*Log[Sec[(a*Pi)/2]^2]^2 + 3*Log[Sec[(a*Pi)/2]^2]*Log[Sin[a*Pi]^2] > - 6*Log[Sec[(a*Pi)/2]^2]*Log[-1 + Tan[(a*Pi)/2]^2] - > 3*Log[Sin[a*Pi]^2]*Log[-1 + Tan[(a*Pi)/2]^2] + 3*Log[Tan[(a*Pi)/ > 2]^2]*Log[-1 + Tan[(a*Pi)/2]^2] + > 6*PolyLog[2, 1/(1 + Cos[a*Pi])] + 3*PolyLog[2, Cos[a*Pi]*Sec[(a*Pi)/ > 2]^2] + 3*PolyLog[2, -Tan[(a*Pi)/2]^2]) > 0 > > Integrate[f[x], {x, 0, Pi}, GenerateConditions -> False] > 0 > > You think and act properly. That is the correct attitude! > > > Nevertheless, in the present situation I do not really understand why M= at= > hematica wants > > me to do that rather trivial variable transformation, which is at the h= ea= > rt of your solution. > > The integrand is still a rather complicated rational function of the sa= me= > order. The form > > of the integrand did not really change > > substantially as it is the case with some other ingenious substitutions= o= > ne uses in order to > > do some complicated looking integrals "by hand". > > I agree with you. But I can't provide you more insight than I did > provide you in my original post. > I think helping in this way Mathematica makes the application of > partial fraction decomposition > which is the heart of Risch Algorithm more easily for Integrate. If we > could understand all of > Mathematica's Integrate implementation algorithm we will probably work > at WRI! > > I agree also that the the variable transformation is rather trivial. > But who tells we must not think > simple things first in order to assist CASs? > > Of course we can think and less trivial valiable transformations! > For example in above mentioned integral: > > integrand = f[x]*dx /. x -> ArcSin[Sqrt[u]] /. dx -> > D[ArcSin[Sqrt[u]], u] > Integrate[integrand, {u, 0, Sin[Pi]^2}] > > Log[u]/(2*(1 - u)) > 0 > > And what is more important as Peter Pein show in his original post in > this way > we can get a more simplified indefinite integral than Mathematica and > is real in the > whole integration range. > > inintegrand = f[x]*dx /. x -> -ArcSin[Sqrt[u]] /. dx -> D[- > ArcSin[Sqrt[u]], u] > Integrate[integrand, {u, 0, Sin[z]^2}, Assumptions -> 0 < z < Pi] > Plot[%, {z, 0, Pi}] > (%% /. z -> Pi) - (%% /. z -> 0) > (D[%%%, z] // Simplify) /. z -> x > > Log[u]/(2*(1 - u)) > (1/12)*(-Pi^2 + 6*PolyLog[2, Cos[z]^2]) > (*plot to be displayed*) > 0 > Log[Sin[x]^2]*Tan[x] > > > > I think the fact that we are forced to such tricks shows that the Mathe= ma= > tica integrator > > is still a bit "immature" in special cases, as also the very interestin= g = > article by D. Lichtblau, > > which you cite, seems to indicate. So all this is probably perfectly kn= ow= > n to the > > Mathematica devellopers. And I hope the next Mathematica version has al= l = > this "ironed out"?? > > Reading again the article. > Bear in your mind that the subject of the symbolic (indefinite and > definite) integration > is perhaps the most serious challenge for all CASs and of course > Mathematica. > You can't accuse Mathematica of immaturity even in special cases. If > you think > that your integral is a trivial one for a CAS (you don't certainly > want to see what output I > got for another CAS!) note Mathematica almost fifteen (yes only 15!) > ago prior to the quite > revolutionary version 3.0 it will return -3/2 for the following > integral > > Integrate[1/x^2, {x, -1, 2}] > > that is, it would have failed to detect at first stage the > nonintegarble singularity at x=0 and > would have returned at second stage a negative value for a possitive > integrand in the integration > range. > > A lot of evolution has taken place. Don't you agree? > > > Kind Regards > Dimitris > > > > =CF/=C7 Michael Weyrauch =DD=E3=F1=E1=F8=E5: > > Hello, > > > > Dimitris, this is a marvelous solution to my problem. I really apprec= ia= > te > > your help. I will now see if I can solve all my other (similar) integra= ls= > using the same trick. > > Timing is not really the big issue if I get results in a reasonable amo= un= > t of time. > > > > Also the references you cited are quite interesting, because they give = so= > me insight > > what might go on inside Mathematica concerning integration. > > > > I also agree with you that it is my task as a programmer to "help" Math= em= > atica > > and guide it into the direction I want it to go. Sometimes this is an "= ar= > t"... > > > > Nevertheless, in the present situation I do not really understand why M= at= > hematica wants > > me to do that rather trivial variable transformation, which is at the h= ea= > rt of your solution. > > The integrand is still a rather complicated rational function of the sa= me= > order. The form > > of the integrand did not really change > > substantially as it is the case with some other ingenious substitutions= o= > ne uses in order to > > do some complicated looking integrals "by hand". > > > > I think the fact that we are forced to such tricks shows that the Mathe= ma= > tica integrator > > is still a bit "immature" in special cases, as also the very interestin= g = > article by D. Lichtblau, > > which you cite, seems to indicate. So all this is probably perfectly kn= ow= > n to the > > Mathematica devellopers. And I hope the next Mathematica version has al= l = > this "ironed out"?? > > > > Many thanks again, Michael

**Re: Definite Integration in Mathematica (continuous antiderivative from Gass' book)**

**Re: Definite Integration in Mathematica**

**Designing a Flexible Mathematica Program for Data Analysis**