# Why adding TimeConstrained to Integrate causes TerminatedEvaluation["RecursionLimit"]?

in Version 13.2.1, calling Integrate works on this integral, and gives result almost immediately in few seconds (result is wrong, it says zero, but that is besides the point).

When adding TimeConstrained, now an error is generated and session terminates.

Compare to version 13.1, where adding TimeConstrained causes no such error.

The question is: Why adding TimeConstrained gives error and not same result without? And is there a workaround?

Notice that 13.1 result is not zero for same integral.

13.2.1 on windows 10.

## Code

ClearAll[x]
integrand = (4335 +
289*x + (-289*x + 5*x^2)*Log[(-289 + 5*x)/x]*
Log[Log[(-289 + 5*x)/x]])/((-289*x + 5*x^2)*Log[(-289 + 5*x)/x]);
Integrate[integrand, x]
TimeConstrained[Integrate[integrand, x], 60*3]


## More examples found

All examples below show the same exact problem as the above. So will only give the integrands to save space.

integrand = (((-3)*x^3 + 6*x^2 + 15*x + (-30))*
Log[((-4)*x^2 + 20)/(x^2)] + ((-30)*x + (-60)))/((4*x^5 +
24*x^4 + 28*x^3 + (-88)*x^2 + (-240)*x + (-160))*
Log[((-4)*x^2 + 20)/(x^2)]^2)

integrand = ((3*x + (-6))*Log[(((-1)*x + 2)*Exp[1])/x] +
2*x)/((x^3 + (-2)*x^2)*Log[(((-1)*x + 2)*Exp[1])/x])

integrand = (3*Exp[Log[4]^8]*
Log[Log[2]] + (3*Exp[Log[4]^8]*Log[x] + ((-8)*x + (-3))*
Exp[Log[4]^8]*Log[(8*x + 3)/x]))/((8*x^2 + 3*x)*
Log[(8*x + 3)/x]^2*Log[Log[2]]^2 + (16*x^2 + 6*x)*
Log[(8*x + 3)/x]^2*Log[x]*Log[Log[2]] + (8*x^2 + 3*x)*
Log[(8*x + 3)/x]^2*Log[x]^2)

integrand = (((-48)*x^5 + 16*x^4 + 225*x + (-75))*
Log[((-3)*x + 1)/x] + (16*x^4 + (-64)*x^3 +
25))/((48*x^5 + (-16)*x^4)*Log[((-3)*x + 1)/x]^2)

integrand = ((8*x + 4)*Log[(4*x + 2)/x] +
x)/((2*x^3 + x^2)*Log[(4*x + 2)/x]*
Log[Log[(4*x + 2)/x]]^2 + (16*x^2 + 8*x)*Log[(4*x + 2)/x]*
Log[Log[(4*x + 2)/x]] + (32*x + 16)*Log[(4*x + 2)/x])

integrand=((4*x^3+8*x^2+(-4)*x+(-8))*Log[(x+1)/x]^2+x)/((x^3+x^2)*Log[(x+1)/x]^2)

integrand = ((5*x*Exp[(-1)*Log[x] + 1] + (-25)*x)*Exp[5*Log[2*x + 2]]*
Log[(-1)*Exp[(-1)*Log[x] + 1] + 5]*
Log[Log[(-1)*Exp[(-1)*Log[x] + 1] + 5]] + (((-1)*x + (-1))*
Exp[(-1)*Log[x] + 1]*Exp[5*Log[2*x + 2]] + (x + 1)*Exp[16]*
Exp[(-1)*Log[x] + 1]))/(((x^2 + x)*
Exp[(-1)*Log[x] + 1] + ((-5)*x^2 + (-5)*x))*
Log[(-1)*Exp[(-1)*Log[x] + 1] + 5])

integrand = ((10*x + (-10))*Log[(x + (-1))/(2*x)]*
Log[x] + ((10*x^3 + (-10)*x^2)*
Log[(x + (-1))/(2*x)] + (-5)))/((x^2 + (-1)*x)*
Log[(x + (-1))/(2*x)])

integrand = (((-3)*x^2 + 6*x + (-3))*Exp[x]*Log[((-1)*x + 1)/x] +
3*Exp[x])/((x^3 + (-1)*x^2)*Exp[1]*Log[((-1)*x + 1)/x]^2)


