Reference · Math

math.erf

signature
math.erf(num) -> float

What it does

The error function, as Python's math.erf: 2 / sqrt(pi) times the integral of exp(-t²) from 0 to x. It runs from -1 to 1, is 0 at 0, and gives the normal distribution's cumulative probability as (1 + erf(x / sqrt(2))) / 2; stats.normal_cdf does that for you.

Examples

print(math.erf(0), math.erf(1), math.erf(-1))print(math.erf(0.5), math.erf(2))print((1 + math.erf(1 / math.sqrt(2))) / 2, stats.normal_cdf(1))
output
0.0 0.8427007929497149 -0.84270079294971490.5204998778130465 0.99532226501895270.8413447460685429 0.8413447460685429

Edge cases

print(math.erf(-0.0), math.erf(3), math.erf(6))print(math.erf(float("inf")), math.erf(float("-inf")), math.erf(float("nan")))
output
-0.0 0.9999779095030014 1.01.0 -1.0 NaN

Errors

An argument that is not a number is a runtime error, not an error value. There is no domain error: every number has an answer.

this one fails
print(math.erf("a"))
output
line 1: `math.erf` expects a number as argument 1, got str

Chaining

In a pipeline the number comes first:

print(1 | math.erf)print([-1, 0, 1] | map(math.erf))
output
0.8427007929497149[-0.8427007929497149, 0.0, 0.8427007929497149]

See also

math.erfc, stats.normal_cdf, math.exp, math.gamma

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On math.erf(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo