import math def erf_approx(x): sign = -1.0 if x < 0.0 else 1.0 a = abs(x) t = 1.0 / (1.0 + 0.3275911 * a) poly = ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t return sign * (1.0 - poly * math.exp(-a * a))