NMSE Section 6.1 mentioned, A

Percentage Accurate: 73.2% → 99.7%
Time: 12.0s
Alternatives: 15
Speedup: 9.7×

Specification

?
\[\begin{array}{l} \\ \frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (/
  (-
   (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x))))
   (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x)))))
  2.0))
double code(double x, double eps) {
	return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
	return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps):
	return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps)
	return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0)
end
function tmp = code(x, eps)
	tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\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 15 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: 73.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (/
  (-
   (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x))))
   (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x)))))
  2.0))
double code(double x, double eps) {
	return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
	return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps):
	return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps)
	return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0)
end
function tmp = code(x, eps)
	tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}

Alternative 1: 99.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 0:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{\varepsilon \cdot x} + e^{\varepsilon \cdot \left(-x\right)}\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<=
      (+
       (* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
       (* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))
      0.0)
   (* 0.5 (* (exp (- x)) (+ x (+ x 2.0))))
   (* 0.5 (+ (exp (* eps x)) (exp (* eps (- x)))))))
double code(double x, double eps) {
	double tmp;
	if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 0.0) {
		tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
	} else {
		tmp = 0.5 * (exp((eps * x)) + exp((eps * -x)));
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((((1.0d0 + (1.0d0 / eps)) * exp((x * (eps + (-1.0d0))))) + (exp((x * ((-1.0d0) - eps))) * (1.0d0 + ((-1.0d0) / eps)))) <= 0.0d0) then
        tmp = 0.5d0 * (exp(-x) * (x + (x + 2.0d0)))
    else
        tmp = 0.5d0 * (exp((eps * x)) + exp((eps * -x)))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((((1.0 + (1.0 / eps)) * Math.exp((x * (eps + -1.0)))) + (Math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 0.0) {
		tmp = 0.5 * (Math.exp(-x) * (x + (x + 2.0)));
	} else {
		tmp = 0.5 * (Math.exp((eps * x)) + Math.exp((eps * -x)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (((1.0 + (1.0 / eps)) * math.exp((x * (eps + -1.0)))) + (math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 0.0:
		tmp = 0.5 * (math.exp(-x) * (x + (x + 2.0)))
	else:
		tmp = 0.5 * (math.exp((eps * x)) + math.exp((eps * -x)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) <= 0.0)
		tmp = Float64(0.5 * Float64(exp(Float64(-x)) * Float64(x + Float64(x + 2.0))));
	else
		tmp = Float64(0.5 * Float64(exp(Float64(eps * x)) + exp(Float64(eps * Float64(-x)))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 0.0)
		tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
	else
		tmp = 0.5 * (exp((eps * x)) + exp((eps * -x)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * N[(x + N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[N[(eps * x), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 0:\\
\;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{\varepsilon \cdot x} + e^{\varepsilon \cdot \left(-x\right)}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 0.0

    1. Initial program 33.8%

      \[\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in eps around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)\right)} \]
      2. mul-1-negN/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + \color{blue}{\left(\mathsf{neg}\left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \color{blue}{\left(-1 \cdot e^{\mathsf{neg}\left(x\right)} - x \cdot e^{\mathsf{neg}\left(x\right)}\right)}\right) \]
      4. associate-+l-N/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - -1 \cdot e^{\mathsf{neg}\left(x\right)}\right) + x \cdot e^{\mathsf{neg}\left(x\right)}\right)} \]
      5. distribute-rgt1-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\left(x + 1\right) \cdot e^{\mathsf{neg}\left(x\right)}} - -1 \cdot e^{\mathsf{neg}\left(x\right)}\right) + x \cdot e^{\mathsf{neg}\left(x\right)}\right) \]
      6. distribute-rgt-out--N/A

        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(x + 1\right) - -1\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) \]
      7. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(x + 1\right) - -1\right) + \color{blue}{e^{\mathsf{neg}\left(x\right)} \cdot x}\right) \]
      8. distribute-lft-outN/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right)} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right)} \]
      10. lower-exp.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{e^{\mathsf{neg}\left(x\right)}} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right) \]
      11. lower-neg.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(e^{\color{blue}{\mathsf{neg}\left(x\right)}} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right) \]
      12. lower-+.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x\right)} \cdot \color{blue}{\left(\left(\left(x + 1\right) - -1\right) + x\right)}\right) \]
    5. Applied rewrites100.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-x} \cdot \left(\left(x + 2\right) + x\right)\right)} \]

    if 0.0 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x)))))

    1. Initial program 100.0%

      \[\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in eps around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
      2. cancel-sign-sub-invN/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \left(\mathsf{neg}\left(-1\right)\right) \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
      3. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \color{blue}{1} \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right) \]
      4. *-lft-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \color{blue}{e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}}\right) \]
      5. lower-+.f64N/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
    5. Applied rewrites100.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{x \cdot \varepsilon - x} + e^{x \cdot \left(-1 - \varepsilon\right)}\right)} \]
    6. Taylor expanded in eps around inf

      \[\leadsto \frac{1}{2} \cdot \left(e^{\varepsilon \cdot x} + e^{\color{blue}{x} \cdot \left(-1 - \varepsilon\right)}\right) \]
    7. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto 0.5 \cdot \left(e^{x \cdot \varepsilon} + e^{\color{blue}{x} \cdot \left(-1 - \varepsilon\right)}\right) \]
      2. Taylor expanded in eps around inf

        \[\leadsto \frac{1}{2} \cdot \left(e^{x \cdot \varepsilon} + e^{-1 \cdot \left(\varepsilon \cdot x\right)}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto 0.5 \cdot \left(e^{x \cdot \varepsilon} + e^{x \cdot \left(-\varepsilon\right)}\right) \]
      4. Recombined 2 regimes into one program.
      5. Final simplification100.0%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 0:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{\varepsilon \cdot x} + e^{\varepsilon \cdot \left(-x\right)}\right)\\ \end{array} \]
      6. Add Preprocessing

      Alternative 2: 92.5% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 2.005:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \left(x \cdot \left(\varepsilon \cdot \varepsilon\right)\right), 1\right)\\ \end{array} \end{array} \]
      (FPCore (x eps)
       :precision binary64
       (if (<=
            (+
             (* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
             (* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))
            2.005)
         (* 0.5 (* (exp (- x)) (+ x (+ x 2.0))))
         (fma x (* 0.5 (* x (* eps eps))) 1.0)))
      double code(double x, double eps) {
      	double tmp;
      	if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 2.005) {
      		tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
      	} else {
      		tmp = fma(x, (0.5 * (x * (eps * eps))), 1.0);
      	}
      	return tmp;
      }
      
      function code(x, eps)
      	tmp = 0.0
      	if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) <= 2.005)
      		tmp = Float64(0.5 * Float64(exp(Float64(-x)) * Float64(x + Float64(x + 2.0))));
      	else
      		tmp = fma(x, Float64(0.5 * Float64(x * Float64(eps * eps))), 1.0);
      	end
      	return tmp
      end
      
      code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.005], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * N[(x + N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 * N[(x * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 2.005:\\
      \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \left(x \cdot \left(\varepsilon \cdot \varepsilon\right)\right), 1\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2.0049999999999999

        1. Initial program 53.3%

          \[\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in eps around 0

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)\right)} \]
        4. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)\right)} \]
          2. mul-1-negN/A

            \[\leadsto \frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \left(-1 \cdot e^{\mathsf{neg}\left(x\right)} + \color{blue}{\left(\mathsf{neg}\left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)}\right)\right) \]
          3. unsub-negN/A

            \[\leadsto \frac{1}{2} \cdot \left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - \color{blue}{\left(-1 \cdot e^{\mathsf{neg}\left(x\right)} - x \cdot e^{\mathsf{neg}\left(x\right)}\right)}\right) \]
          4. associate-+l-N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(e^{\mathsf{neg}\left(x\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) - -1 \cdot e^{\mathsf{neg}\left(x\right)}\right) + x \cdot e^{\mathsf{neg}\left(x\right)}\right)} \]
          5. distribute-rgt1-inN/A

            \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\left(x + 1\right) \cdot e^{\mathsf{neg}\left(x\right)}} - -1 \cdot e^{\mathsf{neg}\left(x\right)}\right) + x \cdot e^{\mathsf{neg}\left(x\right)}\right) \]
          6. distribute-rgt-out--N/A

            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(x + 1\right) - -1\right)} + x \cdot e^{\mathsf{neg}\left(x\right)}\right) \]
          7. *-commutativeN/A

            \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(x + 1\right) - -1\right) + \color{blue}{e^{\mathsf{neg}\left(x\right)} \cdot x}\right) \]
          8. distribute-lft-outN/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right)} \]
          9. lower-*.f64N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right)} \]
          10. lower-exp.f64N/A

            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{e^{\mathsf{neg}\left(x\right)}} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right) \]
          11. lower-neg.f64N/A

            \[\leadsto \frac{1}{2} \cdot \left(e^{\color{blue}{\mathsf{neg}\left(x\right)}} \cdot \left(\left(\left(x + 1\right) - -1\right) + x\right)\right) \]
          12. lower-+.f64N/A

            \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x\right)} \cdot \color{blue}{\left(\left(\left(x + 1\right) - -1\right) + x\right)}\right) \]
        5. Applied rewrites99.4%

          \[\leadsto \color{blue}{0.5 \cdot \left(e^{-x} \cdot \left(\left(x + 2\right) + x\right)\right)} \]

        if 2.0049999999999999 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x)))))

        1. Initial program 99.6%

          \[\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in eps around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
        4. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
          2. cancel-sign-sub-invN/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \left(\mathsf{neg}\left(-1\right)\right) \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
          3. metadata-evalN/A

            \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \color{blue}{1} \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right) \]
          4. *-lft-identityN/A

            \[\leadsto \frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + \color{blue}{e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}}\right) \]
          5. lower-+.f64N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} + e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}\right)} \]
        5. Applied rewrites99.6%

          \[\leadsto \color{blue}{0.5 \cdot \left(e^{x \cdot \varepsilon - x} + e^{x \cdot \left(-1 - \varepsilon\right)}\right)} \]
        6. Taylor expanded in x around 0

          \[\leadsto 1 + \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left(x \cdot \left(\frac{1}{2} \cdot {\left(1 + \varepsilon\right)}^{2} + \frac{1}{2} \cdot {\left(\varepsilon - 1\right)}^{2}\right)\right) + \frac{1}{2} \cdot \left(\left(\varepsilon + -1 \cdot \left(1 + \varepsilon\right)\right) - 1\right)\right)} \]
        7. Applied rewrites83.4%

          \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(x, 0.25 \cdot \mathsf{fma}\left(\varepsilon + 1, \varepsilon + 1, \left(1 - \varepsilon\right) \cdot \left(1 - \varepsilon\right)\right), \mathsf{fma}\left(0.5, \varepsilon + \left(-1 - \varepsilon\right), -0.5\right)\right)}, 1\right) \]
        8. Taylor expanded in eps around inf

          \[\leadsto \mathsf{fma}\left(x, \frac{1}{2} \cdot \left({\varepsilon}^{2} \cdot \color{blue}{x}\right), 1\right) \]
        9. Step-by-step derivation
          1. Applied rewrites83.4%

            \[\leadsto \mathsf{fma}\left(x, 0.5 \cdot \left(x \cdot \color{blue}{\left(\varepsilon \cdot \varepsilon\right)}\right), 1\right) \]
        10. Recombined 2 regimes into one program.
        11. Final simplification92.5%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 2.005:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \left(x \cdot \left(\varepsilon \cdot \varepsilon\right)\right), 1\right)\\ \end{array} \]
        12. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024233 
        (FPCore (x eps)
          :name "NMSE Section 6.1 mentioned, A"
          :precision binary64
          (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))