MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Re: Simple integral wrong

  • To: mathgroup at
  • Subject: [mg25201] Re: [mg25165] Re: [mg25073] Re: Simple integral wrong
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Fri, 15 Sep 2000 02:21:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

David Withoff's response made me look a this example more carefully. I
noticed that I have been rahter naive about how mathematica treats integrals
with symbolic limits and that the situation is actually worse and less
justifiable than I had though.

I had taken at face value the statement, (repeated in a number of
authoritative sources) that Mathematica interprets integrals of the form
Integrate[f[z],{z,a,b}] as contour integrals, usually choosing the straight
line path from a to b as the path of integration. Sometimes one can even
induce Mathematica to choose a different path, e.g. compare:

Integrate[1/x^2, {x, -1, 1}]
Integrate[1/x^2, {x, -1, I, 1}]

The above statement is generally true when the limits a and b are numerical
(real or complex). There are some exceptions, for example, the presence of a
function which can take only real arguments, like UnitStep, will force
Mathematica to interpret the whole integral as integral on the real line:

Integrate[Abs[x]*UnitStep[x], {x, 0, z}]
          1  2
If[z > 0, - z  UnitStep[z],
  Integrate[Abs[x] UnitStep[x], {x, 0, z}]]

Without UnitStep the integral is clearly interpreted as contour integral,
even though Abs is not an analytic function:

Integrate[Abs[x], {x, 0, z}]
1             2        2
- z Sqrt[Im[z]  + Re[z] ]

This lead me to assume that the same is the case in the case which statred
this discussion. However, it it is actually quite obvious (I am still
kicking myself for being so stupid as not to notice it) that this can't be
the case. The answer given by Mathematica:

Integrate[Abs[Cos[x]], {x, 0, z}]
Sqrt[Cos[z] ] Tan[z]

agrees with the contour Integral only for purely imaginary z, e.g.

Integrate[Abs[Cos[x]], {x, 0, z}] /. z -> 5I // N
0. + 74.2032 I

NIntegrate[Abs[Cos[x]], {x, 0, 5I}]
0. + 74.2032 I

but not for general complex numbers, even of small modulus:

Integrate[Abs[Cos[x]], {x, 0, z}] /. z -> (1 + I)/10 // N
0.100333 + 0.0996663 I

NIntegrate[Abs[Cos[x]], {x, 0, (1 + I)/10}]
0.100001 + 0.100001 I

So the solutions given by Mathematica is valid only for certain, very
special values of z. In fact, for complex values of z Mathematica's answer
is even "more wrong" than for real ones, since there is no obvious
correction term as there is in the real case. All this leads me now to
conclude that the answer Mathematica gives in this case is probably worse
than having no answer at all.

On the other hand, if we restict ourselves only to functions on the real
line only, than Mathematica's behaviour looks somewhat better than it did at
first sight. In fact, one can interpret the answer

Integrate[Abs[Cos[x]], {x, 0, z}]

Sqrt[Cos[z] ] Tan[z]

as saying that Mathematica gives a conditional answer, meant to be valid as
long as there are no singularities betwen 0 and z. This is supported by the
fact that when we introduce a singularity in between, the behaviour changes:

Integrate[Abs[Cos[x]], {x, 0, Pi/2, z}]

This is disappointing because it is easy to get a better answer:

Integrate[Abs[Cos[x]], {x, 0, Pi/2}] +
  Limit[Integrate[Abs[Cos[x]], {x, Pi/2 + d, z}], d -> 0]
2 + Sqrt[Cos[z] ] Tan[z]

