Jmat.Real.erf

Percentage Accurate: 79.3% → 99.1%
Time: 26.2s
Alternatives: 9
Speedup: 8.3×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\ 1 - \left(t_0 \cdot \left(0.254829592 + t_0 \cdot \left(-0.284496736 + t_0 \cdot \left(1.421413741 + t_0 \cdot \left(-1.453152027 + t_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
   (-
    1.0
    (*
     (*
      t_0
      (+
       0.254829592
       (*
        t_0
        (+
         -0.284496736
         (*
          t_0
          (+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
     (exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
	double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
    code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
	double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x):
	t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x)))
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x)
	t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x))))
	return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x))))))
end
function tmp = code(x)
	t_0 = 1.0 / (1.0 + (0.3275911 * abs(x)));
	tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x))));
end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t_0 \cdot \left(0.254829592 + t_0 \cdot \left(-0.284496736 + t_0 \cdot \left(1.421413741 + t_0 \cdot \left(-1.453152027 + t_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 79.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\ 1 - \left(t_0 \cdot \left(0.254829592 + t_0 \cdot \left(-0.284496736 + t_0 \cdot \left(1.421413741 + t_0 \cdot \left(-1.453152027 + t_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
   (-
    1.0
    (*
     (*
      t_0
      (+
       0.254829592
       (*
        t_0
        (+
         -0.284496736
         (*
          t_0
          (+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
     (exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
	double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
    code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
	double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x):
	t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x)))
	return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x)
	t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x))))
	return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x))))))
end
function tmp = code(x)
	t_0 = 1.0 / (1.0 + (0.3275911 * abs(x)));
	tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x))));
