| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13248 |
\[\frac{2 \cdot e^{\mathsf{log1p}\left(x\right) - x}}{2}
\]
(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))
(FPCore (x eps) :precision binary64 (let* ((t_0 (exp (- x)))) (/ (* 2.0 (+ t_0 (* x t_0))) 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;
}
double code(double x, double eps) {
double t_0 = exp(-x);
return (2.0 * (t_0 + (x * t_0))) / 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
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = exp(-x)
code = (2.0d0 * (t_0 + (x * t_0))) / 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;
}
public static double code(double x, double eps) {
double t_0 = Math.exp(-x);
return (2.0 * (t_0 + (x * t_0))) / 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
def code(x, eps): t_0 = math.exp(-x) return (2.0 * (t_0 + (x * t_0))) / 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 code(x, eps) t_0 = exp(Float64(-x)) return Float64(Float64(2.0 * Float64(t_0 + Float64(x * t_0))) / 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
function tmp = code(x, eps) t_0 = exp(-x); tmp = (2.0 * (t_0 + (x * t_0))) / 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]
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(2.0 * N[(t$95$0 + N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\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}
\begin{array}{l}
t_0 := e^{-x}\\
\frac{2 \cdot \left(t_0 + x \cdot t_0\right)}{2}
\end{array}
Results
Initial program 29.5
Taylor expanded in eps around 0 0.6
Simplified0.6
Taylor expanded in x around inf 0.6
Final simplification0.6
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 7108 |
| Alternative 3 | |
|---|---|
| Error | 0.6 |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Error | 1.3 |
| Cost | 196 |
| Alternative 5 | |
|---|---|
| Error | 16.7 |
| Cost | 64 |

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