Re: Integrate and Distribution over terms

*To*: mathgroup at smc.vnet.net*Subject*: [mg9304] Re: [mg9255] Integrate and Distribution over terms*From*: David Withoff <withoff>*Date*: Mon, 27 Oct 1997 02:47:16 -0500*Sender*: owner-wri-mathgroup at wolfram.com

> This problem came out of Mark Deckers experimentation with the > UniformDistribution probability density function. (which returns a > function with Sign's in it) > > One of the basic lessons I learned in calculus is that > Integrate[f[x]+g[x]]=Integrate[f[x]]+Integrate[g[x]]. > > I have an example where it appears that Mathematica hasn't figured that > lesson out yet. > > Integrate[Sign[x] Sin[x]/(2 Pi),{x,-4,4}] returns > > 1/Pi-Cos[4]/Pi. > > Integrate[Sign[x-Pi] Sin[x]/(2 Pi),{x,-4,4}] returns > -1/Pi-Cos[4]/Pi. > > But > > Integrate[Sign[x] Sin[x]/(2 Pi)-Sign[x-Pi] Sin[x]/(2 Pi),{x,-4,4}] > > takes about 5 times as long as either of the two preceding integrals and > eventually returns itself. ie Mathematica 3.0 can't do it. It is as > if Integrate didn't know it was supposed to distribute itself over the > terms. If I manually tell Integrate to distribute itself over the > terms > > Distribute[(Integrate[#1, {x, -4, 4}] & )[(Sign[x]*Sin[x])/(2*Pi) - > (Sign[-Pi + x]*Sin[x])/(2*Pi)]] > > then it still takes a long time, but returns the correct answer, 2/Pi. > > Am I correct that Integrate does not automatically distribute itself > over the terms or is there another explanation for this behavior? Is > there some option or package that corrects this seeming flaw? Thanks > for any insight you could offer. In answer to your question, here are a couple of examples where it would not be a good idea to distribute integration over a sum In[1]:= Integrate[1/Sin[x] - 1/x, {x, 0, Pi/2}] 4 Out[1]= Log[--] Pi In[2]:= Integrate[x^x/(x^x+1) + 1/(x^x+1), x] Out[2]= x The existence of such examples is the reason that Integrate does not automatically distribute integration over a sum. Sometimes, as in these examples, distributing integration over a sum will generate divergences or impossible integrals from an otherwise simple problem. The main advantage of distributing integration over a sum is speed. With that in mind, it is not only necessary to find an algorithm that can figure out when it is ok to do this, but also to find a *fast* algorithm, since taking too long to figure out whether or not it is ok to distribute integration over a sum would defeat the original purpose. Until such an algorithm is developed, using Map[Integrate[#, x] &, expr] in place of Integrate[expr, x] is an easy way to get the speed advantages with none of the complications. Dave Withoff Wolfram Research