The imaginary error function, erfi

By Martin McBride, 2025-09-22
Tags: erf function normal distribution gaussian distribution integration by substitution
Categories: special functions
Level:


The imaginary error function, erfi(x), is a close relative of the error function, erf(x). It is used for solving certain types of integrals, but it is also interesting in its own right.

The error function is described in detail here, but we will start with a brief description before moving on to erfi.

The error function

The error function is defined by the following equation:

erf function

Notice that this is a function of x, not a function of t. That is because t is just the variable of integration. The value x determines the range over which the integral is calculated, which determines the final value of the integral. We will call the integrand f(x):

erf function

This graph shows f(x) on the left, and its integral erf(x) on the right:

erf function

f(x) is a bell-shaped function. It is closely related to the normal distribution. The integral of the normal distribution is called the cumulative distribution function, and it is closely related to erf(x) (because erf(x) is the integral of f(x)).

Now it turns out that the integral above is not an elementary integral. This means that it cannot be solved in terms of the usual functions such as sine, cosine, logarithms, etc. Instead, we define erf(x) as a special function. This means that we can solve the integral in terms of erf. For this solution to be useful, we need to be able to find the value of erf(x) for any given x (just like we can find the value of sin(x)). We can't always find the exact value of a special function, but we can find the approximate value to as many decimal places as we want. One way to do this for the erf function is the following Maclaurin expansion of the integral (which is proved in the linked article):

erf function

Adding in the multiplication factor and simplifying gives:

erf function

The erfi function

The erf function is very useful for working with probability distributions. But it might also be useful if we could solve integrals where the exponent is positive, such as this:

erfi function

Here is a graph of the function on the left, and its integral (that we will calculate here) on the right. This time, the function is a U-shape rather than a bell. The function and its integral both get very big, very quickly, even for quite small values of x:

erfi function

We could define another special function for this, but since this looks very similar to the integral used for the erf function, maybe we could use a variant of erf to solve it? So how can we change the -t² into +t²? Well, we know that if we square an imaginary number, we get a negative. So what if we find erf(ix) rather than erf(x)? This means changing the limit of the integral to ix:

erfi function

This might not seem to be much help. We now have a definite integral with an imaginary range, which is awkward. And it still has a negative exponent. Fortunately, there is a simple change in variables that will solve both problems at once. We will substitute:

erfi function

Remember that when we do an integration by substitution, we need to do three things. We need to substitute the variable in the integrand. When we do this, we get the square of iu, which cancels the negative in the exponent:

erfi function

We also need to change the differential, dt. Since t is equal to u multiplied by i, and i is a constant, we need to apply the same factor to the differential:

erfi function

Finally, since this is a definite integral, we need to change the limits of the integral to use u instead of t. The lower limit of 0 is unchanged (when t is zero, u is zero). For the upper limit, when t is ix, u is simply x (because we know that t = iu):

erfi function

Making these three changes, we get:

erfi function

This is exactly what we need, except for that troublesome factor of i in the integral. We were able to take i outside the integral (again because it is a constant), but it would be nice to get rid of it altogether. We can do this by multiplying sides by -i, because, of course, -i times i is 1:

erfi function

So we have our answer. But it is a very strange expression. What exactly are we supposed to do with it?

Calculating the integral

The result looks very odd, but let's trust the maths the brought us here. Remember that we know the Maclaurin expansion of the erf function. So we can use the Maclaurin expansion to find the erf function for any value, even if that value is imaginary:

erfi function

All we have done here is plug the value ix into the Maclaurin expansion, and multiply the whole thing by -i. The new expression contains odd factors of i. These terms simplify to alternating values of +/-i:

erfi function

Applying this to the Maclaurin expansion gives us:

erfi function

Notice that every term inside the brackets has a factor of i. We still have the factor of -i outside the brackets, and of course, the product of those terms is 1, so we can cancel all the i terms on the RHS:

erfi function

So the weird imaginary expression on the left has a real value. If we give it a name, the imaginary error function, or erfi, we can treat it as an ordinary function whose value can be calculated using the Maclaurin expansion (or other methods):

erfi function

What just happened?

The result above might seem strange, perhaps even suspect. That is because, like the parable of the blind men and the elephant, we are looking at two aspects of the erf function but ignoring the whole thing.

In fact, the erf function is a complex-valued function of a complex variable. If we calculate erf(z) for any complex number z, we will get a complex number result w. Sometimes w will be purely real, sometimes it will be purely imaginary, but in most cases it will be a complex number with non-zero real and imaginary parts.

This diagram shows the complete erf function:

erfi function

Each square area is an Argand diagram representing the complex input value z. The horizontal represents the real part of z, from -2 to +2. The vertical represents the imaginary part of z, from -2i to +2i.

The colours represent the value of the complex erf function. The left square is the real part of the erf function, the right square is the imaginary value.

The real erf function, that is erf(x) for real x, is just one small part of the complete function. It is the part of the function along the real axis, that is, the line where the imaginary part of z is zero. This is highlighted here:

erfi function

Notice that, along the real axis, the imaginary part of the complex erf function is zero (shown as white). In other words, for real z, erf is a real-valued function. This is the real erf(x) function we used earlier.

The erfi function is found by looking at the imaginary axis:

erfi function

Along the imaginary axis, the real part of the complex erf function is zero. This means that, for imaginary z, erf is an imaginary function. This is the function erf(ix) we used earlier, which also yielded an imaginary result. If we multiply this function by -i, we get the real-valued erfi function.

Using the erfi function

The erfi function is available in many programming languages, although you might need to include a more specialised library. For example, in Python you can find the erfi function in the scipy library (scipy.special.erfi). This library also includes the complex-valued erf function (used to make the complex plots above). The regular, real-valued erf function is included in the standard math library for Python.

See also



Join the GraphicMaths Newsletter

Sign up using this form to receive an email when new content is added:

Popular tags

adder adjacency matrix alu and gate angle answers area argand diagram binary maths cartesian equation chain rule chord circle cofactor combinations complex modulus complex polygon complex power complex root cosh cosine cosine rule countable cpu cube decagon demorgans law derivative determinant diagonal directrix dodecagon e eigenvalue eigenvector ellipse equilateral triangle erf function euclid euler eulers formula eulers identity exercises exponent exponential exterior angle first principles flip-flop focus gabriels horn galileo gamma function gaussian distribution gradient graph hendecagon heptagon heron hexagon hilbert horizontal hyperbola hyperbolic function hyperbolic functions infinity integration integration by parts integration by substitution interior angle inverse hyperbolic function inverse matrix irrational irrational number irregular polygon isomorphic graph isosceles trapezium isosceles triangle kite koch curve l system lhopitals rule limit line integral locus logarithm maclaurin series major axis matrix matrix algebra mean minor axis n choose r nand gate net newton raphson method nonagon nor gate normal normal distribution not gate octagon or gate parabola parallelogram parametric equation pentagon perimeter permutation matrix permutations pi pi function polar coordinates polynomial power probability probability distribution product rule proof pythagoras proof quadrilateral questions radians radius rectangle regular polygon rhombus root sech segment set set-reset flip-flop simpsons rule sine sine rule sinh sloping lines solving equations solving triangles square square root squeeze theorem standard curves standard deviation star polygon statistics straight line graphs surface of revolution symmetry tangent tanh transformation transformations translation trapezium triangle turtle graphics uncountable variance vertical volume volume of revolution xnor gate xor gate