6.7 Error Function
Error function
\[ erf(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt \]
Complementary error function
\[\begin{equation*} \begin{split} erfc(x) &= 1 - erf(x) \\ &= \frac{2}{\sqrt{\pi}} \int_x^{\infty} e^{-t^2} dt \end{split} \end{equation*}\]
erf
## function (x)
## {
## if (x >= 0)
## return(1 - erfccheb(x))
## else return(erfccheb(-x) - 1)
## }
## <bytecode: 0x000001e2ac3b3128>
## <environment: namespace:math>
erfc
## function (x)
## {
## if (x >= 0)
## return(erfccheb(x))
## else return(2 - erfccheb(-x))
## }
## <bytecode: 0x000001e2ac2e7a08>
## <environment: namespace:math>
erfccheb
## function (z)
## {
## ncof = 28
## cof = c(-1.30265371978171, 0.64196979235649, 0.0194764732041858,
## -0.00956151478680863, -0.000946595344482036, 0.000366839497852761,
## 4.2523324806907e-05, -2.0278578112534e-05, -1.624290004647e-06,
## 1.30365583558e-06, 1.5626441722e-08, -8.5238095915e-08,
## 6.529054439e-09, 5.059343495e-09, -9.91364156e-10, -2.27365122e-10,
## 9.6467911e-11, 2.394038e-12, -6.886027e-12, 8.94487e-13,
## 3.13092e-13, -1.12708e-13, 3.81e-16, 7.106e-15, -1.523e-15,
## -9.4e-17, 1.21e-16, -2.8e-17)
## d = 0
## dd = 0
## if (z < 0) {
## warning("erfccheb requires nonnegative argument")
## return(NULL)
## }
## ty = 8/(2 + z) - 2
## for (j in ncof:2) {
## tmp = d
## d = ty * d - dd + cof[j]
## dd = tmp
## }
## return(t * exp(-z * z + 0.5 * (cof[1] + ty * d) - dd))
## }
## <bytecode: 0x000001e2ac23bba0>
## <environment: namespace:math>