| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 39168 |
\[\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (+ (exp x) -2.0) t_0) 2e-12)
(fma x x (* 0.08333333333333333 (pow x 4.0)))
(+ (exp x) (+ t_0 -2.0)))))double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) + -2.0) + t_0) <= 2e-12) {
tmp = fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = exp(x) + (t_0 + -2.0);
}
return tmp;
}
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) + -2.0) + t_0) <= 2e-12) tmp = fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = Float64(exp(x) + Float64(t_0 + -2.0)); end return tmp end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] + -2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 2e-12], N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 2 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
| Original | 30.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.3 |
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.99999999999999996e-12Initial program 31.2
Simplified31.2
[Start]31.2 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
associate-+l- [=>]31.2 | \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)}
\] |
sub-neg [=>]31.2 | \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)}
\] |
neg-sub0 [=>]31.2 | \[ e^{x} + \color{blue}{\left(0 - \left(2 - e^{-x}\right)\right)}
\] |
associate--r- [=>]31.2 | \[ e^{x} + \color{blue}{\left(\left(0 - 2\right) + e^{-x}\right)}
\] |
metadata-eval [=>]31.2 | \[ e^{x} + \left(\color{blue}{-2} + e^{-x}\right)
\] |
metadata-eval [<=]31.2 | \[ e^{x} + \left(\color{blue}{\left(-2\right)} + e^{-x}\right)
\] |
+-commutative [=>]31.2 | \[ e^{x} + \color{blue}{\left(e^{-x} + \left(-2\right)\right)}
\] |
metadata-eval [=>]31.2 | \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right)
\] |
Taylor expanded in x around 0 0.0
Simplified0
[Start]0.0 | \[ 0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)
\] |
|---|---|
fma-def [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(0.002777777777777778, {x}^{6}, {x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)}
\] |
unpow2 [=>]0.0 | \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \color{blue}{x \cdot x} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)
\] |
fma-def [=>]0 | \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \color{blue}{\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right)
\] |
fma-def [=>]0 | \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right)\right)
\] |
Taylor expanded in x around 0 0.0
Simplified0
[Start]0.0 | \[ {x}^{2} + 0.08333333333333333 \cdot {x}^{4}
\] |
|---|---|
unpow2 [=>]0.0 | \[ \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4}
\] |
fma-def [=>]0 | \[ \color{blue}{\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)}
\] |
if 1.99999999999999996e-12 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 12.1
Simplified12.1
[Start]12.1 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
associate-+l- [=>]12.1 | \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)}
\] |
sub-neg [=>]12.1 | \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)}
\] |
neg-sub0 [=>]12.1 | \[ e^{x} + \color{blue}{\left(0 - \left(2 - e^{-x}\right)\right)}
\] |
associate--r- [=>]12.1 | \[ e^{x} + \color{blue}{\left(\left(0 - 2\right) + e^{-x}\right)}
\] |
metadata-eval [=>]12.1 | \[ e^{x} + \left(\color{blue}{-2} + e^{-x}\right)
\] |
metadata-eval [<=]12.1 | \[ e^{x} + \left(\color{blue}{\left(-2\right)} + e^{-x}\right)
\] |
+-commutative [=>]12.1 | \[ e^{x} + \color{blue}{\left(e^{-x} + \left(-2\right)\right)}
\] |
metadata-eval [=>]12.1 | \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right)
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 39168 |
| Alternative 2 | |
|---|---|
| Error | 0.3 |
| Cost | 26436 |
| Alternative 3 | |
|---|---|
| Error | 0.5 |
| Cost | 20352 |
| Alternative 4 | |
|---|---|
| Error | 0.7 |
| Cost | 6912 |
| Alternative 5 | |
|---|---|
| Error | 1.1 |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Error | 60.3 |
| Cost | 128 |
herbie shell --seed 2023045
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:herbie-target
(* 4.0 (pow (sinh (/ x 2.0)) 2.0))
(+ (- (exp x) 2.0) (exp (- x))))