Correct way to integrate a certain function

This question provides another example of a bug in Integrate (see e.g. this post).
Rewriting the integrand, we can get an idea why the result is incorrect:

Apart[(a + b Cos[t1 - t2])/(c + d Cos[t1 - t2])]
 b/d + (-b c + a d)/(d (c + d Cos[t1 - t2]))

the first term contributes to the result while the integral of the second term vanishes (incorrectly!):

Integrate[(-b c + a d)/(d (c + d Cos[t1 - t2])), {t1, 0, 2 π}, 
           Assumptions -> (a | b) ∈ Reals && c >= 0 && d <= 0 && 
                          c + d >= 0 && 0 <= t2 <= 2 π]
0

Putting appropriate values into Integrate instead of symbolic constants we get reliable results, we can compare them with NIntegrate. Assuming another relations between symbolic constants we can conclude that the source of this bug is the assumption on the phase t2. Therefore if we remove the symbolic phase t2 (we can put a numeric value e.g. π/2) we'll find the correct result:

Integrate[(a + b Cos[t1 - π/2])/(c + d Cos[t1 - π/2]), {t1, 0, 2 π}, 
           Assumptions -> (a | b) ∈ Reals && c >= 0 && d <= 0 && c + d >= 0]
ConditionalExpression[
    (2 (a d + b (-c + Sqrt[c^2 - d^2])) π)/(d Sqrt[(c - d) (c + d)]),
     d < 0 && c + d > 0]

We can verify that when $|c| \gg |d|$ this conditional expression behaves well:

Simplify[ Series[ %, {d, 0, 0}], c > 0]
ConditionalExpression[ (2 a π)/c + O[d]^1, d < 0 && c + d > 0]

Moreover the result does not depend on the phase t2 since we calculate the integrad depending on Cos[t1 - t2] over its total period 2 π.


This seems related to Bug in mathematica analytic integration?

Using the standard substitution

int = Simplify[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]) Dt[t1] /. 
     t1 -> t2 + 2 ArcTan[u] // TrigExpand] /. {Dt[t2] -> 0,  Dt[u] -> 1}
(*
  (2 (a + b + a u^2 - b u^2))/((1 + u^2) (c + d + c u^2 - d u^2))
*)

we obtain

Integrate[int, {u, -Infinity, Infinity}, 
 Assumptions -> {c >= 0, d <= 0, c + d > 0}]
(*
  (2 (a d + b (-c + Sqrt[c^2 - d^2])) π)/(d Sqrt[c^2 - d^2])
*)

It seems annoying, imo, that a standard class of integrals is not handled properly.


It appears Mathematica is using the fundamental theorem of calculus even though it's not valid in this case. Observe:

Simplify[Subtract @@ (Integrate[(a + b*Cos[t1 - t2])/(c + d*Cos[t1 - t2]), t1] /. 
  {{t1 -> 2 Pi}, {t1 -> 0}})]
(* 2*b*Pi/d *)

It's a tough problem to know when you can use FToC. See here for further explanation with an example similar to yours.