Computing continued fraction

I want to build this infinite continued fraction

$$F_{n}(x)= \cfrac{1}{1-x\cfrac{(n+1)^2}{4(n+1)^2-1}F_{n+1}(x)}$$

which gives for $$n=0$$

$$F_{0}(x)=\cfrac{1}{1-\cfrac{(1/3)x}{1-\cfrac{(4/15)x}{1-\cfrac{(9/35)x}{1-\ddots}}}}$$ I took inspiration from this post by @Michael E2, the problem is that when I transform it as a list representation

{b0,{a1, b1},{a2, b2},...}

Clear[F2,iF2];

iF2[0]=0;
iF2[1]={1,1};
iF2[2]={-x/3,1};
iF2[n_]:={-x(n+1)^2/(4(n+1)^2-1),1};
F2[n_]:=Table[iF2[k],{k,0,n}];


I can't find all the terms, so I find for 5 terms

Block[{n=5},F2[n]]
(*{0,{1,1},{-x/3,1},{-16x/63,1},{-25x/99,1},{-36x/143,1}}*)


it lacks after {$$-x/3,1$$} the terms {$$-4x/15,1$$} and {$$-9x/35,1$$}

• In your definition you should change + to -, that is iF2[n_]:={-x(n-1)^2/(4(n-1)^2-1),1}; Jul 6, 2019 at 14:18

It is unfortunate that Mathematica does not provide for something like an NContinuedFractionK[] function. Nevertheless, we can use something like the Lentz-Thompson-Barnett algorithm to numerically evaluate $$F_n(x)$$ (equivalently, 1/(1 + ContinuedFractionK[(k + n)^2/(1 - 4 (k + n)^2) x, 1, {k, 1, ∞}])):

gallagherF[n_, x_] /; Precision[{n, x}] < ∞ := Module[{a, c, d, e2, ee, f, h, k, t},
ee = 10^(-Precision[{n, x}]); e2 = ee^2;
f = c = 1; d = 0; k = 0;
While[k++;
t = (k + n)^2; a = x t/(1 - 4 t);
d = 1 + a d; If[d == 0, d = e2]; d = 1/d;
c = 1 + a/c; If[c == 0, c = e2];
f *= (h = c d);
Abs[h - 1] > ee];
1/f]


Let's look at a few plots:

Plot[Table[gallagherF[n, x], {n, 0, 4}], {x, -2, 1}, Evaluated -> True]


Plot3D[Im[gallagherF[1/2, x + I y]], {x, -5, 1}, {y, -3, 3},
Mesh -> None, PlotPoints -> 45]


You could use Nest to compute the continued fraction:

Nest [# /. F[n_] :> 1/(1 - x (n + 1)^2/(4 (n + 1)^2 - 1) F[n + 1]) &, F[0], 5]
(*1/(1 - x/(3 (1 - (4 x)/(15 (1 - (9 x)/(35 (1 - (16x)/(63 (1 - 25/99 x F[5])))))))))*)

• @Ulrich_Neumann, how to get the value for n=200000? Aug 31, 2019 at 18:55
• @Gallagher Just replace "5" by "200000" ...But I'm afraid, wether Mathematica ever finishs the analytical calculation Sep 1, 2019 at 9:41