# Why does Mathematica choose branches as it does in this situation?

Consider these integrals:

\$Assumptions = {e>0,e<1/2};
term1 = Integrate[x/(1-x) (1/(1-4x+4x^2))^e - 1/(1-x), {x, 0, 1}]
term2 = Integrate[1/2 x(1-x) (1/(1-4x+4x^2))^e, {x, 0, 1}]
term3 = Integrate[x/(1-x) (1/(1-4x+4x^2))^e - 1/(1-x)
+ 1/2 x(1-x) (1/(1-4x+4x^2))^e, {x, 0, 1}]


The third integrand is the sum of the first and second integrands. So it follows that term3 == term1 + term2 should be true.

I won't write down the full results because they're long and mostly irrelevant, but term3 has a nonzero imaginary part, whereas neither term1 nor term2 does:

term3 - term1 - term2 == 2 Pi I


Mathematically, I get why this is a reasonable result (I think): Mathematica has to choose a branch for the exponential function, and in the first integral it chooses the branch that gives a purely real result, whereas in the last case it chooses a different branch. Why would it do that, though? Is there something about these expressions that prompts Mathematica to choose the branch that it does in each specific case? For future integrals, if I run into something like this again, can I tell which branch the integrator is going to pick? Or is it something highly dependent on the details of the algorithm and thus random as far as I'm concerned?

I'm also curious to know if I could input these expressions differently so that Mathematica will choose the real branch of the exponential in every case, but that's not a priority since I know what the answer is, and it may be a matter for a separate question in any case.

-
Possibly related: mathematica.stackexchange.com/questions/13949/… – Mechanical snail Dec 1 '12 at 3:30
Which version of Mathematica are you using? When I used v9 on your integrals term3 - term1 - term2 // FullSimplify  gives 0 – WalkingRandomly Dec 1 '12 at 15:53
When I used v8 term3 was returned unevaluated after a while – WalkingRandomly Dec 1 '12 at 15:55
@WalkingRandomly I've got 8.0.1.0. It doesn't surprise me that this would have changed in version 9. – David Z Dec 1 '12 at 22:29
This issue also turned up here: mathematica.stackexchange.com/questions/24613 – David Speyer Dec 3 '13 at 14:48