22#ifdef NUMERICS_USE_BOOST_MATH
23# include <boost/math/special_functions/bessel.hpp>
24# include <boost/math/special_functions/legendre.hpp>
25# include <boost/math/special_functions/hermite.hpp>
26# include <boost/math/special_functions/laguerre.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/zeta.hpp>
32# include <boost/math/special_functions/beta.hpp>
33# include <boost/math/special_functions/spherical_harmonic.hpp>
40constexpr real pi = 3.14159265358979323846;
41constexpr real e = 2.71828182845904523536;
42constexpr real phi = 1.61803398874989484820;
45constexpr real ln2 = 0.69314718055994530942;
54#ifdef NUMERICS_USE_BOOST_MATH
55 return boost::math::cyl_bessel_j(nu, x);
57 return std::cyl_bessel_j(nu, x);
63#ifdef NUMERICS_USE_BOOST_MATH
64 return boost::math::cyl_neumann(nu, x);
66 return std::cyl_neumann(nu, x);
72#ifdef NUMERICS_USE_BOOST_MATH
73 return boost::math::cyl_bessel_i(nu, x);
75 return std::cyl_bessel_i(nu, x);
81#ifdef NUMERICS_USE_BOOST_MATH
82 return boost::math::cyl_bessel_k(nu, x);
84 return std::cyl_bessel_k(nu, x);
92#ifdef NUMERICS_USE_BOOST_MATH
93 return boost::math::sph_bessel(n, x);
95 return std::sph_bessel(n, x);
101#ifdef NUMERICS_USE_BOOST_MATH
102 return boost::math::sph_neumann(n, x);
104 return std::sph_neumann(n, x);
112#ifdef NUMERICS_USE_BOOST_MATH
113 return boost::math::legendre_p(
static_cast<int>(n), x);
115 return std::legendre(n, x);
121#ifdef NUMERICS_USE_BOOST_MATH
122 return boost::math::legendre_p(
static_cast<int>(n),
static_cast<int>(
m), x);
124 return std::assoc_legendre(n,
m, x);
130#ifdef NUMERICS_USE_BOOST_MATH
131 return boost::math::spherical_harmonic_r(
l,
static_cast<int>(
m), theta,
real(0));
133 return std::sph_legendre(
l,
m, theta);
139#ifdef NUMERICS_USE_BOOST_MATH
140 return boost::math::hermite(n, x);
142 return std::hermite(n, x);
148#ifdef NUMERICS_USE_BOOST_MATH
149 return boost::math::laguerre(n, x);
151 return std::laguerre(n, x);
157#ifdef NUMERICS_USE_BOOST_MATH
158 return boost::math::laguerre(n,
m, x);
160 return std::assoc_laguerre(n,
m, x);
169#ifdef NUMERICS_USE_BOOST_MATH
170 return boost::math::ellint_1(
k);
172 return std::comp_ellint_1(
k);
178#ifdef NUMERICS_USE_BOOST_MATH
179 return boost::math::ellint_2(
k);
181 return std::comp_ellint_2(
k);
187#ifdef NUMERICS_USE_BOOST_MATH
188 return boost::math::ellint_3(
k, n);
190 return std::comp_ellint_3(n,
k);
196#ifdef NUMERICS_USE_BOOST_MATH
197 return boost::math::ellint_1(
k,
phi);
199 return std::ellint_1(
k,
phi);
205#ifdef NUMERICS_USE_BOOST_MATH
206 return boost::math::ellint_2(
k,
phi);
208 return std::ellint_2(
k,
phi);
214#ifdef NUMERICS_USE_BOOST_MATH
215 return boost::math::ellint_3(
k, n,
phi);
217 return std::ellint_3(n,
k,
phi);
225#ifdef NUMERICS_USE_BOOST_MATH
226 return boost::math::expint(x);
228 return std::expint(x);
234#ifdef NUMERICS_USE_BOOST_MATH
235 return boost::math::zeta(x);
237 return std::riemann_zeta(x);
243#ifdef NUMERICS_USE_BOOST_MATH
244 return boost::math::beta(
a,
b);
246 return std::beta(
a,
b);
255 std::vector<real>
out(n);
257 for (
idx i = 0;
i < n; ++
i)
265 std::vector<int>
out(
static_cast<idx>(n));
285 return std::uniform_real_distribution<real>{lo, hi}(
r->engine);
290 return std::normal_distribution<real>{mean,
stddev}(
r->engine);
295 return std::uniform_int_distribution<int>{lo, hi}(
r->engine);
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.
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
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.