Theoretica
A C++ numerical and automatic mathematical library
|
Main namespace of the library which contains all functions and objects. More...
Namespaces | |
algebra | |
Linear algebra routines. | |
autodiff | |
Differential operators with automatic differentiation. | |
distribution | |
Probability distribution functions. | |
ode | |
Numerical methods for ordinary differential equations. | |
parallel | |
Parallelized element-wise evaluation of functions. | |
regression | |
Regression to a model. | |
signal | |
Signal processing module. | |
special | |
Special functions. | |
stats | |
Statistical functions. | |
tables | |
Tabulated values. | |
taylor | |
Taylor series expansions. | |
Classes | |
class | mat_iterator |
A sequential iterator for matrices. More... | |
class | mat |
A generic matrix with a fixed number of rows and columns. More... | |
class | mat< Type, 0, 0 > |
A generic matrix with a variable number of rows and columns. More... | |
class | vec_iterator |
for vectors. More... | |
class | vec |
A statically allocated N-dimensional vector with elements of the given type. More... | |
class | vec< Type, 0 > |
class | dual |
Dual number class. More... | |
class | dual2 |
Second order dual number class. More... | |
class | multidual |
Multidual number algebra for functions of the form \(f: \mathbb{R}^n \rightarrow \mathbb{R}\). More... | |
class | complex |
Complex number in algebraic form \(a + ib\). More... | |
struct | is_complex_type |
Type trait to check whether the given type is a specialization of the complex number class or not, using the static boolean element is_complex_type<T>::value. More... | |
struct | is_complex_type< complex< T > > |
Type trait to check whether the given type is a specialization of the complex number class or not, using the static boolean element is_complex_type<T>::value. More... | |
class | phasor |
Complex number in exponential form \(\rho e^{i \theta}\). More... | |
class | quat |
Quaternion class in the form \(a + bi + cj + dk\). More... | |
struct | is_real_type |
Type trait to check whether a type represents a real number. More... | |
struct | is_real_type< real > |
Type trait to check whether a type represents a real number. More... | |
struct | is_orderable |
Check whether a structure is orderable, by checking that it has a comparison operator<(). More... | |
struct | is_orderable< Structure, _internal::void_t< decltype(std::declval< Structure >()< std::declval< Structure >())> > |
struct | is_indexable |
Check whether a structure is indexable by a single integer index, by checking that it has the operator[](0). More... | |
struct | is_indexable< Structure, _internal::void_t< decltype(std::declval< Structure >()[0])> > |
struct | is_iterable |
Check whether a structure is iterable, by checking that it has a method begin(). More... | |
struct | is_iterable< Structure, _internal::void_t< decltype(std::declval< Structure >().begin())> > |
struct | is_vector |
Check whether a structure is considerable a vector, by checking that it has an operator[] and a size() method. More... | |
struct | is_vector< Structure, _internal::void_t< decltype(std::declval< Structure >()[0]), decltype(std::declval< Structure >().size())> > |
struct | is_matrix |
Check whether a structure is considerable a matrix, by checking that it has an operator(), a rows() method and a cols() method. More... | |
struct | is_matrix< Structure, _internal::void_t< decltype(std::declval< Structure >()(0, 0)), decltype(std::declval< Structure >().rows()), decltype(std::declval< Structure >().cols())> > |
struct | has_type_elements |
Type trait to check whether an indexable container has elements of the given type. More... | |
struct | extract_func_args |
Extract the type of the arguments of a function. More... | |
struct | extract_func_args< Function(Args...)> |
class | ratio |
representing a ratio between two objects, like a fraction or a rational polynomial. More... | |
struct | spline_node |
A cubic splines node for a given x interval. More... | |
class | spline |
A natural cubic spline interpolation class. More... | |
class | polynomial |
A polynomial of arbitrary order. More... | |
class | PRNG |
A pseudorandom number generator. More... | |
struct | pdf_sampler |
A probability density function sampler which generates pseudorandom numbers following asymptotically a given distribution \(f(x; \vec \theta)\). More... | |
class | histogram |
Histogram class with running statistics, can be constructed from the parameters of the bins or from a dataset. More... | |
Typedefs | |
using | mat2 = mat< real, 2, 2 > |
A 2x2 matrix with real entries. | |
using | mat3 = mat< real, 3, 3 > |
A 3x3 matrix with real entries. | |
using | mat4 = mat< real, 4, 4 > |
A 4x4 matrix with real entries. | |
using | cmat = mat< complex<> > |
A variable size matrix with complex entries. | |
using | cmat2 = mat< complex< real >, 2, 2 > |
A 2x2 matrix with real entries. | |
using | cmat3 = mat< complex< real >, 3, 3 > |
A 3x3 matrix with real entries. | |
using | cmat4 = mat< complex< real >, 4, 4 > |
A 4x4 matrix with real entries. | |
using | vec2 = vec< real, 2 > |
A 2-dimensional vector with real elements. | |
using | vec3 = vec< real, 3 > |
A 3-dimensional vector with real elements. | |
using | vec4 = vec< real, 4 > |
A 4-dimensional vector with real elements. | |
using | cvec = vec< complex<> > |
A variable size vector with complex elements. | |
using | cvec2 = vec< complex<>, 2 > |
A 2-dimensional vector with complex elements. | |
using | cvec3 = vec< complex<>, 3 > |
A 3-dimensional vector with complex elements. | |
using | cvec4 = vec< complex<>, 4 > |
A 4-dimensional vector with complex elements. | |
template<typename Type = real> | |
using | bicomplex = complex< complex< Type > > |
A bi-complex number. | |
template<typename Structure > | |
using | has_complex_elements = is_complex_type< vector_element_t< Structure > > |
Type trait to check whether a container has complex elements. | |
template<typename Structure , typename T = bool> | |
using | enable_complex = std::enable_if_t< is_complex_type< Structure >::value, T > |
Enable a function overload if the template typename is considerable a complex number. More... | |
using | real = double |
A real number, defined as a floating point type. More... | |
template<typename Structure > | |
using | vector_element_or_void_t = typename _internal::vector_element_or_void< Structure >::type |
Extract the type of a vector (or any indexable container) from its operator[], returning void if the type has no operator[]. | |
template<typename Structure > | |
using | vector_element_t = std::remove_reference_t< decltype(std::declval< Structure >()[0])> |
Extract the type of a vector (or any indexable container) from its operator[]. | |
template<typename Structure > | |
using | matrix_element_t = std::remove_reference_t< decltype(std::declval< Structure >()(0, 0))> |
Extract the type of a matrix (or any doubly indexable container) from its operator(). | |
template<typename Structure > | |
using | has_real_elements = is_real_type< vector_element_t< Structure > > |
Type trait to check whether an indexable container has real elements. | |
template<typename Structure , typename T = bool> | |
using | enable_matrix = std::enable_if_t< is_matrix< Structure >::value, T > |
Enable a function overload if the template typename is considerable a matrix. More... | |
template<typename Structure , typename T = bool> | |
using | enable_vector = std::enable_if_t< is_vector< Structure >::value, T > |
Enable a function overload if the template typename is considerable a vector. More... | |
template<typename Function > | |
using | is_real_func = std::conditional_t< is_real_type< typename _internal::return_type_or_void< Function, real >::type >::value, std::true_type, std::false_type > |
Type trait to check whether the given function takes a real number as its first argument. | |
template<typename Function , typename T = bool> | |
using | enable_real_func = typename std::enable_if_t< is_real_func< Function >::value, T > |
Enable a certain function overload if the given type is a function taking as first argument a real number. | |
template<typename Function > | |
using | return_type_t = typename _internal::func_helper< Function >::return_type |
Extract the return type of a Callable object, such as a function pointer or lambda function. | |
using | real_function = std::function< real(real)> |
Function pointer to a real function of real variable. | |
using | complex_function = std::function< complex<>(complex<>)> |
Function pointer to a complex function of complex variable. | |
using | stat_function = std::function< real(real, const vec< real > &)> |
Function pointer to a probability distribution function where the first argument is the variable and the second argument is a vector of the parameters of the distribution. | |
using | polyn_recurr_formula = std::function< polynomial< real >(polynomial< real >, polynomial< real >, unsigned int)> |
Polynomial sequence recurrence formula type Used for computing orthogonal polynomial basis elements. | |
using | pseudorandom_function = uint64_t(*)(uint64_t, std::vector< uint64_t > &) |
A function pointer which wraps a pseudorandom generator, taking as input the previous generated value (or seed) and the current state of the algorithm. More... | |
using | pdf_sampling_function = real(*)(const std::vector< real > &, PRNG &) |
A p.d.f sampling function taking as input the parameters of the distribution and a pseudorandom number generator. | |
Enumerations | |
enum | MATH_ERRCODE { NO_ERROR = 0x00 , DIV_BY_ZERO = 0x01 , OUT_OF_DOMAIN = 0x02 , OUT_OF_RANGE = 0x04 , IMPOSSIBLE_OPERATION = 0x08 , NO_ALGO_CONVERGENCE = 0x10 , INVALID_ARGUMENT = 0x20 } |
Math error enumeration. | |
Functions | |
template<typename ElementType , typename Type , typename ... Args> | |
void | make_vec (vec< ElementType > &v, size_t index, Type last) |
template<typename ElementType , typename Type , typename ... Args> | |
void | make_vec (vec< ElementType > &v, size_t index, Type first, Args... elements) |
template<typename Type , typename ... Args> | |
vec< Type > | make_vec (Type first, Args... elements) |
Construct a dynamically allocated vector of type vec<Type> using variadic templates. | |
dual2 | square (dual2 x) |
Return the square of a second order dual number. | |
dual2 | cube (dual2 x) |
Return the cube of a second order dual number. | |
dual2 | conjugate (dual2 x) |
Return the conjugate of a second order dual number. | |
dual2 | pow (dual2 x, int n) |
Compute the n-th power of a second order dual number. | |
dual2 | sqrt (dual2 x) |
Compute the square root of a second order dual number. | |
dual2 | sin (dual2 x) |
Compute the sine of a second order dual number. | |
dual2 | cos (dual2 x) |
Compute the cosine of a second order dual number. | |
dual2 | tan (dual2 x) |
Compute the tangent of a second order dual number. | |
dual2 | cot (dual2 x) |
Compute the cotangent of a second order dual number. | |
dual2 | exp (dual2 x) |
Compute the exponential of a second order dual number. | |
dual2 | ln (dual2 x) |
Compute the natural logarithm of a second order dual number. | |
dual2 | log2 (dual2 x) |
Compute the natural logarithm of a second order dual number. | |
dual2 | log10 (dual2 x) |
Compute the natural logarithm of a second order dual number. | |
dual2 | abs (dual2 x) |
Compute the absolute value of a second order dual number. | |
dual2 | asin (dual2 x) |
Compute the arcsine of a second order dual number. | |
dual2 | acos (dual2 x) |
Compute the arcosine of a second order dual number. | |
dual2 | atan (dual2 x) |
Compute the arctangent of a second order dual number. | |
dual | square (dual x) |
Return the square of a dual number. | |
dual | cube (dual x) |
Return the cube of a dual number. | |
dual | conjugate (dual x) |
Return the conjugate of a dual number. | |
dual | pow (dual x, int n) |
Compute the n-th power of a dual number. | |
dual | sqrt (dual x) |
Compute the square root of a dual number. | |
dual | sin (dual x) |
Compute the sine of a dual number. | |
dual | cos (dual x) |
Compute the cosine of a dual number. | |
dual | tan (dual x) |
Compute the tangent of a dual number. | |
dual | cot (dual x) |
Compute the cotangent of a dual number. | |
dual | exp (dual x) |
Compute the exponential of a dual number. | |
dual | ln (dual x) |
Compute the natural logarithm of a dual number. | |
dual | log2 (dual x) |
Compute the natural logarithm of a dual number. | |
dual | log10 (dual x) |
Compute the natural logarithm of a dual number. | |
dual | abs (dual x) |
Compute the absolute value of a dual number. | |
dual | asin (dual x) |
Compute the arcsine of a dual number. | |
dual | acos (dual x) |
Compute the arccosine of a dual number. | |
dual | atan (dual x) |
Compute the arctangent of a dual number. | |
dual | sinh (dual x) |
Compute the hyperbolic sine of a dual number. | |
dual | cosh (dual x) |
Compute the hyperbolic cosine of a dual number. | |
dual | tanh (dual x) |
Compute the hyperbolic tangent of a dual number. | |
template<unsigned int N> | |
multidual< N > | square (multidual< N > x) |
Return the square of a multidual number. | |
template<unsigned int N> | |
multidual< N > | cube (multidual< N > x) |
Return the cube of a multidual number. | |
template<unsigned int N> | |
multidual< N > | conjugate (multidual< N > x) |
Return the conjugate of a multidual number. | |
template<unsigned int N> | |
multidual< N > | pow (multidual< N > x, int n) |
Compute the n-th power of a multidual number. | |
template<unsigned int N> | |
multidual< N > | sqrt (multidual< N > x) |
Compute the square root of a multidual number. | |
template<unsigned int N> | |
multidual< N > | sin (multidual< N > x) |
Compute the sine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | cos (multidual< N > x) |
Compute the cosine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | tan (multidual< N > x) |
Compute the tangent of a multidual number. | |
template<unsigned int N> | |
multidual< N > | cot (multidual< N > x) |
Compute the cotangent of a multidual number. | |
template<unsigned int N> | |
multidual< N > | exp (multidual< N > x) |
Compute the exponential of a multidual number. | |
template<unsigned int N> | |
multidual< N > | ln (multidual< N > x) |
Compute the natural logarithm of a multidual number. | |
template<unsigned int N> | |
multidual< N > | log2 (multidual< N > x) |
Compute the natural logarithm of a multidual number. | |
template<unsigned int N> | |
multidual< N > | log10 (multidual< N > x) |
Compute the natural logarithm of a multidual number. | |
template<unsigned int N> | |
multidual< N > | abs (multidual< N > x) |
Compute the absolute value of a multidual number. | |
template<unsigned int N> | |
multidual< N > | asin (multidual< N > x) |
Compute the arcsine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | acos (multidual< N > x) |
Compute the arccosine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | atan (multidual< N > x) |
Compute the arctangent of a multidual number. | |
template<unsigned int N> | |
multidual< N > | sinh (multidual< N > x) |
Compute the hyperbolic sine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | cosh (multidual< N > x) |
Compute the hyperbolic cosine of a multidual number. | |
template<unsigned int N> | |
multidual< N > | tanh (multidual< N > x) |
Compute the hyperbolic tangent of a multidual number. | |
template<typename Field = real> | |
polynomial< Field > | deriv (const polynomial< Field > &p) |
Compute the exact derivative of a polynomial function. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv_central (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the first derivative of a real function using the central method. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv_forward (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the first derivative of a real function using the forward method. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv_backward (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the first derivative of a real function using the backward method. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv_ridders2 (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the first derivative of a real function using Ridder's method of second degree. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv_ridders (RealFunction f, real x, real h=0.01, unsigned int degree=3) |
Approximate the first derivative of a real function using Ridder's method of arbitrary degree. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the first derivative of a real function using the best available algorithm. More... | |
template<typename RealFunction = std::function<real(real)>, enable_real_func< RealFunction > = true> | |
real | deriv2 (RealFunction f, real x, real h=CALCULUS_DERIV_STEP) |
Approximate the second derivative of a real function using the best available algorithm. More... | |
template<typename T = real> | |
polynomial< T > | integral (const polynomial< T > &p) |
Compute the indefinite integral of a polynomial. More... | |
template<typename RealFunction > | |
real | integral_midpoint (RealFunction f, real a, real b, unsigned int steps=CALCULUS_INTEGRAL_STEPS) |
Approximate the definite integral of an arbitrary function using the midpoint method. More... | |
template<typename RealFunction > | |
real | integral_trapezoid (RealFunction f, real a, real b, unsigned int steps=CALCULUS_INTEGRAL_STEPS) |
Approximate the definite integral of an arbitrary function using the trapezoid method. More... | |
template<typename RealFunction > | |
real | integral_simpson (RealFunction f, real a, real b, unsigned int steps=CALCULUS_INTEGRAL_STEPS) |
Approximate the definite integral of an arbitrary function using Simpson's method. More... | |
template<typename RealFunction > | |
real | integral_romberg (RealFunction f, real a, real b, unsigned int iter=8) |
Approximate the definite integral of an arbitrary function using Romberg's method accurate to the given order. More... | |
template<typename RealFunction > | |
real | integral_romberg_tol (RealFunction f, real a, real b, real tolerance=CALCULUS_INTEGRAL_TOL) |
Approximate the definite integral of an arbitrary function using Romberg's method to the given tolerance. More... | |
template<typename RealFunction > | |
real | integral_gauss (RealFunction f, const std::vector< real > &x, const std::vector< real > &w) |
Use Gaussian quadrature using the given points and weights. More... | |
template<typename RealFunction > | |
real | integral_gauss (RealFunction f, real *x, real *w, unsigned int n) |
Use Gaussian quadrature using the given points and weights. More... | |
template<typename RealFunction > | |
real | integral_gauss (RealFunction f, real *x, real *w, unsigned int n, real_function Winv) |
Use Gaussian quadrature using the given points and weights. More... | |
template<typename RealFunction > | |
real | integral_legendre (RealFunction f, real a, real b, real *x, real *w, unsigned int n) |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial. More... | |
template<typename RealFunction > | |
real | integral_legendre (RealFunction f, real a, real b, const std::vector< real > &x, const std::vector< real > &w) |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial. More... | |
template<typename RealFunction > | |
real | integral_legendre (RealFunction f, real a, real b, const std::vector< real > &x) |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial. More... | |
template<typename RealFunction > | |
real | integral_legendre (RealFunction f, real a, real b, unsigned int n=16) |
Use Gauss-Legendre quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over [a, b]. More... | |
template<typename RealFunction > | |
real | integral_laguerre (RealFunction f, const std::vector< real > &x) |
Use Gauss-Laguerre quadrature of arbitrary degree to approximate an integral over [0, +inf) providing the roots of the n degree Legendre polynomial. More... | |
template<typename RealFunction > | |
real | integral_laguerre (RealFunction f, real a, real b, const std::vector< real > &x) |
Use Gauss-Laguerre quadrature of arbitrary degree to approximate an integral over [a, b] providing the roots of the n degree Legendre polynomial. More... | |
template<typename RealFunction > | |
real | integral_laguerre (RealFunction f, unsigned int n=16) |
Use Gauss-Laguerre quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over [0, +inf). More... | |
template<typename RealFunction > | |
real | integral_hermite (RealFunction f, const std::vector< real > &x) |
Use Gauss-Hermite quadrature of arbitrary degree to approximate an integral over (-inf, +inf) providing the roots of the n degree Hermite polynomial. More... | |
template<typename RealFunction > | |
real | integral_hermite (RealFunction f, unsigned int n=16) |
Use Gauss-Hermite quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over (-inf, +inf). More... | |
real | integral_inf_riemann (real_function f, real a, real step_sz=1, real tol=CALCULUS_INTEGRAL_TOL, unsigned int max_iter=100) |
Integrate a function from a point up to infinity by integrating it by steps, stopping execution when the variation of the integral is small enough or the number of steps reaches a maximum value. | |
template<typename RealFunction > | |
real | integral (RealFunction f, real a, real b) |
Use the best available algorithm to approximate the definite integral of a real function. More... | |
template<typename RealFunction > | |
real | integral (RealFunction f, real a, real b, real tol) |
Use the best available algorithm to approximate the definite integral of a real function to a given tolerance. More... | |
template<typename T > | |
complex< T > | identity (complex< T > z) |
Complex identity. More... | |
template<typename T > | |
complex< T > | conjugate (complex< T > z) |
Compute the conjugate of a complex number. More... | |
template<typename T > | |
complex< T > | inverse (complex< T > z) |
Compute the conjugate of a complex number. More... | |
template<typename T > | |
complex< T > | square (complex< T > z) |
Compute the square of a complex number. More... | |
template<typename T > | |
complex< T > | cube (complex< T > z) |
Compute the cube of a complex number. More... | |
template<typename T > | |
complex< T > | exp (complex< T > z) |
Compute the complex exponential. More... | |
template<typename T > | |
real | abs (complex< T > z) |
Return the modulus of a complex number. More... | |
template<typename T > | |
complex< T > | sin (complex< T > z) |
Computer the complex sine. More... | |
template<typename T > | |
complex< T > | cos (complex< T > z) |
Compute the complex cosine. More... | |
template<typename T > | |
complex< T > | tan (complex< T > z) |
Compute the complex tangent. More... | |
template<typename T > | |
complex< T > | sqrt (complex< T > z) |
Compute the complex square root. More... | |
template<typename T > | |
complex< T > | ln (complex< T > z) |
Compute the complex logarithm. More... | |
template<typename T > | |
complex< T > | asin (complex< T > z) |
Compute the complex arcsine. More... | |
template<typename T > | |
complex< T > | acos (complex< T > z) |
Compute the complex arccosine. More... | |
template<typename T > | |
complex< T > | atan (complex< T > z) |
Compute the complex arctangent. More... | |
void | mul_uint128 (uint64_t a, uint64_t b, uint64_t &c_low, uint64_t &c_high) |
Multiply two 64-bit unsigned integers and store the result in two 64-bit variables, keeping 128 bits of the result. More... | |
uint64_t | mix_mum (uint64_t a, uint64_t b) |
MUM bit mixing function, computes the 128-bit product of a and b and the XOR of their high and low 64-bit parts. More... | |
template<typename UnsignedIntType > | |
TH_CONSTEXPR UnsignedIntType | bit_rotate (UnsignedIntType x, unsigned int i) |
Bit rotation of unsigned integer types using shifts. More... | |
template<typename Vector , enable_vector< Vector > = true> | |
void | swap_bit_reverse (Vector &x, unsigned int m) |
Swap the elements of a vector pair-wise, by exchanging elements with indices related by bit reversion (e.g. More... | |
template<typename Vector , enable_vector< Vector > = true> | |
auto | product (const Vector &X) |
Compute the product of a set of values. | |
template<typename Vector > | |
auto | product_sum (const Vector &X, const Vector &Y) |
Sum the products of two sets of values. | |
template<typename Vector > | |
auto | product_sum_squares (const Vector &X, const Vector &Y) |
Sum the products of the squares of two sets of data. | |
template<typename Vector > | |
auto | product_sum (const Vector &X, const Vector &Y, const Vector &Z) |
Sum the products of three sets of values. | |
template<typename Vector > | |
auto | quotient_sum (const Vector &X, const Vector &Y) |
Sum the quotients of two sets of values. | |
template<typename Vector > | |
auto | sum_squares (const Vector &X) |
Sum the squares of a set of values. | |
template<typename Vector > | |
real | sum_compensated (const Vector &X) |
Compute the sum of a set of values using the compensated Neumaier-Kahan-Babushka summation algorithm to reduce round-off error. More... | |
template<typename Vector > | |
real | sum_pairwise (const Vector &X, size_t begin=0, size_t end=0, size_t base_size=128) |
Compute the sum of a set of values using pairwise summation to reduce round-off error. More... | |
template<typename Vector , std::enable_if_t< has_real_elements< Vector >::value > = true> | |
auto | sum (const Vector &X) |
Compute the sum of a vector of real values using pairwise summation to reduce round-off error. More... | |
template<typename Vector > | |
auto | sum (const Vector &X) |
Compute the sum of a set of values. More... | |
template<typename Vector , typename Function > | |
Vector & | apply (Function f, Vector &X) |
Apply a function to a set of values element-wise. More... | |
template<typename Vector1 , typename Vector2 = Vector1, typename Function > | |
Vector2 & | map (Function f, const Vector1 &src, Vector2 &dest) |
Get a new vector obtained by applying the function element-wise. More... | |
template<typename Vector2 , typename Vector1 , typename Function > | |
Vector2 | map (Function f, const Vector1 &X) |
Get a new vector obtained by applying the function element-wise. More... | |
template<typename Vector , typename Function > | |
Vector | map (Function f, const Vector &X) |
Get a new vector obtained by applying the function element-wise. More... | |
template<typename Vector1 , typename Vector2 , typename Vector3 = Vector1> | |
Vector3 | concatenate (const Vector1 &v1, const Vector2 &v2) |
Concatenate two datasets to form a single one. | |
template<typename Vector > | |
auto | max (const Vector &X) |
Finds the maximum value inside a dataset. | |
template<typename Vector > | |
auto | min (const Vector &X) |
Finds the minimum value inside a dataset. | |
template<typename Dataset > | |
real | arithmetic_mean (const Dataset &data) |
Compute the arithmetic mean of a set of values. | |
template<typename Dataset > | |
real | harmonic_mean (const Dataset &data) |
Compute the harmonic mean of a set of values. | |
template<typename Dataset > | |
real | geometric_mean (const Dataset &data) |
Compute the geometric mean of a set of values as \(\sqrt[n]{\Pi_i x_i}\). | |
template<typename Dataset1 , typename Dataset2 > | |
real | weighted_mean (const Dataset1 &data, const Dataset2 &weights) |
Compute the weighted mean of a set of values <data> and <weights> must have the same size. | |
template<typename Dataset > | |
real | quadratic_mean (const Dataset &data) |
Compute the quadratic mean (Root Mean Square) of a set of values \(m_q = \sqrt{x1^2 + x2^2 + ...}\). | |
int | th_errcode_to_errno (MATH_ERRCODE err) |
Convert a MATH_ERRCODE to errno error codes. | |
real | nan () |
Return a quiet NaN number in floating point representation. | |
template<typename T > | |
bool | is_nan (const T &x) |
Check whether a generic variable is (equivalent to) a NaN number. More... | |
real | inf () |
Return positive infinity in floating point representation. | |
TH_CONSTEXPR real | identity (real x) |
Identity. | |
template<typename Type , typename = std::enable_if<is_real_type<Type>::value>> | |
TH_CONSTEXPR Type | conjugate (Type x) |
Complex conjugate of a real number (identity) | |
TH_CONSTEXPR real | square (real x) |
Compute the square of a real number. More... | |
TH_CONSTEXPR real | cube (real x) |
Compute the cube of a real number. More... | |
template<typename UnsignedIntType = uint64_t> | |
UnsignedIntType | isqrt (UnsignedIntType n) |
Compute the integer square root of a positive integer. More... | |
template<typename UnsignedIntType = uint64_t> | |
UnsignedIntType | icbrt (UnsignedIntType n) |
Compute the integer cubic root of a positive integer. More... | |
real | sqrt (real x) |
Compute the square root of a real number. More... | |
real | cbrt (real x) |
Compute the cubic root of x. More... | |
real | abs (real x) |
Compute the absolute value of a real number. More... | |
int | sgn (real x) |
Return the sign of x (1 if positive, -1 if negative, 0 if null) More... | |
TH_CONSTEXPR int | floor (real x) |
Compute the floor of x Computes the maximum integer number that is smaller than x. More... | |
real | fract (real x) |
Compute the fractional part of a real number. More... | |
real | max (real x, real y) |
Return the greatest number between two real numbers. More... | |
template<typename T > | |
T | max (T x, T y) |
Compare two objects and return the greatest. More... | |
real | min (real x, real y) |
Return the smallest number between two real numbers. More... | |
template<typename T > | |
T | min (T x, T y) |
Compare two objects and return the greatest. More... | |
real | clamp (real x, real a, real b) |
Clamp x between a and b. More... | |
template<typename T > | |
T | clamp (T x, T a, T b) |
Clamp a value between two other values. More... | |
real | log2 (real x) |
Compute the binary logarithm of a real number. More... | |
real | log10 (real x) |
Compute the base-10 logarithm of x. More... | |
real | ln (real x) |
Compute the natural logarithm of x. More... | |
template<typename UnsignedIntType = uint64_t> | |
UnsignedIntType | ilog2 (UnsignedIntType x) |
Find the integer logarithm of x. More... | |
template<typename UnsignedIntType = uint64_t> | |
UnsignedIntType | pad2 (UnsignedIntType x) |
Get the smallest power of 2 bigger than or equal to x. More... | |
template<typename T = real> | |
TH_CONSTEXPR T | pow (T x, int n) |
Compute the n-th power of x (where n is natural) More... | |
template<typename T = real> | |
TH_CONSTEXPR T | ipow (T x, unsigned int n, T neutral_element=T(1)) |
Compute the n-th positive power of x (where n is natural) More... | |
template<typename IntType = uint64_t> | |
TH_CONSTEXPR IntType | fact (unsigned int n) |
Compute the factorial of n. | |
template<typename T = uint64_t> | |
TH_CONSTEXPR T | falling_fact (T x, unsigned int n) |
Compute the falling factorial of n. | |
template<typename T = uint64_t> | |
TH_CONSTEXPR T | rising_fact (T x, unsigned int n) |
Compute the rising factorial of n. | |
template<typename IntType = unsigned long long int> | |
TH_CONSTEXPR IntType | double_fact (unsigned int n) |
Compute the double factorial of n. | |
real | exp (real x) |
Compute the real exponential. More... | |
real | expm1 (real x) |
Compute the exponential of x minus 1 more accurately for really small x. More... | |
real | powf (real x, real a) |
Approximate x elevated to a real exponent. More... | |
real | root (real x, int n) |
Compute the n-th root of x. More... | |
real | sin (real x) |
Compute the sine of a real number. More... | |
real | cos (real x) |
Compute the cosine of a real number. More... | |
real | tan (real x) |
Compute the tangent of x. More... | |
real | cot (real x) |
Compute the cotangent of x. More... | |
real | atan (real x) |
Compute the arctangent. More... | |
real | asin (real x) |
Compute the arcsine. More... | |
real | acos (real x) |
Compute the arccosine. More... | |
real | atan2 (real y, real x) |
Compute the 2 argument arctangent. More... | |
real | sinh (real x) |
Compute the hyperbolic sine. More... | |
real | cosh (real x) |
Compute the hyperbolic cosine. More... | |
real | tanh (real x) |
Compute the hyperbolic tangent. More... | |
real | coth (real x) |
Compute the hyperbolic cotangent. More... | |
real | asinh (real x) |
Compute the inverse hyperbolic sine. | |
real | acosh (real x) |
Compute the inverse hyperbolic cosine. | |
real | atanh (real x) |
Compute the inverse hyperbolic tangent. | |
real | sigmoid (real x) |
Compute the sigmoid function. More... | |
real | sinc (real x) |
Compute the normalized sinc function. More... | |
real | heaviside (real x) |
Compute the heaviside function. More... | |
template<typename IntType = unsigned long long int> | |
TH_CONSTEXPR IntType | binomial_coeff (unsigned int n, unsigned int m) |
Compute the binomial coefficient. More... | |
TH_CONSTEXPR real | radians (real degrees) |
Convert degrees to radians. More... | |
TH_CONSTEXPR real | degrees (real radians) |
Convert radians to degrees. More... | |
template<typename T > | |
TH_CONSTEXPR T | kronecker_delta (T i, T j) |
Kronecker delta, equals 1 if i is equal to j, 0 otherwise. More... | |
template<typename IntType = unsigned long long int> | |
TH_CONSTEXPR IntType | catalan (unsigned int n) |
The n-th Catalan number. | |
template<typename T = real> | |
polynomial< T > | lagrange_polynomial (const std::vector< vec< T, 2 >> &points) |
Compute the Lagrange polynomial interpolating a set of points. More... | |
template<typename VectorType = std::vector<real>> | |
VectorType | chebyshev_nodes (real a, real b, unsigned int n) |
Compute the n Chebyshev nodes on a given interval. More... | |
polynomial< real > | interpolate_grid (real_function f, real a, real b, unsigned int order) |
Compute the interpolating polynomial of a real function on an equidistant point sample. More... | |
polynomial< real > | interpolate_chebyshev (real_function f, real a, real b, unsigned int order) |
Compute the interpolating polynomial of a real function using Chebyshev nodes as sampling points. More... | |
real | lerp (real x1, real x2, real interp) |
Linear interpolation. | |
template<unsigned int N> | |
vec< real, N > | lerp (const vec< real, N > &P1, const vec< real, N > &P2, real interp) |
Linear interpolation. | |
real | invlerp (real x1, real x2, real value) |
Inverse linear interpolation. | |
template<unsigned int N> | |
vec< real, N > | invlerp (const vec< real, N > &P1, const vec< real, N > &P2, real value) |
Inverse linear interpolation. | |
real | remap (real iFrom, real iTo, real oFrom, real oTo, real value) |
Remap a value from one range to another. | |
template<unsigned int N> | |
vec< real, N > | remap (const vec< real, N > &iFrom, const vec< real, N > &iTo, const vec< real, N > &oFrom, const vec< real, N > &oTo, real value) |
Remap a vector value from one range to another. | |
template<unsigned int N> | |
vec< real, N > | nlerp (const vec< real, N > &P1, const vec< real, N > &P2, real interp) |
Normalized linear interpolation. | |
template<unsigned int N> | |
vec< real, N > | slerp (const vec< real, N > &P1, const vec< real, N > &P2, real t) |
Spherical interpolation. | |
real | smoothstep (real x1, real x2, real interp) |
Smoothstep interpolation. | |
real | smootherstep (real x1, real x2, real interp) |
Smootherstep interpolation. | |
template<unsigned int N> | |
vec< real, N > | quadratic_bezier (const vec< real, N > &P0, const vec< real, N > &P1, const vec< real, N > &P2, real t) |
Quadratic Bezier curve. | |
template<unsigned int N> | |
vec< real, N > | cubic_bezier (const vec< real, N > &P0, const vec< real, N > &P1, const vec< real, N > &P2, vec< real, N > P3, real t) |
Cubic Bezier curve. | |
template<unsigned int N> | |
vec< real, N > | bezier (const std::vector< vec< real, N >> &points, real t) |
Generic Bezier curve in N dimensions. More... | |
template<typename DataPoints = std::vector<vec2>> | |
std::vector< spline_node > | cubic_splines (DataPoints p) |
Compute the cubic splines interpolation of a set of data points. More... | |
template<typename Dataset1 , typename Dataset2 > | |
std::vector< spline_node > | cubic_splines (const Dataset1 &x, const Dataset2 &y) |
Compute the cubic splines interpolation of the sets of X and Y data points. More... | |
template<typename RealFunction > | |
real | maximize_goldensection (RealFunction f, real a, real b) |
Approximate a function maximum using the Golden Section search algorithm. More... | |
template<typename RealFunction > | |
real | minimize_goldensection (RealFunction f, real a, real b) |
Approximate a function minimum using the Golden Section search algorithm. More... | |
template<typename RealFunction > | |
real | maximize_newton (RealFunction f, RealFunction Df, RealFunction D2f, real guess=0) |
Approximate a function maximum given the function and the first two derivatives using Newton-Raphson's method to find a root of the derivative. More... | |
template<typename RealFunction > | |
real | minimize_newton (RealFunction f, RealFunction Df, RealFunction D2f, real guess=0) |
Approximate a function minimum given the function and the first two derivatives using Newton-Raphson's method to find a root of the derivative. More... | |
template<typename RealFunction > | |
real | maximize_bisection (RealFunction f, RealFunction Df, real a, real b) |
Approximate a function maximum inside an interval given the function and its first derivative using bisection on the derivative. More... | |
template<typename RealFunction > | |
real | minimize_bisection (RealFunction f, RealFunction Df, real a, real b) |
Approximate a function minimum inside an interval given the function and its first derivative using bisection on the derivative. More... | |
template<unsigned int N> | |
vec< real, N > | multi_minimize_grad (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real gamma=OPTIMIZATION_MINGRAD_GAMMA, real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE, unsigned int max_iter=OPTIMIZATION_MINGRAD_ITER) |
Find a local minimum of the given multivariate function using fixed-step gradient descent. More... | |
template<unsigned int N> | |
vec< real, N > | multi_maximize_grad (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real gamma=OPTIMIZATION_MINGRAD_GAMMA, real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE, unsigned int max_iter=OPTIMIZATION_MINGRAD_ITER) |
Find a local maximum of the given multivariate function using fixed-step gradient descent. More... | |
template<unsigned int N> | |
vec< real, N > | multi_minimize_lingrad (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE, unsigned int max_iter=OPTIMIZATION_MINGRAD_ITER) |
Find a local minimum of the given multivariate function using gradient descent with linear search. More... | |
template<unsigned int N> | |
vec< real, N > | multi_maximize_lingrad (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE, unsigned int max_iter=OPTIMIZATION_MINGRAD_ITER) |
Find a local maximum of the given multivariate function using gradient descent with linear search. More... | |
template<unsigned int N> | |
vec< real, N > | multi_minimize (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE) |
Use the best available algorithm to find a local minimum of the given multivariate function. More... | |
template<unsigned int N> | |
vec< real, N > | multi_maximize (multidual< N >(*f)(vec< multidual< N >, N >), vec< real, N > guess=vec< real, N >(0), real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE) |
Use the best available algorithm to find a local maximum of the given multivariate function. More... | |
template<unsigned int N> | |
vec< real, N > | multiroot_newton (autodiff::dvec_t< N >(*f)(autodiff::dvec_t< N >), vec< real, N > guess=vec< real, N >(0), real tolerance=OPTIMIZATION_MINGRAD_TOLERANCE, unsigned int max_iter=OPTIMIZATION_MINGRAD_ITER) |
Approximate the root of a multivariate function using Newton's method with pure Jacobian. More... | |
template<typename RealFunction > | |
std::vector< vec2 > | find_root_intervals (RealFunction f, real a, real b, unsigned int steps=10) |
Find candidate intervals for root finding. More... | |
template<typename RealFunction > | |
real | root_bisection (RealFunction f, real a, real b, real tolerance=OPTIMIZATION_TOL) |
Approximate a root of an arbitrary function using bisection inside a compact interval [a, b] where f(a) * f(b) < 0. More... | |
template<typename RealFunction > | |
real | root_newton (RealFunction f, RealFunction Df, real guess=0) |
Approximate a root of an arbitrary function using Newton's method. More... | |
real | root_newton (dual(*f)(dual), real guess=0) |
Approximate a root of an arbitrary function using Newton's method, computing the derivative using automatic differentiation. More... | |
real | root_newton (const polynomial< real > &p, real guess=0) |
Approximate a root of a polynomial using Newton's method. More... | |
complex | root_newton (complex<>(*f)(complex<>), complex<>(*df)(complex<>), complex<> guess=complex<>(0, 0), real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_TOL) |
Approximate a root of an arbitrary complex function using Newton's method,. More... | |
template<typename RealFunction > | |
real | root_halley (RealFunction f, RealFunction Df, RealFunction D2f, real guess=0) |
Approximate a root of an arbitrary function using Halley's method. More... | |
real | root_halley (dual2(*f)(dual2), real guess=0) |
Approximate a root of an arbitrary function using Halley's method, leveraging automatic differentiation to compute the first and second derivatives of the function. More... | |
real | root_halley (const polynomial< real > &p, real guess=0) |
Approximate a root of a polynomial using Halley's method. More... | |
template<typename RealFunction > | |
real | root_steffensen (RealFunction f, real guess=0) |
Approximate a root of an arbitrary function using Steffensen's method. More... | |
real | root_steffensen (const polynomial< real > &p, real guess=0) |
Approximate a root of a polynomial using Steffensen's method. More... | |
template<typename RealFunction > | |
real | root_chebyshev (RealFunction f, RealFunction Df, RealFunction D2f, real guess=0) |
Approximate a root of an arbitrary function using Chebyshev's method. More... | |
real | root_chebyshev (dual2(*f)(dual2), real guess=0) |
Approximate a root of an arbitrary function using Chebyshev's method, by computing the first and second derivatives using automatic differentiation. More... | |
real | root_chebyshev (const polynomial< real > &p, real guess=0) |
Approximate a root of a polynomial using Chebyshev's method. More... | |
template<typename RealFunction > | |
std::vector< real > | roots (RealFunction f, real a, real b, real tolerance=OPTIMIZATION_TOL, real steps=10) |
Find the roots of a function inside a given interval. More... | |
template<typename Field > | |
std::vector< Field > | roots (const polynomial< Field > &p, real tolerance=OPTIMIZATION_TOL, unsigned int steps=0) |
Find all the roots of a polynomial. More... | |
polynomial< real > | gen_polyn_recurr (polynomial< real > P0, polynomial< real > P1, polyn_recurr_formula f, unsigned int n) |
Generate a polynomial basis using a recursion formula. More... | |
polynomial< real > | legendre_polyn_recurr (polynomial< real > P0, polynomial< real > P1, unsigned int l) |
Recursion formula for Legendre polynomials. | |
polynomial< real > | legendre_polynomial (unsigned int n) |
Compute the nth Legendre polynomial. More... | |
real | legendre_polyn_normalization (unsigned int n) |
Normalization constant for the nth Legendre polynomial. | |
std::function< real(real)> | assoc_legendre_polynomial (unsigned int l, int m) |
polynomial< real > | assoc_legendre_polynomial_even (unsigned int l, int m) |
polynomial< real > | laguerre_polyn_recurr (polynomial< real > L0, polynomial< real > L1, unsigned int i) |
Recursion formula for Laguerre polynomials. | |
polynomial< real > | laguerre_polynomial (unsigned int n) |
Compute the nth Laguerre polynomial. | |
polynomial< real > | general_laguerre_polyn_recurr (polynomial< real > L0, polynomial< real > L1, real alpha, unsigned int i) |
Recursion formula for Generalized Laguerre polynomials. | |
polynomial< real > | general_laguerre_polynomial (real alpha, unsigned int n) |
Compute the nth Laguerre polynomial. | |
polynomial< real > | hermite_polyn_recurr (polynomial< real > H0, polynomial< real > H1, unsigned int i) |
Recursion formula for Hermite polynomials. | |
polynomial< real > | hermite_polynomial (unsigned int n) |
Compute the nth Hermite polynomial. More... | |
real | hermite_polyn_normalization (unsigned int n) |
Normalization constant for the nth Hermite polynomial. | |
polynomial< real > | chebyshev_polyn_recurr (polynomial< real > T0, polynomial< real > T1, unsigned int i) |
Recursion formula for Chebyshev polynomials The formula is the same for first and second kind polynomials. | |
polynomial< real > | chebyshev1_polynomial (unsigned int n) |
Compute the nth Chebyshev polynomial of the first kind. More... | |
polynomial< real > | chebyshev2_polynomial (unsigned int n) |
Compute the nth Chebyshev polynomial of the second kind. More... | |
std::vector< real > | legendre_roots (unsigned int n) |
Roots of the n-th Legendre polynomial. More... | |
std::vector< real > | legendre_weights (const std::vector< real > &roots) |
Legendre weights for Gauss-Legendre quadrature of n-th order. More... | |
std::vector< real > | laguerre_weights (const std::vector< real > &roots) |
Laguerre weights for Gauss-Laguerre quadrature of n-th order. More... | |
std::vector< real > | hermite_weights (const std::vector< real > &roots) |
Hermite weights for Gauss-Hermite quadrature of n-th order. More... | |
real | integral_crude (real_function f, real a, real b, PRNG &g, unsigned int N=1000) |
Approximate an integral by using Crude Monte Carlo integration. More... | |
template<unsigned int S> | |
real | integral_crude (real(*f)(vec< real, S >), vec< vec2, S > extremes, PRNG &g, unsigned int N=1000) |
Approximate an integral by using Crude Monte Carlo integration. More... | |
real | integral_quasi_crude (real_function f, real a, real b, unsigned int N=1000) |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence. More... | |
template<unsigned int S> | |
real | integral_quasi_crude (real(*f)(vec< real, S >), vec< vec2, S > extremes, unsigned int N, vec< real, S > alpha) |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence. More... | |
template<unsigned int S> | |
real | integral_quasi_crude (real(*f)(vec< real, S >), vec< vec2, S > extremes, unsigned int N=1000, real alpha=0) |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence. More... | |
real | integral_hom (real_function f, real a, real b, real c, real d, PRNG &g, unsigned int N=1000) |
Approximate an integral by using Hit-or-miss Monte Carlo integration. More... | |
real | integral_hom (real_function f, real a, real b, real f_max, PRNG &g, unsigned int N=1000) |
Approximate an integral by using Hit-or-miss Monte Carlo integration. More... | |
real | integral_quasi_hom (real_function f, real a, real b, real c, real d, unsigned int N=1000) |
Approximate an integral by using Hit-or-miss Quasi-Monte Carlo integration, sampling points from the Weyl bi-dimensional sequence. More... | |
real | integral_quasi_hom (real_function f, real a, real b, real f_max, unsigned int N=1000) |
Approximate an integral by using Hit-or-miss Quasi-Monte Carlo integration, sampling points from the Weyl bi-dimensional sequence. More... | |
real | integral_hom_2d (real(*f)(real, real), real a, real b, real c, real d, real f_max, PRNG &g, unsigned int N=1000) |
Use the Hit-or-Miss Monte Carlo method to approximate a double integral. More... | |
real | integral_impsamp (real_function f, real_function g, real_function Ginv, PRNG &gen, unsigned int N=1000) |
Approximate an integral by using Crude Monte Carlo integration with importance sampling. More... | |
real | integral_quasi_impsamp (real_function f, real_function g, real_function Ginv, unsigned int N=1000) |
Approximate an integral by using Crude Quasi-Monte Carlo integration with importance sampling, using the Weyl sequence. More... | |
template<typename Vector = std::vector<real>, typename Function = std::function<real(vec<real>)>> | |
Vector | sample_mc (Function f, std::vector< pdf_sampler > &rv, unsigned int N) |
Generate a Monte Carlo sample of values of a given function of arbitrary variables following the given distributions. More... | |
template<typename Vector > | |
void | shuffle (Vector &v, PRNG &g, unsigned int rounds=0) |
Shuffle a set by exchanging random couples of elements. More... | |
uint64_t | rand_congruential (uint64_t x, uint64_t a=48271, uint64_t c=0, uint64_t m=((uint64_t) 1<< 31) - 1) |
Generate a pseudorandom number using the congruential pseudorandom number generation algorithm. More... | |
uint64_t | rand_congruential (uint64_t x, std::vector< uint64_t > &state) |
Generate a pseudorandom number using the congruential pseudorandom number generation algorithm (wrapper) More... | |
uint64_t | rand_xoshiro (uint64_t &a, uint64_t &b, uint64_t &c, uint64_t &d) |
Generate a pseudorandom number using the xoshiro256++ pseudorandom number generation algorithm. More... | |
uint64_t | rand_xoshiro (uint64_t x, std::vector< uint64_t > &state) |
Generate a pseudorandom number using the xoshiro256++ pseudorandom number generation algorithm (wrapper) More... | |
uint64_t | rand_splitmix64 (uint64_t x) |
Generate a pseudorandom number using the SplitMix64 pseudorandom number generation algorithm. More... | |
uint64_t | rand_splitmix64 (uint64_t x, std::vector< uint64_t > &p) |
Generate a pseudorandom number using the SplitMix64 pseudorandom number generation algorithm. More... | |
uint64_t | rand_wyrand (uint64_t &seed, uint64_t p1, uint64_t p2) |
Generate a pseudorandom number using the Wyrand pseudorandom number generation, as invented by Yi Wang. More... | |
uint64_t | rand_wyrand (uint64_t x, std::vector< uint64_t > &p) |
Generate a pseudorandom number using the Wyrand pseudorandom number generation, as invented by Yi Wang (wrapper) More... | |
uint64_t | rand_middlesquare (uint64_t seed, uint64_t offset=765872292751861) |
Generate a pseudorandom number using the middle-square pseudorandom number generation algorithm. More... | |
uint64_t | rand_middlesquare (uint64_t x, std::vector< uint64_t > &p) |
Generate a pseudorandom number using the middle-square pseudorandom number generation algorithm (wrapper) More... | |
real | qrand_weyl (unsigned int n, real alpha=INVPHI) |
Weyl quasi-random sequence. More... | |
real | qrand_weyl_recurr (real prev=0, real alpha=INVPHI) |
Weyl quasi-random sequence (computed with recurrence relation) More... | |
template<unsigned int N> | |
vec< real, N > | qrand_weyl_multi (unsigned int n, real alpha) |
Weyl quasi-random sequence in N dimensions. More... | |
vec2 | qrand_weyl2 (unsigned int n, real alpha=0.7548776662466927) |
Weyl quasi-random sequence in 2 dimensions. More... | |
real | rand_uniform (real a, real b, PRNG &g, uint64_t prec=STATISTICS_RAND_PREC) |
Generate a pseudorandom real number in [a, b] using a preexisting generator. More... | |
real | rand_uniform (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_uniform(real, real, PRNG) More... | |
real | rand_cointoss (PRNG &g) |
Coin toss random generator. More... | |
real | rand_cointoss (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_cointoss(PRNG) More... | |
real | rand_diceroll (unsigned int faces, PRNG &g) |
Dice roll random generator. More... | |
real | rand_diceroll (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_diceroll(PRNG) More... | |
real | rand_trycatch (stat_function f, const vec< real > &theta, real x1, real x2, real y1, real y2, PRNG &g, unsigned int max_iter=STATISTICS_TRYANDCATCH_ITER) |
Generate a pseudorandom value following any probability distribution function using the Try-and-Catch (rejection) algorithm. More... | |
real | rand_rejectsamp (stat_function f, const vec< real > &theta, real_function p, real_function Pinv, PRNG &g, unsigned int max_tries=100) |
Generate a random number following any given distribution using rejection sampling. More... | |
real | rand_gaussian_polar (real mean, real sigma, PRNG &g) |
Generate a random number following a Gaussian distribution using Marsaglia's polar method. More... | |
real | rand_gaussian_boxmuller (real mean, real sigma, PRNG &g) |
Generate a random number following a Gaussian distribution using the Box-Muller method. More... | |
real | rand_gaussian_clt (real mean, real sigma, PRNG &g) |
Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem. More... | |
real | rand_gaussian_clt (real mean, real sigma, PRNG &g, unsigned int N) |
Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem. More... | |
real | rand_gaussian (real mean, real sigma, PRNG &g) |
Generate a random number following a Gaussian distribution using the best available algorithm. | |
real | rand_gaussian (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_gaussian(real, real, PRNG) More... | |
real | rand_exponential (real lambda, PRNG &g) |
Generate a random number following an exponential distribution using the quantile (inverse) function method. | |
real | rand_exponential (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_exponential(real, PRNG) More... | |
real | rand_rayleigh (real sigma, PRNG &g) |
Generate a random number following a Rayleigh distribution using the quantile (inverse) function method. | |
real | rand_rayleigh (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_rayleigh(real, PRNG) More... | |
real | rand_cauchy (real mu, real alpha, PRNG &g) |
Generate a random number following a Cauchy distribution using the quantile (inverse) function method. | |
real | rand_cauchy (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_cauchy(real, real, PRNG) More... | |
real | rand_laplace (real mu, real b, PRNG &g) |
Generate a random number following a Laplace distribution using the quantile (inverse) function method. | |
real | rand_laplace (const std::vector< real > &theta, PRNG &g) |
Generate a random number following a Laplace distribution using the quantile (inverse) function method. | |
real | rand_pareto (real x_m, real alpha, PRNG &g) |
Generate a random number following a Pareto distribution using the quantile (inverse) function method. | |
real | rand_pareto (const std::vector< real > &theta, PRNG &g) |
Wrapper for rand_pareto(real, real, PRNG) More... | |
real | metropolis (real_function pdf, pdf_sampler &g, real x0, PRNG &rnd, unsigned int depth=STATISTICS_METROPOLIS_DEPTH) |
Metropolis algorithm for distribution sampling using a symmetric proposal distribution. More... | |
real | metropolis (real_function pdf, pdf_sampler &g, real x0, unsigned int depth=STATISTICS_METROPOLIS_DEPTH) |
Metropolis algorithm for distribution sampling using a symmetric proposal distribution. More... | |
real | max (const histogram &h) |
Compute the maximum value of the elements of a histogram. | |
real | min (const histogram &h) |
Compute the minimum value of the elements of a histogram. | |
template<typename Type > | |
void | print (const Type &curr) |
Print the given argument to standard output. | |
template<typename Type , typename ... Args> | |
void | print (const Type &curr, Args... args) |
Print the given arguments to standard output separated by a space. | |
template<typename Type > | |
void | fprint (std::ostream &out, const Type &last) |
Print the given argument to a stream. | |
template<typename Type , typename ... Args> | |
void | fprint (std::ostream &out, const Type &curr, Args... args) |
Print the given arguments to standard output separated by a space. | |
void | println () |
Print a newline to standard output. | |
template<typename Type > | |
void | println (const Type &curr) |
Print the given argument to standard output followed by a newline. | |
template<typename Type , typename ... Args> | |
void | println (const Type &curr, Args... args) |
Print the given arguments to standard output separated by a space and followed by a newline. | |
template<typename Type > | |
void | fprintln (std::ostream &out, const Type &curr) |
Print the given argument to an output stream followed by a newline. | |
template<typename Type , typename ... Args> | |
void | fprintln (std::ostream &out, const Type &curr, Args... args) |
Print the given arguments to an output stream separated by a space and followed by a newline. | |
template<typename Type = real> | |
vec< Type > | readln (std::istream &in, const std::string &terminator, std::function< Type(std::string)> parse) |
Insert a data set of the given type from a stream, reading line by line until a line is equal to the terminator and parsing each line using the given function, returning the list of values. | |
vec< real > | readln (std::istream &in, const std::string &terminator="") |
Insert a data set of the given type from a stream, reading line by line until a line is equal to the terminator and parsing each line as a real value, returning the list of values. | |
vec< real > | readln (const std::string &terminator="") |
Insert a data set of the given type from standard input, reading line by line until a line is equal to the terminator and parsing each line as a real value, returning the list of values. | |
Variables | |
constexpr real | MACH_EPSILON = std::numeric_limits<real>::epsilon() |
Machine epsilon for the real type. | |
constexpr real | PHI = 1.6180339887498948482045868 |
The Phi (Golden Section) mathematical constant. | |
constexpr real | INVPHI = 0.6180339887498948482045868 |
The inverse of the Golden Section mathematical constant. | |
constexpr real | PI = 3.141592653589793238462643 |
The Pi mathematical constant. | |
constexpr real | PI2 = 1.57079632679489655799898 |
Half of Pi. | |
constexpr real | PI4 = PI / 4.0 |
A quarter of Pi. | |
constexpr real | PIDOUBLE = PI * 2 |
Pi multiplied by 2. | |
constexpr real | TAU = PI * 2 |
The Tau mathematical constant (Pi times 2) | |
constexpr real | INVPI = 1.0 / PI |
The inverse of Pi. | |
constexpr real | SQRTPI = 1.7724538509055159927 |
The square root of Pi. | |
constexpr real | E = 2.718281828459045235360287 |
The Euler mathematical constant (e) | |
constexpr real | LOG2E = 1.44269504088896338700465094 |
The binary logarithm of e. | |
constexpr real | LOG210 = 3.32192809488736218170856773213 |
The binary logarithm of 10. | |
constexpr real | LOG10E = 0.434294481903 |
The base-10 logarithm of e. | |
constexpr real | LN2 = 0.69314718056 |
The natural logarithm of 2. | |
constexpr real | LN10 = 2.30258509299 |
The natural logarithm of 10. | |
constexpr real | DEG2RAD = 0.017453292519943295474371680598 |
The scalar conversion factor from degrees to radians. | |
constexpr real | RAD2DEG = 57.2957795130823228646477218717 |
The scalar conversion factor from radians to degrees. | |
constexpr real | SQRT2 = 1.4142135623730950488 |
The square root of 2. | |
constexpr real | INVSQR2 = 0.7071067811865475 |
The inverse of the square root of 2. | |
constexpr real | SQRT3 = 1.732050807568877 |
The square root of 3. | |
constexpr real | ALGEBRA_ELEMENT_TOL = THEORETICA_ALGEBRA_ELEMENT_TOL |
Tolerance for the elements of matrices. | |
constexpr real | ALGEBRA_EIGEN_TOL = THEORETICA_ALGEBRA_EIGEN_TOL |
Tolerance for eigensolvers. | |
constexpr real | ALGEBRA_EIGEN_ITER = THEORETICA_ALGEBRA_EIGEN_ITER |
Maximum number of iterations for eigensolvers. | |
constexpr int | CORE_TAYLOR_ORDER = THEORETICA_CORE_TAYLOR_ORDER |
Order of Taylor series approximations. | |
constexpr int | CALCULUS_INTEGRAL_STEPS = THEORETICA_CALCULUS_INTEGRAL_STEPS |
Default number of steps for integral approximation. | |
constexpr real | CALCULUS_INTEGRAL_TOL = THEORETICA_CALCULUS_INTEGRAL_TOL |
constexpr real | OPTIMIZATION_TOL = THEORETICA_OPTIMIZATION_TOL |
Approximation tolerance for root finding. | |
constexpr unsigned int | OPTIMIZATION_BISECTION_ITER = THEORETICA_OPTIMIZATION_BISECTION_ITER |
Maximum number of iterations for the bisection algorithm. | |
constexpr unsigned int | OPTIMIZATION_GOLDENSECTION_ITER = THEORETICA_OPTIMIZATION_GOLDENSECTION_ITER |
Maximum number of iterations for the golden section search algorithm. | |
constexpr unsigned int | OPTIMIZATION_HALLEY_ITER = THEORETICA_OPTIMIZATION_HALLEY_ITER |
Maximum number of iterations for Halley's method. | |
constexpr unsigned int | OPTIMIZATION_NEWTON_ITER = THEORETICA_OPTIMIZATION_NEWTON_ITER |
Maximum number of iterations for the Newton-Raphson algorithm. | |
constexpr unsigned int | OPTIMIZATION_STEFFENSEN_ITER = THEORETICA_OPTIMIZATION_STEFFENSEN_ITER |
Maximum number of iterations for the Steffensen algorithm. | |
constexpr unsigned int | OPTIMIZATION_CHEBYSHEV_ITER = THEORETICA_OPTIMIZATION_CHEBYSHEV_ITER |
Maximum number of iterations for the Chebyshev algorithm. | |
constexpr unsigned int | STATISTICS_TRYANDCATCH_ITER = THEORETICA_STATISTICS_TRYANDCATCH_ITER |
Maximum number of failed iterations for the Try-and-Catch algorithm. | |
constexpr real | CALCULUS_DERIV_STEP = THEORETICA_CALCULUS_DERIV_STEP |
Default variation for derivative approximation. | |
constexpr real | OPTIMIZATION_MINGRAD_GAMMA = THEORETICA_OPTIMIZATION_MINGRAD_GAMMA |
Default step size for gradient descent minimization. | |
constexpr real | OPTIMIZATION_MINGRAD_TOLERANCE = THEORETICA_OPTIMIZATION_MINGRAD_TOLERANCE |
Default tolerance for gradient descent minimization. | |
constexpr unsigned int | OPTIMIZATION_MINGRAD_ITER = THEORETICA_OPTIMIZATION_MINGRAD_ITER |
Maximum number of iterations for gradient descent minimization. | |
constexpr uint64_t | STATISTICS_RAND_PREC = THEORETICA_STATISTICS_RAND_PREC |
Default precision for random number generation using rand_uniform() | |
constexpr unsigned int | STATISTICS_METROPOLIS_DEPTH = THEORETICA_STATISTICS_METROPOLIS_DEPTH |
Default depth of the Metropolis algorithm. | |
Main namespace of the library which contains all functions and objects.
using theoretica::enable_complex = typedef std::enable_if_t<is_complex_type<Structure>::value, T> |
Enable a function overload if the template typename is considerable a complex number.
The std::enable_if structure is used, with type T which defaults to bool.
using theoretica::enable_matrix = typedef std::enable_if_t<is_matrix<Structure>::value, T> |
Enable a function overload if the template typename is considerable a matrix.
The std::enable_if structure is used, with type T which defaults to bool.
using theoretica::enable_vector = typedef std::enable_if_t<is_vector<Structure>::value, T> |
Enable a function overload if the template typename is considerable a vector.
The std::enable_if structure is used, with type T which defaults to bool.
using theoretica::pseudorandom_function = typedef uint64_t (*)(uint64_t, std::vector<uint64_t>&) |
A function pointer which wraps a pseudorandom generator, taking as input the previous generated value (or seed) and the current state of the algorithm.
Such functions may be passed to the PRNG class to simplify the usage of generators.
using theoretica::real = typedef double |
A real number, defined as a floating point type.
The underlying type is determined by the defined macros: By default, real
will be defined as the double
type. If THEORETICA_FLOAT_PREC
is defined, real
will be defined as a float
, if THEORETICA_LONG_DOUBLE_PREC
is defined, real
will be defined as a long double
THEORETICA_ARBITRARY_PREC
option is currently unsupported Return the modulus of a complex number.
z | A complex number |
Compute the absolute value of a real number.
x | A real number |
On x86 architectures, if THEORETICA_X86
is defined, the fabs
instruction will be used.
Compute the complex arccosine.
z | A complex number |
Compute the arccosine.
x | A real number |
Domain: [-1, 1]. The identities \(acos(x) = atan(\frac{sqrt{1 - x^2}}{x})\) and \(acos(x) = atan(\frac{\sqrt{1 - x^2}}{x}) + \pi\) are used.
|
inline |
Apply a function to a set of values element-wise.
f | The function to apply |
X | The vector to modify the elements of |
Compute the complex arcsine.
z | A complex number |
Compute the arcsine.
x | A real number |
Domain: [-1, 1]. The identity \(asin(x) = atan(\frac{x}{\sqrt{1 - x^2}})\) is used.
Compute the complex arctangent.
z | A complex number |
Compute the arctangent.
x | An angle in radians |
A degree 9 interpolating polynomial through Chebyshev nodes is used to approximate \(atan(x)\). Domain reduction to [-1, 1] is performed.
Compute the 2 argument arctangent.
y | The y coordinate in Cartesian space |
x | The x coordinate in Cartesian space |
Computed using identities on atan(x).
|
inline |
Generic Bezier curve in N dimensions.
points | The control points |
t | The curve parameter between 0 and 1 |
The generic Bezier curve is computed by successive linear interpolations. For cubic and quadratic Bezier curves the related functions should be preferred.
|
inline |
Compute the binomial coefficient.
n | A natural number |
m | A natural number smaller than n |
|
inline |
Bit rotation of unsigned integer types using shifts.
x | The unsigned integer to rotate the bits of |
i | The index of the rotated bits |
Compute the cubic root of x.
x | A real number |
Domain: [-inf, +inf]
The Newton-Raphson algorithm, optimized for the cubic root and limited by the THEORETICA_OPTIMIZATION_NEWTON_ITER
macro constant, is used. Domain reduction to [0, 1] is applied to ensure convergence of the algorithm.
|
inline |
Compute the nth Chebyshev polynomial of the first kind.
|
inline |
Compute the nth Chebyshev polynomial of the second kind.
|
inline |
Compute the n Chebyshev nodes on a given interval.
a | The lower bound of the interval |
b | The upper bound of the interval |
n | The number of points to evaluate |
Clamp x between a and b.
x | The real number to clamp |
a | The lower bound |
b | The upper bound |
|
inline |
Clamp a value between two other values.
x | The value to clamp |
a | The lower bound |
b | The upper bound |
The templated T type must have comparison operators.
Compute the conjugate of a complex number.
z | A complex number |
Compute the complex cosine.
z | A complex number |
Compute the cosine of a real number.
x | An angle in radians |
On x86 architectures, if THEORETICA_X86
is defined, the fcos
instruction will be used.
Compute the hyperbolic cosine.
x | A real number |
\(cosh = \frac{e^x + e^{-x}}{2}\)
Compute the cotangent of x.
x | An angle in radians |
On x86 architectures, if THEORETICA_X86
is defined, the fsincos
instruction will be used if supported by the compiler.
Compute the hyperbolic cotangent.
x | A real number |
Compute the cube of a complex number.
z | A complex number |
|
inline |
Compute the cube of a real number.
x | A real number |
Domain: [-inf, +inf]
|
inline |
Compute the cubic splines interpolation of the sets of X and Y data points.
The X values should be strictly increasing.
|
inline |
Compute the cubic splines interpolation of a set of data points.
The X values should be strictly increasing.
|
inline |
Convert radians to degrees.
radians | An angle in radians |
The RAD2DEG
scalar factor is used.
|
inline |
Compute the exact derivative of a polynomial function.
p | The polynomial to differentiate |
|
inline |
Approximate the first derivative of a real function using the best available algorithm.
f | The function to approximate the derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
|
inline |
Approximate the second derivative of a real function using the best available algorithm.
f | The function to approximate the second derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
|
inline |
Approximate the first derivative of a real function using the backward method.
f | The function to approximate the derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
|
inline |
Approximate the first derivative of a real function using the central method.
f | The function to approximate the derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
|
inline |
Approximate the first derivative of a real function using the forward method.
f | The function to approximate the derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
|
inline |
Approximate the first derivative of a real function using Ridder's method of arbitrary degree.
f | The function to approximate the derivative of |
x | The real value to approximate at |
degree | The degree of the algorithm |
h | The step size to use in the finite differences method |
|
inline |
Approximate the first derivative of a real function using Ridder's method of second degree.
f | The function to approximate the derivative of |
x | The real value to approximate at |
h | The step size to use in the finite differences method |
Compute the complex exponential.
z | A complex number |
Compute the real exponential.
x | A real number |
The exponential is computed as \(e^{floor(x)} \cdot e^{fract(x)}\), where \(e^{floor(x)} = pow(e, floor(x))\) and \(e^{fract(x)}\) is approximated using Taylor series on [0, 0.25]
Compute the exponential of x minus 1 more accurately for really small x.
For |x| > 0.001, th::exp is used.
x | A real number. |
|
inline |
Find candidate intervals for root finding.
f | A function of real variable |
a | The lower extreme of the region of interest |
b | The upper extreme of the region of interest |
steps | The number of subintervals to check (optional) |
|
inline |
Compute the floor of x Computes the maximum integer number that is smaller than x.
x | A real number |
e.g. floor(1.6) = 1 e.g. floor(-0.3) = -1
Compute the fractional part of a real number.
x | A real number |
e.g. fract(2.5) = 0.5 e.g. fract(-0.2) = 0.2
|
inline |
Generate a polynomial basis using a recursion formula.
P0 | First polynomial of the sequence |
P1 | Second polynomial of the sequence |
f | Recursion formula |
n | Degree of the final polynomial |
Compute the heaviside function.
x | A real number |
|
inline |
Compute the nth Hermite polynomial.
Hermite weights for Gauss-Hermite quadrature of n-th order.
roots | The n roots of the n-th Hermite polynomial |
|
inline |
Compute the integer cubic root of a positive integer.
n | A positive integer number |
Complex identity.
z | A complex number |
|
inline |
Find the integer logarithm of x.
Defined as the biggest n so that 2^n is smaller than x.
x | An integer value |
|
inline |
Compute the indefinite integral of a polynomial.
p | The polynomial to integrate |
|
inline |
Use the best available algorithm to approximate the definite integral of a real function.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
|
inline |
Use the best available algorithm to approximate the definite integral of a real function to a given tolerance.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
tol | Tolerance |
|
inline |
Approximate an integral by using Crude Monte Carlo integration.
f | The function to integrate |
extremes | A vector of the extremes of integration |
g | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Approximate an integral by using Crude Monte Carlo integration.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
g | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Use Gaussian quadrature using the given points and weights.
f | The function to integrate |
x | The points of evaluation |
w | The weights of the linear combination |
|
inline |
Use Gaussian quadrature using the given points and weights.
f | The function to integrate |
x | The points of evaluation |
w | The weights of the linear combination |
n | The number of points used |
|
inline |
Use Gaussian quadrature using the given points and weights.
f | The function to integrate |
x | The points of evaluation |
w | The weights of the linear combination |
n | The number of points used |
Winv | The inverse of the weight function |
|
inline |
Use Gauss-Hermite quadrature of arbitrary degree to approximate an integral over (-inf, +inf) providing the roots of the n degree Hermite polynomial.
f | The function to integrate |
x | The roots of the n degree Hermite polynomial |
|
inline |
Use Gauss-Hermite quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over (-inf, +inf).
f | The function to integrate |
n | The order of the polynomial (available values are 2, 4, 8 or 16). |
|
inline |
Approximate an integral by using Hit-or-miss Monte Carlo integration.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
c | The function minimum in the domain [a, b] |
d | The function maximum in the domain [a, b] |
g | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Approximate an integral by using Hit-or-miss Monte Carlo integration.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
f_max | The function maximum in the [a, b] interval |
g | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Use the Hit-or-Miss Monte Carlo method to approximate a double integral.
f | The multivariate function to integrate |
a | The lower extreme of integration on x |
b | The upper extreme of integration on x |
c | The lower extreme of integration on y |
d | The upper extreme of integration on y |
f_max | The function maximum in the [a, b]x[c, d] interval |
g | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Approximate an integral by using Crude Monte Carlo integration with importance sampling.
f | The function to integrate |
g | The importance function (normalized) |
Ginv | The inverse of the primitive of g, with domain [0, 1] |
gen | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Use Gauss-Laguerre quadrature of arbitrary degree to approximate an integral over [0, +inf) providing the roots of the n degree Legendre polynomial.
f | The function to integrate |
x | The roots of the n degree Laguerre polynomial |
|
inline |
Use Gauss-Laguerre quadrature of arbitrary degree to approximate an integral over [a, b] providing the roots of the n degree Legendre polynomial.
f | The function to integrate |
x | The roots of the n degree Laguerre polynomial |
a | The lower extreme of integration |
b | The upper extreme of integration |
|
inline |
Use Gauss-Laguerre quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over [0, +inf).
f | The function to integrate |
n | The order of the polynomial (available values are 2, 4, 8 or 16). |
|
inline |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
x | The roots of the n degree Legendre polynomial |
|
inline |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
x | The roots of the n degree Legendre polynomial |
w | The weights computed for the n-th order quadrature |
|
inline |
Use Gauss-Legendre quadrature of arbitrary degree to approximate a definite integral providing the roots of the n degree Legendre polynomial.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
x | The roots of the n degree Legendre polynomial |
w | The weights computed for the n-th order quadrature |
|
inline |
Use Gauss-Legendre quadrature of degree 2, 4, 8 or 16, using pre-computed values, to approximate an integral over [a, b].
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
n | The order of the polynomial (available values are 2, 4, 8, 16 or 32). |
|
inline |
Approximate the definite integral of an arbitrary function using the midpoint method.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
steps | The number of steps |
|
inline |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence.
f | The function to integrate |
extremes | A vector of the extremes of integration |
alpha | A vector of the irrational numbers to use for the Weyl sequence |
N | The number of points to generate |
|
inline |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence.
f | The function to integrate |
extremes | A vector of the extremes of integration |
alpha | An irrational number |
N | The number of points to generate |
|
inline |
Approximate an integral by using Crude Quasi-Monte Carlo integration by sampling from the Weyl sequence.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
N | The number of points to generate |
|
inline |
Approximate an integral by using Hit-or-miss Quasi-Monte Carlo integration, sampling points from the Weyl bi-dimensional sequence.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
f_max | The function maximum in the [a, b] interval |
N | The number of points to generate |
|
inline |
Approximate an integral by using Hit-or-miss Quasi-Monte Carlo integration, sampling points from the Weyl bi-dimensional sequence.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
f_max | The function maximum in the [a, b] interval |
N | The number of points to generate |
|
inline |
Approximate an integral by using Crude Quasi-Monte Carlo integration with importance sampling, using the Weyl sequence.
f | The function to integrate |
g | The importance function (normalized) |
Ginv | The inverse of the primitive of g, with domain [0, 1] |
gen | An already initialized PRNG |
N | The number of points to generate |
|
inline |
Approximate the definite integral of an arbitrary function using Romberg's method accurate to the given order.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
order | The order of accuracy |
|
inline |
Approximate the definite integral of an arbitrary function using Romberg's method to the given tolerance.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
tolerance | Convergence tolerance for the algorithm |
|
inline |
Approximate the definite integral of an arbitrary function using Simpson's method.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
steps | The number of steps |
|
inline |
Approximate the definite integral of an arbitrary function using the trapezoid method.
f | The function to integrate |
a | The lower extreme of integration |
b | The upper extreme of integration |
steps | The number of steps |
|
inline |
Compute the interpolating polynomial of a real function using Chebyshev nodes as sampling points.
f | The function to interpolate |
a | Lower bound of the interval |
b | Upper bound of the interval |
order | Order of the resulting polynomial |
|
inline |
Compute the interpolating polynomial of a real function on an equidistant point sample.
f | The function to interpolate |
a | Lower bound of the interval |
b | Upper bound of the interval |
order | Order of the resulting polynomial |
Compute the conjugate of a complex number.
z | A complex number |
|
inline |
Compute the n-th positive power of x (where n is natural)
x | Any element of a multiplicative algebra |
n | The integer exponent |
neutral_element | The neutral element of the given type T |
|
inline |
Check whether a generic variable is (equivalent to) a NaN number.
NaN numbers are the only variables which do not compare equal to themselves in floating point operations. This is valid for real types but also for any mathematical structure, as NaNs are used to report failure inside the library.
x | The mathematical structure to test for being a NaN or NaN-equivalent structure. |
|
inline |
Compute the integer square root of a positive integer.
n | A positive integer number |
|
inline |
Kronecker delta, equals 1 if i is equal to j, 0 otherwise.
i | The first value to compare |
j | The second value to compare |
|
inline |
Compute the Lagrange polynomial interpolating a set of points.
points | The set of n points to interpolate |
Laguerre weights for Gauss-Laguerre quadrature of n-th order.
roots | The n roots of the n-th Laguerre polynomial |
|
inline |
Compute the nth Legendre polynomial.
|
inline |
Roots of the n-th Legendre polynomial.
n | The degree of the polynomial |
Legendre weights for Gauss-Legendre quadrature of n-th order.
roots | The n roots of the n-th Legendre polynomial |
Compute the complex logarithm.
z | A complex number |
Compute the natural logarithm of x.
x | A real number bigger than 0 |
Domain: (0, +inf]
On x86 architectures, if THEORETICA_X86
is defined, the fyl2x
instruction will be used.
Compute the base-10 logarithm of x.
x | A real number bigger than 0 |
Domain: (0, +inf]
On x86 architectures, if THEORETICA_X86
is defined, the fyl2x
instruction will be used.
Compute the binary logarithm of a real number.
x | A real number bigger than 0 |
Domain: (0, +inf]
On x86 architectures, if THEORETICA_X86
is defined, the fyl2x
instruction will be used.
|
inline |
Get a new vector obtained by applying the function element-wise.
f | The function to apply |
X | The input vector |
|
inline |
Get a new vector obtained by applying the function element-wise.
f | The function to apply |
src | The input vector |
dest | The output vector |
|
inline |
Get a new vector obtained by applying the function element-wise.
f | The function to apply |
X | The input vector |
Return the greatest number between two real numbers.
x | A real number |
y | A real number |
If THEORETICA_BRANCHLESS
is defined, a branchless implementation will be used
|
inline |
Compare two objects and return the greatest.
x | The first object to compare |
y | The second object to compare |
The templated T type must have comparison operators.
|
inline |
Approximate a function maximum inside an interval given the function and its first derivative using bisection on the derivative.
f | The function to search a local minimum of. |
Df | The derivative of the function. |
a | The lower extreme of the search interval. |
b | The upper extreme of the search interval. |
|
inline |
Approximate a function maximum using the Golden Section search algorithm.
f | The function to search a local maximum of. |
a | The lower extreme of the search interval. |
b | The upper extreme of the search interval. |
|
inline |
Approximate a function maximum given the function and the first two derivatives using Newton-Raphson's method to find a root of the derivative.
f | The function to search a local maximum of. |
Df | The derivative of the function. |
D2f | The second derivative of the function. |
guess | The initial guess (defaults to 0). |
|
inline |
Metropolis algorithm for distribution sampling using a symmetric proposal distribution.
The target distribution | |
g | A pdf_sampler already initialized to sample from the proposal distribution |
rnd | An already initialized PRNG |
depth | The number of iterations of the algorithm (defaults to STATISTICS_METROPOLIS_DEPTH) |
|
inline |
Metropolis algorithm for distribution sampling using a symmetric proposal distribution.
This function uses the same PRNG as the proposal distribution sampler to generate uniform samples.
The target distribution | |
g | A pdf_sampler already initialized to sample from the proposal distribution |
depth | The number of iterations of the algorithm (defaults to STATISTICS_METROPOLIS_DEPTH) |
Return the smallest number between two real numbers.
x | A real number |
y | A real number |
If THEORETICA_BRANCHLESS
is defined, a branchless implementation will be used
|
inline |
Compare two objects and return the greatest.
x | The first object to compare |
y | The second object to compare |
The templated T type must have comparison operators.
|
inline |
Approximate a function minimum inside an interval given the function and its first derivative using bisection on the derivative.
f | The function to search a local minimum of. |
Df | The derivative of the function. |
a | The lower extreme of the search interval. |
b | The upper extreme of the search interval. |
|
inline |
Approximate a function minimum using the Golden Section search algorithm.
f | The function to search a local minimum of. |
a | The lower extreme of the search interval. |
b | The upper extreme of the search interval. |
|
inline |
Approximate a function minimum given the function and the first two derivatives using Newton-Raphson's method to find a root of the derivative.
f | The function to search a local minimum of. |
Df | The derivative of the function. |
D2f | The second derivative of the function. |
guess | The initial guess (defaults to 0). |
|
inline |
MUM bit mixing function, computes the 128-bit product of a and b and the XOR of their high and low 64-bit parts.
a | The first operand |
b | The second operand |
|
inline |
Multiply two 64-bit unsigned integers and store the result in two 64-bit variables, keeping 128 bits of the result.
a | The first number to multiply |
b | The second number to multiply |
c_low | The variable to store the lowest 64 bits of the result. |
c_high | The variable to store the highest 64 bits of the result. |
|
inline |
Use the best available algorithm to find a local maximum of the given multivariate function.
f | The function to multi_maximize |
guess | The initial guess |
tolerance | The minimum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
|
inline |
Find a local maximum of the given multivariate function using fixed-step gradient descent.
f | The function to multi_maximize |
guess | The initial guess, defaults to the origin |
gamma | The fixed step size, defaults to OPTIMIZATION_MINGRAD_GAMMA |
tolerance | The maximum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
max_iter | The maximum number of iterations to perform before stopping execution of the routine. |
|
inline |
Find a local maximum of the given multivariate function using gradient descent with linear search.
f | The function to multi_maximize |
guess | The initial guess, defaults to the origin |
tolerance | The minimum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
max_iter | The maximum number of iterations to perform before stopping execution of the routine. |
|
inline |
Use the best available algorithm to find a local minimum of the given multivariate function.
f | The function to multi_minimize |
guess | The initial guess |
tolerance | The minimum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
|
inline |
Find a local minimum of the given multivariate function using fixed-step gradient descent.
f | The function to multi_minimize |
guess | The initial guess, defaults to the origin |
gamma | The fixed step size, defaults to OPTIMIZATION_MINGRAD_GAMMA |
tolerance | The maximum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
max_iter | The maximum number of iterations to perform before stopping execution of the routine. |
|
inline |
Find a local minimum of the given multivariate function using gradient descent with linear search.
f | The function to multi_minimize |
guess | The initial guess, defaults to the origin |
tolerance | The maximum magnitude of the gradient to stop the algorithm at, defaults to OPTIMIZATION_MINGRAD_TOLERANCE. |
max_iter | The maximum number of iterations to perform before stopping execution of the routine. |
|
inline |
Approximate the root of a multivariate function using Newton's method with pure Jacobian.
f | The function to find the root of |
guess | The first guess (defaults to the origin) |
tolerance | The tolerance over the final result (defaults to OPTIMIZATION_MINGRAD_TOLERANCE) |
max_iter | The maximum number of iterations before stopping the algorithm |
|
inline |
Get the smallest power of 2 bigger than or equal to x.
This function is useful to add padding to vectors and matrices to apply recursive algorithms such as the FFT.
x | An integer number |
|
inline |
Compute the n-th power of x (where n is natural)
x | Any element of a multiplicative algebra |
n | The integer exponent |
Approximate x elevated to a real exponent.
x | A real number |
a | A real exponent |
Approximated as \(e^{a ln(|x|) sgn(x)}\)
Weyl quasi-random sequence.
n | The index of the element in the sequence |
alpha | The base of the sequence, defaults to the inverse of the Golden Section |
The Weyl sequence is defined as \(x_n = \{n \alpha\}\), where \(\{ \}\) is the fractional part.
Weyl quasi-random sequence in 2 dimensions.
n | The index of the element in the sequence |
alpha | The base of the sequence |
|
inline |
Weyl quasi-random sequence in N dimensions.
n | The index of the element in the sequence |
alpha | The base of the sequence |
Weyl quasi-random sequence (computed with recurrence relation)
prev | The previously computed value |
alpha | The base of the sequence, defaults to the inverse of the Golden Section |
If no arguments are provided or prev is zero, the function computes the first element of the Weyl sequence associated to the parameter alpha.
|
inline |
Convert degrees to radians.
degrees | An angle in degrees |
The DEG2RAD
scalar factor is used.
Wrapper for rand_cauchy(real, real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Wrapper for rand_cointoss(PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Coin toss random generator.
Extracts 1 or -1 with equal probability.
g | An already initialized PRNG |
|
inline |
Generate a pseudorandom number using the congruential pseudorandom number generation algorithm (wrapper)
x | The current recurrence value of the algorithm ( \(x_n\)) |
state | A vector containing the state of the algorithm (a, c, m in this order) |
|
inline |
Generate a pseudorandom number using the congruential pseudorandom number generation algorithm.
x | The current recurrence value of the algorithm (x_n) |
a | The multiplier term |
c | The increment term |
m | The modulus term |
The congruential generator is defined by the recurrence formula \(x_{n+1} = (a x_n + c) mod m\)
If no parameters are passed, the generator defaults to a = 48271, c = 0, m = (1 << 31) - 1.
Wrapper for rand_diceroll(PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Dice roll random generator.
Extracts a random natural number in [1, faces] with equal probability.
faces | The number of faces of the dice |
Wrapper for rand_exponential(real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Wrapper for rand_gaussian(real, real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Generate a random number following a Gaussian distribution using the Box-Muller method.
Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem.
mean | The mean of the target distribution |
sigma | The sigma of the target distribution |
g | An already initialized PRNG |
Exactly 12 real numbers in a range are generated and the mean is computed to get a single real number following (asymptotically) a Gaussian distribution.
Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem.
mean | The mean of the target distribution |
sigma | The sigma of the target distribution |
g | An already initialized PRNG |
N | The number of random numbers to generate |
Many real numbers in a range are generated and the mean is computed to get a single real number following (asymptotically) a Gaussian distribution.
Generate a random number following a Gaussian distribution using Marsaglia's polar method.
|
inline |
Generate a pseudorandom number using the middle-square pseudorandom number generation algorithm.
seed | The (changing) seed of the algorithm |
An offset is added to the 64-bit seed and the result is squared, taking the middle 64-bit of the 128-bit result.
|
inline |
Generate a pseudorandom number using the middle-square pseudorandom number generation algorithm (wrapper)
x | The seed of the algorithm |
p | Algorithm parameters, p[0] is the offset |
Wrapper for rand_pareto(real, real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
Wrapper for rand_rayleigh(real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
|
inline |
Generate a random number following any given distribution using rejection sampling.
f | Target distribution |
theta | The parameters of the target distribution |
p | Proposal distribution |
Pinv | Inverse cumulative function of the proposal distribution |
g | An already initialized PRNG |
max_tries | Maximum number of tries before stopping execution. |
|
inline |
Generate a pseudorandom number using the SplitMix64 pseudorandom number generation algorithm.
x | The 64-bit state of the algorithm |
Adapted from the reference implementation by Sebastiano Vigna.
|
inline |
Generate a pseudorandom number using the SplitMix64 pseudorandom number generation algorithm.
x | The 64-bit state of the algorithm |
p | Dummy variable (needed for function signature) |
|
inline |
Generate a pseudorandom value following any probability distribution function using the Try-and-Catch (rejection) algorithm.
f | A probability distribution function |
theta | The parameters of the pdf |
x1 | The left extreme of the rectangle |
x2 | The right extreme of the rectangle |
y1 | The lower extreme of the rectangle |
y2 | The upper extreme of the rectangle |
g | An already initialized PRNG to use for number generation |
max_iter | The maximum number of failed generations before stopping execution (defaults to STATISTICS_TRYANDCATCH_ITER) |
Random real numbers are generated inside a rectangle defined by x1, x2, y1 and y2 following a uniform distribution. Only numbers below the pdf are returned.
Wrapper for rand_uniform(real, real, PRNG)
theta | The parameters of the distribution |
g | An already initialized PRNG |
|
inline |
Generate a pseudorandom real number in [a, b] using a preexisting generator.
a | The lower extreme of the interval |
b | The higher extreme of the interval |
g | An already initialized pseudorandom number generator |
prec | Precision parameters for the normalization, defaults to STATISTICS_RAND_PREC. |
The algorithm generates a random integer number, computes its modulus and divides it by prec: \(x = \frac{(n mod p)}{2^p}\), where n is the random integer and p is the prec parameter
|
inline |
Generate a pseudorandom number using the Wyrand pseudorandom number generation, as invented by Yi Wang.
seed | The (changing) seed of the algorithm |
p0 | Additive constant (ideally a large prime number) |
p1 | Mask for the algorithm |
|
inline |
Generate a pseudorandom number using the Wyrand pseudorandom number generation, as invented by Yi Wang (wrapper)
x | Dummy variable |
p | Algorithm parameters |
p[0] is the initial seed, p[1] a large prime number and p[2] is the bit mask.
|
inline |
Generate a pseudorandom number using the xoshiro256++ pseudorandom number generation algorithm.
x | Dummy parameter (needed for function signature) |
state | The four 64-bit integer state of the algorithm which will be updated during the iteration. |
Adapted from the reference implementation by Sebastiano Vigna.
|
inline |
Generate a pseudorandom number using the xoshiro256++ pseudorandom number generation algorithm (wrapper)
x | Dummy parameter (needed for function signature) |
state | The four 64-bit integer state of the algorithm which will be updated during the iteration. |
Compute the n-th root of x.
x | A real number |
n | The root number |
The Newton-Raphson method is used, limited by the THEORETICA_OPTIMIZATION_NEWTON_ITER
macro constant.
|
inline |
Approximate a root of an arbitrary function using bisection inside a compact interval [a, b] where f(a) * f(b) < 0.
f | The real function to search the root of. |
a | The lower extreme of the interval. |
b | The upper extreme of the interval. |
tolerance | The minimum size of the bound to stop the algorithm. |
|
inline |
Approximate a root of a polynomial using Chebyshev's method.
p | The polynomial to search the root of. |
guess | The initial guess (defaults to 0). |
Approximate a root of an arbitrary function using Chebyshev's method, by computing the first and second derivatives using automatic differentiation.
f | The real function to search the root of, with dual2 argument and return value. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of an arbitrary function using Chebyshev's method.
f | The real function to search the root of. |
Df | The first derivative of the function. |
D2f | The second derivative of the function. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of a polynomial using Halley's method.
p | The polynomial to search the root of. @guess The initial guess (defaults to 0). |
Approximate a root of an arbitrary function using Halley's method, leveraging automatic differentiation to compute the first and second derivatives of the function.
f | The real function to search the root of, with dual2 argument and return value. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of an arbitrary function using Halley's method.
f | The real function to search the root of. |
Df | The first derivative of the function. |
D2f | The second derivative of the function. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of an arbitrary complex function using Newton's method,.
f | The complex function to search the root of |
df | The derivative of the function |
guess | The initial guess (defaults to 0). |
tolerance | The minimum tolerance to stop the algorithm when reached. |
max_iter | The maximum number of iterations before stopping the algorithm (defaults to OPTIMIZATION_TOL). |
|
inline |
Approximate a root of a polynomial using Newton's method.
p | The polynomial to search the root of. |
guess | The initial guess (defaults to 0). |
Approximate a root of an arbitrary function using Newton's method, computing the derivative using automatic differentiation.
f | The real function to search the root of, with dual argument and return value. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of an arbitrary function using Newton's method.
f | The real function to search the root of. |
Df | The derivative of the function. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of a polynomial using Steffensen's method.
p | The polynomial to search the root of. |
guess | The initial guess (defaults to 0). |
|
inline |
Approximate a root of an arbitrary function using Steffensen's method.
f | The real function to search the root of. |
guess | The initial guess (defaults to 0). |
|
inline |
Find all the roots of a polynomial.
An interval bound on the roots is found using Cauchy's theorem.
p | The polynomial to search the roots of. |
steps | The number of steps to use (defaults to twice the polynomial's order). |
|
inline |
Find the roots of a function inside a given interval.
f | The real function to search the root of. |
a | The lower extreme of the search interval. |
b | The upper extreme of the search interval. |
steps | The number of sub-intervals to check for alternating sign (optional). |
Vector theoretica::sample_mc | ( | Function | f, |
std::vector< pdf_sampler > & | rv, | ||
unsigned int | N | ||
) |
Generate a Monte Carlo sample of values of a given function of arbitrary variables following the given distributions.
f | The function with argument vec<real> |
rv | A vector of distribution samplers from the distributions of the random variables |
N | The size of the sample |
|
inline |
Return the sign of x (1 if positive, -1 if negative, 0 if null)
x | A real number |
|
inline |
Shuffle a set by exchanging random couples of elements.
v | The set to shuffle (as a Vector with [] and .size() methods) |
g | An already initialized PRNG |
rounds | The number of pairs to exchange (defaults to (N - 1)^2) |
Compute the sigmoid function.
x | A real number |
Computer the complex sine.
z | A complex number |
Compute the sine of a real number.
x | An angle in radians |
On x86 architectures, if THEORETICA_X86
is defined, the fsin
instruction will be used.
Compute the normalized sinc function.
x | A real number |
Compute the hyperbolic sine.
x | A real number |
\(sinh = \frac{e^x - e^{-x}}{2}\)
Compute the complex square root.
z | A complex number |
Compute the square root of a real number.
x | A real number |
Domain: [0, +inf]
The Newton-Raphson algorithm, optimized for the square root and limited by the THEORETICA_OPTIMIZATION_NEWTON_ITER
macro constant, is used. Domain reduction to [0, 1] is applied to ensure convergence of the algorithm. On x86 architectures, if THEORETICA_X86
is defined, the fsqrt
instruction will be used.
Compute the square of a complex number.
z | A complex number |
|
inline |
Compute the square of a real number.
x | A real number |
Domain: [-inf, +inf]
|
inline |
Compute the sum of a vector of real values using pairwise summation to reduce round-off error.
X | The vector of values to sum |
|
inline |
Compute the sum of a set of values.
X | The vector of values to sum |
|
inline |
Compute the sum of a set of values using the compensated Neumaier-Kahan-Babushka summation algorithm to reduce round-off error.
X | The vector of real values to sum |
|
inline |
Compute the sum of a set of values using pairwise summation to reduce round-off error.
The function does not check for validity of begin and end indices.
X | The vector of real values to sum |
begin | The starting index of the sum, defaults to 0 |
end | One plus the last index of the sum, defaults to X.size() |
base_size | The size of the base case, defaults to 128 |
|
inline |
Swap the elements of a vector pair-wise, by exchanging elements with indices related by bit reversion (e.g.
\(110_2\) and \(011_2\)).
x | The vector of elements to swap in-place |
m | The maximum bit to consider when computing bit reversion |
Compute the complex tangent.
z | A complex number |
Compute the tangent of x.
x | An angle in radians |
On x86 architectures, if THEORETICA_X86
is defined, the fsincos
instruction will be used if supported by the compiler.