# Slow Indefinite Integral

This might have been asked before but I couldn't find the answer. I want to perform an indefinite integral. I tried it both on Mathematica and Maple and the commutation time is significantly different. It takes roughly 45 seconds on Mathematica while it's instantaneous with Maple. Could someone give an answer to why this is and how to speed up the computation on Mathematica? Here is the integral:

Integrate[-(1/((1/2 + x) (1.15.048133091869577 - 0.7271265201866038 x -
0.14586605445765533 x^2 - 0.14353734279040942 x^3 -
0.34371764036609265 x^4 + 0.04221841339432375 x^5 -
6.584428946770302 x^6))), x] // Timing


Now I tried to speed it up by using Apart and Distribute like this

-(1/((1/2 + x) (1.15.048133091869577 - 0.7271265201866038 x -
0.14586605445765533 x^2 - 0.14353734279040942 x^3 -
0.34371764036609265 x^4 + 0.04221841339432375 x^5 -
6.584428946770302 x^6)));
Apart[%];
Distribute[Integrate[%, x]] // Timing


But this I had to stop because it was giving me anything after several minutes. The workaround is to Distribute "integrate" and then replace it with Integrate.

-(1/((1/2 + x) (1.15.048133091869577 - 0.7271265201866038 x -
0.14586605445765533 x^2 - 0.14353734279040942 x^3 -
0.34371764036609265 x^4 + 0.04221841339432375 x^5 -
6.584428946770302 x^6)));
Apart[%];
Distribute[integrate[%, x]];
%/. integrate -> Integrate // Timing


And in this case, the computation only takes 0.04 seconds.

Note that all 3 approaches worked just fine on Maple and gave result as soon as I pressed enter.

• I suspect the Distribute[Integrate[...]] is not doing what you intend. Map would get it done quickly. Try e1=...; e2 = Apart[e1];Timing[Map[Integrate[#, x] &, e2]]. Feb 2 '18 at 18:06
• Thanks @DanielLichtblau ! Using Map is much faster. It's actually the fastest approach. I need to remember to use map more often. Feb 5 '18 at 11:54

It's usually better to use exact input for exact solvers:

N@Integrate[
Rationalize[-(1/((1/2 + x) (1.15.048133091869577 -
0.7271265201866038 x - 0.14586605445765533 x^2 -
0.14353734279040942 x^3 - 0.34371764036609265 x^4 +
0.04221841339432375 x^5 - 6.584428946770302 x^6))), 0],
x] // AbsoluteTiming

(*
{0.096958,
-0.820105 Log[0.5 + x] +
0.0546737 (3.10295 Log[-0.627436 + x] + (1.4933 +
1.65819 I) Log[(-0.414587 - 0.597065 I) + x] + (1.4933 -
1.65819 I) Log[(-0.414587 + 0.597065 I) + x] + (1.37539 +
2.17793 I) Log[(0.338503 - 0.691313 I) + x] + (1.37539 -
2.17793 I) Log[(0.338503 + 0.691313 I) + x] +
6.15967 Log[0.773193 + x])}
*)


SetPrecision is a little faster than Rationalize:

N@Integrate[SetPrecision[
-(1/((1/2 + x) (1.15.048133091869577 - 0.7271265201866038 x -
0.14586605445765533 x^2 - 0.14353734279040942 x^3 -
0.34371764036609265 x^4 + 0.04221841339432375 x^5 -
6.584428946770302 x^6))),
Infinity], x] // AbsoluteTiming
(*
{0.059878,
1.80144*10^16 (4.5525*10^-17 (0.206864 Log[-1.25487 + 2 x] +
(0.0995533 + 0.110546 I) Log[(-0.829175 - 1.19413 I) + 2 x] +
(0.0995533 - 0.110546 I) Log[(-0.829175 + 1.19413 I) + 2 x] +
(0.0916924 + 0.145195 I) Log[(0.677006 - 1.38263 I) + 2 x] +
(0.0916924 - 0.145195 I) Log[(0.677006 + 1.38263 I) + 2 x] +
0.410645 Log[1.54639 + 2 x]) - 4.5525*10^-17 Log[1. + 2. x])}
*)
`
• Thanks for the help. That is precisely what I was looking for. Feb 2 '18 at 15:24