# Hypergeometric function with large parameters

I need an efficient and accurate method to evaluate hypergeometric ratios of the form:

$$\frac{_{2}F_{1}(a+1,b;c;x)}{_{2}F_{1}(a,b;c;x)}$$

for large positive values of a, b, c. However, if you plot:

Plot[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x]/
Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x], {x, 0, 1}]


you will see that these ratios can be inaccurate in Mathematica.

What can I do?

Using N on exact input avoids the round-off error from calculating the two hypergeometric functions separately. (I stopped before x = 1, since that produces a divide-by-zero error.)

ListLinePlot@
N@Table[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x] /
Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x],
{x, 0, 1 - 1/100, 1/100}]


Alternatively, one could use a relatively high WorkingPrecision:

Plot[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x] /
Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x],
{x, 0, 1}, WorkingPrecision -> 50]


(Pretty much the same graph as above.)

Using one of the three-term recurrences satisfied by ${}_2 F_1$, and exploiting the fact that $a$ and $c$ are integers, here is an implementation of the continued fraction expansion of the hypergeometric function ratio in the OP:

ratio2f1[a_Integer?Positive, b_, c_Integer?Positive, z_] :=
((a (z - 2) - b z + c)/a +
ContinuedFractionK[(a - k - c)/(a - k) (z - 1),
((a - k - 1) (z - 2) - b z + c)/(a - k - 1),
{k, 0, a - 2}])/(z - 1)


This implementation is now quite stable for plotting purposes:

Plot[{Hypergeometric2F1Regularized[601, 1001/10, 100, x]/
Hypergeometric2F1Regularized[600, 1001/10, 100, x],
ratio2f1[600, 1001/10, 100, x]}, {x, 0, 1},
PlotStyle -> {AbsoluteThickness[5], AbsoluteThickness[2]}]


Let me also present an alternative implementation that avoids using ContinuedFractionK[], which may be useful for e.g. making a compiled function. I used the Lentz-Thompson-Barnett algorithm to evaluate the continued fraction:

ratio2f1[a_Integer?Positive, b_, c_Integer?Positive, z_] := Module[{ak, bk, ck, dk, f},
f = ck = (a (z - 2) - b z + c)/a; dk = 0;
Do[ak = (a - k - c)/(a - k) (z - 1);
bk = ((a - k - 1) (z - 2) - b z + c)/(a - k - 1);
dk = 1/(bk + ak dk); ck = bk + ak/ck; f *= ck dk,
{k, 0, a - 2}];
f/(z - 1)]