Problem with evaluation of the integral

I am trying to evaluate the following integral:

Integrate[(1 + k^2)/(2 k Sqrt[1 + k^2 + k^4]) - 1/(2 k ), k]

which does not work. Mathematica is just unable to find the primitive function. However, if I separate this integral into two integrals

Integrate[(1 + k^2)/(2 k Sqrt[1 + k^2 + k^4]), k] + Integrate[-1/(2 k ), k]

Mathematica yields

1/4 (ArcSinh[(1 + 2 k^2)/Sqrt[3]] - Log[2 + k^2 + 2 Sqrt[1 + k^2 + k^4]])

I don't understand why the first formula does not work. Am I missing some conditions or something?

• One possibility is that if you apply FullSimplify to the expression, you can see that it does not remain as two separate terms. Most likely Integrate tries to integrate the combined fullsimplified version rather than the separate terms. – bill s May 20 '17 at 1:59
• – Michael E2 May 20 '17 at 2:00
• I do understand that Mathematica cannot integrate it because it simplifies the expression. However, this is apart of a bigger program, that I am trying to make and I need to get this fixed in a simple way. Is there any way how to tell Mathematica not to simplify expression before the integration is performed? – Versor295 May 20 '17 at 9:53

Here are a few ways that work. These give answers that differ by a constant.

Substitutions

ClearAll[trysub];
SetAttributes[trysub, HoldFirst];
trysub[Integrate[int_, x_], sub_Equal, u_] := Module[{sol, newint},
sol = Solve[sub, x];                                        (* should check Solve *)
newint = int*Dt[x] /. Last[sol] /. Dt[u] -> 1 // Simplify;
Integrate[newint, u] /. Last@Solve[sub, u] // Simplify      (* should check Solve *)
];


Try the expression inside Sqrt:

Assuming[u > 1 && k ∈ Reals,
int1 = trysub[
Integrate[(1 + k^2)/(2 k Sqrt[1 + k^2 + k^4]) - 1/(2 k), k],
1 + k^2 + k^4 == u, u]
]
(*  1/4 (ArcSinh[(1 + 2 k^2)/Sqrt[3]] - Log[4 + 2 k^2 + 4 Sqrt[1 + k^2 + k^4]])  *)


Try the Sqrt (squared):

Assuming[u > 1 && k ∈ Reals,
int2 = trysub[
Integrate[(1 + k^2)/(2 k Sqrt[1 + k^2 + k^4]) - 1/(2 k), k],
1 + k^2 + k^4 == u^2, u]
]
(*
1/4 (-2 Log[1 + Sqrt[1 + k^2 + k^4]] +
Log[(1 + 2 k^2 + 2 Sqrt[1 + k^2 + k^4]) (2 - 2 k^2 + 4 Sqrt[1 + k^2 + k^4])])
*)


Try u = k^2:

Assuming[u > 0 && k ∈ Reals,
int3 = trysub[
Integrate[(1 + k^2)/(2 k Sqrt[1 + k^2 + k^4]) - 1/(2 k), k],
k^2 == u, u]
]
(*  1/4 (ArcSinh[(1 + 2 k^2)/Sqrt[3]] - Log[2 + k^2 + 2 Sqrt[1 + k^2 + k^4]])  *)


Use the real Surd instead of the complex Sqrt.

int4 = Simplify[
Integrate[(1 + k^2)/(2 k Surd[1 + k^2 + k^4, 2]) - 1/(2 k), k],
k ∈ Reals]
(*  1/4 (ArcSinh[(1 + 2 k^2)/Sqrt[3]] - Log[2 + k^2 + 2 Sqrt[1 + k^2 + k^4]])  *)


I believe this works because 1/Sqrt[u] is rewritten as Power[u, -1/2], where as 1/Surd[pu, 2] is unaltered. For an unknown reason (to me), Mathematica fails to come up with a key transformation of the integral in the Sqrt case, but succeeds in the Surd case.