# Mathematica Kernel crashes when evaluating Limit[ recursive function ]

GROUPS:
 f[n_] := If[n == 1, 1, Sqrt[3 f[n - 1] - 1]]Limit[f[n], n -> Infinity]Evaluating these two lines makes the Mathematica 8.0 kernel crash.
4 years ago
10 Replies
 duplicated here with 8.0.4 and 9.0.1 on Macintosh. In[1]:= f[n_] := If[n == 1, 1, Sqrt[3 f[n - 1] - 1]]In[2]:= Limit[f[n], n -> Infinity]Segmentation faultA dubious input, but the Kernel should not crash.
4 years ago
 Marco Thiel 1 Vote I don't get a segmentation fault on a Mac and Mathematica 9.0.1, but the limit does not evaluate either. I can, however, evaluate for examplef[n_] := Sqrt[3 f[n - 1] - 1]f[1] = 1;N[f[100], 20]and then useWolframAlpha[ToString[N[f[100], 20]], IncludePods -> "PossibleClosedForm"]That gives the result.
4 years ago
 I used the Mathematica Kernel directly, so the error message showed. In the Mathematica FrontEnd, the message does not come through.
4 years ago
 Udo Krause 1 Vote If you do this right, it will not crash In[22]:= Remove[weitzerF] weitzerF[n_?Positive] := weitzerF[n] = Sqrt[3 weitzerF[n - 1] - 1] weitzerF[1] = 1;  In[30]:= Limit[weitzerF[o], o -> \[Infinity]] Out[30]= Limit[weitzerF[o], o -> \[Infinity]]  In[31]:= Limit[N[weitzerF[o]], o -> \[Infinity]] Out[31]= Limit[weitzerF[o], o -> \[Infinity]]In[32]:= \$VersionOut[32]= "9.0 for Microsoft Windows (64-bit) (January 25, 2013)"but it does also not deliver a result. Therefore, if you do it even more right, you see that the very recursive nature of the weitzerF[] function tends to the usage of FixedPoint[] In[43]:= weitzerF[1] Out[43]= 1  In[44]:= weitzerF[2] Out[44]= Sqrt[2]  In[45]:= weitzerF[3] Out[45]= Sqrt[-1 + 3 Sqrt[2]] In[46]:= weitzerF[4]Out[46]= Sqrt[-1 + 3 Sqrt[-1 + 3 Sqrt[2]]]and here is the limitIn[53]:= FixedPoint[N[Sqrt[-1 + 3 #], 53] &, Sqrt[-1 + 3 Sqrt[2]]]Out[53]= 2.6180339887498948482045868343656381177203091798057628Your original construction was misleading the kernel: The If[] contains a recursive function while n tends to infinity while nothing evaluates to a numerical value! Bad luck. Nonetheless the kernel should not crash and with newer versions it doesn't.
4 years ago
 Daniel Lichtblau 2 Votes You can get candidates for the limit simply by solving an equation for it.In[83]:= candidates = limF /. Solve[limF == Sqrt[3*limF - 1], limF]Out[83]= {1/2 (3 - Sqrt[5]), 1/2 (3 + Sqrt[5])}The crash has been fixed for a future release. It will instead return unevaluated, as it should.
4 years ago
 I think the main problem is, is that Limit will not go exactly over the integers. So it will never stop by the f[1] definition, because it might be f[1.56] or so that will be evaluated. The answer of Daniel is much more practical, and the correct way of solving this in my view.
4 years ago
 Udo Krause 2 Votes In[18]:= RootApproximant[FixedPoint[N[Sqrt[-1 + 3 #], 53] &, Sqrt[-1 + 3 Sqrt[2]]], 2]Out[18]= 1/2 (3 + Sqrt[5])