Note
Go to the end to download the full example code.
The error function and the normal distribution#
Recovers the 68-95-99.7 rule from erf, and shows why erfc is needed in the far tail, where 1 - erf(x) rounds to zero.
import math
import matplotlib.pyplot as plt
import numpy as np
from mathematicskit.special_functions import complementary_error_function, error_function
The 68-95-99.7 rule#
P(|X - mu| < 1 sigma) = erf(1/sqrt 2) = 0.682689
P(|X - mu| < 2 sigma) = erf(2/sqrt 2) = 0.954500
P(|X - mu| < 3 sigma) = erf(3/sqrt 2) = 0.997300
erf and erfc#

Text(0.5, 1.0, 'The error function')
The far tail#
x = 3: 1 - erf(x) = 2.209e-05, erfc(x) = 2.209e-05
x = 6: 1 - erf(x) = 0.000e+00, erfc(x) = 2.152e-17
x = 9: 1 - erf(x) = 0.000e+00, erfc(x) = 4.137e-37
Total running time of the script: (0 minutes 0.023 seconds)