Class inte_adapt_cern (o2scl)

O2scl : Class List

class inte_adapt_cern

Adaptive integration (CERNLIB)

Uses a base integration object (default is inte_gauss56_cern) to perform adaptive integration by automatically subdividing the integration interval. At each step, the interval with the largest absolute uncertainty is divided in half. The routine succeeds if the absolute tolerance is less than tol_abs or if the relative tolerance is less than tol_rel, i.e.

\[ \mathrm{err}\leq\mathrm{tol\_abs}~\mathrm{or}~ \mathrm{err}\leq\mathrm{tol\_rel}\cdot|I| \]
where \( I \) is the current estimate for the integral and \( \mathrm{err} \) is the current estimate for the uncertainty. If the number of subdivisions exceeds the template parameter nsub, the error handler is called, since the integration may not have been successful. The number of subdivisions used in the last integration can be obtained from get_nsubdivisions().

The template parameter nsub, is the maximum number of subdivisions. It is automatically set to 100 in the original CERNLIB routine, and defaults to 100 here. The default base integration object is of type inte_gauss56_cern. This is the CERNLIB default, but can be modified by calling set_inte().

This class is based on the CERNLIB routines RADAPT and DADAPT which are documented at http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d102/top.html

Idea for Future:

  • Allow user to set the initial subdivisions?

  • It might be interesting to directly compare the performance of this class to o2scl::inte_qag_gsl .

  • There is a fixme entry in the code which could be resolved.

  • Output the point where most subdividing was required?

Basic usage

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<25>> cpp_dec_float_25
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<35>> cpp_dec_float_35
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>> cpp_dec_float_50
template<typename func_t, class fp_t>
inline int integ_err_funct(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err, double target_tol, double integ_tol, inte_subdiv<fp_t> &is)

Integrate function func from a to b giving result res and error err.

template<typename func_t, class fp_t>
inline int integ_iu_err_int(func_t &&func, fp_t a, fp_t &res, fp_t &err, double target_tol, double integ_tol, double func_tol)
template<typename func_t, class fp_t>
inline int integ_il_err_int(func_t &&func, fp_t b, fp_t &res, fp_t &err, double target_tol, double integ_tol, double func_tol)
template<typename func_t, class fp_t>
inline int integ_i_err_int(func_t &&func, fp_t &res, fp_t &err, double target_tol, double integ_tol, double func_tol)
template<typename func_t, class fp_t>
inline int integ_err_int(func_t &&func, fp_t a, fp_t b, fp_t &res, fp_t &err, double target_tol, double integ_tol, double func_tol)

Internal version of integration function.

template<typename func_t, class fp_t>
inline int integ_err_is(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err, inte_subdiv<fp_t> &is)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_il_err_is(func_t &func, fp_t b, fp_t &res, fp_t &err, inte_subdiv<fp_t> &is)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_iu_err_is(func_t &func, fp_t a, fp_t &res, fp_t &err, inte_subdiv<fp_t> &is)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_i_err_is(func_t &func, fp_t &res, fp_t &err, inte_subdiv<fp_t> &is)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_il_err(func_t &func, fp_t b, fp_t &res, fp_t &err)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_iu_err(func_t &func, fp_t a, fp_t &res, fp_t &err)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_i_err(func_t &func, fp_t &res, fp_t &err)

Integrate function func from a to b and place the result in res and the error in err.

template<typename func_t, class fp_t>
inline fp_t integ(func_t &func, fp_t a, fp_t b)

Integrate function func from a to b.

template<typename func_t, class fp_t>
inline int integ_err_multip(func_t &&func, fp_t a, fp_t b, fp_t &res, fp_t &err, double integ_tol = -1.0)

Integrate function func from a to b using multipreicsion, placing the result in res and the error in err.

template<typename func_t, class fp_t>
inline int integ_iu_err_multip(func_t &&func, fp_t a, fp_t &res, fp_t &err, double integ_tol = -1.0)
template<typename func_t, class fp_t>
inline int integ_il_err_multip(func_t &&func, fp_t b, fp_t &res, fp_t &err, double integ_tol = -1.0)
template<typename func_t, class fp_t>
inline int integ_i_err_multip(func_t &&func, fp_t &res, fp_t &err, double integ_tol = -1.0)

Subdivisions

size_t nsubdiv

Number of subdivisions.

The options are

  • 0: Use previous binning and do not subdivide further

  • 1: Automatic - adapt until tolerance is attained (default)

  • n: (n>1) split first in n equal subdivisions, then adapt until tolerance is obtained.

Public Functions

inline inte_adapt_cern()
inline void set_nsub(int n)

Set the number of subdivisions for the next integration.

Public Members

int last_iter

The last number of required iterations.

int nsub

The number of subdivisions for the next integration.

double tol_rel_multip

The maximum relative uncertainty for multipreicsion integrals (default \( -1 \))

double pow_tol_func

Power for tolerance of function evaluations in multiprecision integrations (default 1.33)

double tol_rel

The maximum relative uncertainty in the value of the integral (default \( 10^{-8} \))

double tol_abs

The maximum absolute uncertainty in the value of the integral (default \( 10^{-8} \))

int verbose

Verbosity parameter.

bool err_nonconv

If true, call the error handler if the integration does not succeed (default true)