# Two different results for same symbolic integral

I am trying to compute the following integral

$\int_0^\infty dk \frac{e^{i k a}}{k^2}[\sin(kb)-kb\cos(kb)]$

When computing it as-is, i.e, with the code

Integrate[E^(I k a) (Sin[k b]-k b Cos[k b] )/ k^2, {k, 0, ∞}, Assumptions ->
a ∈ Reals && b > 0]


I obtain a very long, piecewise function.

On the other hand, if I write the exponential forms of the sine and cosine, i.e, if I compute the following

$\int_0^\infty dk \frac{e^{i k a}}{k^2}[\frac{1}{2i}(e^{i k b}-e^{-ikb})-kb\frac{1}{2}(e^{i k b}+e^{-ikb})]$

With the code

Integrate[1/k^2 E^(I k a)(1/(2 I) (Exp[I k b] - Exp[-I k b])- k b 1/2 (Exp[I k b]
+ Exp[-I k b])), {k, 0, ∞}, Assumptions -> a ∈ Reals && b > 0]


then I obtain a non-piecewise function. Numerically giving random values to $a$ and $b$ and computing the relative error, I get that the two values differ in around 67%. Additionally, I have the feeling that Mathematica is somehow "omitting" or "hiding" contributions like Dirac deltas or Heaviside step functions or similar objects.

My question is: How to know which of the two (if any) is the correct expression? If none is, how to get the correct one?

• One way is to compare with a numerically computed result (NIntegrate) for specific values of a and b. – Szabolcs Dec 7 '15 at 15:21
• Try to express everything in either trigonometric or exponential function. I think you will get same answer in both cases. And you can always verify the reliability using NIntegrate as @Szabolcs suggested. To make the convergence faster you can choose the integration limit from, say 0.00001, instead of 0. – Sumit Dec 7 '15 at 15:51
• I have compared with numerical computations as suggested. It indeed points to the first method giving the right result, but I still wonder why there is this difference... – Alex Dec 7 '15 at 16:01
• You can also use analytic Integrate with specific values for the parameters. In this case both expressions yield the same result, as do both expressions with NIntegrate. The first piecewise expression agrees with all of that. ( I just tried a couple of a,b values though ) – george2079 Dec 7 '15 at 16:03
• Another expression can be obtained via expanding Exp[I k a] and it doesn't seem to match your second expression. – b.gates.you.know.what Dec 7 '15 at 20:58

There does appear to be a substantive difference between the two applications of Integrate, even though the integrands are equal.

(1/k^2 E^(I k a) (1/(2 I) (Exp[I k b] - Exp[-I k b]) - k b 1/2 (Exp[I k b] + Exp[-I k b]))
- E^(I k a) (Sin[k b] - k b Cos[k b])/k^2) // FullSimplify
(* 0 *)


Now integrate each in turn

s1 = Integrate[E^(I k a) (Sin[k b] - k b Cos[k b])/k^2, {k, 0, ∞},
Assumptions -> a ∈ Reals && b > 0] // FullSimplify
(* Piecewise[{{b - a*ArcTanh[b/a], a^2 > b^2},
{(2*b + I*a*Pi + a*Log[-a + b] - a*Log[a + b])/2, b^2/a^2 > 1}}, 0] *)
Plot[Evaluate[ReIm[s1 /. b -> 1]], {a, -5, 5}, PlotRange -> All]


s2 = Integrate[1/k^2 E^(I k a) (1/(2 I) (Exp[I k b] - Exp[-I k b]) -
k b 1/2 (Exp[I k b] + Exp[-I k b])), {k, 0, ∞},
Assumptions -> a ∈ Reals && b > 0] // FullSimplify
(* 1/8 (2 b (4 EulerGamma + Log[(a - b)^2] + Log[(a + b)^2]) + \[Pi] (-2 I Abs[a - b] +
2 I Abs[a + b] + ((a - b)^2 - 2 I b) Sign[a - b] - (2 I b + (a + b)^2) Sign[a + b])) *)
Plot[Evaluate[ReIm[s2 /. b -> 1]], {a, -5, 5}]


They are far from being identical. (The same curves are obtained with FullSimplify not applied, so it is not at fault.) Now, if the two integrals are performed for a specific values of the parameters, say, {b -> 1, a -> 3}, the result is

(* 1 - Log[8]/2 *)


in both cases. Its numerical value is -0.0397208. Yet,

{s1 /. {b -> 1, a -> 3}, N[s1 /. {b -> 1, a -> 3}]}
(* {1 - 3 ArcTanh[1/3], -0.0397208} *)
{s2 /. {b -> 1, a -> 3}, N[s2 /. {b -> 1, a -> 3}]}
(* {1/8 (-12 π + 2 (4 EulerGamma + Log[4] + Log[16])), -3.09545} *)


Similar behavior occurs for {b -> 1, a -> 1/2}. Manifestly, s2 is incorrect.

• Note that FourierTransform[UnitStep[k] (Sin[k b] - k b Cos[k b])/k^2, k, a, Assumptions -> (b > 0), FourierParameters -> {1, 1}] gives a result that is consistent with s1. – J. M. is in limbo Dec 11 '16 at 11:04