## `erf, erfc` -- the error function and the complementary error function

#### Introduction

`erf(x)` represents the error function (2/sqrt(PI))*int(exp(-t^2), t=0..x). The complementary error function is erfc(x)=1-erf(x) =(2/sqrt(PI))*int(exp(-t^2), x..infinity).

#### Call(s)

`erf(x)`
`erfc(x)`

#### Parameters

`x` | - | an arithmetical expression

#### Returns

an arithmetical expression.

#### Side Effects

When called with a floating point argument, the functions are sensitive to the environment variable `DIGITS` which determines the numerical working precision.

#### Details

- Theses functions are defined for all complex arguments.
- Floating point values are returned for floating point arguments. The exact values:

  erf(0)=0, erf(infinity)=1, erf(-infinity)=-1,

  erfc(0)=1, erfc(infinity)=0, erfc(-infinity)=2

  are implemented. For all other arguments, unevaluated function calls are returned.

- For floating point arguments of large absolute value internal numerical underflow may happen. The section of the complex plane where abs(Im(x))<=abs(Re(x))/10, is protected against such underflows: when the real part of x is a large positive number, the result returned by `erfc` may be truncated to `0.0`. For large negative real part it may be rounded to `2.0`. Knowing that erf(x)=1-erfc(x), `erf` may also return correspondingly rounded values for arguments in this section. Cf. example 2.
- The float attributes are kernel functions, i.e., floating point evaluation is fast.

#### Example 1

We demonstrate some calls with exact and symbolic input data:

    >> erf(0), erf(3/2), erf(sqrt(2)), erf(infinity)

                                               1/2
                             0, erf(3/2), erf(2   ), 1

    >> erfc(0), erfc(x + 1), erfc(-infinity)

                                 1, erfc(x + 1), 2

Floating point values are computed for floating point arguments:

    >> erf(-7.2), erf(2.0 + 3.5*I), erfc(100.0 + 100.0*I)

          -1.0, 421.8123327 + 343.6612334 I,

             0.0006523436638 - 0.003935726363 I

#### Example 2

For large floating point arguments with positive real parts the values returned by `erfc` may be truncated to `0.0`:

    >> erfc(2411.3), erfc(2411.4)

                             3.678326052e-2525152, 0.0

This protection against numerical underflow is builtin for arguments satisfying abs(Im(x))<=abs(Re(x))/10.

    >> erfc(2500.0 + 250.0*I)

                                        0.0

Errors may occur outside this region in the complex plane:

    >> erfc(2500.0 + 250.1*I)

          Error: Overflow/underflow in arithmetical operation;
          during evaluation of 'erfc::float'

#### Example 3

The functions `diff`, `float`, `limit`, and `series` handle expressions involving the error functions:

    >> diff(erf(x), x, x, x), float(ln(3 + erfc(sqrt(PI)*I)))

                2        2             2
             8 x  exp(- x )   4 exp(- x )
             -------------- - -----------, 2.309003461 - 1.16207002 I
                   1/2             1/2
                 PI              PI

    >> limit(x/(1 + x)*erf(x), x = infinity)

                                         1

    >> series(erfc(x), x = infinity, 4)

                             2           2      /        2  \
                      exp(- x )   exp(- x )     | exp(- x ) |
                      --------- - ---------- + O| --------- |
                           1/2       3   1/2    |     4     |
                       x PI       2 x  PI       \    x      /

#### Background

- `erf` and `erfc` are entire functions.

#### Changes

- Floating point evaluation is now possible for all complex arguments. Rounded values may be returned for arguments of large absolute value to prevent numerical underflow.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000