The following examples are different from all the above, in that Integrate[integrand, x] does not give zero, but adding TimeConstrained still gives TerminatedEvaluation["RecursionLimit"]

Code

integrand = (((x + 13)*Log[5] + (x^3 + 13*x^2 + x + 13))*
Log[(3*x + 39)/x]^2 + (x^3 + 13*x^2)*Log[(3*x + 39)/x] +
13*x^2)/((x^3 + 13*x^2)*Log[(3*x + 39)/x]^2)
Integrate[integrand, x]
TimeConstrained[Integrate[integrand, x], 60]


Code

integrand = ((2*x^4*Exp[2] + 2*x^5)*
Log[(12*Exp[2] + 12*x)/x]^4 + (-4)*x^4*Exp[2]*
Log[(12*Exp[2] + 12*x)/x]^3 + (2*x^3*Exp[2] + 2*x^4)*
Log[(12*Exp[2] + 12*x)/x]^2 + (4*x^2*Exp[2]*Log[3] + (-4)*x^3*
Exp[2])*Log[(12*Exp[2] + 12*x)/x] + (((-2)*Exp[2] + (-2)*x)*
Log[3]^2 + (2*x*Exp[2] + 2*x^2)*Log[3]))/(x^3*Exp[2] + x^4)
Integrate[integrand, x]
TimeConstrained[Integrate[integrand, x], 60]


ps. in case this is a new bug, I also just send email to Wolfram support. Case ID [CASE:5023223]

• Perhaps not in order of importance, but (1) Regarding "[R]result is wrong, it says zero, but that is besides the point" I would say instead that this is a separate bug (or bugs), also quite important, but outside the scope of this question. (2) Regarding "When adding TimeConstrained, now an error is generated and session terminates", this is not actually what a terminated evaluation does. A session ending is generally taken to mean either kernel or all of Mathematica has crashed. More to come. Commented Apr 21, 2023 at 15:09
• (3) Offhand I do not know what was the cause of these issues, but it appears that all of them are fixed for version 13.3. (4) Those last two examples, while not returning 0, are giving results that are not correct. The first has been corrected in 13.3. The second returns unevaluated in 13.3. So this does seem like progress. (5) I suspect the 0 results were a bad side-effect of some fixes to indefinite integration. Not sure why the terminated evaluations have appeared. Commented Apr 21, 2023 at 15:13
• And (6) I apologize for these problems having appeared in 13.2. It's a lesson in humility I guess. (for me, not you or other users). Commented Apr 21, 2023 at 15:15

\$Version

(* "13.2.1 for Mac OS X x86 (64-bit) (January 27, 2023)" *)

Clear["Global*"]

integrand = (4335 + 289*x + (-289*x + 5*x^2)*
Log[(-289 + 5*x)/x]*
Log[Log[(-289 + 5*x)/x]])/
((-289*x + 5*x^2)*Log[(-289 + 5*x)/x]);


The TerminatedEvaluation[RecursionLimit] arises without specifying a time constraint using other approaches.

Assuming[x > 0, Integrate[integrand, x]]

(* TerminatedEvaluation["RecursionLimit"] *)

Assuming[x < 0, Integrate[integrand, x]]

(* TerminatedEvaluation["RecursionLimit"] *)

Assuming[x != 0, Integrate[integrand, x]]

(* TerminatedEvaluation["RecursionLimit"] *)

Integrate[#, x] & /@ Simplify[integrand]

(* 289 ∫(15 + x)/(x (-289 + 5 x) Log[5 - 289/x]) \[DifferentialD]x +
TerminatedEvaluation["RecursionLimit"] *)

Integrate[#, x] & /@ Expand[integrand]

(* -289 ∫(
x Log[Log[(-289 + 5 x)/x]])/(-289 x + 5 x^2) \[DifferentialD]x +
5 ∫(
x^2 Log[Log[(-289 + 5 x)/x]])/(-289 x + 5 x^2) \[DifferentialD]x +
2 TerminatedEvaluation["RecursionLimit"] *)

Integrate[#, x] & /@ (Simplify /@ Expand[integrand])

(* -289 ∫Log[Log[5 - 289/x]]/(-289 + 5 x) \[DifferentialD]x +
5 ∫(x Log[Log[5 - 289/x]])/(-289 + 5 x) \[DifferentialD]x +
2 TerminatedEvaluation["RecursionLimit"] *)
`