# Why won't mathematica evaluate the integral I've defined?

I defined

Integrate[Exp[p_. Cos[x_] + q_. Sin[x_]]*Sin[a_. Cos[x_] + b_. Sin[x_] - m_. x_],
{x_, 0, 2*Pi}] := Sqrt[-1]*Pi*((b - p)^2 + (a + q)^2)^(-m/2)*(((p^2 - q^2 + a^2 - b^2)
+ Sqrt[-1]*(2*(p*q + a*b)))^(m/2)*BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) -
Sqrt[-1]*(2 (a*p + b*q))]] - ((p^2 - q^2 + a^2 - b^2) -
Sqrt[-1]*(2 (p*q + a*b)))^(m/2)*BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) +
Sqrt[-1]*(2 (a*p + b*q))]])


In accordance with the examples given in the mathematica documentation. However, the integral only evaluates for the exact symbolic values p,q,a,b,m. If I try to evaluate any other form of the integral, e.g.

Integrate[Exp[Cos[x]+Sin[x]]*Sin[Sin[x]+Cos[x]-x],{x,0,2*Pi}]


Mathematica is unable to evaluate the integral. Why doesn't the integral, the way I've defined it, evaluate for any given values of p,q,a,b,m?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Jun 21 '16 at 3:07
• Related: (6169), (19534) Jun 21 '16 at 3:36
• BTW, what examples are given in the documentation? (Where are they?) Jun 21 '16 at 3:37

One problem is that Exp[y] evaluates to Power[E, y], so that the integral does not match the (held) pattern with Exp. Another is that other functions sometimes evaluate to other forms, such as Sin:

Sin[Sin[x] + Cos[x] - x]
(* -Sin[x - Cos[x] - Sin[x]] *)


Here is a fix that works on the example. I added a constant factor c_ to take care of the -1 factoring out of Sin[], and changed -m_ to +m_, mutatis mutandis. Other examples may simplify in other ways, so some testing may be necessary to cover all possible use-cases.

InternalInheritedBlock[{Integrate},
Unprotect[Integrate];
Integrate[
c_. Power[E, p_. Cos[x_] + q_. Sin[x_]]*
Sin[a_. Cos[x_] + b_. Sin[x_] + m_. x_], {x_, 0, 2*Pi}] :=
c (Sqrt[-1]*
Pi*((b - p)^2 + (a + q)^2)^(m/2) *
(((p^2 - q^2 + a^2 - b^2) + Sqrt[-1]*(2*(p*q + a*b)))^(-m/2) *
BesselI[-m, Sqrt[(p^2 + q^2 - a^2 - b^2) - Sqrt[-1]*(2 (a*p + b*q))]] -
((p^2 - q^2 + a^2 - b^2) - Sqrt[-1]*(2 (p*q + a*b)))^(-m/2)*
BesselI[-m, Sqrt[(p^2 + q^2 - a^2 - b^2) + Sqrt[-1]*(2 (a*p + b*q))]]));
Protect[Integrate];
Integrate[Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2*Pi}]
]
(*
-2 I π (-(1/2) (-1)^(3/4) BesselI[1, 2 (-1)^(1/4)] +
1/2 (-1)^(1/4) BesselI[1, 2 (-1)^(3/4)])
*)


See here for InternalInheritedBlock.

Michael E2 and Bob have solved the integral. Here is an alternative method which might be of interest as well. I have used the similar method already in How to solve this integration?.

We solve the integral transforming it into a complex contour integral which, after a simple binomial expansion, can easily be soved by the Cauchy theorem. The remaining infinte sum can be expressed by a hypergeometric function which reduces to a modified Bessel function of the first kind.

Let

f := Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x]
g := Integrate[f, {x, 0, 2 \[Pi]}]


First we shall use the exponential form of the Sin[] outside the Exp[] function in f (in the end we take the imaginary part)

Sin[Sin[x] + Cos[x] - x] == Im[Exp[I (Sin[x] + Cos[x] - x)]];
ComplexExpand[%]

(* Out[812]= True *)


so that the argument of the Exp[] function becomes

