NAG Library Routine Document

1Purpose

s22bff returns a value for the Gauss hypergeometric function ${}_{2}F_{1}\left(a,b;c;x\right)$ for real parameters $a,b$ and $c$, and real argument $x$. The result is returned in the scaled form ${}_{2}F_{1}\left(a,b;c;x\right)={f}_{\mathrm{fr}}×{2}^{{f}_{\mathrm{sc}}}$.

2Specification

Fortran Interface
 Subroutine s22bff ( ani, adr, bni, bdr, cni, cdr, x, frf, scf,
 Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: scf Real (Kind=nag_wp), Intent (In) :: ani, adr, bni, bdr, cni, cdr, x Real (Kind=nag_wp), Intent (Out) :: frf
#include <nagmk26.h>
 void s22bff_ (const double *ani, const double *adr, const double *bni, const double *bdr, const double *cni, const double *cdr, const double *x, double *frf, Integer *scf, Integer *ifail)

3Description

s22bff returns a value for the Gauss hypergeometric function ${}_{2}F_{1}\left(a,b;c;x\right)$ for real parameters $a$, $b$ and $c$, and for real argument $x$.
The Gauss hypergeometric function is a solution to the hypergeometric differential equation,
 $x1-x d2 f dx2 + c- a+b+1 x d f dx - ab f = 0 .$ (1)
For $\left|x\right|<1$, it may be defined by the Gauss series,
 $F1 2 a,b;c;x = ∑ s=0 ∞ as bs cs s! xs = 1+ ab c x + aa+1 bb+1 cc+1 2! x2 + ⋯ ,$ (2)
where ${\left(a\right)}_{s}=1\left(a\right)\left(a+1\right)\left(a+2\right)\dots \left(a+s-1\right)$ is the rising factorial of $a$. ${}_{2}F_{1}\left(a,b;c;x\right)$ is undefined for $c=0$ or $c$ a negative integer.
For $\left|x\right|<1$, the series is absolutely convergent and ${}_{2}F_{1}\left(a,b;c;x\right)$ is finite.
For $x<1$, linear transformations of the form,
 $F1 2 a,b;c;x = C1 a1,b1,c1,x1 F1 2 a1, b1 ;c1;x1 + C2 a2,b2,c2,x2 F1 2 a2, b2 ;c2;x2$ (3)
exist, where ${x}_{1}$, ${x}_{2}\in \left(0,1\right]$. ${C}_{1}$ and ${C}_{2}$ are real valued functions of the parameters and argument, typically involving products of gamma functions. When these are degenerate, finite limiting cases exist. Hence for $x<0$, ${}_{2}F_{1}\left(a,b;c;x\right)$ is defined by analytic continuation, and for $x<1$, ${}_{2}F_{1}\left(a,b;c;x\right)$ is real and finite.
For $x=1$, the following apply:
• If $c>a+b$, ${}_{2}F_{1}\left(a,b;c;1\right)=\frac{\Gamma \left(c\right)\Gamma \left(c-a-b\right)}{\Gamma \left(c-a\right)\Gamma \left(c-b\right)}$, and hence is finite. Solutions also exist for the degenerate cases where $c-a$ or $c-b$ are negative integers or zero.
• If $c\le a+b$, ${}_{2}F_{1}\left(a,b;c;1\right)$ is infinite, and the sign of ${}_{2}F_{1}\left(a,b;c;1\right)$ is determinable as $x$ approaches $1$ from below.
In the complex plane, the principal branch of ${}_{2}F_{1}\left(a,b;c;z\right)$ is taken along the real axis from $x=1.0$ increasing. ${}_{2}F_{1}\left(a,b;c;z\right)$ is multivalued along this branch, and for real parameters $a,b$ and $c$ is typically not real valued. As such, this routine will not compute a solution when $x>1$.
The solution strategy used by this routine is primarily dependent upon the value of the argument $x$. Once trivial cases and the case $x=1.0$ are eliminated, this proceeds as follows.
For $0, sets of safe parameters $\left\{{\alpha }_{i,j},{\beta }_{i,j},{\zeta }_{i,j},{\chi }_{j}\left|1\le j\le 2\right|,1\le i\le 4\right\}$ are determined, such that the values of ${}_{2}F_{1}\left({a}_{j},{b}_{j};{c}_{j};{x}_{j}\right)$ required for an appropriate transformation of the type (3) may be calculated either directly or using recurrence relations from the solutions of ${}_{2}F_{1}\left({\alpha }_{i,j},{\beta }_{i,j};{\zeta }_{i,j};{\chi }_{j}\right)$. If $c$ is positive, then only transformations with ${C}_{2}=0.0$ will be used, implying only ${}_{2}F_{1}\left({a}_{1},{b}_{1};{c}_{1};{x}_{1}\right)$ will be required, with the transformed argument ${x}_{1}=x$. If $c$ is negative, in some cases a transformation with ${C}_{2}\ne 0.0$ will be used, with the argument ${x}_{2}=1.0-x$. The routine then cycles through these sets until acceptable solutions are generated. If no computation produces an accurate answer, the least inaccurate answer is selected to complete the computation. See Section 7.
For $0.5, an identical approach is first used with the argument $x$. Should this fail, a linear transformation resulting in both transformed arguments satisfying ${x}_{j}=1.0-x$ is employed, and the above strategy for $0 is utilized on both components. Further transformations in these sub-computations are however, limited to single terms with no argument transformation.
For $x<0$, a linear transformation mapping the argument $x$ to the interval $\left(0,0.5\right]$ is first employed. The strategy for $0 is then used on each component, including possible further two term transforms. To avoid some degenerate cases, a transform mapping the argument $x$ to $\left[0.5,1\right)$ may also be used.
For improved precision in the final result, this routine accepts $a,b$ and $c$ split into an integral and a decimal fractional component. Specifically, $a={a}_{i}+{a}_{r}$, where $\left|{a}_{r}\right|\le 0.5$ and ${a}_{i}=a-{a}_{r}$ is integral. The other parameters $b$ and $c$ are similarly deconstructed.
In addition to the above restrictions on $c$ and $x$, an artificial bound, arbnd, is placed on the magnitudes of $a,b,c$ and $x$ to minimize the occurrence of overflow in internal calculations, particularly those involving real to integer conversions. $\mathit{arbnd}=0.0001×{I}_{\mathrm{max}}$, where ${I}_{\mathrm{max}}$ is the largest machine integer (see x02bbf). It should however, not be assumed that this routine will produce accurate answers for all values of $a,b,c$ and $x$ satisfying this criterion.
This routine also tests for non-finite values of the parameters and argument on entry, and assigns non-finite values upon completion if appropriate. See Section 9 and Chapter X07.
Please consult the NIST Digital Library of Mathematical Functions for a detailed discussion of the Gauss hypergeometric function including special cases, transformations, relations and asymptotic approximations.

4References

NIST Digital Library of Mathematical Functions
Pearson J (2009) Computation of hypergeometric functions MSc Dissertation, Mathematical Institute, University of Oxford

5Arguments

1:     $\mathbf{ani}$ – Real (Kind=nag_wp)Input
On entry: ${a}_{i}$, the nearest integer to $a$, satisfying ${a}_{i}=a-{a}_{r}$.
Constraints:
• ${\mathbf{ani}}=⌊{\mathbf{ani}}⌋$;
• $\left|{\mathbf{ani}}\right|\le \mathit{arbnd}$.
2:     $\mathbf{adr}$ – Real (Kind=nag_wp)Input
On entry: ${a}_{r}$, the signed decimal remainder satisfying ${a}_{r}=a-{a}_{i}$ and $\left|{a}_{r}\right|\le 0.5$.
Constraint: $\left|{\mathbf{adr}}\right|\le 0.5$.
3:     $\mathbf{bni}$ – Real (Kind=nag_wp)Input
On entry: ${b}_{i}$, the nearest integer to $b$, satisfying ${b}_{i}=b-{b}_{r}$.
Constraints:
• ${\mathbf{bni}}=⌊{\mathbf{bni}}⌋$;
• $\left|{\mathbf{bni}}\right|\le \mathit{arbnd}$.
4:     $\mathbf{bdr}$ – Real (Kind=nag_wp)Input
On entry: ${b}_{r}$, the signed decimal remainder satisfying ${b}_{r}=b-{b}_{i}$ and $\left|{b}_{r}\right|\le 0.5$.
Constraint: $\left|{\mathbf{bdr}}\right|\le 0.5$.
5:     $\mathbf{cni}$ – Real (Kind=nag_wp)Input
On entry: ${c}_{i}$, the nearest integer to $c$, satisfying ${c}_{i}=c-{c}_{r}$.
Constraints:
• ${\mathbf{cni}}=⌊{\mathbf{cni}}⌋$;
• $\left|{\mathbf{cni}}\right|\le \mathit{arbnd}$;
• if $\left|{\mathbf{cdr}}\right|<16.0\epsilon$, ${\mathbf{cni}}\ge 1.0$.
6:     $\mathbf{cdr}$ – Real (Kind=nag_wp)Input
On entry: ${c}_{r}$, the signed decimal remainder satisfying ${c}_{r}=c-{c}_{i}$ and $\left|{c}_{r}\right|\le 0.5$.
Constraint: $\left|{\mathbf{cdr}}\right|\le 0.5$.
7:     $\mathbf{x}$ – Real (Kind=nag_wp)Input
On entry: the argument $x$.
Constraint: $-\mathit{arbnd}<{\mathbf{x}}\le 1$.
8:     $\mathbf{frf}$ – Real (Kind=nag_wp)Output
On exit: ${f}_{\mathrm{fr}}$, the scaled real component of the solution satisfying ${f}_{\mathrm{fr}}={}_{2}F_{1}\left(a,b;c;x\right)×{2}^{-{f}_{\mathrm{sc}}}$, i.e., ${}_{2}F_{1}\left(a,b;c;x\right)={f}_{\mathrm{fr}}×{2}^{{f}_{\mathrm{sc}}}$. See Section 9 for the behaviour of ${f}_{\mathrm{fr}}$ when a finite or non-finite answer is returned.
9:     $\mathbf{scf}$ – IntegerOutput
On exit: ${f}_{\mathrm{sc}}$, the scaling power of two, satisfying ${f}_{\mathrm{sc}}={\mathrm{log}}_{2}\left(\frac{{}_{2}F_{1}\left(a,b;c;x\right)}{{f}_{\mathrm{fr}}}\right)$, i.e., ${}_{2}F_{1}\left(a,b;c;x\right)={f}_{\mathrm{fr}}×{2}^{{f}_{\mathrm{sc}}}$. See Section 9 for the behaviour of ${f}_{\mathrm{sc}}$ when a non-finite answer is returned.
10:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value  is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value  is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
Underflow occurred during the evaluation of ${}_{2}F_{1}\left(a,b;c;x\right)$. The returned value may be inaccurate.
${\mathbf{ifail}}=2$
All approximations have completed, and the final residual estimate indicates some precision may have been lost.
$\text{Relative residual}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=3$
All approximations have completed, and the final residual estimate indicates no accuracy can be guaranteed.
$\text{Relative residual}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$, $c=〈\mathit{\text{value}}〉$, $a+b=〈\mathit{\text{value}}〉$.
${}_{2}F_{1}\left(a,b;c;1\right)$ is infinite in the case $c\le a+b$.
${\mathbf{ifail}}=5$
On completion, overflow occurred in the evaluation of ${}_{2}F_{1}\left(a,b;c;x\right)$.
${\mathbf{ifail}}=6$
Overflow occurred in a subcalculation of ${}_{2}F_{1}\left(a,b;c;x\right)$. The answer may be completely incorrect.
${\mathbf{ifail}}=9$
An internal calculation has resulted in an undefined result.
${\mathbf{ifail}}=11$
On entry, ani does not satisfy $\left|{\mathbf{ani}}\right|\le \mathit{arbnd}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=13$
ani is non-integral.
On entry, ${\mathbf{ani}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ani}}=⌊{\mathbf{ani}}⌋$.
${\mathbf{ifail}}=21$
On entry, adr does not satisfy $\left|{\mathbf{adr}}\right|\le 0.5$.
${\mathbf{ifail}}=31$
On entry, bni does not satisfy $\left|{\mathbf{bni}}\right|\le \mathit{arbnd}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=33$
bni is non-integral.
On entry, ${\mathbf{bni}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bni}}=⌊{\mathbf{bni}}⌋$.
${\mathbf{ifail}}=41$
On entry, bdr does not satisfy $\left|{\mathbf{bdr}}\right|\le 0.5$.
${\mathbf{ifail}}=51$
On entry, cni does not satisfy $\left|{\mathbf{cni}}\right|\le \mathit{arbnd}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=52$
On entry, $c={\mathbf{cni}}+{\mathbf{cdr}}=〈\mathit{\text{value}}〉$.
${}_{2}F_{1}\left(a,b;c;x\right)$ is undefined when $c$ is zero or a negative integer.
${\mathbf{ifail}}=53$
cni is non-integral.
On entry, ${\mathbf{cni}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cni}}=⌊{\mathbf{cni}}⌋$.
${\mathbf{ifail}}=61$
On entry, cdr does not satisfy $\left|{\mathbf{cdr}}\right|\le 0.5$.
${\mathbf{ifail}}=71$
On entry, x does not satisfy $\left|{\mathbf{x}}\right|\le \mathit{arbnd}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=72$
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
In general, ${}_{2}F_{1}\left(a,b;c;x\right)$ is not real valued when $x>1$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7Accuracy

