# Integration gives wrong result

Already several pages of stack exchange dedicated to the integration problem in Mathematica. However, by reading them I did not find solution to my own integral. I know from NIntegrate and other criteria that the answer of following integral:

Integrate[
(16 Cos[k]^2 Sin[th]^4 + Sin[2 (k)]^2 Sin[2 th]^2) /
( 16 (-1 + Cos[k]^2 Cos[th]^2)^2),
{k, -π + alpha, π + alpha},
PrincipalValue -> True]


gives the following wrong answer

-2 π Tan[th]^2


However, it gives different results by using NIntegrate?

Show @
Table[
Plot[{f[th, {0, 0.3, 0.5}[[i]]], -2 π Tan[ th]^2}, {th, -π, π},
PlotStyle ->
{Directive[Dotted, {Black, Blue, Red}[[i]]],
Directive[Line, {Black, Blue, Red}[[i]]]}],
{i, 1, 3}]


where,

f[th_, alpha_] := NIntegrate[(16 Cos[k]^2 Sin[th]^4 + Sin[2 (k)]^2 Sin[2 th]^2)/(16 (-1 + Cos[k]^2 Cos[th]^2)^2), {k, -π + alpha, π + alpha}] I would appreciate any comments or help.

• Hello there! Please edit your question by providing more information so others can try to reproduce your results. Namely, what are alpha and f? What was the result you expected to get and how do you know the result you do get is wrong?
– Kiro
Jul 25, 2020 at 10:18
• Plots Plot[(16 Cos[k]^2 Sin[th]^4 + Sin[2 (k)]^2 Sin[2 th]^2)/(16 (-1 + Cos[k]^2 Cos[th]^2)^2) /. th -> 1/2, {k, -\[Pi], \[Pi]}] and Plot[(16 Cos[k]^2 Sin[th]^4 + Sin[2 (k)]^2 Sin[2 th]^2)/(16 (-1 + Cos[k]^2 Cos[th]^2)^2) /. th -> -1, {k, -\[Pi], \[Pi]}] show no singularity. Jul 25, 2020 at 10:57
• Plot Plot3D[(16 Cos[k]^2 Sin[th]^4 + Sin[2 (k)]^2 Sin[2 th]^2)/(16 (-1 + Cos[k]^2 Cos[th]^2)^2), {k, -\[Pi], \[Pi]}, {th, -Pi, Pi}]] shows no singularity too. Therefore, the PrincipalValue->True option is superfluous. Jul 25, 2020 at 16:34
• @kiro, sorry for the late update. Jul 27, 2020 at 2:40

\$Version

(* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *)

Clear["Global*"]

expr = (16 Cos[k]^2 Sin[th]^4 +
Sin[2 (k)]^2 Sin[2 th]^2)/(16 (-1 + Cos[k]^2 Cos[th]^2)^2);

int1[th_] =
Integrate[expr, {k, -π + alpha, π + alpha}, PrincipalValue -> True] int2[th_] = Assuming[{-Pi < th < Pi, 0 < alpha < 1},
Integrate[expr, {k, -π + alpha, π + alpha}, PrincipalValue -> True]]

(* 2 π (-1 + Abs[Csc[th]]) Tan[th]^2 *)


The numeric integral is

int3[th_?NumericQ] := NIntegrate[expr, {k, -π + 1/10, π + 1/10}]


Visually comparing the integrals

Plot[Evaluate@{int1[th] // Normal, int2[th], int3[th]},
{th, -Pi, Pi},
PlotRange -> {-10, 4},
PlotStyle -> {Automatic, Automatic, Dashed},
PlotLegends -> Automatic] // Quiet int2 is consistent with the numeric integration

• So I think we have to use your approach to other problems. I mean putting integration in the assuming environment. Jul 27, 2020 at 2:48
• The problem is not with the assumptions, but as @Andreas says, that older versions "do not see the jumps of ArcTan at the poles of its argument", at k==-Pi/2 and Pi/2. A general workaround is to build the limit of the indefinite integral at these points (if function is not to complicated for Limit). See next comment. int[k_] = Integrate[integrand, k]  . Jul 27, 2020 at 6:59
• (Limit[int[k], k -> Pi + alpha, Direction -> 1, Assumptions -> 0 <= alpha < 1] - Limit[int[k], k -> Pi/2, Direction -> -1] + Limit[int[k], k -> Pi/2, Direction -> 1] - Limit[int[k], k -> -Pi/2, Direction -> -1] + Limit[int[k], k -> -Pi/2, Direction -> 1] - Limit[int[k], k -> -Pi + alpha, Direction -> -1, Assumptions -> 0 <= alpha < 1]) // Simplify  yields 2 \[Pi] (-1 + Sqrt[Csc[th]^2]) Tan[th]^2  . Jul 27, 2020 at 7:00

First: the function can be simplified to

1/(1 + Csc[th]^2 Tan[k]^2).


Then you find the antiderivative

Integrate[1/(1 + Csc[th]^2 Tan[k]^2), k]

Sec[th] (ArcTan[Csc[th] Tan[k]] - k Sin[th]) Tan[th].


The problem with the integral is that it doesn't see the jumps of the ArcTan at the poles of its argument,so it is not continuous. A continuous antiderivative is:

Sec[th] (ArcTan[Csc[th] Tan[k]] - k Sin[th]) Tan[th] + π Sec[   th] Tan[th] Floor[k/π + 1/2].


This can be evaluated with your integration limits to:

2 π (Sec[th] - Tan[th]) Tan[th].


This agrees for π > th > 0 with Nintegrate numbers.

• Solution for -Pi < th < Pi is 2 \[Pi] Sec[th] (Sign[Csc[th]] - Sin[th]) Tan[th]` Jul 28, 2020 at 9:27