|
numerics
|
Thin wrappers around C++17 <cmath> and <numeric> with readable names.
More...
#include "core/types.hpp"#include <cmath>#include <numeric>#include <random>#include <vector>#include <cassert>Go to the source code of this file.
Classes | |
| struct | num::Rng |
| Seeded pseudo-random number generator (Mersenne Twister). Pass a pointer to rng_* functions to draw samples. More... | |
Namespaces | |
| namespace | num |
Functions | |
| real | num::bessel_j (real nu, real x) |
| J_nu(x) – Bessel function of the first kind. | |
| real | num::bessel_y (real nu, real x) |
| Y_nu(x) – Bessel function of the second kind (Neumann function) | |
| real | num::bessel_i (real nu, real x) |
| I_nu(x) – modified Bessel function of the first kind. | |
| real | num::bessel_k (real nu, real x) |
| K_nu(x) – modified Bessel function of the second kind. | |
| real | num::sph_bessel_j (unsigned int n, real x) |
| j_n(x) – spherical Bessel function of the first kind | |
| real | num::sph_bessel_y (unsigned int n, real x) |
| y_n(x) – spherical Neumann function (spherical Bessel of the second kind) | |
| real | num::legendre (unsigned int n, real x) |
| P_n(x) – Legendre polynomial of degree n. | |
| real | num::assoc_legendre (unsigned int n, unsigned int m, real x) |
| P_n^m(x) – associated Legendre polynomial. | |
| real | num::sph_legendre (unsigned int l, unsigned int m, real theta) |
| Y_l^m(theta) – spherical harmonic (real part, theta in radians) | |
| real | num::hermite (unsigned int n, real x) |
| H_n(x) – (physicists') Hermite polynomial. | |
| real | num::laguerre (unsigned int n, real x) |
| L_n(x) – Laguerre polynomial. | |
| real | num::assoc_laguerre (unsigned int n, unsigned int m, real x) |
| L_n^m(x) – associated Laguerre polynomial. | |
| real | num::ellint_K (real k) |
| K(k) – complete elliptic integral of the first kind. | |
| real | num::ellint_E (real k) |
| E(k) – complete elliptic integral of the second kind. | |
| real | num::ellint_Pi (real n, real k) |
| Pi(n, k) – complete elliptic integral of the third kind. | |
| real | num::ellint_F (real k, real phi) |
| F(k, phi) – incomplete elliptic integral of the first kind. | |
| real | num::ellint_Ei (real k, real phi) |
| E(k, phi) – incomplete elliptic integral of the second kind. | |
| real | num::ellint_Pi_inc (real n, real k, real phi) |
| Pi(n, k, phi) – incomplete elliptic integral of the third kind. | |
| real | num::expint (real x) |
| Ei(x) – exponential integral. | |
| real | num::zeta (real x) |
| zeta(x) – Riemann zeta function | |
| real | num::beta (real a, real b) |
| B(a, b) – beta function. | |
| std::vector< real > | num::linspace (real start, real stop, idx n) |
| Evenly spaced values from start to stop, inclusive. MATLAB/NumPy linspace. | |
| std::vector< int > | num::int_range (int start, int n) |
| Integer sequence [start, start+1, ..., start+n-1]. Wraps std::iota. | |
| real | num::rng_uniform (Rng *r, real lo, real hi) |
| Uniform real in [lo, hi). | |
| real | num::rng_normal (Rng *r, real mean, real stddev) |
| Normal (Gaussian) sample with given mean and standard deviation. | |
| int | num::rng_int (Rng *r, int lo, int hi) |
| Uniform integer in [lo, hi] (inclusive on both ends). | |
Variables | |
| constexpr real | num::pi = 3.14159265358979323846 |
| constexpr real | num::e = 2.71828182845904523536 |
| constexpr real | num::phi = 1.61803398874989484820 |
| Golden ratio. | |
| constexpr real | num::sqrt2 = 1.41421356237309504880 |
| constexpr real | num::sqrt3 = 1.73205080756887729353 |
| constexpr real | num::ln2 = 0.69314718055994530942 |
| constexpr real | num::inv_pi = 0.31830988618379067154 |
| 1/pi | |
| constexpr real | num::two_pi = 6.28318530717958647692 |
| 2pi | |
| constexpr real | num::half_pi = 1.57079632679489661923 |
| pi/2 | |
Thin wrappers around C++17 <cmath> and <numeric> with readable names.
The standard library names for special functions (cyl_bessel_j, comp_ellint_1, cyl_neumann, etc.) are accurate but opaque. This header re-exports them under the names used in textbooks and mathematical literature.
Random number generation wraps the mt19937 boilerplate into a plain struct.
Include this header instead of pulling <cmath> special functions directly.
Definition in file math.hpp.