S22BEF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

NAG Library Routine Document

S22BEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

S22BEF returns a value for the Gauss hypergeometric function F 1 2 a,b;c;x  for real parameters a,b and c, and real argument x.

2  Specification

FUNCTION S22BEF ( A, B, C, X, IFAIL)
REAL (KIND=nag_wp) S22BEF
INTEGER  IFAIL
REAL (KIND=nag_wp)  A, B, C, X

3  Description

S22BEF returns a value for the Gauss hypergeometric function F1 2 a,b;c;x  for real parameters a, b and c, and for real argument x.
The associated routine S22BFF performs the same operations, but returns F1 2 a,b;c;x  in the scaled form F1 2 a,b;c;x=ffr×2fsc to allow calculations to be performed when F1 2 a,b;c;x  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,
x1-x d2 f dx2 + c-a+b+1x d f dx - a b f = 0 . (1)
For x<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 as=1aa+1a+2a+s-1 is the rising factorial of a. F1 2 a,b;c;x  is undefined for c=0 or c a negative integer.
For x<1, the series is absolutely convergent and F1 2 a,b;c;x  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 x1, x20,1. C1 and C2 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, F1 2 a,b;c;x  is defined by analytic continuation, and for x<1, F1 2 a,b;c;x  is real and finite.
For x=1, the following apply:
In the complex plane, the principal branch of F1 2 a,b;c;z  is taken along the real axis from x=1.0 increasing. F1 2 a,b;c;z  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<x0.5, sets of safe parameters αi,j;βi,j;ζi,j; χj 1j2 ;1i4  are determined, such that the values of F 1 2 aj,bj;cj;xj  required for an appropriate transformation of the type (3) may be calculated either directly or using recurrence relations from the solutions of F 1 2 αi,j,βi,j ;ζi,j;χj . If c is positive, then only transformations with C2=0.0 will be used, implying only F 1 2 a1,b1;c1;x1  will be required, with the transformed argument x1=x. If c is negative, in some cases a transformation with C20.0 will be used, with the argument x2=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<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 xj=1.0-x is employed, and the above strategy for 0<x0.5 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 0,0.5 is first employed. The strategy for 0<x0.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 0.5,1 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. arbnd=0.0001×Imax, where Imax 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 or the companion (2010) for a detailed discussion of the Gauss hypergeometric function including special cases, transformations, relations and asymptotic approximations.

4  References

NIST Handbook of Mathematical Functions (2010) (eds F W J Olver, D W Lozier, R F Boisvert, C W Clark) Cambridge University Press
Pearson J (2009) Computation of hypergeometric functions MSc Dissertation, Mathematical Institute, University of Oxford

5  Parameters

1:     A – REAL (KIND=nag_wp)Input
On entry: the parameter a.
Constraint: Aarbnd.
2:     B – REAL (KIND=nag_wp)Input
On entry: the parameter b.
Constraint: Barbnd.
3:     C – REAL (KIND=nag_wp)Input
On entry: the parameter c.
Constraints:
  • Carbnd;
  • C0,-1,-2,.
4:     X – REAL (KIND=nag_wp)Input
On entry: the argument x.
Constraint: -arbnd<X1.
5:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
Underflow occurred during the evaluation of F 1 2 a,b; c;x . The returned value may be inaccurate.
IFAIL=2
All approximations have completed, and the final residual estimate indicates some precision may have been lost.
Relative residual=value.
IFAIL=3
All approximations have completed, and the final residual estimate indicates no accuracy can be guaranteed.
Relative residual=value.
IFAIL=4
On entry, X=value, c=value, a+b=value.
F 1 2 a,b; c;1  is infinite in the case ca+b.
IFAIL=5
On completion, overflow occurred in the evaluation of F 1 2 a,b; c;x .
IFAIL=6
Overflow occurred in a subcalculation of F 1 2 a,b; c;x . The result may or may not be infinite.
IFAIL=9
An internal calculation has resulted in an undefined result.
IFAIL=11
On entry, A does not satisfy Aarbnd=value.
IFAIL=21
On entry, B does not satisfy Barbnd=value.
IFAIL=31
On entry, C does not satisfy Carbnd=value.
IFAIL=32
On entry, C=value.
F 1 2 a,b; c;x  is undefined when c is zero or a negative integer.
IFAIL=41
On entry, X does not satisfy Xarbnd=value.
IFAIL=42
On entry, X=value.
In general, F 1 2 a,b; c;x  is not real valued when x>1.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

In general, if IFAIL=0, the value of F1 2 a,b;c;x  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 res is made internally using equation (1). If the magnitude of res is sufficiently large, a nonzero IFAIL will be returned. Specifically,
IFAIL=0 or 1 res1000ε
IFAIL=2 1000ε<res0.1
IFAIL=3 res>0.1
where ε is the machine precision as returned by X02AJF.
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 F 1 2 a+1,b+1; c+1;x  and F 1 2 a+2,b+2; c+2;x .
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=ci+cr=100+1.0E−6, then on a machine with 16 decimal digits of precision, the internal calculation of cr 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 S22BFF, which requires you to supply the correct decimal fraction.

8  Parallelism and Performance

Not applicable.

9  Further Comments

S22BEF 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 IFAIL=0, or IFAIL=1, 2 or 3, a finite value will have been returned with an approximate accuracy as detailed in Section 7.
If IFAIL=4 then F1 2 a,b;c;x  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 IFAIL=5 then upon completion, F1 2 a,b;c;x > Rmax , where Rmax is the largest machine number given by X02ALF, and hence is too large to be representable. The result will be returned as a signed infinity. The sign should be correct.
If IFAIL=6 then overflow occurred during a subcalculation of F1 2 a,b;c;x . A signed infinity will have been returned, however there is no guarantee that this is representative of either the magnitude or the sign of F1 2 a,b;c;x .
For all other error exits, S22BEF will return a signalling NaN (see X07BBF).
If IFAIL=9 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 IFAIL=32 then c is too close to a negative integer or zero on entry, and F1 2 a,b;c;x  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 cj not being negative integers,
(ii) for any cj which remain as negative integers, one of the corresponding parameters aj or bj is a negative integer of magnitude less than cj.
In the first case, the transformation coefficients Cj aj,bj,cj,xj  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 IFAIL=11, 21, 31 or 41 then no computation will have been performed. The actual solution may however be finite.
IFAIL=42 indicates x>1. Hence the requested solution is on the boundary of the principal branch of F1 2 a,b;c;x , and hence is multivalued, typically with a non-zero imaginary component. It is however strictly finite.

10  Example

This example evaluates F 1 2 a,b;c;x  at a fixed set of parameters a,b and c, and for several values for the argument x.

10.1  Program Text

Program Text (s22befe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (s22befe.r)


S22BEF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015