NAG CL Interface
s22bec (hyperg_gauss_real)
1
Purpose
s22bec 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$.
2
Specification
double 
s22bec (double a,
double b,
double c,
double x,
NagError *fail) 

The function may be called by the names: s22bec, nag_specfun_hyperg_gauss_real or nag_specfun_2f1_real.
3
Description
s22bec 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 associated function
s22bfc performs the same operations, but returns
${}_{2}F_{1}\left(a,b;c;x\right)$ in the scaled form
${}_{2}F_{1}\left(a,b;c;x\right)={f}_{\mathrm{fr}}\times {2}^{{f}_{\mathrm{sc}}}$ to allow calculations to be performed when
${}_{2}F_{1}\left(a,b;c;x\right)$ is not representable as a single working precision number. It also accepts the parameters
$a$,
$b$ and
$c$ as summations of an integer and a decimal fraction, giving higher accuracy when any are close to an integer.
The Gauss hypergeometric function is a solution to the hypergeometric differential equation,
For
$\leftx\right<1$, it may be defined by the Gauss series,
where
${\left(a\right)}_{s}=1\left(a\right)\left(a+1\right)\left(a+2\right)\dots \left(a+s1\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 $\leftx\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,
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(cab\right)}{\Gamma \left(ca\right)\Gamma \left(cb\right)}$, and hence is finite. Solutions also exist for the degenerate cases where $ca$ or $cb$ 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 function will not compute a solution when $x>1$.
The solution strategy used by this function 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<x\le 0.5$, sets of safe parameters
$\left\{{\alpha}_{i,j};{\beta}_{i,j};{\zeta}_{i,j};{\chi}_{j}\left1\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.0x$. The function 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<x<1.0$, 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.0x$ is employed, and the above strategy for $0<x\le 0.5$ is utilized on both components. Further transformations in these subcomputations 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<x\le 0.5$ 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.
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\times {I}_{\mathrm{max}}$, where
${I}_{\mathrm{max}}$ is the largest machine integer (see
X02BBC). It should however, not be assumed that this function will produce accurate answers for all values of
$a,b,c$ and
$x$ satisfying this criterion.
This function also tests for nonfinite values of the parameters and argument on entry, and assigns nonfinite 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.
4
References
Pearson J (2009) Computation of hypergeometric functions MSc Dissertation, Mathematical Institute, University of Oxford
5
Arguments

1:
$\mathbf{a}$ – double
Input

On entry: the parameter $a$.
Constraint:
$\left{\mathbf{a}}\right\le \mathit{arbnd}$.

2:
$\mathbf{b}$ – double
Input

On entry: the parameter $b$.
Constraint:
$\left{\mathbf{b}}\right\le \mathit{arbnd}$.

3:
$\mathbf{c}$ – double
Input

On entry: the parameter $c$.
Constraints:
 $\left{\mathbf{c}}\right\le \mathit{arbnd}$;
 ${\mathbf{c}}\ne 0,1,2,\dots $.

4:
$\mathbf{x}$ – double
Input

On entry: the argument $x$.
Constraint:
$\mathit{arbnd}<{\mathbf{x}}\le 1$.

5:
$\mathbf{fail}$ – NagError *
Input/Output

The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
 NE_CANNOT_CALCULATE

An internal calculation has resulted in an undefined result.
 NE_COMPLEX

On entry, ${\mathbf{x}}=\u2329\mathit{\text{value}}\u232a$.
In general, ${}_{2}F_{1}\left(a,b;c;x\right)$ is not real valued when $x>1$.
 NE_INFINITE

On entry, ${\mathbf{x}}=\u2329\mathit{\text{value}}\u232a$, $c=\u2329\mathit{\text{value}}\u232a$, $a+b=\u2329\mathit{\text{value}}\u232a$.
${}_{2}F_{1}\left(a,b;c;1\right)$ is infinite in the case $c\le a+b$.
 NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
 NE_NO_LICENCE

Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
 NE_OVERFLOW

Overflow occurred in a subcalculation of ${}_{2}F_{1}\left(a,b;c;x\right)$. The result may or may not be infinite.
 NE_REAL

On entry, ${\mathbf{c}}=\u2329\mathit{\text{value}}\u232a$.
${}_{2}F_{1}\left(a,b;c;x\right)$ is undefined when $c$ is zero or a negative integer.
 NE_REAL_RANGE_CONS

On entry,
a does not satisfy
$\left{\mathbf{a}}\right\le \mathit{arbnd}=\u2329\mathit{\text{value}}\u232a$.
On entry,
b does not satisfy
$\left{\mathbf{b}}\right\le \mathit{arbnd}=\u2329\mathit{\text{value}}\u232a$.
On entry,
c does not satisfy
$\left{\mathbf{c}}\right\le \mathit{arbnd}=\u2329\mathit{\text{value}}\u232a$.
On entry,
x does not satisfy
$\left{\mathbf{x}}\right\le \mathit{arbnd}=\u2329\mathit{\text{value}}\u232a$.
 NE_TOTAL_PRECISION_LOSS

All approximations have completed, and the final residual estimate indicates no accuracy can be guaranteed.
$\text{Relative residual}=\u2329\mathit{\text{value}}\u232a$.
 NW_OVERFLOW_WARN

On completion, overflow occurred in the evaluation of ${}_{2}F_{1}\left(a,b;c;x\right)$.
 NW_SOME_PRECISION_LOSS

All approximations have completed, and the final residual estimate indicates some precision may have been lost.
$\text{Relative residual}=\u2329\mathit{\text{value}}\u232a$.
 NW_UNDERFLOW_WARN

Underflow occurred during the evaluation of ${}_{2}F_{1}\left(a,b;c;x\right)$. The returned value may be inaccurate.
7
Accuracy
In general, if
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_NOERROR, 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 under or overflow, an error estimate
$\mathit{res}$ is made internally using equation
(1). If the magnitude of
$\mathit{res}$ is sufficiently large, a
different
fail.code
will be returned. Specifically,
where
$\epsilon $ is the
machine precision as returned by
X02AJC.
A further estimate of the residual can be constructed using equation
(1), and the differential identity,
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)$.
Furthermore, the accuracy of the solution, and the error estimate, can be dependent upon the accuracy of the decimal fraction of the input parameters
$a$ and
$b$. For example, if
$c={c}_{i}+{c}_{r}=100+\text{1.0e\u22126}$, then on a machine with
$16$ decimal digits of precision, the internal calculation of
${c}_{r}$ will only be accurate to
$8$ decimal places. This can subsequently pollute the final solution by several decimal places without affecting the residual estimate as greatly. Should you require higher accuracy in such regions, then you should use
s22bfc, which requires you to supply the correct decimal fraction.
8
Parallelism and Performance
s22bec is not threaded in any implementation.
s22bec returns nonfinite values when appropriate. See
Chapter X07 for more information on the definitions of nonfinite values.
Should a nonfinite value be returned, this will be indicated in the value of
fail, as detailed in the following cases.
If
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_NOERROR, or
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_TOTAL_PRECISION_LOSS,
NW_SOME_PRECISION_LOSS or
NW_UNDERFLOW_WARN, a finite value will have been returned with an approximate accuracy as detailed in
Section 7.
If
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_INFINITE then
${}_{2}F_{1}\left(a,b;c;x\right)$ is infinite, and a signed infinity will have been returned. The sign of the infinity should be correct when taking the limit as
$x$ approaches
$1$ from below.
If
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NW_OVERFLOW_WARN then upon completion,
$\left{}_{2}F_{1}\left(a,b;c;x\right)\right>{R}_{\mathrm{max}}$, where
${R}_{\mathrm{max}}$ is the largest machine number given by
X02ALC, and hence is too large to be representable. The result will be returned as a signed infinity. The sign should be correct.
If
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_OVERFLOW then overflow occurred during a subcalculation of
${}_{2}F_{1}\left(a,b;c;x\right)$. A signed infinity will have been returned, however, there is no guarantee that this is representative of either the magnitude or the sign of
${}_{2}F_{1}\left(a,b;c;x\right)$.
For all other error exits,
s22bec will return a signalling NaN (see
x07bbc).
If
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_CANNOT_CALCULATE then 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{fail}}\mathbf{.}\mathbf{code}=$ NE_REAL then
$c$ is too close to a negative integer or zero on entry, and
${}_{2}F_{1}\left(a,b;c;x\right)$ is considered 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{fail}}\mathbf{.}\mathbf{code}=$ NE_REAL_RANGE_CONS then no computation will have been performed. The actual solution may however, be finite.
${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_COMPLEX indicates
$x>1$. Hence the requested solution is on the boundary of the principal branch of
${}_{2}F_{1}\left(a,b;c;x\right)$, and hence is multivalued, typically with a nonzero imaginary component. It is however, strictly finite.
10
Example
This example evaluates ${}_{2}F_{1}\left(a,b;c;x\right)$ at a fixed set of parameters $a,b$ and $c$, and for several values for the argument $x$.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results