end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t_0 \cdot \left(0.254829592 + t_0 \cdot \left(-0.284496736 + t_0 \cdot \left(1.421413741 + t_0 \cdot \left(-1.453152027 + t_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}

Alternative 1: 99.1% accurate, 4.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.25 \cdot 10^{-24}:\\ \;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\ \mathbf{elif}\;x_m \leq 0.89:\\ \;\;\;\;{\left({\left(10^{-9} + x_m \cdot 1.128386358070218\right)}^{3}\right)}^{0.3333333333333333}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 1.25e-24)
   (sqrt (cbrt 1e-54))
   (if (<= x_m 0.89)
     (pow (pow (+ 1e-9 (* x_m 1.128386358070218)) 3.0) 0.3333333333333333)
     1.0)))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.25e-24) {
		tmp = sqrt(cbrt(1e-54));
	} else if (x_m <= 0.89) {
		tmp = pow(pow((1e-9 + (x_m * 1.128386358070218)), 3.0), 0.3333333333333333);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.25e-24) {
		tmp = Math.sqrt(Math.cbrt(1e-54));
	} else if (x_m <= 0.89) {
		tmp = Math.pow(Math.pow((1e-9 + (x_m * 1.128386358070218)), 3.0), 0.3333333333333333);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.25e-24)
		tmp = sqrt(cbrt(1e-54));
	elseif (x_m <= 0.89)
		tmp = (Float64(1e-9 + Float64(x_m * 1.128386358070218)) ^ 3.0) ^ 0.3333333333333333;
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.25e-24], N[Sqrt[N[Power[1e-54, 1/3], $MachinePrecision]], $MachinePrecision], If[LessEqual[x$95$m, 0.89], N[Power[N[Power[N[(1e-9 + N[(x$95$m * 1.128386358070218), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision], 1.0]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.25 \cdot 10^{-24}:\\
\;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\

\mathbf{elif}\;x_m \leq 0.89:\\
\;\;\;\;{\left({\left(10^{-9} + x_m \cdot 1.128386358070218\right)}^{3}\right)}^{0.3333333333333333}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 98.9% accurate, 1.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := \frac{1}{1 + \left|x_m\right| \cdot 0.3275911}\\ t_1 := \frac{1}{1 + x_m \cdot 0.3275911}\\ \mathbf{if}\;\left|x_m\right| \leq 10^{-8}:\\ \;\;\;\;\sqrt[3]{10^{-27} + \mathsf{fma}\left(x_m, 3.385159074210654 \cdot 10^{-18}, \mathsf{fma}\left(3.819767313236556 \cdot 10^{-9}, {x_m}^{2}, {x_m}^{3} \cdot 1.4367244311350222\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(t_0 \cdot \left(1.453152027 - t_0 \cdot 1.061405429\right) - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ 1.0 (* (fabs x_m) 0.3275911))))
        (t_1 (/ 1.0 (+ 1.0 (* x_m 0.3275911)))))
   (if (<= (fabs x_m) 1e-8)
     (cbrt
      (+
       1e-27
       (fma
        x_m
        3.385159074210654e-18
        (fma
         3.819767313236556e-9
         (pow x_m 2.0)
         (* (pow x_m 3.0) 1.4367244311350222)))))
     (+
      1.0
      (*
       t_1
       (*
        (exp (* x_m (- x_m)))
        (-
         (*
          t_1
          (-
           (* t_1 (- (* t_0 (- 1.453152027 (* t_0 1.061405429))) 1.421413741))
           -0.284496736))
         0.254829592)))))))
x_m = fabs(x);
double code(double x_m) {
	double t_0 = 1.0 / (1.0 + (fabs(x_m) * 0.3275911));
	double t_1 = 1.0 / (1.0 + (x_m * 0.3275911));
	double tmp;
	if (fabs(x_m) <= 1e-8) {
		tmp = cbrt((1e-27 + fma(x_m, 3.385159074210654e-18, fma(3.819767313236556e-9, pow(x_m, 2.0), (pow(x_m, 3.0) * 1.4367244311350222)))));
	} else {
		tmp = 1.0 + (t_1 * (exp((x_m * -x_m)) * ((t_1 * ((t_1 * ((t_0 * (1.453152027 - (t_0 * 1.061405429))) - 1.421413741)) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	t_0 = Float64(1.0 / Float64(1.0 + Float64(abs(x_m) * 0.3275911)))
	t_1 = Float64(1.0 / Float64(1.0 + Float64(x_m * 0.3275911)))
	tmp = 0.0
	if (abs(x_m) <= 1e-8)
		tmp = cbrt(Float64(1e-27 + fma(x_m, 3.385159074210654e-18, fma(3.819767313236556e-9, (x_m ^ 2.0), Float64((x_m ^ 3.0) * 1.4367244311350222)))));
	else
		tmp = Float64(1.0 + Float64(t_1 * Float64(exp(Float64(x_m * Float64(-x_m))) * Float64(Float64(t_1 * Float64(Float64(t_1 * Float64(Float64(t_0 * Float64(1.453152027 - Float64(t_0 * 1.061405429))) - 1.421413741)) - -0.284496736)) - 0.254829592))));
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(N[Abs[x$95$m], $MachinePrecision] * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 + N[(x$95$m * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[x$95$m], $MachinePrecision], 1e-8], N[Power[N[(1e-27 + N[(x$95$m * 3.385159074210654e-18 + N[(3.819767313236556e-9 * N[Power[x$95$m, 2.0], $MachinePrecision] + N[(N[Power[x$95$m, 3.0], $MachinePrecision] * 1.4367244311350222), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(1.0 + N[(t$95$1 * N[(N[Exp[N[(x$95$m * (-x$95$m)), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$1 * N[(N[(t$95$1 * N[(N[(t$95$0 * N[(1.453152027 - N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.421413741), $MachinePrecision]), $MachinePrecision] - -0.284496736), $MachinePrecision]), $MachinePrecision] - 0.254829592), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := \frac{1}{1 + \left|x_m\right| \cdot 0.3275911}\\
t_1 := \frac{1}{1 + x_m \cdot 0.3275911}\\
\mathbf{if}\;\left|x_m\right| \leq 10^{-8}:\\
\;\;\;\;\sqrt[3]{10^{-27} + \mathsf{fma}\left(x_m, 3.385159074210654 \cdot 10^{-18}, \mathsf{fma}\left(3.819767313236556 \cdot 10^{-9}, {x_m}^{2}, {x_m}^{3} \cdot 1.4367244311350222\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(t_0 \cdot \left(1.453152027 - t_0 \cdot 1.061405429\right) - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 98.9% accurate, 2.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := \frac{1}{1 + \left|x_m\right| \cdot 0.3275911}\\ t_1 := \frac{1}{1 + x_m \cdot 0.3275911}\\ \mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\ \mathbf{else}:\\ \;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(t_0 \cdot \left(1.453152027 - t_0 \cdot 1.061405429\right) - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ 1.0 (* (fabs x_m) 0.3275911))))
        (t_1 (/ 1.0 (+ 1.0 (* x_m 0.3275911)))))
   (if (<= x_m 3.4e-16)
     (sqrt (cbrt 1e-54))
     (+
      1.0
      (*
       t_1
       (*
        (exp (* x_m (- x_m)))
        (-
         (*
          t_1
          (-
           (* t_1 (- (* t_0 (- 1.453152027 (* t_0 1.061405429))) 1.421413741))
           -0.284496736))
         0.254829592)))))))
x_m = fabs(x);
double code(double x_m) {
	double t_0 = 1.0 / (1.0 + (fabs(x_m) * 0.3275911));
	double t_1 = 1.0 / (1.0 + (x_m * 0.3275911));
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = sqrt(cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (exp((x_m * -x_m)) * ((t_1 * ((t_1 * ((t_0 * (1.453152027 - (t_0 * 1.061405429))) - 1.421413741)) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double t_0 = 1.0 / (1.0 + (Math.abs(x_m) * 0.3275911));
	double t_1 = 1.0 / (1.0 + (x_m * 0.3275911));
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = Math.sqrt(Math.cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (Math.exp((x_m * -x_m)) * ((t_1 * ((t_1 * ((t_0 * (1.453152027 - (t_0 * 1.061405429))) - 1.421413741)) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	t_0 = Float64(1.0 / Float64(1.0 + Float64(abs(x_m) * 0.3275911)))
	t_1 = Float64(1.0 / Float64(1.0 + Float64(x_m * 0.3275911)))
	tmp = 0.0
	if (x_m <= 3.4e-16)
		tmp = sqrt(cbrt(1e-54));
	else
		tmp = Float64(1.0 + Float64(t_1 * Float64(exp(Float64(x_m * Float64(-x_m))) * Float64(Float64(t_1 * Float64(Float64(t_1 * Float64(Float64(t_0 * Float64(1.453152027 - Float64(t_0 * 1.061405429))) - 1.421413741)) - -0.284496736)) - 0.254829592))));
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(N[Abs[x$95$m], $MachinePrecision] * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 + N[(x$95$m * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 3.4e-16], N[Sqrt[N[Power[1e-54, 1/3], $MachinePrecision]], $MachinePrecision], N[(1.0 + N[(t$95$1 * N[(N[Exp[N[(x$95$m * (-x$95$m)), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$1 * N[(N[(t$95$1 * N[(N[(t$95$0 * N[(1.453152027 - N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.421413741), $MachinePrecision]), $MachinePrecision] - -0.284496736), $MachinePrecision]), $MachinePrecision] - 0.254829592), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := \frac{1}{1 + \left|x_m\right| \cdot 0.3275911}\\
t_1 := \frac{1}{1 + x_m \cdot 0.3275911}\\
\mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\
\;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\

\mathbf{else}:\\
\;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(t_0 \cdot \left(1.453152027 - t_0 \cdot 1.061405429\right) - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 98.9% accurate, 3.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := 1 + x_m \cdot 0.3275911\\ t_1 := \frac{1}{t_0}\\ \mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\ \mathbf{else}:\\ \;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(\left(-1.453152027 + \frac{1.061405429}{1 + \left|x_m\right| \cdot 0.3275911}\right) \cdot \frac{-1}{t_0} - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* x_m 0.3275911))) (t_1 (/ 1.0 t_0)))
   (if (<= x_m 3.4e-16)
     (sqrt (cbrt 1e-54))
     (+
      1.0
      (*
       t_1
       (*
        (exp (* x_m (- x_m)))
        (-
         (*
          t_1
          (-
           (*
            t_1
            (-
             (*
              (+ -1.453152027 (/ 1.061405429 (+ 1.0 (* (fabs x_m) 0.3275911))))
              (/ -1.0 t_0))
             1.421413741))
           -0.284496736))
         0.254829592)))))))
x_m = fabs(x);
double code(double x_m) {
	double t_0 = 1.0 + (x_m * 0.3275911);
	double t_1 = 1.0 / t_0;
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = sqrt(cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (exp((x_m * -x_m)) * ((t_1 * ((t_1 * (((-1.453152027 + (1.061405429 / (1.0 + (fabs(x_m) * 0.3275911)))) * (-1.0 / t_0)) - 1.421413741)) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double t_0 = 1.0 + (x_m * 0.3275911);
	double t_1 = 1.0 / t_0;
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = Math.sqrt(Math.cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (Math.exp((x_m * -x_m)) * ((t_1 * ((t_1 * (((-1.453152027 + (1.061405429 / (1.0 + (Math.abs(x_m) * 0.3275911)))) * (-1.0 / t_0)) - 1.421413741)) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	t_0 = Float64(1.0 + Float64(x_m * 0.3275911))
	t_1 = Float64(1.0 / t_0)
	tmp = 0.0
	if (x_m <= 3.4e-16)
		tmp = sqrt(cbrt(1e-54));
	else
		tmp = Float64(1.0 + Float64(t_1 * Float64(exp(Float64(x_m * Float64(-x_m))) * Float64(Float64(t_1 * Float64(Float64(t_1 * Float64(Float64(Float64(-1.453152027 + Float64(1.061405429 / Float64(1.0 + Float64(abs(x_m) * 0.3275911)))) * Float64(-1.0 / t_0)) - 1.421413741)) - -0.284496736)) - 0.254829592))));
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(1.0 + N[(x$95$m * 0.3275911), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / t$95$0), $MachinePrecision]}, If[LessEqual[x$95$m, 3.4e-16], N[Sqrt[N[Power[1e-54, 1/3], $MachinePrecision]], $MachinePrecision], N[(1.0 + N[(t$95$1 * N[(N[Exp[N[(x$95$m * (-x$95$m)), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$1 * N[(N[(t$95$1 * N[(N[(N[(-1.453152027 + N[(1.061405429 / N[(1.0 + N[(N[Abs[x$95$m], $MachinePrecision] * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] - 1.421413741), $MachinePrecision]), $MachinePrecision] - -0.284496736), $MachinePrecision]), $MachinePrecision] - 0.254829592), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := 1 + x_m \cdot 0.3275911\\
t_1 := \frac{1}{t_0}\\
\mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\
\;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\

\mathbf{else}:\\
\;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(t_1 \cdot \left(\left(-1.453152027 + \frac{1.061405429}{1 + \left|x_m\right| \cdot 0.3275911}\right) \cdot \frac{-1}{t_0} - 1.421413741\right) - -0.284496736\right) - 0.254829592\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 98.9% accurate, 3.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := 1 + x_m \cdot 0.3275911\\ t_1 := \frac{1}{t_0}\\ \mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\ \mathbf{else}:\\ \;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(\left(1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{t_0}}{t_0}\right) \cdot \frac{-1}{1 + \left|x_m\right| \cdot 0.3275911} - -0.284496736\right) - 0.254829592\right)\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* x_m 0.3275911))) (t_1 (/ 1.0 t_0)))
   (if (<= x_m 3.4e-16)
     (sqrt (cbrt 1e-54))
     (+
      1.0
      (*
       t_1
       (*
        (exp (* x_m (- x_m)))
        (-
         (*
          t_1
          (-
           (*
            (+ 1.421413741 (/ (+ -1.453152027 (/ 1.061405429 t_0)) t_0))
            (/ -1.0 (+ 1.0 (* (fabs x_m) 0.3275911))))
           -0.284496736))
         0.254829592)))))))
x_m = fabs(x);
double code(double x_m) {
	double t_0 = 1.0 + (x_m * 0.3275911);
	double t_1 = 1.0 / t_0;
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = sqrt(cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (exp((x_m * -x_m)) * ((t_1 * (((1.421413741 + ((-1.453152027 + (1.061405429 / t_0)) / t_0)) * (-1.0 / (1.0 + (fabs(x_m) * 0.3275911)))) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double t_0 = 1.0 + (x_m * 0.3275911);
	double t_1 = 1.0 / t_0;
	double tmp;
	if (x_m <= 3.4e-16) {
		tmp = Math.sqrt(Math.cbrt(1e-54));
	} else {
		tmp = 1.0 + (t_1 * (Math.exp((x_m * -x_m)) * ((t_1 * (((1.421413741 + ((-1.453152027 + (1.061405429 / t_0)) / t_0)) * (-1.0 / (1.0 + (Math.abs(x_m) * 0.3275911)))) - -0.284496736)) - 0.254829592)));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	t_0 = Float64(1.0 + Float64(x_m * 0.3275911))
	t_1 = Float64(1.0 / t_0)
	tmp = 0.0
	if (x_m <= 3.4e-16)
		tmp = sqrt(cbrt(1e-54));
	else
		tmp = Float64(1.0 + Float64(t_1 * Float64(exp(Float64(x_m * Float64(-x_m))) * Float64(Float64(t_1 * Float64(Float64(Float64(1.421413741 + Float64(Float64(-1.453152027 + Float64(1.061405429 / t_0)) / t_0)) * Float64(-1.0 / Float64(1.0 + Float64(abs(x_m) * 0.3275911)))) - -0.284496736)) - 0.254829592))));
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(1.0 + N[(x$95$m * 0.3275911), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / t$95$0), $MachinePrecision]}, If[LessEqual[x$95$m, 3.4e-16], N[Sqrt[N[Power[1e-54, 1/3], $MachinePrecision]], $MachinePrecision], N[(1.0 + N[(t$95$1 * N[(N[Exp[N[(x$95$m * (-x$95$m)), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$1 * N[(N[(N[(1.421413741 + N[(N[(-1.453152027 + N[(1.061405429 / t$95$0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(1.0 + N[(N[Abs[x$95$m], $MachinePrecision] * 0.3275911), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - -0.284496736), $MachinePrecision]), $MachinePrecision] - 0.254829592), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := 1 + x_m \cdot 0.3275911\\
t_1 := \frac{1}{t_0}\\
\mathbf{if}\;x_m \leq 3.4 \cdot 10^{-16}:\\
\;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\

\mathbf{else}:\\
\;\;\;\;1 + t_1 \cdot \left(e^{x_m \cdot \left(-x_m\right)} \cdot \left(t_1 \cdot \left(\left(1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{t_0}}{t_0}\right) \cdot \frac{-1}{1 + \left|x_m\right| \cdot 0.3275911} - -0.284496736\right) - 0.254829592\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 97.6% accurate, 4.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 2.8 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (if (<= x_m 2.8e-5) (sqrt (cbrt 1e-54)) 1.0))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 2.8e-5) {
		tmp = sqrt(cbrt(1e-54));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 2.8e-5) {
		tmp = Math.sqrt(Math.cbrt(1e-54));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 2.8e-5)
		tmp = sqrt(cbrt(1e-54));
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 2.8e-5], N[Sqrt[N[Power[1e-54, 1/3], $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.8 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\sqrt[3]{10^{-54}}}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 97.4% accurate, 8.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 0.00029:\\ \;\;\;\;\sqrt[3]{10^{-27} + x_m \cdot 3.385159074210654 \cdot 10^{-18}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 0.00029) (cbrt (+ 1e-27 (* x_m 3.385159074210654e-18))) 1.0))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 0.00029) {
		tmp = cbrt((1e-27 + (x_m * 3.385159074210654e-18)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 0.00029) {
		tmp = Math.cbrt((1e-27 + (x_m * 3.385159074210654e-18)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 0.00029)
		tmp = cbrt(Float64(1e-27 + Float64(x_m * 3.385159074210654e-18)));
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 0.00029], N[Power[N[(1e-27 + N[(x$95$m * 3.385159074210654e-18), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.00029:\\
\;\;\;\;\sqrt[3]{10^{-27} + x_m \cdot 3.385159074210654 \cdot 10^{-18}}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 96.9% accurate, 8.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 2.8 \cdot 10^{-5}:\\ \;\;\;\;\sqrt[3]{10^{-27}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (if (<= x_m 2.8e-5) (cbrt 1e-27) 1.0))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 2.8e-5) {
		tmp = cbrt(1e-27);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 2.8e-5) {
		tmp = Math.cbrt(1e-27);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 2.8e-5)
		tmp = cbrt(1e-27);
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 2.8e-5], N[Power[1e-27, 1/3], $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.8 \cdot 10^{-5}:\\
\;\;\;\;\sqrt[3]{10^{-27}}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 55.7% accurate, 856.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ 1 \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 1.0)
x_m = fabs(x);
double code(double x_m) {
	return 1.0;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    code = 1.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	return 1.0;
}
x_m = math.fabs(x)
def code(x_m):
	return 1.0
x_m = abs(x)
function code(x_m)
	return 1.0
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = 1.0;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := 1.0
\begin{array}{l}
x_m = \left|x\right|

\\
1
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2024010 
(FPCore (x)
  :name "Jmat.Real.erf"
  :precision binary64
  (- 1.0 (* (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 0.254829592 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -0.284496736 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 1.421413741 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -1.453152027 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) 1.061405429))))))))) (exp (- (* (fabs x) (fabs x)))))))