nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Specialized Mathematical Functions (specfun)

Bessel functions, Airy functions, Gamma, Beta, Error functions, and Number Theory primitives. More...

Files

file  specfun.hpp
 Special mathematical functions (gamma, beta, erf, Bessel, Airy, combinatorics).

Classes

struct  nk::builtin::EllipKE
 Complete elliptic integrals of the first and second kinds ([K, E] = ellipke(M)). More...
struct  nk::builtin::EllipJ
 Jacobi elliptic functions ([sn, cn, dn] = ellipj(u, M)). More...

Functions

Value nk::builtin::gamma (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Complete gamma function (Γ(x)).
Value nk::builtin::gammaln (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Logarithm of the absolute value of the gamma function (ln|Γ(x)|).
Value nk::builtin::gammainc (const Value &x, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Incomplete gamma function (P(a, x)).
Value nk::builtin::gammaincinv (const Value &y, const Value &a, std::pmr::memory_resource *mr=nullptr)
 Inverse incomplete gamma function.
Value nk::builtin::psi (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Digamma / polygamma function (ψ(x) = d/dx ln Γ(x)).
Value nk::builtin::beta (const Value &z, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Beta function (B(z, w) = Γ(z)Γ(w) / Γ(z+w)).
Value nk::builtin::betaln (const Value &z, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Natural logarithm of the beta function (ln B(z, w)).
Value nk::builtin::betainc (const Value &x, const Value &z, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Incomplete beta function (I_x(z, w)).
Value nk::builtin::betaincinv (const Value &y, const Value &z, const Value &w, std::pmr::memory_resource *mr=nullptr)
 Inverse incomplete beta function.
Value nk::builtin::erf (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Error function (erf(x) = 2/√π ∫_0^x e^(-t^2) dt).
Value nk::builtin::erfc (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Complementary error function (erfc(x) = 1 - erf(x)).
Value nk::builtin::erfcx (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Scaled complementary error function (erfcx(x) = exp(x^2) * erfc(x)).
Value nk::builtin::erfinv (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Inverse error function (erfinv(y)).
Value nk::builtin::erfcinv (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Inverse complementary error function (erfcinv(y)).
Value nk::builtin::besselj (const Value &nu, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Bessel function of the first kind (J_ν(z)).
Value nk::builtin::bessely (const Value &nu, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Bessel function of the second kind (Neumann function Y_ν(z)).
Value nk::builtin::besseli (const Value &nu, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Modified Bessel function of the first kind (I_ν(z)).
Value nk::builtin::besselk (const Value &nu, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Modified Bessel function of the second kind (K_ν(z)).
Value nk::builtin::besselh (const Value &nu, int k, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Bessel function of the third kind (Hankel function H_ν^(k)(z)).
Value nk::builtin::airy (int k, const Value &z, std::pmr::memory_resource *mr=nullptr)
 Airy function (Ai(z) or k-th derivative / Bi).
Value nk::builtin::airy (const Value &z, std::pmr::memory_resource *mr=nullptr)
 Airy function of the first kind (Ai(z)).
Value nk::builtin::expint (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Exponential integral function (E_1(x)).
EllipKE nk::builtin::ellipke (const Value &m, std::pmr::memory_resource *mr=nullptr)
 Complete elliptic integrals of the first and second kind ([K, E] = ellipke(m)).
EllipJ nk::builtin::ellipj (const Value &u, const Value &m, std::pmr::memory_resource *mr=nullptr)
 Jacobi elliptic functions ([sn, cn, dn] = ellipj(u, m)).
Value nk::builtin::legendre (int n, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Associated Legendre functions (P_n^m(x)).
Value nk::builtin::factorial (const Value &n, std::pmr::memory_resource *mr=nullptr)
 Factorial of non-negative integer elements (n!).
Value nk::builtin::primes (double n, std::pmr::memory_resource *mr=nullptr)
 Generates row vector of all prime numbers less than or equal to n (primes(n)).
Value nk::builtin::primes (const Value &n, std::pmr::memory_resource *mr=nullptr)
 Generates row vector of all prime numbers less than or equal to n (primes(n)).
Value nk::builtin::isprime (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Tests if array elements are prime numbers (isprime(x)).
Value nk::builtin::factor (double n, std::pmr::memory_resource *mr=nullptr)
 Computes prime factors of positive integer (factor(n)).
Value nk::builtin::factor (const Value &n, std::pmr::memory_resource *mr=nullptr)
 Computes prime factors of positive integer value (factor(n)).
Value nk::builtin::nchoosek (double n, double k, std::pmr::memory_resource *mr=nullptr)
 Computes binomial coefficient n choose k (nchoosek(n, k)).
Value nk::builtin::nchoosekCombinations (const Value &v, double kd, std::pmr::memory_resource *mr=nullptr)
 Generates all combinations of vector elements taken k at a time (nchoosek(v, k)).
Value nk::builtin::nchoosek (const Value &v, int k, std::pmr::memory_resource *mr=nullptr)
 Binomial coefficient or all combinations (nchoosek(v, k)).
Value nk::builtin::nchoosek (const Value &v, const Value &k, std::pmr::memory_resource *mr=nullptr)
 Binomial coefficient or all combinations (nchoosek(v, k)).
Value nk::builtin::perms (const Value &v, std::pmr::memory_resource *mr=nullptr)
 All permutations of a vector elements.
Value nk::builtin::gcd (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Greatest common divisor of two integers or arrays (gcd(a, b)).
Value nk::builtin::lcm (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Least common multiple of two integers or arrays (lcm(a, b)).
Value nk::builtin::colperm (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Column permutation vector for sparse matrix bandwidth/fill-in reduction (colperm(s)).
Value nk::builtin::symrcm (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Symmetric reverse Cuthill-McKee ordering permutation vector (symrcm(s)).

Detailed Description

Bessel functions, Airy functions, Gamma, Beta, Error functions, and Number Theory primitives.

Function Documentation

◆ airy() [1/2]

Value nk::builtin::airy ( const Value & z,
std::pmr::memory_resource * mr = nullptr )

Airy function of the first kind (Ai(z)).

Parameters
zArgument.
mrMemory resource.
Returns
Airy function values.

◆ airy() [2/2]

Value nk::builtin::airy ( int k,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Airy function (Ai(z) or k-th derivative / Bi).

Parameters
kFunction kind / derivative index (0: Ai, 1: Ai', 2: Bi, 3: Bi').
zArgument.
mrMemory resource.
Returns
Airy function values.

◆ besselh()

Value nk::builtin::besselh ( const Value & nu,
int k,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Bessel function of the third kind (Hankel function H_ν^(k)(z)).

Parameters
nuOrder.
kKind index (1 or 2).
zArgument.
mrMemory resource.
Returns
Hankel function values.
See also
besselj, bessely

◆ besseli()

Value nk::builtin::besseli ( const Value & nu,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Modified Bessel function of the first kind (I_ν(z)).

Parameters
nuOrder.
zArgument.
mrMemory resource.
Returns
Modified Bessel function values.
See also
besselk

◆ besselj()

Value nk::builtin::besselj ( const Value & nu,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Bessel function of the first kind (J_ν(z)).

Parameters
nuOrder of the Bessel function.
zArgument.
mrMemory resource.
Returns
Bessel function values.
See also
bessely, besseli, besselk

◆ besselk()

Value nk::builtin::besselk ( const Value & nu,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Modified Bessel function of the second kind (K_ν(z)).

Parameters
nuOrder.
zArgument.
mrMemory resource.
Returns
Modified Bessel function values.
See also
besseli

◆ bessely()

Value nk::builtin::bessely ( const Value & nu,
const Value & z,
std::pmr::memory_resource * mr = nullptr )

Bessel function of the second kind (Neumann function Y_ν(z)).

Parameters
nuOrder of the Bessel function.
zArgument.
mrMemory resource.
Returns
Bessel function values.
See also
besselj

◆ beta()

Value nk::builtin::beta ( const Value & z,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Beta function (B(z, w) = Γ(z)Γ(w) / Γ(z+w)).

Parameters
zFirst parameter.
wSecond parameter.
mrMemory resource.
Returns
Beta function values.
See also
betaln, betainc

◆ betainc()

Value nk::builtin::betainc ( const Value & x,
const Value & z,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Incomplete beta function (I_x(z, w)).

Parameters
xUpper limit in [0, 1].
zFirst parameter.
wSecond parameter.
mrMemory resource.
Returns
Regularized incomplete beta values.
See also
beta, betaincinv

◆ betaincinv()

Value nk::builtin::betaincinv ( const Value & y,
const Value & z,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Inverse incomplete beta function.

Parameters
yValue in [0, 1].
zFirst parameter.
wSecond parameter.
mrMemory resource.
Returns
Value x such that betainc(x, z, w) == y.
See also
betainc

◆ betaln()

Value nk::builtin::betaln ( const Value & z,
const Value & w,
std::pmr::memory_resource * mr = nullptr )

Natural logarithm of the beta function (ln B(z, w)).

Parameters
zFirst parameter.
wSecond parameter.
mrMemory resource.
Returns
Log-beta values.
See also
beta

◆ colperm()

Value nk::builtin::colperm ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Column permutation vector for sparse matrix bandwidth/fill-in reduction (colperm(s)).

Parameters
sSparse or dense matrix.
mrMemory resource.
Returns
Column permutation vector.
See also
symrcm

◆ ellipj()

EllipJ nk::builtin::ellipj ( const Value & u,
const Value & m,
std::pmr::memory_resource * mr = nullptr )

Jacobi elliptic functions ([sn, cn, dn] = ellipj(u, m)).

Parameters
uArgument.
mParameter.
mrMemory resource.
Returns
Jacobi elliptic function values.

◆ ellipke()

EllipKE nk::builtin::ellipke ( const Value & m,
std::pmr::memory_resource * mr = nullptr )

Complete elliptic integrals of the first and second kind ([K, E] = ellipke(m)).

Parameters
mParameter m = k^2.
mrMemory resource.
Returns
Complete elliptic integral values.

◆ erf()

Value nk::builtin::erf ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Error function (erf(x) = 2/√π ∫_0^x e^(-t^2) dt).

Parameters
xInput value or array.
mrMemory resource.
Returns
Error function values.
See also
erfc, erfinv

◆ erfc()

Value nk::builtin::erfc ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Complementary error function (erfc(x) = 1 - erf(x)).

Parameters
xInput value or array.
mrMemory resource.
Returns
Complementary error function values.
See also
erf, erfcx

◆ erfcinv()

Value nk::builtin::erfcinv ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Inverse complementary error function (erfcinv(y)).

Parameters
xValue in (0, 2).
mrMemory resource.
Returns
Value y such that erfc(y) == x.
See also
erfc, erfinv

◆ erfcx()

Value nk::builtin::erfcx ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Scaled complementary error function (erfcx(x) = exp(x^2) * erfc(x)).

Parameters
xInput value or array.
mrMemory resource.
Returns
Scaled complementary error values.
See also
erfc

◆ erfinv()

Value nk::builtin::erfinv ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Inverse error function (erfinv(y)).

Parameters
xValue in (-1, 1).
mrMemory resource.
Returns
Value y such that erf(y) == x.
See also
erf, erfcinv

◆ expint()

Value nk::builtin::expint ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Exponential integral function (E_1(x)).

Parameters
xArgument.
mrMemory resource.
Returns
Exponential integral values.

◆ factor() [1/2]

Value nk::builtin::factor ( const Value & n,
std::pmr::memory_resource * mr = nullptr )

Computes prime factors of positive integer value (factor(n)).

Parameters
nPositive integer value.
mrMemory resource.
Returns
Row vector containing prime factors.

◆ factor() [2/2]

Value nk::builtin::factor ( double n,
std::pmr::memory_resource * mr = nullptr )

Computes prime factors of positive integer (factor(n)).

Parameters
nPositive integer.
mrMemory resource.
Returns
Row vector containing prime factors in ascending order.
See also
primes, isprime

◆ factorial()

Value nk::builtin::factorial ( const Value & n,
std::pmr::memory_resource * mr = nullptr )

Factorial of non-negative integer elements (n!).

Parameters
nNon-negative integers.
mrMemory resource.
Returns
Factorials.
See also
gamma, nchoosek

◆ gamma()

Value nk::builtin::gamma ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Complete gamma function (Γ(x)).

Parameters
xInput value or array.
mrMemory resource for allocations (nullptr for default).
Returns
Array containing gamma function values.
See also
gammaln, gammainc, psi

◆ gammainc()

Value nk::builtin::gammainc ( const Value & x,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Incomplete gamma function (P(a, x)).

Parameters
xUpper limit of integration.
aScaling parameter.
mrMemory resource.
Returns
Regularized lower incomplete gamma values.
See also
gamma, gammaincinv

◆ gammaincinv()

Value nk::builtin::gammaincinv ( const Value & y,
const Value & a,
std::pmr::memory_resource * mr = nullptr )

Inverse incomplete gamma function.

Parameters
yFunction value in [0, 1].
aScaling parameter.
mrMemory resource.
Returns
Value x such that gammainc(x, a) == y.
See also
gammainc

◆ gammaln()

Value nk::builtin::gammaln ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Logarithm of the absolute value of the gamma function (ln|Γ(x)|).

Parameters
xInput value or array.
mrMemory resource.
Returns
Array containing log-gamma values.
See also
gamma, psi

◆ gcd()

Value nk::builtin::gcd ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Greatest common divisor of two integers or arrays (gcd(a, b)).

Parameters
aFirst operand.
bSecond operand.
mrMemory resource.
Returns
Greatest common divisor.
See also
lcm

◆ isprime()

Value nk::builtin::isprime ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Tests if array elements are prime numbers (isprime(x)).

Parameters
xInput array of integers.
mrMemory resource.
Returns
Logical array where true indicates prime numbers.
See also
primes, factor

◆ lcm()

Value nk::builtin::lcm ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Least common multiple of two integers or arrays (lcm(a, b)).

Parameters
aFirst operand.
bSecond operand.
mrMemory resource.
Returns
Least common multiple.
See also
gcd

◆ legendre()

Value nk::builtin::legendre ( int n,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Associated Legendre functions (P_n^m(x)).

Parameters
nDegree of the Legendre function.
xArgument.
mrMemory resource.
Returns
Associated Legendre values.

◆ nchoosek() [1/3]

Value nk::builtin::nchoosek ( const Value & v,
const Value & k,
std::pmr::memory_resource * mr = nullptr )

Binomial coefficient or all combinations (nchoosek(v, k)).

Parameters
vInput vector or scalar n.
kSubset size value.
mrMemory resource.
Returns
Binomial coefficient or combinations matrix.

◆ nchoosek() [2/3]

Value nk::builtin::nchoosek ( const Value & v,
int k,
std::pmr::memory_resource * mr = nullptr )

Binomial coefficient or all combinations (nchoosek(v, k)).

Parameters
vInput vector or scalar n.
kSubset size.
mrMemory resource.
Returns
Binomial coefficient or combinations matrix.

◆ nchoosek() [3/3]

Value nk::builtin::nchoosek ( double n,
double k,
std::pmr::memory_resource * mr = nullptr )

Computes binomial coefficient n choose k (nchoosek(n, k)).

Parameters
nTotal number of items.
kItems chosen.
mrMemory resource.
Returns
Binomial coefficient value.
See also
perms, factorial

◆ nchoosekCombinations()

Value nk::builtin::nchoosekCombinations ( const Value & v,
double kd,
std::pmr::memory_resource * mr = nullptr )

Generates all combinations of vector elements taken k at a time (nchoosek(v, k)).

Parameters
vInput vector.
kdNumber of elements to pick.
mrMemory resource.
Returns
Matrix with nchoosek(length(v), k) rows and k columns.

◆ perms()

Value nk::builtin::perms ( const Value & v,
std::pmr::memory_resource * mr = nullptr )

All permutations of a vector elements.

Parameters
vInput vector.
mrMemory resource.
Returns
Matrix of all n! permutations.
See also
nchoosek, randperm

◆ primes() [1/2]

Value nk::builtin::primes ( const Value & n,
std::pmr::memory_resource * mr = nullptr )

Generates row vector of all prime numbers less than or equal to n (primes(n)).

Parameters
nUpper limit value.
mrMemory resource.
Returns
Row vector of prime numbers.
See also
isprime, factor

◆ primes() [2/2]

Value nk::builtin::primes ( double n,
std::pmr::memory_resource * mr = nullptr )

Generates row vector of all prime numbers less than or equal to n (primes(n)).

Parameters
nUpper limit.
mrMemory resource.
Returns
Row vector of prime numbers.
See also
isprime, factor

◆ psi()

Value nk::builtin::psi ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Digamma / polygamma function (ψ(x) = d/dx ln Γ(x)).

Parameters
xInput value or array.
mrMemory resource.
Returns
Logarithmic derivative of gamma function.
See also
gamma, gammaln

◆ symrcm()

Value nk::builtin::symrcm ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Symmetric reverse Cuthill-McKee ordering permutation vector (symrcm(s)).

Parameters
sSymmetric sparse or dense adjacency matrix.
mrMemory resource.
Returns
Permutation vector that reduces matrix bandwidth.
See also
colperm