The Cuba library offers a choice of four independent routines for multidimensional numerical integration: Vegas, Suave, Divonne, and Cuhre.

They work by very different methods, summarized in the following table:

Routine | Basic integration method | Algorithm type | Variance reduction |
---|---|---|---|

Vegas | Sobol quasi-random sampleor Mersenne Twister pseudo-random sampleor Ranlux pseudo-random sample |
Monte Carlo Monte Carlo Monte Carlo |
importance sampling |

Suave | Sobol quasi-random sampleor Mersenne Twister pseudo-random sampleor Ranlux pseudo-random sample |
Monte Carlo Monte Carlo Monte Carlo |
globally adaptive subdivision + importance sampling |

Divonne | Korobov quasi-random sampleor Sobol quasi-random sampleor Mersenne Twister pseudo-random sampleor Ranlux pseudo-random sampleor cubature rules |
Monte Carlo Monte Carlo Monte Carlo Monte Carlo deterministic |
stratified sampling, aided by methods from numerical optimization |

Cuhre | cubature rules | deterministic | globally adaptive subdivision |

All four have a C/C++, Fortran, and Mathematica interface and can integrate vector integrands. Their invocation is very similar, so it is easy to substitute one method by another for cross-checking. For further safeguarding, the output is supplemented by a χ²-probability which quantifies the reliability of the error estimate.

The source code compiles with gcc, the GNU C compiler. The C functions can be called from Fortran directly, so there is no need for adapter code. Similarly, linking Fortran code with the library is straightforward and requires no extra tools.

In Fortran and C/C++ the Cuba library can (and usually does) automatically parallelize the sampling of the integrand.

- Cuba has been published in Comput. Phys. Commun. 168 (2005) 78 [hep-ph/0404043].
- The parallel features are described in Comput. Phys. Commun. 207 (2016) 341 [arXiv:1408.6373].
- Here is a talk on Cuba given at ACAT 05 [proceedings].
- Here is a somewhat more theoretical lecture on numerical integration in general, given at CAPP 05.
- There are a number of third-party wrappers/links which make Cuba available in other environments: Maple REDUCE R Python Julia Rust

Downloads (hover over download link for MD5):

- Cuba-4.2.1.tar.gz [744 kB] of 28 Jun 2021
- Fixes for mathlink.h from Mathematica 12.3.

- Cuba-4.2.tar.gz [590 kB] of 24 Nov 2020
- Cuba-4.1.tar.gz [742 kB] of 28 Nov 2014
- Cuba-4.0.tar.gz [582 kB] of 25 Nov 2014
- Cuba-3.3.tar.gz [427 kB] of 5 Jun 2014
- Cuba-3.2.tar.gz [428 kB] of 6 Dec 2013
- Cuba-3.1.tar.gz [420 kB] of 6 Jun 2013
- Cuba-3.0.tar.gz [414 kB] of 6 Jun 2013
- Cuba-2.1.tar.gz [311 kB] of 21 Jun 2011
- Cuba-2.0.tar.gz [310 kB] of 20 Jul 2010
- Cuba-1.7.tar.gz [309 kB] of 12 Feb 2010
- Cuba-1.6.tar.gz [344 kB] of 22 Jul 2009
- Cuba-1.5.tar.gz [314 kB] of 3 Mar 2009
- Cuba-1.4.tar.gz [341 kB] of 4 Apr 2008
- Cuba-1.3.tar.gz [321 kB] of 30 Nov 2007
- Cuba-1.2.tar.gz [315 kB] of 5 Jan 2006
- Cuba-1.1.tar.gz [255 kB] of 27 Jan 2005
- Cuba-1.0.tar.gz [260 kB] of 23 Dec 2004

Windows users: Cuba 3 and up uses

Ready-made MathLink executables (Version 4.2, statically linked as far as possible):

Linux x86-64:

- Vegas-Linux.gz [915 kB]
- Suave-Linux.gz [928 kB]
- Divonne-Linux.gz [962 kB]
- Cuhre-Linux.gz [914 kB]

MacOS x86-64:

- Vegas-Mac.gz [1.09 MB]
- Suave-Mac.gz [1.1 MB]
- Divonne-Mac.gz [1.15 MB]
- Cuhre-Mac.gz [1.09 MB]

Cygwin/Windows:

- Vegas-Windows.exe.gz [31 kB]
- Suave-Windows.exe.gz [37 kB]
- Divonne-Windows.exe.gz [85 kB]
- Cuhre-Windows.exe.gz [31 kB]

Instructions: download and gunzip the executable, then make it
executable with "`chmod 755 file`".

**Vegas** is the simplest of the four. It uses importance
sampling for variance reduction, but is only in some cases competitive
in terms of the number of samples needed to reach a prescribed accuracy.
Nevertheless, it has a few improvements over the original algorithm and
comes in handy for cross-checking the results of other methods.

**Suave** is a new algorithm which combines the advantages of two
popular methods: importance sampling as done by Vegas and subregion
sampling in a manner similar to Miser. By dividing into subregions,
Suave manages to a certain extent to get around Vegas' difficulty to
adapt its weight function to structures not aligned with the coordinate
axes.

**Divonne** is a further development of the CERNLIB routine D151.
Divonne works by stratified sampling, where the partitioning of the
integration region is aided by methods from numerical optimization. A
number of improvements have been added to this algorithm, the most
significant being the possibility to supply knowledge about the
integrand. Narrow peaks in particular are difficult to find without
sampling very many points, especially in high dimensions. Often the
exact or approximate location of such peaks is known from analytic
considerations, however, and with such hints the desired accuracy can be
reached with far fewer points.

**Cuhre** employs a cubature rule for subregion estimation in a
globally adaptive subdivision scheme. It is hence a deterministic, not
a Monte Carlo method. In each iteration, the subregion with the largest
error is halved along the axis where the integrand has the largest
fourth difference. Cuhre is quite powerful in moderate dimensions, and
is usually the only viable method to obtain high precision, say relative
accuracies much below 1e–3.

Upward of 75% of all questions regarding Cuba have to do with how to
choose **bounds different from the unit hypercube** in Fortran, C,
and C++. The solution is not to choose bounds but to scale the
integrand. For the mathematically challenged, the explicit
transformation is (in one dimension)

*
∫
_{a}
^{b}
*d

where the final *(b - a)* is the one-dimensional version of the
Jacobian. This generalizes straightforwardly to more than one
dimension.

For constant integration bounds, this transformation might be implemented in Fortran as

integer function ScaledIntegrand(ndim, x, ncomp, result) implicit none integer ndim, ncomp double precision x(ndim), result(ncomp) integer maxdim parameter (maxdim = 16) integer Integrand external Integrand double precision upper(maxdim) common /ubound/ upper double precision lower(maxdim) common /lbound/ lower integer dim, comp double precision range, jacobian, scaledx(maxdim) jacobian = 1 do dim = 1, ndim range = upper(dim) - lower(dim) jacobian = jacobian*range scaledx(dim) = lower(dim) + x(dim)*range enddo ScaledIntegrand = Integrand(ndim, scaledx, ncomp, result) do comp = 1, ncomp result(comp) = result(comp)*jacobian enddo end

This site and the programs offered here are not commercial.
Cuba is an open-source package and free of charge.

If you want to use Cuba in a commercial application, make sure you
understand the GNU
Lesser General Public License under which Cuba is distributed.

Cuba is being developed at the
Max Planck Institute for Physics
in Munich.

Data protection statement and Imprint

Last update: 28 Jun 21 Thomas Hahn