Skip to content

tk-yoshimura/ErrorFunctionApproximation

Repository files navigation

ErrorFunctionApproximation

Download DLL
Download Nuget

Definition

The error function (erf) is defined by the following equation:

erf

The complementary error function (erfc) is defined by the following equation:

erfc

Convergence Equation

To obtain these numerical solutions, use the following equations:

Taylor series:

taylor series

Continued fraction expansion:

continued fraction expansion

Taylor series

First, Taylor series convergence becomes slow as the absolute value of z increases.

The absolute value of each term is as follows:

Taylor series term

The behavior for each z:

Taylor series convergence

The ratio to the next term is less than 1:

Taylor scale

Taylor scale value

The number of terms required to obtain arbitrary precision is as follows:
In addition, in order to obtain the expected value, 128-bit expansion was performed to absorb cancellation.

erf convergence zwise

erf convergence bitwise

Continued fraction expansion

Next, in Continued fraction expansion, when the absolute value of z is small, the convergence becomes slow.

Replace continued fractions:

frac f1

The recursive part can be written below:

frac e2

frac e4

The fixed points at n = 1 are:

frac x2

frac x4

These approximate the true values:

frac x

frac x valuefrac x error

Solve the continued fraction F1 (z) backward with X4 (z) as the initial value.
Let N be the recursion times (Fn+4(z) to Fn(z)), and N until convergence is as follows:

erfc convergence zwise

erfc convergence bitwise

Double Precision (IEEE 754) Approx

The calculation error is at most 2 epsilons.
C# code

erf result
erf result
erfc result
erfc result
inverse erf result
inverse erf result
inverse erfc result
inverse erfc result

The following is used to approximate the error of machine epsilon in the entire domain.

near zero:
erf approx nearzero

greater than 1/2:
erfc approx az

erfc az

erfc az diff

pade definition

pade erf precision16
pade erf precision32
pade erfc precision16
pade erfc precision32

Inverse Function

InverseErfc NearZero

inverse erfc nearzero

pade inverfc precision16
pade inverfc precision32

InverseErf NearZero

series inverf e20
series inverf e40
series inverf e80