NMSE Section 6.1 mentioned, A

Percentage Accurate: 73.3% → 98.5%
Time: 12.8s
Alternatives: 13
Speedup: 2.0×

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 13 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.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;
}
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: 98.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;eps_m \leq 5.1 \cdot 10^{-31}:\\
\;\;\;\;\frac{\frac{x + 1}{e^{x}} + \left(x + 1\right) \cdot e^{-x}}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{eps_m \cdot x} + e^{eps_m \cdot \left(-x\right)}}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 98.9% accurate, 1.1× speedup?

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

\\
\frac{e^{x \cdot \left(eps_m + -1\right)} + e^{x \cdot \left(-1 - eps_m\right)}}{2}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 85.6% accurate, 1.1× speedup?

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

\\
\frac{e^{eps_m \cdot x} + e^{eps_m \cdot \left(-x\right)}}{2}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 77.5% accurate, 2.0× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -145000:\\ \;\;\;\;\frac{\frac{\mathsf{expm1}\left(-x\right)}{eps_m}}{2}\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+229}:\\ \;\;\;\;\frac{e^{eps_m \cdot x} - -1}{2}\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{+271}:\\ \;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x -145000.0)
   (/ (/ (expm1 (- x)) eps_m) 2.0)
   (if (<= x 1.25e+229)
     (/ (- (exp (* eps_m x)) -1.0) 2.0)
     (if (<= x 4.2e+271)
       (/ (+ (- 1.0 (/ -1.0 eps_m)) (- (/ -1.0 eps_m) -1.0)) 2.0)
       (/ (* eps_m x) 2.0)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= -145000.0) {
		tmp = (expm1(-x) / eps_m) / 2.0;
	} else if (x <= 1.25e+229) {
		tmp = (exp((eps_m * x)) - -1.0) / 2.0;
	} else if (x <= 4.2e+271) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= -145000.0) {
		tmp = (Math.expm1(-x) / eps_m) / 2.0;
	} else if (x <= 1.25e+229) {
		tmp = (Math.exp((eps_m * x)) - -1.0) / 2.0;
	} else if (x <= 4.2e+271) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= -145000.0:
		tmp = (math.expm1(-x) / eps_m) / 2.0
	elif x <= 1.25e+229:
		tmp = (math.exp((eps_m * x)) - -1.0) / 2.0
	elif x <= 4.2e+271:
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0
	else:
		tmp = (eps_m * x) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= -145000.0)
		tmp = Float64(Float64(expm1(Float64(-x)) / eps_m) / 2.0);
	elseif (x <= 1.25e+229)
		tmp = Float64(Float64(exp(Float64(eps_m * x)) - -1.0) / 2.0);
	elseif (x <= 4.2e+271)
		tmp = Float64(Float64(Float64(1.0 - Float64(-1.0 / eps_m)) + Float64(Float64(-1.0 / eps_m) - -1.0)) / 2.0);
	else
		tmp = Float64(Float64(eps_m * x) / 2.0);
	end
	return tmp
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, -145000.0], N[(N[(N[(Exp[(-x)] - 1), $MachinePrecision] / eps$95$m), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.25e+229], N[(N[(N[Exp[N[(eps$95$m * x), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 4.2e+271], N[(N[(N[(1.0 - N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -145000:\\
\;\;\;\;\frac{\frac{\mathsf{expm1}\left(-x\right)}{eps_m}}{2}\\

\mathbf{elif}\;x \leq 1.25 \cdot 10^{+229}:\\
\;\;\;\;\frac{e^{eps_m \cdot x} - -1}{2}\\

\mathbf{elif}\;x \leq 4.2 \cdot 10^{+271}:\\
\;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 84.4% accurate, 2.0× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-298}:\\ \;\;\;\;\frac{1 + e^{eps_m \cdot \left(-x\right)}}{2}\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+229}:\\ \;\;\;\;\frac{e^{eps_m \cdot x} - -1}{2}\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+272}:\\ \;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x -2e-298)
   (/ (+ 1.0 (exp (* eps_m (- x)))) 2.0)
   (if (<= x 1.25e+229)
     (/ (- (exp (* eps_m x)) -1.0) 2.0)
     (if (<= x 1.9e+272)
       (/ (+ (- 1.0 (/ -1.0 eps_m)) (- (/ -1.0 eps_m) -1.0)) 2.0)
       (/ (* eps_m x) 2.0)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= -2e-298) {
		tmp = (1.0 + exp((eps_m * -x))) / 2.0;
	} else if (x <= 1.25e+229) {
		tmp = (exp((eps_m * x)) - -1.0) / 2.0;
	} else if (x <= 1.9e+272) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: tmp
    if (x <= (-2d-298)) then
        tmp = (1.0d0 + exp((eps_m * -x))) / 2.0d0
    else if (x <= 1.25d+229) then
        tmp = (exp((eps_m * x)) - (-1.0d0)) / 2.0d0
    else if (x <= 1.9d+272) then
        tmp = ((1.0d0 - ((-1.0d0) / eps_m)) + (((-1.0d0) / eps_m) - (-1.0d0))) / 2.0d0
    else
        tmp = (eps_m * x) / 2.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= -2e-298) {
		tmp = (1.0 + Math.exp((eps_m * -x))) / 2.0;
	} else if (x <= 1.25e+229) {
		tmp = (Math.exp((eps_m * x)) - -1.0) / 2.0;
	} else if (x <= 1.9e+272) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= -2e-298:
		tmp = (1.0 + math.exp((eps_m * -x))) / 2.0
	elif x <= 1.25e+229:
		tmp = (math.exp((eps_m * x)) - -1.0) / 2.0
	elif x <= 1.9e+272:
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0
	else:
		tmp = (eps_m * x) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= -2e-298)
		tmp = Float64(Float64(1.0 + exp(Float64(eps_m * Float64(-x)))) / 2.0);
	elseif (x <= 1.25e+229)
		tmp = Float64(Float64(exp(Float64(eps_m * x)) - -1.0) / 2.0);
	elseif (x <= 1.9e+272)
		tmp = Float64(Float64(Float64(1.0 - Float64(-1.0 / eps_m)) + Float64(Float64(-1.0 / eps_m) - -1.0)) / 2.0);
	else
		tmp = Float64(Float64(eps_m * x) / 2.0);
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	tmp = 0.0;
	if (x <= -2e-298)
		tmp = (1.0 + exp((eps_m * -x))) / 2.0;
	elseif (x <= 1.25e+229)
		tmp = (exp((eps_m * x)) - -1.0) / 2.0;
	elseif (x <= 1.9e+272)
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	else
		tmp = (eps_m * x) / 2.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, -2e-298], N[(N[(1.0 + N[Exp[N[(eps$95$m * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.25e+229], N[(N[(N[Exp[N[(eps$95$m * x), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.9e+272], N[(N[(N[(1.0 - N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

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

\mathbf{elif}\;x \leq 1.25 \cdot 10^{+229}:\\
\;\;\;\;\frac{e^{eps_m \cdot x} - -1}{2}\\

\mathbf{elif}\;x \leq 1.9 \cdot 10^{+272}:\\
\;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 64.1% accurate, 2.1× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} t_0 := \frac{-1}{eps_m} - -1\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x \cdot \left(t_0 \cdot \left(-1 - eps_m\right)\right)}{2}\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{+228}:\\ \;\;\;\;\frac{1 + e^{x}}{2}\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{+271}:\\ \;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + t_0}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (let* ((t_0 (- (/ -1.0 eps_m) -1.0)))
   (if (<= x -1.0)
     (/ (* x (* t_0 (- -1.0 eps_m))) 2.0)
     (if (<= x 1.8e+228)
       (/ (+ 1.0 (exp x)) 2.0)
       (if (<= x 7.5e+271)
         (/ (+ (- 1.0 (/ -1.0 eps_m)) t_0) 2.0)
         (/ (* eps_m x) 2.0))))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double t_0 = (-1.0 / eps_m) - -1.0;
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 1.8e+228) {
		tmp = (1.0 + exp(x)) / 2.0;
	} else if (x <= 7.5e+271) {
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((-1.0d0) / eps_m) - (-1.0d0)
    if (x <= (-1.0d0)) then
        tmp = (x * (t_0 * ((-1.0d0) - eps_m))) / 2.0d0
    else if (x <= 1.8d+228) then
        tmp = (1.0d0 + exp(x)) / 2.0d0
    else if (x <= 7.5d+271) then
        tmp = ((1.0d0 - ((-1.0d0) / eps_m)) + t_0) / 2.0d0
    else
        tmp = (eps_m * 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 / eps_m) - -1.0;
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 1.8e+228) {
		tmp = (1.0 + Math.exp(x)) / 2.0;
	} else if (x <= 7.5e+271) {
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	t_0 = (-1.0 / eps_m) - -1.0
	tmp = 0
	if x <= -1.0:
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0
	elif x <= 1.8e+228:
		tmp = (1.0 + math.exp(x)) / 2.0
	elif x <= 7.5e+271:
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0
	else:
		tmp = (eps_m * x) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	t_0 = Float64(Float64(-1.0 / eps_m) - -1.0)
	tmp = 0.0
	if (x <= -1.0)
		tmp = Float64(Float64(x * Float64(t_0 * Float64(-1.0 - eps_m))) / 2.0);
	elseif (x <= 1.8e+228)
		tmp = Float64(Float64(1.0 + exp(x)) / 2.0);
	elseif (x <= 7.5e+271)
		tmp = Float64(Float64(Float64(1.0 - Float64(-1.0 / eps_m)) + t_0) / 2.0);
	else
		tmp = Float64(Float64(eps_m * x) / 2.0);
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	t_0 = (-1.0 / eps_m) - -1.0;
	tmp = 0.0;
	if (x <= -1.0)
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	elseif (x <= 1.8e+228)
		tmp = (1.0 + exp(x)) / 2.0;
	elseif (x <= 7.5e+271)
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	else
		tmp = (eps_m * x) / 2.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, -1.0], N[(N[(x * N[(t$95$0 * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.8e+228], N[(N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 7.5e+271], N[(N[(N[(1.0 - N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
t_0 := \frac{-1}{eps_m} - -1\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{x \cdot \left(t_0 \cdot \left(-1 - eps_m\right)\right)}{2}\\

\mathbf{elif}\;x \leq 1.8 \cdot 10^{+228}:\\
\;\;\;\;\frac{1 + e^{x}}{2}\\

\mathbf{elif}\;x \leq 7.5 \cdot 10^{+271}:\\
\;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + t_0}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 70.4% accurate, 2.1× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -145000:\\ \;\;\;\;\frac{\frac{\mathsf{expm1}\left(-x\right)}{eps_m}}{2}\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{+227}:\\ \;\;\;\;\frac{1 + e^{x}}{2}\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{+273}:\\ \;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x -145000.0)
   (/ (/ (expm1 (- x)) eps_m) 2.0)
   (if (<= x 7.6e+227)
     (/ (+ 1.0 (exp x)) 2.0)
     (if (<= x 2.3e+273)
       (/ (+ (- 1.0 (/ -1.0 eps_m)) (- (/ -1.0 eps_m) -1.0)) 2.0)
       (/ (* eps_m x) 2.0)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= -145000.0) {
		tmp = (expm1(-x) / eps_m) / 2.0;
	} else if (x <= 7.6e+227) {
		tmp = (1.0 + exp(x)) / 2.0;
	} else if (x <= 2.3e+273) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= -145000.0) {
		tmp = (Math.expm1(-x) / eps_m) / 2.0;
	} else if (x <= 7.6e+227) {
		tmp = (1.0 + Math.exp(x)) / 2.0;
	} else if (x <= 2.3e+273) {
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= -145000.0:
		tmp = (math.expm1(-x) / eps_m) / 2.0
	elif x <= 7.6e+227:
		tmp = (1.0 + math.exp(x)) / 2.0
	elif x <= 2.3e+273:
		tmp = ((1.0 - (-1.0 / eps_m)) + ((-1.0 / eps_m) - -1.0)) / 2.0
	else:
		tmp = (eps_m * x) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= -145000.0)
		tmp = Float64(Float64(expm1(Float64(-x)) / eps_m) / 2.0);
	elseif (x <= 7.6e+227)
		tmp = Float64(Float64(1.0 + exp(x)) / 2.0);
	elseif (x <= 2.3e+273)
		tmp = Float64(Float64(Float64(1.0 - Float64(-1.0 / eps_m)) + Float64(Float64(-1.0 / eps_m) - -1.0)) / 2.0);
	else
		tmp = Float64(Float64(eps_m * x) / 2.0);
	end
	return tmp
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, -145000.0], N[(N[(N[(Exp[(-x)] - 1), $MachinePrecision] / eps$95$m), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 7.6e+227], N[(N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2.3e+273], N[(N[(N[(1.0 - N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -145000:\\
\;\;\;\;\frac{\frac{\mathsf{expm1}\left(-x\right)}{eps_m}}{2}\\

\mathbf{elif}\;x \leq 7.6 \cdot 10^{+227}:\\
\;\;\;\;\frac{1 + e^{x}}{2}\\

\mathbf{elif}\;x \leq 2.3 \cdot 10^{+273}:\\
\;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + \left(\frac{-1}{eps_m} - -1\right)}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 62.6% accurate, 9.7× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} t_0 := \frac{-1}{eps_m} - -1\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x \cdot \left(t_0 \cdot \left(-1 - eps_m\right)\right)}{2}\\ \mathbf{elif}\;x \leq 0.00095:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+149} \lor \neg \left(x \leq 2.75 \cdot 10^{+228}\right) \land x \leq 3.6 \cdot 10^{+271}:\\ \;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + t_0}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (let* ((t_0 (- (/ -1.0 eps_m) -1.0)))
   (if (<= x -1.0)
     (/ (* x (* t_0 (- -1.0 eps_m))) 2.0)
     (if (<= x 0.00095)
       1.0
       (if (or (<= x 3.1e+149) (and (not (<= x 2.75e+228)) (<= x 3.6e+271)))
         (/ (+ (- 1.0 (/ -1.0 eps_m)) t_0) 2.0)
         (/ (* eps_m x) 2.0))))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double t_0 = (-1.0 / eps_m) - -1.0;
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 0.00095) {
		tmp = 1.0;
	} else if ((x <= 3.1e+149) || (!(x <= 2.75e+228) && (x <= 3.6e+271))) {
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((-1.0d0) / eps_m) - (-1.0d0)
    if (x <= (-1.0d0)) then
        tmp = (x * (t_0 * ((-1.0d0) - eps_m))) / 2.0d0
    else if (x <= 0.00095d0) then
        tmp = 1.0d0
    else if ((x <= 3.1d+149) .or. (.not. (x <= 2.75d+228)) .and. (x <= 3.6d+271)) then
        tmp = ((1.0d0 - ((-1.0d0) / eps_m)) + t_0) / 2.0d0
    else
        tmp = (eps_m * 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 / eps_m) - -1.0;
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 0.00095) {
		tmp = 1.0;
	} else if ((x <= 3.1e+149) || (!(x <= 2.75e+228) && (x <= 3.6e+271))) {
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	} else {
		tmp = (eps_m * x) / 2.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	t_0 = (-1.0 / eps_m) - -1.0
	tmp = 0
	if x <= -1.0:
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0
	elif x <= 0.00095:
		tmp = 1.0
	elif (x <= 3.1e+149) or (not (x <= 2.75e+228) and (x <= 3.6e+271)):
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0
	else:
		tmp = (eps_m * x) / 2.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	t_0 = Float64(Float64(-1.0 / eps_m) - -1.0)
	tmp = 0.0
	if (x <= -1.0)
		tmp = Float64(Float64(x * Float64(t_0 * Float64(-1.0 - eps_m))) / 2.0);
	elseif (x <= 0.00095)
		tmp = 1.0;
	elseif ((x <= 3.1e+149) || (!(x <= 2.75e+228) && (x <= 3.6e+271)))
		tmp = Float64(Float64(Float64(1.0 - Float64(-1.0 / eps_m)) + t_0) / 2.0);
	else
		tmp = Float64(Float64(eps_m * x) / 2.0);
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	t_0 = (-1.0 / eps_m) - -1.0;
	tmp = 0.0;
	if (x <= -1.0)
		tmp = (x * (t_0 * (-1.0 - eps_m))) / 2.0;
	elseif (x <= 0.00095)
		tmp = 1.0;
	elseif ((x <= 3.1e+149) || (~((x <= 2.75e+228)) && (x <= 3.6e+271)))
		tmp = ((1.0 - (-1.0 / eps_m)) + t_0) / 2.0;
	else
		tmp = (eps_m * x) / 2.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, -1.0], N[(N[(x * N[(t$95$0 * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 0.00095], 1.0, If[Or[LessEqual[x, 3.1e+149], And[N[Not[LessEqual[x, 2.75e+228]], $MachinePrecision], LessEqual[x, 3.6e+271]]], N[(N[(N[(1.0 - N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
t_0 := \frac{-1}{eps_m} - -1\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{x \cdot \left(t_0 \cdot \left(-1 - eps_m\right)\right)}{2}\\

\mathbf{elif}\;x \leq 0.00095:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 3.1 \cdot 10^{+149} \lor \neg \left(x \leq 2.75 \cdot 10^{+228}\right) \land x \leq 3.6 \cdot 10^{+271}:\\
\;\;\;\;\frac{\left(1 - \frac{-1}{eps_m}\right) + t_0}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 62.6% accurate, 14.8× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{eps_m \cdot \left(-x\right)}{2}\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{+152}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+228} \lor \neg \left(x \leq 2.4 \cdot 10^{+276}\right):\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x -1.0)
   (/ (* eps_m (- x)) 2.0)
   (if (<= x 5.2e+21)
     1.0
     (if (<= x 9.6e+152)
       0.0
       (if (or (<= x 8e+228) (not (<= x 2.4e+276)))
         (/ (* eps_m x) 2.0)
         0.0)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= -1.0) {
		tmp = (eps_m * -x) / 2.0;
	} else if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 9.6e+152) {
		tmp = 0.0;
	} else if ((x <= 8e+228) || !(x <= 2.4e+276)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: tmp
    if (x <= (-1.0d0)) then
        tmp = (eps_m * -x) / 2.0d0
    else if (x <= 5.2d+21) then
        tmp = 1.0d0
    else if (x <= 9.6d+152) then
        tmp = 0.0d0
    else if ((x <= 8d+228) .or. (.not. (x <= 2.4d+276))) then
        tmp = (eps_m * x) / 2.0d0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= -1.0) {
		tmp = (eps_m * -x) / 2.0;
	} else if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 9.6e+152) {
		tmp = 0.0;
	} else if ((x <= 8e+228) || !(x <= 2.4e+276)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= -1.0:
		tmp = (eps_m * -x) / 2.0
	elif x <= 5.2e+21:
		tmp = 1.0
	elif x <= 9.6e+152:
		tmp = 0.0
	elif (x <= 8e+228) or not (x <= 2.4e+276):
		tmp = (eps_m * x) / 2.0
	else:
		tmp = 0.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= -1.0)
		tmp = Float64(Float64(eps_m * Float64(-x)) / 2.0);
	elseif (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 9.6e+152)
		tmp = 0.0;
	elseif ((x <= 8e+228) || !(x <= 2.4e+276))
		tmp = Float64(Float64(eps_m * x) / 2.0);
	else
		tmp = 0.0;
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	tmp = 0.0;
	if (x <= -1.0)
		tmp = (eps_m * -x) / 2.0;
	elseif (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 9.6e+152)
		tmp = 0.0;
	elseif ((x <= 8e+228) || ~((x <= 2.4e+276)))
		tmp = (eps_m * x) / 2.0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, -1.0], N[(N[(eps$95$m * (-x)), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 5.2e+21], 1.0, If[LessEqual[x, 9.6e+152], 0.0, If[Or[LessEqual[x, 8e+228], N[Not[LessEqual[x, 2.4e+276]], $MachinePrecision]], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{eps_m \cdot \left(-x\right)}{2}\\

\mathbf{elif}\;x \leq 5.2 \cdot 10^{+21}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 9.6 \cdot 10^{+152}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 8 \cdot 10^{+228} \lor \neg \left(x \leq 2.4 \cdot 10^{+276}\right):\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 62.5% accurate, 14.8× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x \cdot \left(\left(\frac{-1}{eps_m} - -1\right) \cdot \left(-1 - eps_m\right)\right)}{2}\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+153}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{+228} \lor \neg \left(x \leq 3.35 \cdot 10^{+271}\right):\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x -1.0)
   (/ (* x (* (- (/ -1.0 eps_m) -1.0) (- -1.0 eps_m))) 2.0)
   (if (<= x 5.2e+21)
     1.0
     (if (<= x 1.65e+153)
       0.0
       (if (or (<= x 1.02e+228) (not (<= x 3.35e+271)))
         (/ (* eps_m x) 2.0)
         0.0)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (((-1.0 / eps_m) - -1.0) * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 1.65e+153) {
		tmp = 0.0;
	} else if ((x <= 1.02e+228) || !(x <= 3.35e+271)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: tmp
    if (x <= (-1.0d0)) then
        tmp = (x * ((((-1.0d0) / eps_m) - (-1.0d0)) * ((-1.0d0) - eps_m))) / 2.0d0
    else if (x <= 5.2d+21) then
        tmp = 1.0d0
    else if (x <= 1.65d+153) then
        tmp = 0.0d0
    else if ((x <= 1.02d+228) .or. (.not. (x <= 3.35d+271))) then
        tmp = (eps_m * x) / 2.0d0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= -1.0) {
		tmp = (x * (((-1.0 / eps_m) - -1.0) * (-1.0 - eps_m))) / 2.0;
	} else if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 1.65e+153) {
		tmp = 0.0;
	} else if ((x <= 1.02e+228) || !(x <= 3.35e+271)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= -1.0:
		tmp = (x * (((-1.0 / eps_m) - -1.0) * (-1.0 - eps_m))) / 2.0
	elif x <= 5.2e+21:
		tmp = 1.0
	elif x <= 1.65e+153:
		tmp = 0.0
	elif (x <= 1.02e+228) or not (x <= 3.35e+271):
		tmp = (eps_m * x) / 2.0
	else:
		tmp = 0.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= -1.0)
		tmp = Float64(Float64(x * Float64(Float64(Float64(-1.0 / eps_m) - -1.0) * Float64(-1.0 - eps_m))) / 2.0);
	elseif (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 1.65e+153)
		tmp = 0.0;
	elseif ((x <= 1.02e+228) || !(x <= 3.35e+271))
		tmp = Float64(Float64(eps_m * x) / 2.0);
	else
		tmp = 0.0;
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	tmp = 0.0;
	if (x <= -1.0)
		tmp = (x * (((-1.0 / eps_m) - -1.0) * (-1.0 - eps_m))) / 2.0;
	elseif (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 1.65e+153)
		tmp = 0.0;
	elseif ((x <= 1.02e+228) || ~((x <= 3.35e+271)))
		tmp = (eps_m * x) / 2.0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, -1.0], N[(N[(x * N[(N[(N[(-1.0 / eps$95$m), $MachinePrecision] - -1.0), $MachinePrecision] * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 5.2e+21], 1.0, If[LessEqual[x, 1.65e+153], 0.0, If[Or[LessEqual[x, 1.02e+228], N[Not[LessEqual[x, 3.35e+271]], $MachinePrecision]], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{x \cdot \left(\left(\frac{-1}{eps_m} - -1\right) \cdot \left(-1 - eps_m\right)\right)}{2}\\

\mathbf{elif}\;x \leq 5.2 \cdot 10^{+21}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 1.65 \cdot 10^{+153}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 1.02 \cdot 10^{+228} \lor \neg \left(x \leq 3.35 \cdot 10^{+271}\right):\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 54.9% accurate, 17.1× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq 5.2 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+145}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+229} \lor \neg \left(x \leq 5.5 \cdot 10^{+272}\right):\\ \;\;\;\;\frac{eps_m \cdot x}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
 :precision binary64
 (if (<= x 5.2e+21)
   1.0
   (if (<= x 5e+145)
     0.0
     (if (or (<= x 1.08e+229) (not (<= x 5.5e+272)))
       (/ (* eps_m x) 2.0)
       0.0))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 5e+145) {
		tmp = 0.0;
	} else if ((x <= 1.08e+229) || !(x <= 5.5e+272)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: tmp
    if (x <= 5.2d+21) then
        tmp = 1.0d0
    else if (x <= 5d+145) then
        tmp = 0.0d0
    else if ((x <= 1.08d+229) .or. (.not. (x <= 5.5d+272))) then
        tmp = (eps_m * x) / 2.0d0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= 5.2e+21) {
		tmp = 1.0;
	} else if (x <= 5e+145) {
		tmp = 0.0;
	} else if ((x <= 1.08e+229) || !(x <= 5.5e+272)) {
		tmp = (eps_m * x) / 2.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= 5.2e+21:
		tmp = 1.0
	elif x <= 5e+145:
		tmp = 0.0
	elif (x <= 1.08e+229) or not (x <= 5.5e+272):
		tmp = (eps_m * x) / 2.0
	else:
		tmp = 0.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 5e+145)
		tmp = 0.0;
	elseif ((x <= 1.08e+229) || !(x <= 5.5e+272))
		tmp = Float64(Float64(eps_m * x) / 2.0);
	else
		tmp = 0.0;
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	tmp = 0.0;
	if (x <= 5.2e+21)
		tmp = 1.0;
	elseif (x <= 5e+145)
		tmp = 0.0;
	elseif ((x <= 1.08e+229) || ~((x <= 5.5e+272)))
		tmp = (eps_m * x) / 2.0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, 5.2e+21], 1.0, If[LessEqual[x, 5e+145], 0.0, If[Or[LessEqual[x, 1.08e+229], N[Not[LessEqual[x, 5.5e+272]], $MachinePrecision]], N[(N[(eps$95$m * x), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.2 \cdot 10^{+21}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 5 \cdot 10^{+145}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 1.08 \cdot 10^{+229} \lor \neg \left(x \leq 5.5 \cdot 10^{+272}\right):\\
\;\;\;\;\frac{eps_m \cdot x}{2}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 56.3% accurate, 74.1× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ \begin{array}{l} \mathbf{if}\;x \leq 5.2 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m) :precision binary64 (if (<= x 5.2e+21) 1.0 0.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
	double tmp;
	if (x <= 5.2e+21) {
		tmp = 1.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    real(8) :: tmp
    if (x <= 5.2d+21) then
        tmp = 1.0d0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	double tmp;
	if (x <= 5.2e+21) {
		tmp = 1.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	tmp = 0
	if x <= 5.2e+21:
		tmp = 1.0
	else:
		tmp = 0.0
	return tmp
eps_m = abs(eps)
function code(x, eps_m)
	tmp = 0.0
	if (x <= 5.2e+21)
		tmp = 1.0;
	else
		tmp = 0.0;
	end
	return tmp
end
eps_m = abs(eps);
function tmp_2 = code(x, eps_m)
	tmp = 0.0;
	if (x <= 5.2e+21)
		tmp = 1.0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := If[LessEqual[x, 5.2e+21], 1.0, 0.0]
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.2 \cdot 10^{+21}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 15.9% accurate, 227.0× speedup?

\[\begin{array}{l} eps_m = \left|\varepsilon\right| \\ 0 \end{array} \]
eps_m = (fabs.f64 eps)
(FPCore (x eps_m) :precision binary64 0.0)
eps_m = fabs(eps);
double code(double x, double eps_m) {
	return 0.0;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps_m
    code = 0.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
	return 0.0;
}
eps_m = math.fabs(eps)
def code(x, eps_m):
	return 0.0
eps_m = abs(eps)
function code(x, eps_m)
	return 0.0
end
eps_m = abs(eps);
function tmp = code(x, eps_m)
	tmp = 0.0;
end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := 0.0
\begin{array}{l}
eps_m = \left|\varepsilon\right|

\\
0
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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