In general, if ${\mathbf{ifail}}={\mathbf{0}}$, the value of ${}_{2}F_{1}\left(a,b;c;x\right)$ may be assumed accurate, with the possible loss of one or two decimal places. Assuming the result does not overflow, an error estimate $\mathit{res}$ is made internally using equation (1). If the magnitude of this residual $\mathit{res}$ is sufficiently large, a nonzero ifail will be returned. Specifically,
 ${\mathbf{ifail}}={\mathbf{0}}$ or ${\mathbf{1}}$ $\mathit{res}\le 1000\epsilon$ ${\mathbf{ifail}}={\mathbf{2}}$ $1000\epsilon <\mathit{res}\le 0.1$ ${\mathbf{ifail}}={\mathbf{3}}$ $\mathit{res}>0.1$
where $\epsilon$ is the machine precision as returned by x02ajf. Note that underflow may also have occurred if ${\mathbf{ifail}}={\mathbf{2}}$ or ${\mathbf{3}}$.
A further estimate of the residual can be constructed using equation (1), and the differential identity,
 $d F 1 2 a,b;c;x dx = ab c F 1 2 a+1, b+1 ;c+1;x d2 F 1 2 a,b;c;x dx2 = aa+1 bb+1 cc+1 F 1 2 a+2, b+2 ;c+2;x$ (4)
