24#ifdef NUMERICS_USE_BOOST_MATH
25#include <boost/math/special_functions/bessel.hpp>
26#include <boost/math/special_functions/beta.hpp>
27#include <boost/math/special_functions/ellint_1.hpp>
28#include <boost/math/special_functions/ellint_2.hpp>
29#include <boost/math/special_functions/ellint_3.hpp>
30#include <boost/math/special_functions/expint.hpp>
31#include <boost/math/special_functions/hermite.hpp>
32#include <boost/math/special_functions/laguerre.hpp>
33#include <boost/math/special_functions/legendre.hpp>
34#include <boost/math/special_functions/spherical_harmonic.hpp>
35#include <boost/math/special_functions/zeta.hpp>
42constexpr real pi = 3.14159265358979323846;
43constexpr real e = 2.71828182845904523536;
44constexpr real phi = 1.61803398874989484820;
47constexpr real ln2 = 0.69314718055994530942;
56#ifdef NUMERICS_USE_BOOST_MATH
57 return boost::math::cyl_bessel_j(nu, x);
59 return std::cyl_bessel_j(nu, x);
65#ifdef NUMERICS_USE_BOOST_MATH
66 return boost::math::cyl_neumann(nu, x);
68 return std::cyl_neumann(nu, x);
74#ifdef NUMERICS_USE_BOOST_MATH
75 return boost::math::cyl_bessel_i(nu, x);
77 return std::cyl_bessel_i(nu, x);
83#ifdef NUMERICS_USE_BOOST_MATH
84 return boost::math::cyl_bessel_k(nu, x);
86 return std::cyl_bessel_k(nu, x);
94#ifdef NUMERICS_USE_BOOST_MATH
95 return boost::math::sph_bessel(n, x);
97 return std::sph_bessel(n, x);
104#ifdef NUMERICS_USE_BOOST_MATH
105 return boost::math::sph_neumann(n, x);
107 return std::sph_neumann(n, x);
115#ifdef NUMERICS_USE_BOOST_MATH
116 return boost::math::legendre_p(
static_cast<int>(n), x);
118 return std::legendre(n, x);
124#ifdef NUMERICS_USE_BOOST_MATH
125 return boost::math::legendre_p(
static_cast<int>(n),
static_cast<int>(m), x);
127 return std::assoc_legendre(n, m, x);
133#ifdef NUMERICS_USE_BOOST_MATH
134 return boost::math::spherical_harmonic_r(l,
static_cast<int>(m), theta,
137 return std::sph_legendre(l, m, theta);
143#ifdef NUMERICS_USE_BOOST_MATH
144 return boost::math::hermite(n, x);
146 return std::hermite(n, x);
152#ifdef NUMERICS_USE_BOOST_MATH
153 return boost::math::laguerre(n, x);
155 return std::laguerre(n, x);
161#ifdef NUMERICS_USE_BOOST_MATH
162 return boost::math::laguerre(n, m, x);
164 return std::assoc_laguerre(n, m, x);
174#ifdef NUMERICS_USE_BOOST_MATH
175 return boost::math::ellint_1(k);
177 return std::comp_ellint_1(k);
183#ifdef NUMERICS_USE_BOOST_MATH
184 return boost::math::ellint_2(k);
186 return std::comp_ellint_2(k);
192#ifdef NUMERICS_USE_BOOST_MATH
193 return boost::math::ellint_3(k, n);
195 return std::comp_ellint_3(n, k);
201#ifdef NUMERICS_USE_BOOST_MATH
202 return boost::math::ellint_1(k,
phi);
204 return std::ellint_1(k,
phi);
210#ifdef NUMERICS_USE_BOOST_MATH
211 return boost::math::ellint_2(k,
phi);
213 return std::ellint_2(k,
phi);
219#ifdef NUMERICS_USE_BOOST_MATH
220 return boost::math::ellint_3(k, n,
223 return std::ellint_3(n, k,
phi);
231#ifdef NUMERICS_USE_BOOST_MATH
232 return boost::math::expint(x);
234 return std::expint(x);
240#ifdef NUMERICS_USE_BOOST_MATH
241 return boost::math::zeta(x);
243 return std::riemann_zeta(x);
249#ifdef NUMERICS_USE_BOOST_MATH
250 return boost::math::beta(a, b);
252 return std::beta(a, b);
262 std::vector<real> out(n);
263 real step = (stop - start) /
static_cast<real>(n - 1);
264 for (
idx i = 0; i < n; ++i)
265 out[i] = start +
static_cast<real>(i) * step;
272 std::vector<int> out(
static_cast<idx>(n));
273 std::iota(out.begin(), out.end(), start);
292 return std::uniform_real_distribution<real>{lo, hi}(r->
engine);
297 return std::normal_distribution<real>{mean, stddev}(r->
engine);
302 return std::uniform_int_distribution<int>{lo, hi}(r->
engine);
311 real dx = x - cx, dy = y - cy;
312 return std::exp(-((dx * dx) + (dy * dy)) / (2.0 * sigma * sigma));
real gaussian2d(real x, real y, real cx, real cy, real sigma)
2D isotropic Gaussian centred at with width :
constexpr real phi
Golden ratio.
constexpr real inv_pi
1/pi
real ellint_F(real k, real phi)
F(k, phi) – incomplete elliptic integral of the first kind.
std::vector< real > linspace(real start, real stop, idx n)
Evenly spaced values from start to stop, inclusive. MATLAB/NumPy linspace.
real bessel_j(real nu, real x)
J_nu(x) – Bessel function of the first kind.
real expint(real x)
Ei(x) – exponential integral.
int rng_int(Rng *r, int lo, int hi)
Uniform integer in [lo, hi] (inclusive on both ends).
real sph_legendre(unsigned int l, unsigned int m, real theta)
Y_l^m(theta) – spherical harmonic (real part, theta in radians)
real ellint_E(real k)
E(k) – complete elliptic integral of the second kind.
real rng_uniform(Rng *r, real lo, real hi)
Uniform real in [lo, hi).
real beta(real a, real b)
B(a, b) – beta function.
real legendre(unsigned int n, real x)
P_n(x) – Legendre polynomial of degree n.
real rng_normal(Rng *r, real mean, real stddev)
Normal (Gaussian) sample with given mean and standard deviation.
real assoc_legendre(unsigned int n, unsigned int m, real x)
P_n^m(x) – associated Legendre polynomial.
real bessel_k(real nu, real x)
K_nu(x) – modified Bessel function of the second kind.
real ellint_K(real k)
K(k) – complete elliptic integral of the first kind.
std::vector< int > int_range(int start, int n)
Integer sequence [start, start+1, ..., start+n-1]. Wraps std::iota.
real zeta(real x)
zeta(x) – Riemann zeta function
real laguerre(unsigned int n, real x)
L_n(x) – Laguerre polynomial.
constexpr real half_pi
pi/2
real hermite(unsigned int n, real x)
H_n(x) – (physicists') Hermite polynomial.
real bessel_i(real nu, real x)
I_nu(x) – modified Bessel function of the first kind.
real bessel_y(real nu, real x)
Y_nu(x) – Bessel function of the second kind (Neumann function)
real assoc_laguerre(unsigned int n, unsigned int m, real x)
L_n^m(x) – associated Laguerre polynomial.
real ellint_Pi(real n, real k)
Pi(n, k) – complete elliptic integral of the third kind.
real sph_bessel_j(unsigned int n, real x)
j_n(x) – spherical Bessel function of the first kind
real sph_bessel_y(unsigned int n, real x)
y_n(x) – spherical Neumann function (spherical Bessel of the second kind)
real ellint_Pi_inc(real n, real k, real phi)
Pi(n, k, phi) – incomplete elliptic integral of the third kind.
real ellint_Ei(real k, real phi)
E(k, phi) – incomplete elliptic integral of the second kind.
Seeded pseudo-random number generator (Mersenne Twister). Pass a pointer to rng_* functions to draw s...
Rng()
Seed from hardware entropy.