NMSE Section 6.1 mentioned, A

Percentage Accurate: 74.3% → 99.8%
Time: 6.3s
Alternatives: 2
Speedup: N/A×

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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps)
use fmin_fmax_functions
    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 2 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: 74.3% 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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps)
use fmin_fmax_functions
    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, N/A× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} t_0 := -1 \cdot \left(x - -1\right)\\ t_1 := {\left(e^{-1}\right)}^{x}\\ \mathbf{if}\;eps\_m \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\frac{t\_0 \cdot \left(-1 \cdot t\_1\right) - t\_0 \cdot t\_1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(e^{-1}\right)}^{\left(\left(1 - eps\_m\right) \cdot x\right)} - \left(-1 \cdot 0 - {\left(e^{-1}\right)}^{\left(\left(eps\_m + 1\right) \cdot x\right)}\right)}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (let* ((t_0 (* -1.0 (- x -1.0))) (t_1 (pow (exp -1.0) x)))
   (if (<= eps_m 2e-38)
     (/ (- (* t_0 (* -1.0 t_1)) (* t_0 t_1)) 2.0)
     (/
      (-
       (pow (exp -1.0) (* (- 1.0 eps_m) x))
       (- (* -1.0 0.0) (pow (exp -1.0) (* (+ eps_m 1.0) x))))
      2.0))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double t_0 = -1.0 * (x - -1.0);
	double t_1 = pow(exp(-1.0), x);
	double tmp;
	if (eps_m <= 2e-38) {
		tmp = ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
	} else {
		tmp = (pow(exp(-1.0), ((1.0 - eps_m) * x)) - ((-1.0 * 0.0) - pow(exp(-1.0), ((eps_m + 1.0) * x)))) / 2.0;
	}
	return tmp;
}
eps_m =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-1.0d0) * (x - (-1.0d0))
    t_1 = exp((-1.0d0)) ** x
    if (eps_m <= 2d-38) then
        tmp = ((t_0 * ((-1.0d0) * t_1)) - (t_0 * t_1)) / 2.0d0
    else
        tmp = ((exp((-1.0d0)) ** ((1.0d0 - eps_m) * x)) - (((-1.0d0) * 0.0d0) - (exp((-1.0d0)) ** ((eps_m + 1.0d0) * x)))) / 2.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double t_0 = -1.0 * (x - -1.0);
	double t_1 = Math.pow(Math.exp(-1.0), x);
	double tmp;
	if (eps_m <= 2e-38) {
		tmp = ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
	} else {
		tmp = (Math.pow(Math.exp(-1.0), ((1.0 - eps_m) * x)) - ((-1.0 * 0.0) - Math.pow(Math.exp(-1.0), ((eps_m + 1.0) * x)))) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	t_0 = -1.0 * (x - -1.0)
	t_1 = math.pow(math.exp(-1.0), x)
	tmp = 0
	if eps_m <= 2e-38:
		tmp = ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0
	else:
		tmp = (math.pow(math.exp(-1.0), ((1.0 - eps_m) * x)) - ((-1.0 * 0.0) - math.pow(math.exp(-1.0), ((eps_m + 1.0) * x)))) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	t_0 = Float64(-1.0 * Float64(x - -1.0))
	t_1 = exp(-1.0) ^ x
	tmp = 0.0
	if (eps_m <= 2e-38)
		tmp = Float64(Float64(Float64(t_0 * Float64(-1.0 * t_1)) - Float64(t_0 * t_1)) / 2.0);
	else
		tmp = Float64(Float64((exp(-1.0) ^ Float64(Float64(1.0 - eps_m) * x)) - Float64(Float64(-1.0 * 0.0) - (exp(-1.0) ^ Float64(Float64(eps_m + 1.0) * x)))) / 2.0);
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	t_0 = -1.0 * (x - -1.0);
	t_1 = exp(-1.0) ^ x;
	tmp = 0.0;
	if (eps_m <= 2e-38)
		tmp = ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
	else
		tmp = ((exp(-1.0) ^ ((1.0 - eps_m) * x)) - ((-1.0 * 0.0) - (exp(-1.0) ^ ((eps_m + 1.0) * x)))) / 2.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(-1.0 * N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]}, If[LessEqual[eps$95$m, 2e-38], N[(N[(N[(t$95$0 * N[(-1.0 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[Power[N[Exp[-1.0], $MachinePrecision], N[(N[(1.0 - eps$95$m), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] - N[(N[(-1.0 * 0.0), $MachinePrecision] - N[Power[N[Exp[-1.0], $MachinePrecision], N[(N[(eps$95$m + 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
t_0 := -1 \cdot \left(x - -1\right)\\
t_1 := {\left(e^{-1}\right)}^{x}\\
\mathbf{if}\;eps\_m \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\frac{t\_0 \cdot \left(-1 \cdot t\_1\right) - t\_0 \cdot t\_1}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{{\left(e^{-1}\right)}^{\left(\left(1 - eps\_m\right) \cdot x\right)} - \left(-1 \cdot 0 - {\left(e^{-1}\right)}^{\left(\left(eps\_m + 1\right) \cdot x\right)}\right)}{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if eps < 1.9999999999999999e-38

    1. Initial program 59.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 \frac{\color{blue}{\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)}}{2} \]
    4. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \frac{\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)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)}}{2} \]
      2. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(x + 1\right) \cdot {\left(e^{-1}\right)}^{x} - -1 \cdot \left(\left(x + 1\right) \cdot e^{-1 \cdot x}\right)}{2} \]
      15. exp-prodN/A

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

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

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

    if 1.9999999999999999e-38 < eps

    1. Initial program 97.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 \frac{\color{blue}{e^{\mathsf{neg}\left(x \cdot \left(1 - \varepsilon\right)\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}}}{2} \]
    4. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \frac{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)}}}{2} \]
      2. mul-1-negN/A

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

        \[\leadsto \frac{e^{-1 \cdot \left(\left(1 - \varepsilon\right) \cdot x\right)} - -1 \cdot e^{\mathsf{neg}\left(x \cdot \left(1 + \varepsilon\right)\right)}}{2} \]
      4. exp-prodN/A

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

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

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

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

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

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

        \[\leadsto \frac{{\left(e^{-1}\right)}^{\left(\left(1 - \varepsilon\right) \cdot x\right)} - -1 \cdot \frac{1}{e^{\left(1 + \varepsilon\right) \cdot x}}}{2} \]
      11. exp-negN/A

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

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

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

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

      \[\leadsto \frac{\color{blue}{{\left(e^{-1}\right)}^{\left(\left(1 - \varepsilon\right) \cdot x\right)} - -1 \cdot {\left(e^{-1}\right)}^{\left(\left(\varepsilon + 1\right) \cdot x\right)}}}{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.0%

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

Alternative 2: 57.9% accurate, N/A× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} t_0 := -1 \cdot \left(x - -1\right)\\ t_1 := {\left(e^{-1}\right)}^{x}\\ \frac{t\_0 \cdot \left(-1 \cdot t\_1\right) - t\_0 \cdot t\_1}{2} \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (let* ((t_0 (* -1.0 (- x -1.0))) (t_1 (pow (exp -1.0) x)))
   (/ (- (* t_0 (* -1.0 t_1)) (* t_0 t_1)) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double t_0 = -1.0 * (x - -1.0);
	double t_1 = pow(exp(-1.0), x);
	return ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
}
eps_m =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: t_0
    real(8) :: t_1
    t_0 = (-1.0d0) * (x - (-1.0d0))
    t_1 = exp((-1.0d0)) ** x
    code = ((t_0 * ((-1.0d0) * t_1)) - (t_0 * t_1)) / 2.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double t_0 = -1.0 * (x - -1.0);
	double t_1 = Math.pow(Math.exp(-1.0), x);
	return ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	t_0 = -1.0 * (x - -1.0)
	t_1 = math.pow(math.exp(-1.0), x)
	return ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0
eps_m = abs(eps)
function code(x, eps_m)
	t_0 = Float64(-1.0 * Float64(x - -1.0))
	t_1 = exp(-1.0) ^ x
	return Float64(Float64(Float64(t_0 * Float64(-1.0 * t_1)) - Float64(t_0 * t_1)) / 2.0)
end
eps_m = abs(eps);
function tmp = code(x, eps_m)
	t_0 = -1.0 * (x - -1.0);
	t_1 = exp(-1.0) ^ x;
	tmp = ((t_0 * (-1.0 * t_1)) - (t_0 * t_1)) / 2.0;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(-1.0 * N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]}, N[(N[(N[(t$95$0 * N[(-1.0 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
t_0 := -1 \cdot \left(x - -1\right)\\
t_1 := {\left(e^{-1}\right)}^{x}\\
\frac{t\_0 \cdot \left(-1 \cdot t\_1\right) - t\_0 \cdot t\_1}{2}
\end{array}
\end{array}
Derivation
  1. Initial program 71.9%

    \[\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 \frac{\color{blue}{\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)}}{2} \]
  4. Step-by-step derivation
    1. lower--.f64N/A

      \[\leadsto \frac{\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)} + -1 \cdot \left(x \cdot e^{\mathsf{neg}\left(x\right)}\right)\right)}}{2} \]
    2. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(x + 1\right) \cdot {\left(e^{-1}\right)}^{x} - -1 \cdot \left(\left(x + 1\right) \cdot e^{-1 \cdot x}\right)}{2} \]
    15. exp-prodN/A

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

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

    \[\leadsto \frac{\color{blue}{\left(x + 1\right) \cdot {\left(e^{-1}\right)}^{x} - -1 \cdot \left(\left(x + 1\right) \cdot {\left(e^{-1}\right)}^{x}\right)}}{2} \]
  6. Final simplification58.4%

    \[\leadsto \frac{\left(-1 \cdot \left(x - -1\right)\right) \cdot \left(-1 \cdot {\left(e^{-1}\right)}^{x}\right) - \left(-1 \cdot \left(x - -1\right)\right) \cdot {\left(e^{-1}\right)}^{x}}{2} \]
  7. Add Preprocessing

Reproduce

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