# How to avoid complex terms in the results given by Integrate?

As shown by In1, integrating Sqrt[x^2 - 1]/(a + x^2) (1/x) returns a result with a complex terms; however, after I make a transformation as shown in In2, Mathematica gives a simpler form.

I have no doubt the two outputs are both right and are actually the same thing, but my question is: for the input as given in In1, is there any method that can be applied to the output of In1 that will give the same output as Out2? That is, can the result of In1 be transformed by Mathematica itself into the desired form, thus, making the integration easier?

In1:

Integrate[Sqrt[x^2 - 1]/(a + x^2) (1/x), {x, 1, t}, Assumptions -> t > 1 && a > 5] In2:

Integrate[Sqrt[y - 1]/(a + y) (1/(2y)), {y, 1, t^2}, Assumptions -> t > 1 && a > 5] Mathematica is good in integration, but I think Rubi's Mathematica integration package produces more optimal results in general. See this for more examples.

In this case, Rubi produced the same result as your second integral (Rubi only does indefinite integration, but one can use limits to compute the definite integration (assuming it is valid to do so, i.e. the antiderivative that resulted is defined over the range on integration, etc..).

Compare the indefinite integration of your first example between Mathematica result and Rubi's

Clear[x, a];
r = Int[Sqrt[x^2 - 1]/(a + x^2) (1/x), x] Clear[x, a];
r2 = Integrate[Sqrt[x^2 - 1]/(a + x^2) (1/x), x] To evaluate the definite integral:

  sol = Limit[r, x -> t] - Limit[r, x -> 1] Compare this to the result from your second example

Clear[y, a, t]
sol2 = Integrate[Sqrt[y-1]/(a + y)(1/(2 y)), {y, 1, t^2}, Assumptions -> t > 1 && a > 5];
Assuming[t > 1 && a > 5, Simplify[sol - sol2]] I could not simplify Mathematica result to remove the complex result. Even using the assumptions you have.