This page contains the description of one-dimensional integration algorithms included into the ALGLIB package.

Subroutine AutoGKSmooth includes an elementary algorithm of adaptive integration that calculates integrals of smooth functions. The algorithm is based on recursive partition of integration interval and processing the resulting subintervals with the Gauss-Kronrod quadrature formula (current implementation uses a 15-node formula). This quadrature formula allows for calculation of the integral itself and the estimate of its error. Subintervals are added into a heap and then the interval with the biggest absolute error is retrieved from the heap and partitioned again. The process is repeated until the aggregate relative error is not close to machine accuracy (the current implementation uses the following criterion: *|Err| ≤ ··ε·|Integral|*).

There is an alternative subroutine version - AutoGKSmoothW - which makes sure that the interval will be fragmented into subintervals that are no longer then a given value xwidth. This subroutine can be used to integrate functions with narrow peaks that can occur between two nodes of the Gauss-Kronrod quadrature formula and remain unnoticed. The subroutine AutoGKSmoothW makes sure that any peak not less then xwidth wide will be identified and taken into account when integrating the function.

The subroutines described above work well with smooth functions. However, their efficiency is substantially decreased if the function has integrable singularities at the interval ends, i.e. behaves like *(x-a) ^{ α}* or

The AutoGKSingular subroutine solves this problem. By change of variable it can make any singularity like *(x-a) ^{ α}* or

The integration algorithm shall obtain values of a function during its operation. This problem is solved in most program packages by transferring the pointer to the function (C++, Delphi) or delegate (C#) which is used to calculate function value.

The ALGLIB package, differently from other libraries, makes use of reverse communication to solve this problem. When a value of a function needs to be calculated, the algorithm state is stored within a special structure, control is returned to the calling program, which makes all calculations and recalls the computing subroutine.

Thus, the integration algorithm is used in accordance in the following order:

- AutoGKState data structure preparation by means of one of the algorithm initialization subrotuines (AutoGKSmooth, AutoGKSmoothW, AutoGKSingular).
- AutoGKIteration subroutine call.
- If False is returned from the subroutine, then the algorithm operation is completed and integral is successfully calculated (the integral itself can be obtained by calling the MinLMResults subprogram).
- If True is returned from the subroutine, the latter will make a request for information on the function. Calculate function value at State.X and save it in the State.F field. Then call AutoGKIteration again.

Please note that when using the AutoGKSingular subroutine (i.e. when integrating functions with singularities at the ends of the interval) one may need the function value at the point that is too close to one of the interval ends. For instance, when integrating the *f(x) = (1-x) ^{ -0.95}* function at the

To avoid this situation, the following measures are taken. When it is required to calculate the function value, the algorithm fills in both State.X field and the State.XMinusA and State.BMinusX fields. In the example above, State.X and State.XMinusA will be uqual to *1* (when using a double precision arithmetics), the field State.BMinusX will have the value of *10 ^{ -25}*. Using the field State.BMinusX allows for avoiding the zero divide error when calculating the function value. An example of using these fields can be found in the "Subroutines Description" section.

*This article is licensed for personal use only.*

ALGLIB Project offers you two editions of ALGLIB:

**ALGLIB Free Edition**:

delivered for free

offers full set of numerical functionality

extensive algorithmic optimizations

no low level optimizations

non-commercial license

**ALGLIB Commercial Edition**:

flexible pricing

offers full set of numerical functionality

extensive algorithmic optimizations

high performance (SMP, SIMD)

commercial license with support plan

Links to download sections for Free and Commercial editions can be found below:

C++ library.

Delivered with sources.

Monolithic design.

Extreme portability.

Delivered with sources.

Monolithic design.

Extreme portability.

C# library with native kernels.

Delivered with sources.

VB.NET and IronPython wrappers.

Extreme portability.

Delivered with sources.

VB.NET and IronPython wrappers.

Extreme portability.

Delphi wrapper around C core.

Delivered as precompiled binary.

Compatible with FreePascal.

Delivered as precompiled binary.

Compatible with FreePascal.

CPython wrapper around C core.

Delivered as precompiled binary.

Delivered as precompiled binary.