Average Error: 13.1 → 0.9
Time: 11.6s
Precision: binary64
Cost: 32580
\[1 - \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(0.254829592 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-0.284496736 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(1.421413741 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-1.453152027 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|} \]
\[\begin{array}{l} \mathbf{if}\;\left|x\right| \leq 5 \cdot 10^{-10}:\\ \;\;\;\;10^{-9} + \sqrt{{\left({\left(\sqrt[3]{x \cdot 1.128386358070218}\right)}^{3}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
(FPCore (x)
 :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)))))))
(FPCore (x)
 :precision binary64
 (if (<= (fabs x) 5e-10)
   (+ 1e-9 (sqrt (pow (pow (cbrt (* x 1.128386358070218)) 3.0) 2.0)))
   1.0))
double code(double x) {
	return 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))));
}
double code(double x) {
	double tmp;
	if (fabs(x) <= 5e-10) {
		tmp = 1e-9 + sqrt(pow(pow(cbrt((x * 1.128386358070218)), 3.0), 2.0));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
public static double code(double x) {
	return 1.0 - (((1.0 / (1.0 + (0.3275911 * Math.abs(x)))) * (0.254829592 + ((1.0 / (1.0 + (0.3275911 * Math.abs(x)))) * (-0.284496736 + ((1.0 / (1.0 + (0.3275911 * Math.abs(x)))) * (1.421413741 + ((1.0 / (1.0 + (0.3275911 * Math.abs(x)))) * (-1.453152027 + ((1.0 / (1.0 + (0.3275911 * Math.abs(x)))) * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
public static double code(double x) {
	double tmp;
	if (Math.abs(x) <= 5e-10) {
		tmp = 1e-9 + Math.sqrt(Math.pow(Math.pow(Math.cbrt((x * 1.128386358070218)), 3.0), 2.0));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
function code(x)
	return Float64(1.0 - Float64(Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(0.254829592 + Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(-0.284496736 + Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(1.421413741 + Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(-1.453152027 + Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x))))))
end
function code(x)
	tmp = 0.0
	if (abs(x) <= 5e-10)
		tmp = Float64(1e-9 + sqrt(((cbrt(Float64(x * 1.128386358070218)) ^ 3.0) ^ 2.0)));
	else
		tmp = 1.0;
	end
	return tmp
end
code[x_] := N[(1.0 - N[(N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.254829592 + N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.284496736 + N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.421413741 + N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.453152027 + N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 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]
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 5e-10], N[(1e-9 + N[Sqrt[N[Power[N[Power[N[Power[N[(x * 1.128386358070218), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]
1 - \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(0.254829592 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-0.284496736 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(1.421413741 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-1.453152027 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 5 \cdot 10^{-10}:\\
\;\;\;\;10^{-9} + \sqrt{{\left({\left(\sqrt[3]{x \cdot 1.128386358070218}\right)}^{3}\right)}^{2}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (fabs.f64 x) < 5.00000000000000031e-10

    1. Initial program 27.1

      \[1 - \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(0.254829592 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-0.284496736 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(1.421413741 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-1.453152027 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|} \]
    2. Applied egg-rr27.2

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.254829592 + \frac{-0.284496736 + \frac{1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)} \cdot \left(-{\left(e^{x}\right)}^{x}\right)\right)}} \]
    3. Taylor expanded in x around 0 0.7

      \[\leadsto \color{blue}{10^{-9} + 1.128386358070218 \cdot x} \]
    4. Applied egg-rr0.0

      \[\leadsto 10^{-9} + \color{blue}{\sqrt{{\left(1.128386358070218 \cdot x\right)}^{2}}} \]
    5. Applied egg-rr0.0

      \[\leadsto 10^{-9} + \sqrt{{\color{blue}{\left({\left(\sqrt[3]{1.128386358070218 \cdot x}\right)}^{3}\right)}}^{2}} \]

    if 5.00000000000000031e-10 < (fabs.f64 x)

    1. Initial program 0.5

      \[1 - \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(0.254829592 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-0.284496736 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(1.421413741 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(-1.453152027 + \frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|} \]
    2. Applied egg-rr63.6

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{0.254829592 + \frac{-0.284496736 + \frac{1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)}}{\mathsf{fma}\left(0.3275911, x, 1\right)} \cdot \left(-{\left(e^{x}\right)}^{x}\right)\right)}} \]
    3. Taylor expanded in x around inf 1.7

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 5 \cdot 10^{-10}:\\ \;\;\;\;10^{-9} + \sqrt{{\left({\left(\sqrt[3]{x \cdot 1.128386358070218}\right)}^{3}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternatives

Alternative 1
Error1.8
Cost13448
\[\begin{array}{l} \mathbf{if}\;x \leq -3608213680744282000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.0568407606825256 \cdot 10^{-16}:\\ \;\;\;\;10^{-9} + \sqrt{{\left(x \cdot 1.128386358070218\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 2
Error1.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3608213680744282000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.0568407606825256 \cdot 10^{-16}:\\ \;\;\;\;10^{-9} + x \cdot -1.128386358070218\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 3
Error2.4
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -3608213680744282000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.0568407606825256 \cdot 10^{-16}:\\ \;\;\;\;10^{-9}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error30.5
Cost64
\[10^{-9} \]

Error

Reproduce

herbie shell --seed 2022308 
(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)))))))