Isn't this obviously what Mathematica shoud have done above? In general I
would propose that Integrate[f[x],{x,a,s}] with symbolic s should lead
Mathematica to assume that there are no singularities between a and s.
Integrate[[f[x],{x,a,d, s}] where s is symbolic should mean that there is
just one singularity at d, etc. One can easily implement this sort of
approach in the above case.

In addition, I now think that we should be able to specify whether we want
to consider an integral as a contour integral in the complex plane or not,
perhaps through the Assumptions mechanism. (E.g.
Integrate[f[z],{z,a,b},Assumptions->Element[z,Reals]]. (Of course this is
needed only in the case when at least one of the limits is symbolic and the
other symbolic or real. ). Thus in this particular case my preferred answers
would be:

Integrate[Abs[Cos[x]], {x, 0, z}]

Integrate[Abs[Cos[x]], {x, 0, z}]

(unevaluated input returned)

Integrate[Abs[Cos[x]], {x, 0, z}, Assumptions->Element[z,Reals]]

Sqrt[Cos[z] ] Tan[z]

Integrate[ Integrate[Abs[Cos[x]], {x, 0,Pi/2, z},

Sqrt[Cos[z] ] Tan[z] +2


Andrzej Kozlowski
Toyama International University

on 9/12/00 3:58 PM, David Withoff at withoff at wrote:

>> A couple of people told me that
>> Plot[Integrate[Abs[Cos[u]], {u, 0, x  Pi]}], {x, 0, 3}]
>> works fine. The result is monotonic increasing as expected.
>> But try
>> Plot[Evaluate[Integrate[Abs[Cos[u]],{u,0,Pi*x}]],{x,0,3}]
>> and see what happens! The evaluate forces Mathematica to do the
>> integral symbolically. It was doing it numerically without the Evaluate.
> These examples behave differently because the limits of integration are
> numerical in the first example and non-numerical in the second.  All of
> the integrals here are done symbolically.  (You could use NIntegrate to
> see what happens if the integrals are done numerically.)  With numerical
> limits for the integral Mathematica can invoke a difficult but
> implementable procedure to correct for the discontinuities of the
> corresponding indefinite integral that fall within the range of
> integration.  Without numerical values for the limits it is not possible
> in general to know which discontinuities fall within the range of integration.
> One conceivable approach to this problem would be to add some sort of
> symbolic correction for the discontinuities, as suggested in:
>> Or just type
>> Integrate[Abs[Cos[u]],{u,0,Pi x}]
>> Mathematica 4 returns
>> 2
>> Out[1]= Sqrt[Cos[Pi x] ] Tan[Pi x]
>> This plots as a saw-tooth. The true solution should be
>> Sqrt[Cos[Pi x]^2] Tan[Pi x] + 2 Floor[x + 1/2]
>> Mathematica misses the step functions necessary to make the solution
>> continuous.
> One problem with this is that the suggested result isn't correct for all
> values of x.   Apparently there is an implicit assumption that x is real.
> Even if one makes that assumption (which exposes another set of difficulties)
> there is the problem that there is no known computer algorithm for
> constructing the necessary correction.  If you try constructing
> the necessary correction for a non-trivial examples you can quickly
> come to appreciate why no one has worked out a way to construct
> such corrections automatically (and are not likely to do so any
> time soon).
> Examples like this are very common.  If you look up the following
> integral in a book, for example, you will probably find a result
> similar to the result given by Mathematica:
> In[1]:= Integrate[1/(3 + Cos[2 x]), x]
> Out[1]= ArcTan[Tan[x]/Sqrt[2]]/(2 Sqrt[2])
> This result has discontinuities along the real axis.  Tables of
> integrals do not normally include piecewise constant functions to
> correct for those discontinuities, and neither does Mathematica.
> Changing this to a definite integral with symbolic limits of integration
> doesn't really change the situation.  A definite integral with
> symbolic limits of integration is still essentially handled as
> an indefinite integral:
> In[2]:= Integrate[1/(3 + Cos[2 x]), {x, 0, t}]
> Out[2]= ArcTan[Tan[t]/Sqrt[2]]/(2 Sqrt[2])
> There isn't a single formula that will give a correct result for this
> integral for any value of x and for any contour of integration.  If
> someone figures out a better approach for handling some subset of
> examples like this one, that would probably make a nice addition to
> some future version of Mathmematica.
> Dave Withoff
> Wolfram Research

  • Prev by Date: Re: Re: PseudoInverse for exact matrices: Comments...
  • Next by Date: Re: Re: Mathematica Publication Question
  • Previous by thread: Re: Re: Simple integral wrong
  • Next by thread: Re: Exporting to MS Word