Average Error: 14.0 → 0.8
Time: 18.9s
Precision: binary64
\[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 2.9221847357607688 \cdot 10^{-19}:\\ \;\;\;\;1.0000000272292198 \cdot 10^{-09} + 1.0000000272292198 \cdot 10^{-09} \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;1 - \left(\frac{0.254829592}{1 + \left|x\right| \cdot 0.3275911} + \frac{-0.284496736 + \frac{1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{1 + \left|x\right| \cdot 0.3275911}}{1 + \left|x\right| \cdot 0.3275911}}{1 + \left|x\right| \cdot 0.3275911}}{\left(1 + \left|x\right| \cdot 0.3275911\right) \cdot \left(1 + \left|x\right| \cdot 0.3275911\right)}\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}\\ \end{array}\]
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 2.9221847357607688 \cdot 10^{-19}:\\
\;\;\;\;1.0000000272292198 \cdot 10^{-09} + 1.0000000272292198 \cdot 10^{-09} \cdot {x}^{3}\\

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

\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) 2.9221847357607688e-19)
   (+ 1.0000000272292198e-09 (* 1.0000000272292198e-09 (pow x 3.0)))
   (-
    1.0
    (*
     (+
      (/ 0.254829592 (+ 1.0 (* (fabs x) 0.3275911)))
      (/
       (+
        -0.284496736
        (/
         (+
          1.421413741
          (/
           (+ -1.453152027 (/ 1.061405429 (+ 1.0 (* (fabs x) 0.3275911))))
           (+ 1.0 (* (fabs x) 0.3275911))))
         (+ 1.0 (* (fabs x) 0.3275911))))
       (* (+ 1.0 (* (fabs x) 0.3275911)) (+ 1.0 (* (fabs x) 0.3275911)))))
     (exp (- (* (fabs x) (fabs x))))))))
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) <= 2.9221847357607688e-19) {
		tmp = 1.0000000272292198e-09 + (1.0000000272292198e-09 * pow(x, 3.0));
	} else {
		tmp = 1.0 - (((0.254829592 / (1.0 + (fabs(x) * 0.3275911))) + ((-0.284496736 + ((1.421413741 + ((-1.453152027 + (1.061405429 / (1.0 + (fabs(x) * 0.3275911)))) / (1.0 + (fabs(x) * 0.3275911)))) / (1.0 + (fabs(x) * 0.3275911)))) / ((1.0 + (fabs(x) * 0.3275911)) * (1.0 + (fabs(x) * 0.3275911))))) * exp(-(fabs(x) * fabs(x))));
	}
	return tmp;
}

Error

Bits error versus x

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) < 2.9221847357607688e-19

    1. Initial program 28.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|}\]
    2. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{1.0000000272292198 \cdot 10^{-09} + 1.0000000272292198 \cdot 10^{-09} \cdot {x}^{3}}\]

    if 2.9221847357607688e-19 < (fabs.f64 x)

    1. Initial program 1.3

      \[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. Using strategy rm
    3. Applied distribute-rgt-in_binary641.3

      \[\leadsto 1 - \color{blue}{\left(0.254829592 \cdot \frac{1}{1 + 0.3275911 \cdot \left|x\right|} + \left(\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) \cdot \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\right)} \cdot e^{-\left|x\right| \cdot \left|x\right|}\]
    4. Simplified1.3

      \[\leadsto 1 - \left(\color{blue}{\frac{0.254829592}{1 + 0.3275911 \cdot \left|x\right|}} + \left(\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) \cdot \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}\]
    5. Simplified1.3

      \[\leadsto 1 - \left(\frac{0.254829592}{1 + 0.3275911 \cdot \left|x\right|} + \color{blue}{\frac{-0.284496736 + \frac{1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{1 + 0.3275911 \cdot \left|x\right|}}{1 + 0.3275911 \cdot \left|x\right|}}{1 + 0.3275911 \cdot \left|x\right|}}{\left(1 + 0.3275911 \cdot \left|x\right|\right) \cdot \left(1 + 0.3275911 \cdot \left|x\right|\right)}}\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 2.9221847357607688 \cdot 10^{-19}:\\ \;\;\;\;1.0000000272292198 \cdot 10^{-09} + 1.0000000272292198 \cdot 10^{-09} \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;1 - \left(\frac{0.254829592}{1 + \left|x\right| \cdot 0.3275911} + \frac{-0.284496736 + \frac{1.421413741 + \frac{-1.453152027 + \frac{1.061405429}{1 + \left|x\right| \cdot 0.3275911}}{1 + \left|x\right| \cdot 0.3275911}}{1 + \left|x\right| \cdot 0.3275911}}{\left(1 + \left|x\right| \cdot 0.3275911\right) \cdot \left(1 + \left|x\right| \cdot 0.3275911\right)}\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}\\ \end{array}\]

Reproduce

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