This estimate is however, dependent upon the error involved in approximating ${}_{2}F_{1}\left(a+1,b+1;c+1;x\right)$ and ${}_{2}F_{1}\left(a+2,b+2;c+2;x\right)$.

8Parallelism and Performance

s22bff is not threaded in any implementation.

s22bff returns non-finite values when appropriate. See Chapter X07 for more information on the definitions of non-finite values.
Should a non-finite value be returned, this will be indicated in the value of ifail, as detailed in the following cases.
If ${\mathbf{ifail}}={\mathbf{0}}$ or ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$ or ${\mathbf{3}}$, a finite value will have been returned with approximate accuracy as detailed in Section 7.
The values of ${f}_{fr}$ and ${f}_{sc}$ are implementation dependent. In most cases, if ${}_{2}F_{1}\left(a,b;c;x\right)=0$, ${f}_{fr}=0$ and ${f}_{sc}=0$ will be returned, and if ${}_{2}F_{1}\left(a,b;c;x\right)$ is finite, the fractional component will be bound by $0.5\le \left|{f}_{fr}\right|<1$, with ${f}_{sc}$ chosen accordingly.
The values returned in frf (${f}_{\mathrm{fr}}$) and scf (${f}_{\mathrm{sc}}$) may be used to explicitly evaluate ${}_{2}F_{1}\left(a,b;c;x\right)$, and may also be used to evaluate products and ratios of multiple values of ${}_{2}F_{1}$ as follows,
 $F 1 2 a,b;c;x = ffr × 2 fsc F 1 2 a1, b1 ;c1;x1 × F 1 2 a2, b2 ;c2;x2 = ffr1 × ffr2 × 2 fsc1 + fsc2 F 1 2 a1, b1 ;c1;x1 F 1 2 a2, b2 ;c2;x2 = ffr1 ffr2 × 2 fsc1 - fsc2 ln F 1 2 a,b;c;x = lnffr + fsc × ln2 .$
