D01GZF (PDF version)
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$.
Korobov N M (1963) Number Theoretic Methods in Approximate Analysis Fizmatgiz, Moscow

## 5  Parameters

1:     $\mathrm{NDIM}$ – INTEGERInput
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{NDIM}}\ge 1$.
2:     $\mathrm{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:     $\mathrm{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:     $\mathrm{VK}\left({\mathbf{NDIM}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the $n$ optimal coefficients.
5:     $\mathrm{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.
${\mathbf{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.
${\mathbf{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.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

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

Not applicable.

## 9  Further Comments

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

## 10  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$.

### 10.1  Program Text

Program Text (d01gzfe.f90)

None.

### 10.3  Program Results

Program Results (d01gzfe.r)

D01GZF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual