| Alternative 1 | |
|---|---|
| Error | 1.11% |
| Cost | 6912 |
\[x \cdot x + {x}^{4} \cdot 0.08333333333333333
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x) :precision binary64 (+ (* x x) (* (pow x 4.0) (+ (* 0.002777777777777778 (* x x)) 0.08333333333333333))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
return (x * x) + (pow(x, 4.0) * ((0.002777777777777778 * (x * x)) + 0.08333333333333333));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) + ((x ** 4.0d0) * ((0.002777777777777778d0 * (x * x)) + 0.08333333333333333d0))
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
public static double code(double x) {
return (x * x) + (Math.pow(x, 4.0) * ((0.002777777777777778 * (x * x)) + 0.08333333333333333));
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
def code(x): return (x * x) + (math.pow(x, 4.0) * ((0.002777777777777778 * (x * x)) + 0.08333333333333333))
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function code(x) return Float64(Float64(x * x) + Float64((x ^ 4.0) * Float64(Float64(0.002777777777777778 * Float64(x * x)) + 0.08333333333333333))) end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
function tmp = code(x) tmp = (x * x) + ((x ^ 4.0) * ((0.002777777777777778 * (x * x)) + 0.08333333333333333)); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * x), $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * N[(N[(0.002777777777777778 * N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
x \cdot x + {x}^{4} \cdot \left(0.002777777777777778 \cdot \left(x \cdot x\right) + 0.08333333333333333\right)
Results
| Original | 46.11% |
|---|---|
| Target | 0.07% |
| Herbie | 0.94% |
Initial program 46.11
Simplified46.13
[Start]46.11 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
associate-+l- [=>]46.13 | \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)}
\] |
sub-neg [=>]46.13 | \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)}
\] |
neg-sub0 [=>]46.13 | \[ e^{x} + \color{blue}{\left(0 - \left(2 - e^{-x}\right)\right)}
\] |
associate--r- [=>]46.13 | \[ e^{x} + \color{blue}{\left(\left(0 - 2\right) + e^{-x}\right)}
\] |
metadata-eval [=>]46.13 | \[ e^{x} + \left(\color{blue}{-2} + e^{-x}\right)
\] |
metadata-eval [<=]46.13 | \[ e^{x} + \left(\color{blue}{\left(-2\right)} + e^{-x}\right)
\] |
+-commutative [=>]46.13 | \[ e^{x} + \color{blue}{\left(e^{-x} + \left(-2\right)\right)}
\] |
metadata-eval [=>]46.13 | \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right)
\] |
Taylor expanded in x around 0 0.94
Simplified0.94
[Start]0.94 | \[ 0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)
\] |
|---|---|
fma-def [=>]0.94 | \[ \color{blue}{\mathsf{fma}\left(0.002777777777777778, {x}^{6}, {x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)}
\] |
unpow2 [=>]0.94 | \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4}\right)
\] |
Applied egg-rr0.94
Applied egg-rr0.94
Final simplification0.94
| Alternative 1 | |
|---|---|
| Error | 1.11% |
| Cost | 6912 |
| Alternative 2 | |
|---|---|
| Error | 1.56% |
| Cost | 192 |
| Alternative 3 | |
|---|---|
| Error | 94.06% |
| Cost | 128 |
herbie shell --seed 2023089
(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))))