Error Functions, Dawson’s and Fresnel Integrals

GNSTLIB includes implementations of the error functions, Dawson’s integral and more generally the Faddeeva function for complex arguments by wrapping the C++ library Faddeeva package. These functions and other such as Fresnel integrals or Voigt profiles are included in the main header file:

#include <gnstlib.hpp>

Main function

GNSTLIB::erf

double erf(const double x, int &err_id)

Computes the error function \(\text{erf}(x)\) for real \(x\).The error function is defined by

\[\text{erf}(z) = \frac{2}{\sqrt{\pi}} \int_0^z e^{-t^2} \mathop{dt}.\]
  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Argument x is too small. Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> erf(const std::complex<double> z, int &err_id)
  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Argument z is too large. Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Argument z is too small. Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::erfc

double erfc(const double x, int &err_id)

Computes the complementary error function \(\text{erfc}(x)\) for real \(x\). The complementary error function is defined by

\[\text{erfc}(z) = \frac{2}{\sqrt{\pi}} \int_z^{\infty} e^{-t^2} \mathop{dt} = 1 - \text{erf}(z).\]
  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Argument x is too large, more precisely x \(\gtrsim 26.55\). Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> erfc(const std::complex<double> z, int &err_id)

Computes the complementary error function \(\text{erfc}(z)\) for complex \(z\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::erfcx

double erfcx(const double x, int &err_id)

Computes the scaled complementary error function \(\text{erfcx}(x)\) for real \(x\). \(\text{erfcx}(z)\) is given by

\[\text{erfcx}(z) = e^{z^2} \text{erfc}(z).\]

The scaled complement of the error function may be used to replace and expression of the form \(e^{z^2} \text{erfc}(z)\), in order to handle cases prone to underflow or overflow errors.

  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Argument x is too large and negative, more precisely x \(< -26.628\). Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Argument x is too large, more precisely x \(>\) MAXDOUBLE. Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> erfcx(const std::complex<double> z, int &err_id)

Computes the scaled complementary error function \(\text{erfcx}(z)\) for complex \(z\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::erfi

double erfi(const double x, int &err_id)

Computes the imaginary error function \(\text{erfi}(x)\) for real \(x\). \(\text{erfi}(z)\) is an entire function defined by

\[\text{erfi}(z) = -i \text{erf}(iz).\]
  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Argument x is too large, more precisely \(|\) x \(|\) \(> 26.642\). Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Argument x is too small, more precisely x \(<\) 1.0/MAXDOUBLE. Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> erfi(const std::complex<double> z, int &err_id)

Computes the imaginary error function \(\text{erfi}(z)\) for complex \(z\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::faddeeva

std::complex<double> faddeeva(const std::complex<double> z, int &err_id)

Computes the Faddeeva function or plasma dispersion function \(w(z)\) for complex \(z\). Most of the error functions are expressible in terms of \(w(z)\). The Faddeeva function is defined by

\[w(z) = e^{-z^2} \left(1 + \frac{2i}{\sqrt{\pi}} \int_0^z e^{t^2} \mathop{dt} \right) = e^{-z^2} \text{erfc}(-iz).\]

The Faddeeva function has the symmetry property: \(w(-z) = 2 e^{-z^2} - w(z)\) and \(w(\overline{z}) = \overline{w(-z)}\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::dawson

double dawson(const double x, int &err_id)

Computes the Dawson’s integral \(F(x)\) for real \(x\). The Dawson’s integral is defined by

\[F(z) = e^{-z^2} \int_0^z e^{t^2} \mathop{dt} = \frac{\sqrt{\pi}}{2} e^{-z^2} \text{erfi}(z).\]
  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> dawson(const std::complex<double> z, int &err_id)

Computes the Dawson’s integral \(F(z)\) for complex \(z\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::fresnelc

double fresnelc(const double x, int &err_id)

Computes the Fresnel integral \(C(x)\) for real \(x\). The Fresnel integral \(C(z)\) is defined by

\[C(z) = \int_0^z \cos \left(\frac{\pi t^2}{2}\right) \mathop{dt}.\]

Function \(C(z)\) satisfies the symmetry property \(C(-z) = -C(z)\).

  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> fresnelc(const std::complex<double> z, int &err_id)

Computes the Fresnel integral \(C(z)\) for complex \(z\). A relevant case is, \(C(iz) = i C(z)\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

GNSTLIB::fresnels

double fresnels(const double x, int &err_id)

Computes the Fresnel integral \(S(x)\) for real \(x\). The Fresnel integral \(S(z)\) is defined by

\[S(z) = \int_0^z \sin \left(\frac{\pi t^2}{2}\right) \mathop{dt}\]

Function \(C(z)\) satisfies the symmetry property \(S(-z) = -S(z)\).

  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument x is NaN or an unexpected error occurred. Contact the authors.

std::complex<double> fresnels(const std::complex<double> z, int &err_id)

Computes the Fresnel integral \(S(z)\) for complex \(z\). A relevant case is, \(S(iz) = -i S(z)\).

  1. Arguments:

    • z: (complex) - argument.

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = -1:

      Argument z is NaN or an unexpected error occurred. Contact the authors.

Inverse functions

GNSTLIB::inverf

double inverf(const double x, int &err_id)

Computes the inverse function for \(\text{erf}(x)\) for real \(x \in [-1, 1]\), defined by \(\text{erf}(\text{erf}^{-1}(x)) = x\).

  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

GNSTLIB::inverfc

double inverfc(const double x, int &err_id)

Computes the inverse function for \(\text{erfc}(x)\) for real \(x \in [0, 2]\), defined by \(\text{erfc}(\text{erfc}^{-1}(x)) = x\).

  1. Arguments:

    • x: (double) - argument.

    • err_id: (int) - error identifier.

Applications

GNSTLIB::voigt_profile

double voigt_profile(const double x, const double sigma, const double gamma, int &err_id)

The Voigt profile is a line profile resulting from the convolution of the two broadening mechanisms, a Gaussian profile and a Lorentzian profile. Voigt profiles typically arise in many branches of spectroscopy and diffraction, and in particular, in the modelling and analysis of radiative transfer in the atmosphere. A closed form is given by

\[V(x; \sigma, \gamma) = \frac{\Re(w(z))}{\sigma \sqrt{2\pi}}, \quad z = \frac{x + i \gamma}{\sigma \sqrt{2}},\]

where \(\Re(w(z))\) indicates the real part of the Faddeeva function.

  1. Arguments:

    • x: (double) - argument.

    • sigma: (double) - argument.

      Constraint: sigma \(> 0\).

    • gamma: (double) - argument.

      Constraint: gamma \(> 0\).

    • err_id: (int) - error identifier.

  2. Errors and Warnings:

    • err_id = 1:

      Result is too large to be represented and \(\infty\) is returned.

    • err_id = 2:

      Result is too small to be represented and 0.0 is returned.

    • err_id = 3:

      The result is a denormalized / subnormal number.

    • err_id = 4:

      Argument sigma and/or gamma is negative or zero, NaN is returned.

    • err_id = -1:

      One or several arguments are NaN or an unexpected error occurred. Contact the authors.

Vectorized functions

GNSTLIB::erf_vec

void erf_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void erf_vec(const int n, const double *v, double *r, unsigned short option = 0)
void erf_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void erf_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::erfc_vec

void erfc_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void erfc_vec(const int n, const double *v, double *r, unsigned short option = 0)
void erfc_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void erfc_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::erfcx_vec

void erfcx_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void erfcx_vec(const int n, const double *v, double *r, unsigned short option = 0)
void erfcx_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void erfcx_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::erfi_vec

void erfi_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void erfi_vec(const int n, const double *v, double *r, unsigned short option = 0)
void erfi_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void erfi_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::dawson_vec

void dawson_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void dawson_vec(const int n, const double *v, double *r, unsigned short option = 0)
void dawson_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void dawson_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::faddeeva_vec

void faddeeva_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void faddeeva_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::fresnelc_vec

void fresnelc_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void fresnelc_vec(const int n, const double *v, double *r, unsigned short option = 0)
void fresnelc_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void fresnelc_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)

GNSTLIB::fresnels_vec

void fresnels_vec(std::vector<double> &v, std::vector<double> &r, unsigned short option = 0)
void fresnels_vec(const int n, const double *v, double *r, unsigned short option = 0)
void fresnels_vec(std::vector<std::complex<double>> &v, std::vector<std::complex<double>> &r, unsigned short option = 0)
void fresnels_vec(const int n, const std::complex<double> *v, std::complex<double> *r, unsigned short option = 0)