Boost Math

Special Math Functions

The Special Functions section of the Boost Math library cover a broad range of areas:

These are all exposed for direct use in boostmath without needing any additional compilation:

hypergeometric_pFq(c(1, 2.5), c(0.5, 2), 1)
#> [1] 6.675991
ibeta_inv(2.1, 5.2, 0.7)
#> [1] 0.361431
owens_t(2.1, 4.2)
#> [1] 0.00893221

Quadrature and Differentiation

Boost’s integration routines are also available for use with R functions:

trapezoidal(function(x) { 1/(5 - 4*cos(x)) }, a = 0, b = 2*pi)
#> [1] 2.094395

gauss_legendre(function(x) { x * x * atan(x) }, a = 0, b = 1, points = 20)
#> [1] 0.2106573

gauss_kronrod(function(x) { exp(-x * x / 2) }, a = 0, b = Inf, points = 15)
#> [1] 1.253314

tanh_sinh(function(x) { log(x)*log1p(-x) }, a = 0, b = 1)
#> [1] 0.3550659

sinh_sinh(function(x) { exp(-x*x) })
#> [1] 1.772454

exp_sinh(function(x) { exp(-3*x) }, a = 0, b = Inf)
#> [1] 0.3333333

ooura_fourier_sin(function(x) { 1 / x})
#> [1] 1.570796

ooura_fourier_cos(function(x) { 1 / (x * x + 1)})
#> [1] 0.5778637

As well as numerical differentiation by finite-differences:

finite_difference_derivative(exp, 1.7)
#> [1] 5.473947

Distribution Functions

The PDF, CDF, log-PDF, log-CDF, and quantile functions for statistical distributions are also exposed:

beta_pdf(0.1, 1.2, 2.1)
#> [1] 1.569287
beta_lpdf(0.1, 1.2, 2.1)
#> [1] 0.4506213
beta_cdf(0.1, 1.2, 2.1)
#> [1] 0.1380638
beta_lcdf(0.1, 1.2, 2.1)
#> [1] -1.98004
beta_quantile(0.5, 1.2, 2.1)
#> [1] 0.3335097