How to improve ( mathematica ) performance when dealing with recursive functions?
问题 Background. I want to print a table of convergents for 31^(1/2). I made the following recursive definition of the table. ( Exchange 31^(1/2) with the golden ratio and the table below would contain the Fibonacci series ). cf := ContinuedFraction tf := TableForm p[-1] = 0; p[0] = 1; q[-1] = 1; q[0] = 0; a[k_] := cf[Sqrt[31], k][[k]] p[k_] := a[k]*p[k - 1] + p[k - 2] q[k_] := a[k]*q[k - 1] + q[k - 2] s[n_] := Timing[Table[{k, a[k], p[k], q[k]}, {k, 8, 8 n, 8}]] // tf Timing increases