NMSE Section 6.1 mentioned, A

Percentage Accurate: 72.9% → 99.8%
Time: 13.6s
Alternatives: 17
Speedup: 5.6×

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 17 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: 72.9% 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.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := e^{x \cdot \left(-1 - \varepsilon\right)}\\
\mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + t\_0 \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(t\_0 + e^{\varepsilon \cdot x}\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 36.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 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) \]
    8. Recombined 2 regimes into one program.
    9. 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^{x \cdot \left(-1 - \varepsilon\right)} + e^{\varepsilon \cdot x}\right)\\ \end{array} \]
    10. Add Preprocessing

    Alternative 2: 92.8% 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 4:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(\varepsilon + -1, \varepsilon + -1, \left(-1 - \varepsilon\right) \cdot \left(-1 - \varepsilon\right)\right), x \cdot 0.25, -1\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))))
          4.0)
       (* 0.5 (* (exp (- x)) (+ x (+ x 2.0))))
       (fma
        x
        (fma
         (fma (+ eps -1.0) (+ eps -1.0) (* (- -1.0 eps) (- -1.0 eps)))
         (* x 0.25)
         -1.0)
        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)))) <= 4.0) {
    		tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
    	} else {
    		tmp = fma(x, fma(fma((eps + -1.0), (eps + -1.0), ((-1.0 - eps) * (-1.0 - eps))), (x * 0.25), -1.0), 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)))) <= 4.0)
    		tmp = Float64(0.5 * Float64(exp(Float64(-x)) * Float64(x + Float64(x + 2.0))));
    	else
    		tmp = fma(x, fma(fma(Float64(eps + -1.0), Float64(eps + -1.0), Float64(Float64(-1.0 - eps) * Float64(-1.0 - eps))), Float64(x * 0.25), -1.0), 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], 4.0], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * N[(x + N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(N[(eps + -1.0), $MachinePrecision] * N[(eps + -1.0), $MachinePrecision] + N[(N[(-1.0 - eps), $MachinePrecision] * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * 0.25), $MachinePrecision] + -1.0), $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 4:\\
    \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(\varepsilon + -1, \varepsilon + -1, \left(-1 - \varepsilon\right) \cdot \left(-1 - \varepsilon\right)\right), x \cdot 0.25, -1\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))))) < 4

      1. Initial program 53.1%

        \[\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.3%

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

      if 4 < (-.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.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 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.9%

        \[\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 0

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

          \[\leadsto e^{-x} \]
        2. Taylor expanded in x around 0

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

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

          \[\leadsto \mathsf{fma}\left(x, \frac{1}{4} \cdot \left(x \cdot \left({\left(1 + \varepsilon\right)}^{2} + {\left(\varepsilon - 1\right)}^{2}\right)\right) - 1, 1\right) \]
        5. Step-by-step derivation
          1. Applied rewrites84.0%

            \[\leadsto \mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(\varepsilon + -1, \varepsilon + -1, \left(1 + \varepsilon\right) \cdot \left(1 + \varepsilon\right)\right), x \cdot \color{blue}{0.25}, -1\right), 1\right) \]
        6. Recombined 2 regimes into one program.
        7. Final simplification92.8%

          \[\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 4:\\ \;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(\varepsilon + -1, \varepsilon + -1, \left(-1 - \varepsilon\right) \cdot \left(-1 - \varepsilon\right)\right), x \cdot 0.25, -1\right), 1\right)\\ \end{array} \]
        8. Add Preprocessing

        Reproduce

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