D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD01GZF

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.

## 1  Purpose

D01GZF calculates the optimal coefficients for use by D01GCF and D01GDF, when the number of points is the product of two primes.

## 2  Specification

 SUBROUTINE D01GZF ( NDIM, NP1, NP2, VK, IFAIL)
 INTEGER NDIM, NP1, NP2, IFAIL REAL (KIND=nag_wp) VK(NDIM)

## 3  Description

Korobov (1963) gives a procedure for calculating optimal coefficients for $p$-point integration over the $n$-cube ${\left[0,1\right]}^{n}$, when the number of points is
 $p=p1p2$ (1)
where ${p}_{1}$ and ${p}_{2}$ are distinct prime numbers.
The advantage of this procedure is that if ${p}_{1}$ is chosen to be the nearest prime integer to ${p}_{2}^{2}$, then the number of elementary operations required to compute the rule is of the order of ${p}^{4/3}$ which grows less rapidly than the number of operations required by D01GYF. The associated error is likely to be larger although it may be the only practical alternative for high values of $p$.

## 4  References

Korobov N M (1963) Number Theoretic Methods in Approximate Analysis Fizmatgiz, Moscow

## 5  Parameters

1:     NDIM – INTEGERInput
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{NDIM}}\ge 1$.
2:     NP1 – INTEGERInput
On entry: the larger prime factor ${p}_{1}$ of the number of points in the integration rule.
Constraint: ${\mathbf{NP1}}$ must be a prime number $\text{}\ge 5$.
3:     NP2 – INTEGERInput
On entry: the smaller prime factor ${p}_{2}$ of the number of points in the integration rule. For maximum efficiency, ${p}_{2}^{2}$ should be close to ${p}_{1}$.
Constraint: ${\mathbf{NP2}}$ must be a prime number such that ${\mathbf{NP1}}>{\mathbf{NP2}}\ge 2$.
4:     VK(NDIM) – REAL (KIND=nag_wp) arrayOutput
On exit: the $n$ optimal coefficients.
5:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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$
 On entry, ${\mathbf{NDIM}}<1$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{NP1}}<5$, or ${\mathbf{NP2}}<2$, or ${\mathbf{NP1}}\le {\mathbf{NP2}}$.
${\mathbf{IFAIL}}=3$
The value ${\mathbf{NP1}}×{\mathbf{NP2}}$ exceeds the largest integer representable on the machine, and hence the optimal coefficients could not be used in a valid call of D01GCF or D01GDF.
${\mathbf{IFAIL}}=4$
 On entry, NP1 is not a prime number.
${\mathbf{IFAIL}}=5$
 On entry, NP2 is not a prime number.
${\mathbf{IFAIL}}=6$
The precision of the machine is insufficient to perform the computation exactly. Try smaller values of NP1 or NP2, or use an implementation with higher precision.

## 7  Accuracy

The optimal coefficients are returned as exact integers (though stored in a real array).

The time taken by D01GZF grows at least as fast as ${\left({p}_{1}{p}_{2}\right)}^{4/3}$. (See Section 3.)

## 9  Example

This example calculates the Korobov optimal coefficients where the number of dimensons is $4$ and the number of points is the product of the two prime numbers, $89$ and $11$.

### 9.1  Program Text

Program Text (d01gzfe.f90)

None.

### 9.3  Program Results

Program Results (d01gzfe.r)