| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 13568 |
\[\frac{\frac{x}{e^{x}} + e^{-x} \cdot \left(x + 2\right)}{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))) (t_1 (+ t_0 (* x t_0)))) (/ (+ t_1 t_1) 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);
double t_1 = t_0 + (x * t_0);
return (t_1 + t_1) / 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
real(8) :: t_1
t_0 = exp(-x)
t_1 = t_0 + (x * t_0)
code = (t_1 + t_1) / 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);
double t_1 = t_0 + (x * t_0);
return (t_1 + t_1) / 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) t_1 = t_0 + (x * t_0) return (t_1 + t_1) / 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)) t_1 = Float64(t_0 + Float64(x * t_0)) return Float64(Float64(t_1 + t_1) / 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); t_1 = t_0 + (x * t_0); tmp = (t_1 + t_1) / 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]}, Block[{t$95$1 = N[(t$95$0 + N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 + t$95$1), $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}\\
t_1 := t_0 + x \cdot t_0\\
\frac{t_1 + t_1}{2}
\end{array}
Results
Initial program 54.1%
Simplified54.1%
[Start]54.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}
\] |
|---|---|
div-sub [=>]54.1 | \[ \color{blue}{\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x}}{2} - \frac{\left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}}
\] |
+-rgt-identity [<=]54.1 | \[ \frac{\color{blue}{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} + 0}}{2} - \frac{\left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\] |
div-sub [<=]54.1 | \[ \color{blue}{\frac{\left(\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} + 0\right) - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}}
\] |
Taylor expanded in eps around 0 99.1%
Final simplification99.1%
| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 13568 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 964 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 196 |
| Alternative 7 | |
|---|---|
| Accuracy | 26.4% |
| Cost | 64 |
herbie shell --seed 2023146
(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))