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>
43constexpr real pi = 3.14159265358979323846;
44constexpr real e = 2.71828182845904523536;
45constexpr real phi = 1.61803398874989484820;
48constexpr real ln2 = 0.69314718055994530942;
57#ifdef NUMERICS_USE_BOOST_MATH
58 return boost::math::cyl_bessel_j(nu, x);
60 return std::cyl_bessel_j(nu, x);
66#ifdef NUMERICS_USE_BOOST_MATH
67 return boost::math::cyl_neumann(nu, x);
69 return std::cyl_neumann(nu, x);
75#ifdef NUMERICS_USE_BOOST_MATH
76 return boost::math::cyl_bessel_i(nu, x);
78 return std::cyl_bessel_i(nu, x);
84#ifdef NUMERICS_USE_BOOST_MATH
85 return boost::math::cyl_bessel_k(nu, x);
87 return std::cyl_bessel_k(nu, x);
95#ifdef NUMERICS_USE_BOOST_MATH
96 return boost::math::sph_bessel(n, x);
98 return std::sph_bessel(n, x);
105#ifdef NUMERICS_USE_BOOST_MATH
106 return boost::math::sph_neumann(n, x);
108 return std::sph_neumann(n, x);
116#ifdef NUMERICS_USE_BOOST_MATH
117 return boost::math::legendre_p(
static_cast<int>(n), x);
119 return std::legendre(n, x);
125#ifdef NUMERICS_USE_BOOST_MATH
126 return boost::math::legendre_p(
static_cast<int>(n),
static_cast<int>(m), x);
128 return std::assoc_legendre(n, m, x);
134#ifdef NUMERICS_USE_BOOST_MATH
135 return boost::math::spherical_harmonic_r(l,
static_cast<int>(m), theta,
real(0));
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);
284 explicit Rng(uint32_t seed)
289 :
engine(std::random_device{}()) {}
294 return std::uniform_real_distribution<real>{lo, hi}(r->
engine);
299 return std::normal_distribution<real>{mean, stddev}(r->
engine);
304 return std::uniform_int_distribution<int>{lo, hi}(r->
engine);
313 real dx = x - cx, dy = y - cy;
314 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.