If ${\mathbf{ifail}}={\mathbf{4}}$ then ${}_{2}F_{1}\left(a,b;c;x\right)$ is infinite. A signed infinity will have been returned for frf, and ${\mathbf{scf}}=0$. The sign of frf should be correct when taking the limit as $x$ approaches $1$ from below.
If ${\mathbf{ifail}}={\mathbf{5}}$ then upon completion, $\left|{}_{2}F_{1}\left(a,b;c;x\right)\right|>{2}^{{I}_{\mathrm{max}}}$, where ${I}_{\mathrm{max}}$ is given by x02bbf, and hence is too large to be representable even in the scaled form. The scaled real component returned in frf may still be correct, whilst ${\mathbf{scf}}={I}_{\mathrm{max}}$ will have been returned.
If ${\mathbf{ifail}}={\mathbf{6}}$ then overflow occurred during a subcalculation of ${}_{2}F_{1}\left(a,b;c;x\right)$. The same result as for ${\mathbf{ifail}}={\mathbf{5}}$ will have been returned, however, there is no guarantee that this is representative of either the magnitude of the scaling power ${f}_{\mathrm{sc}}$, or the scaled component ${f}_{\mathrm{fr}}$ of ${}_{2}F_{1}\left(a,b;c;x\right)$.
For all other error exits, ${\mathbf{scf}}=0$ will be returned and frf will be returned as a signalling NaN (see x07bbf).
If ${\mathbf{ifail}}={\mathbf{9}}$ an internal computation produced an undefined result. This may occur when two terms overflow with opposite signs, and the result is dependent upon their summation for example.
If ${\mathbf{ifail}}={\mathbf{52}}$ then $c$ is too close to a negative integer or zero on entry, and ${}_{2}F_{1}\left(a,b;c;x\right)$ is undefined. Note, this will also be the case when $c$ is a negative integer, and a (possibly trivial) linear transformation of the form (3) would result in either:
 (i) all ${c}_{j}$ not being negative integers, (ii) for any ${c}_{j}$ which remain as negative integers, one of the corresponding parameters ${a}_{j}$ or ${b}_{j}$ is a negative integer of magnitude less than ${c}_{j}$.
In the first case, the transformation coefficients ${C}_{j}\left({a}_{j},{b}_{j},{c}_{j},{x}_{j}\right)$ are typically either infinite or undefined, preventing a solution being constructed. In the second case, the series (2) will terminate before the degenerate term, resulting in a polynomial of fixed degree, and hence potentially a finite solution.
If ${\mathbf{ifail}}={\mathbf{11}}$, ${\mathbf{31}}$, ${\mathbf{51}}$ or ${\mathbf{71}}$ then no computation will have been performed due to the risk of integer overflow. The actual solution may however, be finite.
${\mathbf{ifail}}={\mathbf{72}}$ indicates $x>1$, and hence the requested solution is on the boundary of the principal branch of ${}_{2}F_{1}\left(a,b;c;x\right)$. Hence it is multivalued, typically with a nonzero imaginary component. It is however, strictly finite.

10Example

This example evaluates the Gauss hypergeometric function at two points in scaled form using s22bff, and subsequently calculates their product and ratio implicitly.

10.1Program Text

Program Text (s22bffe.f90)

None.

10.3Program Results

Program Results (s22bffe.r)