# NAG FL Interfaceg05ymf (quasi_​uniform)

## 1Purpose

g05ymf generates a uniformly distributed low-discrepancy sequence as proposed by Sobol, Faure or Niederreiter. It must be preceded by a call to one of the initialization routines g05ylf or g05ynf.

## 2Specification

Fortran Interface
 Subroutine g05ymf ( n, quas, iref,
 Integer, Intent (In) :: n, rcord, ldquas Integer, Intent (Inout) :: iref(*), ifail Real (Kind=nag_wp), Intent (Inout) :: quas(ldquas,*)
#include <nag.h>
 void g05ymf_ (const Integer *n, const Integer *rcord, double quas[], const Integer *ldquas, Integer iref[], Integer *ifail)
The routine may be called by the names g05ymf or nagf_rand_quasi_uniform.

## 3Description

Low discrepancy (quasi-random) sequences are used in numerical integration, simulation and optimization. Like pseudorandom numbers they are uniformly distributed but they are not statistically independent, rather they are designed to give more even distribution in multidimensional space (uniformity). Therefore they are often more efficient than pseudorandom numbers in multidimensional Monte Carlo methods.
g05ymf generates a set of points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ with high uniformity in the $S$-dimensional unit cube ${I}^{S}={\left[0,1\right]}^{S}$.
Let $G$ be a subset of ${I}^{S}$ and define the counting function ${S}_{N}\left(G\right)$ as the number of points ${x}^{i}\in G$. For each $x=\left({x}_{1},{x}_{2},\dots ,{x}_{S}\right)\in {I}^{S}$, let ${G}_{x}$ be the rectangular $S$-dimensional region
 $G x = 0, x 1 × 0, x 2 ×⋯× 0, x S$
with volume ${x}_{1},{x}_{2},\dots ,{x}_{S}$. Then one measure of the uniformity of the points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ is the discrepancy:
 $DN* x1,x2,…,xN = sup x∈IS SN Gx - N x1 , x2 , … , xS .$
which has the form
 $DN*x1,x2,…,xN≤CSlog⁡NS+Olog⁡NS-1 for all N≥2.$
The principal aim in the construction of low-discrepancy sequences is to find sequences of points in ${I}^{S}$ with a bound of this form where the constant ${C}_{S}$ is as small as possible.
The type of low-discrepancy sequence generated by g05ymf depends on the initialization routine called and can include those proposed by Sobol, Faure or Niederreiter. If the initialization routine g05ynf was used then the sequence will be scrambled (see Section 3 in g05ynf for details).

## 4References

Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software 14(1) 88–100
Fox B L (1986) Algorithm 647: implementation and relative efficiency of quasirandom sequence generators ACM Trans. Math. Software 12(4) 362–376

## 5Arguments

Note: the following variables are used in the parameter descriptions:
• $\mathit{idim}={\mathbf{idim}}$, the number of dimensions required, see g05ylf or g05ynf
• $\mathit{liref}={\mathbf{liref}}$, the length of iref as supplied to the initialization routine g05ylf or g05ynf
1: $\mathbf{n}$Integer Input
On entry: the number of quasi-random numbers required.
Constraint: ${\mathbf{n}}\ge 0$ and ${\mathbf{n}}+\text{previous number of generated values}\le {2}^{31}-1$.
2: $\mathbf{rcord}$Integer Input
On entry: the order in which the generated values are returned.
Constraint: ${\mathbf{rcord}}=1$ or $2$.
3: $\mathbf{quas}\left({\mathbf{ldquas}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array quas must be at least ${\mathbf{n}}$ if ${\mathbf{rcord}}=1$ and at least $\mathit{idim}$ if ${\mathbf{rcord}}=2$.
On exit: contains the n quasi-random numbers of dimension idim.
If ${\mathbf{rcord}}=1$, ${\mathbf{quas}}\left(i,j\right)$ holds the $j$th value for the $i$th dimension.
If ${\mathbf{rcord}}=2$, ${\mathbf{quas}}\left(i,j\right)$ holds the $i$th value for the $j$th dimension.
4: $\mathbf{ldquas}$Integer Input
On entry: the first dimension of the array quas as declared in the (sub)program from which g05ymf is called.
Constraints:
• if ${\mathbf{rcord}}=1$, ${\mathbf{ldquas}}\ge \mathit{idim}$;
• if ${\mathbf{rcord}}=2$, ${\mathbf{ldquas}}\ge {\mathbf{n}}$.
5: $\mathbf{iref}\left(*\right)$Integer array Communication Array
Note: the dimension of the array iref must be at least $\mathit{liref}$.
On entry: contains information on the current state of the sequence.
On exit: contains updated information on the state of the sequence.
6: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 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$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, value of n would result in too many calls to the generator: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, generator has previously been called $〈\mathit{\text{value}}〉$ times.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{rcord}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{rcord}}=1$ or $2$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{ldquas}}=〈\mathit{\text{value}}〉$, $\mathit{idim}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{rcord}}=1$, ${\mathbf{ldquas}}\ge \mathit{idim}$.
On entry, ${\mathbf{ldquas}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{rcord}}=2$, ${\mathbf{ldquas}}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=5$
On entry, iref has either not been initialized or has been corrupted.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g05ymf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The Sobol, Sobol (A659) and Niederreiter quasi-random number generators in g05ymf have been parallelized, but require quite large problem sizes to see any significant performance gain. Parallelism is only enabled when ${\mathbf{rcord}}=2$. The Faure generator is serial.

None.

## 10Example

This example calls g05ylf and g05ymf to estimate the value of the integral
 $∫01 ⋯ ∫01 ∏ i=1 s 4xi-2 dx1, dx2, …, dxs = 1 .$
In this example the number of dimensions $S$ is set to $8$.

### 10.1Program Text

Program Text (g05ymfe.f90)

### 10.2Program Data

Program Data (g05ymfe.d)

### 10.3Program Results

Program Results (g05ymfe.r)