Inspired by this question on Math.SE, I wanted to see what Mathematica could do with the integral $$ \int_0^{\pi}e^{k\cos t}\cos(k\sin t)\,dt. $$ Thus, I entered into Mathematica (tried on both 10.3 and 10.4)

 Integrate[Exp[k Cos[t]] Cos[k Sin[t]], {t, 0, Pi}]

and was surprised to see the result

 ConditionalExpression[0, k == 0]

For $k=0$, the value of the integral is $\pi$ since the integrand is constant, equal to $1$. (For $k\neq 0$, $k$ real, I expect the integral to evaluate to $\pi$ as well.)

Question: Does anyone have a possible explanation, or is this simply a bug that should be reported to Wolfram?

Edit There was a request for a calculation of the integral. One way is the following. If we let $I(k)$ denote the value of the integral, then, by differentiating and simplifying the integrand, we find that $$ I'(k)=\int_0^{\pi}e^{k\cos t}\cos(t+k\sin t)\,dt. $$ Now, as it happens, it is easy to calculate that integral. We find that (here one might be a bit careful in the case $k=0$) $$ I'(k)=\int_0^{\pi}e^{k\cos t}\cos(t+k\sin t)\,dt=\Bigl[\frac{1}{k}e^{k\cos t}\sin(k\sin t)\Bigr]_0^{\pi}=0. $$ Hence $$ I(k)=I(0)=\int_0^{\pi}1\,dt=\pi. $$

  • $\begingroup$ Maybe the answer is somewhere in here $\endgroup$
    – Jason B.
    Mar 23, 2016 at 12:32
  • $\begingroup$ @JasonB Thank you for your comment. It is in the top of that file, but I don't know what that is supposed to mean? Is it already reported? $\endgroup$
    – mickep
    Mar 23, 2016 at 13:03
  • 3
    $\begingroup$ Sorry, that is the result from running Block[{Internal`Integrate`debugSwitch = 10}, Integrate[Exp[k Cos[t]] Cos[k Sin[t]], {t, 0, Pi}]] - presumably, the reason it is giving an error is in there somewhere. I'd be grateful if someone could point me to the derivation that shows this integral is Pi for any value of k $\endgroup$
    – Jason B.
    Mar 23, 2016 at 13:27
  • $\begingroup$ @JasonB Good to know, I will try to look at the output more closely, but I'm not used to that type of output, so probably others will have more luck. In any case, I added a way to calculate the integral (another way is outlined in the original question at Math.SE). $\endgroup$
    – mickep
    Mar 23, 2016 at 13:51
  • $\begingroup$ Possibly the same underlying reason why Integrate[Cos[k Exp[I t]], {t, 0, Pi}, Assumptions -> {k >= 0}] evaluetes to Pi while Integrate[Cos[k Exp[I t]], {t, 0, Pi}, Assumptions -> {k < 0}] evaluates to `I (Conjugate[CosIntegral[k]] - CosIntegral[-k]). $\endgroup$ Mar 23, 2016 at 15:20

1 Answer 1



I think I have to correct myself. I believe now that the integral is an analytic function of k and that the cut coming from Mathematica's antiderivative is spurious and so are the complications in performing the integral.

The argument is that the integrand is analytic in k and hence is expandable into a convergent series around k = 0 which can be integrated over t term by term.

The problem arises because Mathematica finds an antidrivative with respect to the variable t which contains a branch point singularity in the other varable k. We could choose a better antiderivative subtracting a Log[k] term which has the same branch point and thus get rid of the spurious singularity.

The integrand

h = Exp[ k Exp[I t]];

is obviously an analytic function of k for any fixed value of t, and also an analytic function of t for fixed k.

Expanding h in a series about k = 0, taking three terms, gives

hk = Series[h, {k, 0, 3}] // Normal

(* Out[4]= 1 + E^(I t) k + 1/2 E^(2 I t) k^2 + 1/6 E^(3 I t) k^3 *)

The definite integral becomes

hkint = Integrate[hk, {t, 0, \[Pi]}]

(* Out[77]= 2 I k + (I k^3)/9 + \[Pi] *)

Hence the real part, which is the original integral, is Pi. Whereas the imaginary part can be shown to sum up to

khi = 2 SinhIntegral[k]

SinhIntegral is defined as

Integrate[Sinh[z]/z, {z, 0, k}]

(* Out[80]= SinhIntegral[k] *)

And the documentation tells us that SinhIntegral[z] is an entire function of z with no branch cut discontinuities.

So we have found the complete function theoretic picture of the integral as a function of the complex variable k.

But now, let us have a look at the antiderivative obtained by Mathematica via the indefinite integral

a = Integrate[Exp[k Exp[I t]], t]

(* Out[81]= -I ExpIntegralEi[E^(I t) k] *)

This function is not well defined for k = 0:

a /. k -> 0

$i \infty$

The series expansion gives

Series[a, {k, 0, 2}] // Normal

(* Out[116]= -I EulerGamma - I E^(I t) k - 
 1/4 I E^(2 I t)
   k^2 + t + \[Pi] Floor[(\[Pi] - Arg[E^(I t)] - Arg[k])/(
   2 \[Pi])] - \[Pi] Floor[(\[Pi] - Arg[E^(-I t)] + Arg[k])/(
   2 \[Pi])] + \[Pi] Floor[(\[Pi] - Re[t])/(
   2 \[Pi])] - \[Pi] Floor[(\[Pi] + Re[t])/(2 \[Pi])] - I Log[k] *)

The Log[k] term gives rise to the branch cut which is confirmed in the documentation whch says: the function ExpIntegralEi[z] has a branch cut discontinuity in the complex z plane running from -\[Infinity] to 0.

And even the difference appearing via the fundamental theorem of calculus

a1 = (a /. t -> \[Pi]) - (a /. t -> 0)

(* Out[84]= -I ExpIntegralEi[-k] + I ExpIntegralEi[k] *)

has some difficulties

In[85]:= a1 /. k -> 0

During evaluation of In[85]:= Infinity::indet: Indeterminate expression (-I) [Infinity]+I [Infinity] encountered. >>

(* Out[85]= Indeterminate *)

Hence the unfavorable choice of the antiderivative gives rise to the problems encountered by Mathematica.

Original post

The problem arises due to the branch cut singularity at k=0. We can see it from the following developments:

Let the integral in question be

f := Integrate[Exp[k Cos[t]] Cos[k Sin[t]], {t, 0, Pi}]

Considering instead of f this integral

Integrate[Exp[k Cos[t]] Exp[I k Sin[t]], {t, 0, Pi}]

or simplifying the exponent

g := Integrate[Exp[k Exp[I t]], {t, 0, Pi}]

For real k we have f = Re[g] .

If we let Mathematica calculate this definite integral without Assumptions we get


Out[45]= ConditionalExpression[-I (ExpIntegralEi[-k] - ExpIntegralEi[k]), 
 Re[k] == 0 && Im[k] <= 0]

Which is the bug noted in the OP because for k->0 the result is zero:

Limit[-I (ExpIntegralEi[-k] - ExpIntegralEi[k]), k -> 0]

(* Out[75]= 0 *)

Notice that g has exactly the form of applying the fundamental theorem of calculus to the antiderivative, which is

a = Integrate[Exp[k Exp[I t]], t]

(* Out[76]= -I ExpIntegralEi[E^(I t) k] *)

As is well known and has been discussed many times in this forum, errors may arise from doing this carelessly. In fact, there is a branch point (logarithmic) singularity at k = 0

Series[ExpIntegralEi[k], {k, 0, 1}, Assumptions -> k > 0] // Normal

(* Out[123]= EulerGamma + k + Log[k] *)

An alternative approach makes assumptions on k.

For example

g1 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> k >= 0]

$-i \left(-2 \text{Shi}(k)+\left( \begin{array}{cc} \{ & \begin{array}{cc} i \pi & k>0 \\ 0 & \text{True} \\ \end{array} \\ \end{array} \right)\right)$

% /. k -> 0

(* Out[107]= 0 *)

Still wrong.


g2 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> {k > 0}]

(* Out[111]= \[Pi] + 2 I SinhIntegral[k] *)

% /. k -> 0

(* Out[112]= \[Pi] *)

g3 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> {k < 0}]

(* Out[113]= \[Pi] + 2 I SinhIntegral[k] *)

% /. k -> 0

(* Out[114]= \[Pi] *)

g4 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> {k == 0}]

(* Out[115]= \[Pi] *)

The expressions g2 through g4 look as if we can collectively assume this

g5 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> Im[k] == 0]

$\text{ConditionalExpression}\left[-i \left(-2 \text{Shi}(k)+\left( \begin{array}{cc} \{ & \begin{array}{cc} i \pi & k>0 \\ 0 & \text{True} \\ \end{array} \\ \end{array} \right)\right),k\geq 0\right]$

 % /. k -> 0

(* Out[117]= 0 *)

But it is not the case. Going on the two banks of the cut gives:

g6 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> Im[k] > 0]

(* Out[120]= -\[Pi] + 2 I SinhIntegral[k] *)

g7 = Integrate[Exp[k Exp[I t]], {t, 0, Pi}, Assumptions -> Im[k] < 0]

(* Out[121]= \[Pi] + 2 I SinhIntegral[k] *)

These results show that Mathematica considers the initial integral as a function of the complex variable k, and care has to be taken in when approaching the branch point k = 0.

  • $\begingroup$ Thank you very much for you insightful answer! I'm rather convinced that the idea you have in your update is correct. (Sorry for the long time it took me to comment, I've been partly afk. I will probably accept this answer, but I would like to keep the question open for some days still.) $\endgroup$
    – mickep
    Mar 28, 2016 at 19:31
  • $\begingroup$ @mickep Yes I think my original post was wrong and should be abandoned. But I agree to leave the question open for some time. Maybe others join in. BTW have you noticed the related problem mathematica.stackexchange.com/questions/111284/… ? $\endgroup$ Mar 28, 2016 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.