Cos[x] + Sin[x] + I (Cos[x] + Sin[x] - x)


which can be written as

Exp[I x] + I Exp[-I x] - I x


The integral g then becomes

g := Integrate[Exp[Exp[I x] + I Exp[-I x] - I x], {x, 0, 2 \[Pi]}]


Now with the substitution

{z -> Exp[-I x], dz = -I z dx};


g simplifies to a contour integral around the origin

h = I  Integrate[Exp[1/z + I z], {z, 1, I, -1, -I, 1}]

(* Out[814]= Integrate[E^(1/z + I z), {z, 1, I, -1, -I, 1}] *)


As this integral is returned unevaluated we expand the Exp[] function in a power series.

A typical term can in turn be expanded into a binomial sum

(1/z + I z)^n == Sum[Binomial[n, k] z^-k (I z)^(n - k), {k, 0, n}] ==
Sum[Binomial[n, k] z^(n - 2 k) I^(n - k), {k, 0, n}];


Now, by the Cauchy theorem, the contour integral of integer powers of z is only different from zero for the first negative power. Examples are

Table[{m, Integrate[z^m, {z, 1, I, -1, -I, 1}]}, {m, -2, 1}]

(* Out[820]= {{-2, 0}, {-1, 2 I \[Pi]}, {0, 0}, {1, 0}} *)


Hence we have the condition

Reduce[n - 2 k == -1, Integers ] /. C[1] -> m

(* Out[827]= m \[Element] Integers && k == m && n == -1 + 2 m *)


Taking into account the factor 2 \[Pi] I from the integration and the 1/n! from the Exp[] function we arrive at the sum which is immediatey evaluated by Mathematica:

h1 = 2 \[Pi] Sum[
1/(2 m - 1)! Binomial[2 m - 1, m] I^(m - 1), {m, 0, \[Infinity]}]

(* Out[843]= -2 (-1)^(3/4) \[Pi] BesselI[1, 2 (-1)^(1/4)] *)


The original integral is the imaginary part of h1.

Numerically

h1 // N

(* Out[868]= 5.76177 + 3.09803 I *)


Another form of h1 is obtained by expressing (-1) in exponential form

h1 /. (-1)^c_ -> Exp[I \[Pi] c]

(* Out[865]= -2 E^((3 I \[Pi])/4) \[Pi] BesselI[1, 2 E^((I \[Pi])/4)] *)


Which can be simplified to

FullSimplify[%]

(* Out[866]= 2 \[Pi] Hypergeometric0F1Regularized[2, I] *)

% // N

(* Out[867]= 5.76177 + 3.09803 I *)

• N.B. $I_n(z)$ is a modified Bessel function of the first kind; it's $Y_n(z)$ that's a Bessel function of the second kind. Jun 21 '16 at 15:15
• @J.M. corrected, thanks for the hint. Jun 21 '16 at 18:11

Rather than define a function, you can define a replacement rule using Hold and RuleDelayed

rule = Hold[Integrate[
Exp[p_. Cos[x_] + q_. Sin[x_]]*
Sin[a_. Cos[x_] + b_. Sin[x_] - m_. x_], {x_, 0, 2 Pi}]] :>
I*Pi*((b - p)^2 + (a + q)^2)^(-m/
2)*(((p^2 - q^2 + a^2 - b^2) + I*(2*(p*q + a*b)))^(m/2)*
BesselI[m,
Sqrt[(p^2 + q^2 - a^2 - b^2) -
I*(2 (a*p + b*q))]] - ((p^2 - q^2 + a^2 - b^2) -
I*(2 (p*q + a*b)))^(m/2)*
BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) + I*(2 (a*p + b*q))]]);

Hold[Integrate[
Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2 Pi}]] /.
rule // Simplify

(*  (-(-1)^(1/4))*Pi*
(BesselI[1, 2*(-1)^(1/4)] +
I*BesselI[1, 2*(-1)^(3/4)])  *)


With inexact numerical values and using Chop to remove the negligible imaginary artifact

% // N // Chop

(*  3.09803  *)


Verifying with NIntegrate

NIntegrate[Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2 Pi}]

(*  3.09803  *)