| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 704 |
\[\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 0.08333333333333333\right) + 1\right)
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x) :precision binary64 (+ (* x x) (* (* x x) (* (* x x) 0.08333333333333333))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
return (x * x) + ((x * x) * ((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 * x) * ((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) + ((x * x) * ((x * x) * 0.08333333333333333));
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
def code(x): return (x * x) + ((x * x) * ((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(Float64(x * x) * Float64(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 * x) * ((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[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
x \cdot x + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.08333333333333333\right)
Results
| Original | 53.8% |
|---|---|
| Target | 99.9% |
| Herbie | 98.9% |
Initial program 53.8%
Simplified53.8%
[Start]53.8 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
associate-+l- [=>]53.8 | \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)}
\] |
sub-neg [=>]53.8 | \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)}
\] |
sub-neg [=>]53.8 | \[ e^{x} + \left(-\color{blue}{\left(2 + \left(-e^{-x}\right)\right)}\right)
\] |
+-commutative [=>]53.8 | \[ e^{x} + \left(-\color{blue}{\left(\left(-e^{-x}\right) + 2\right)}\right)
\] |
distribute-neg-in [=>]53.8 | \[ e^{x} + \color{blue}{\left(\left(-\left(-e^{-x}\right)\right) + \left(-2\right)\right)}
\] |
remove-double-neg [=>]53.8 | \[ e^{x} + \left(\color{blue}{e^{-x}} + \left(-2\right)\right)
\] |
metadata-eval [=>]53.8 | \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right)
\] |
Taylor expanded in x around 0 98.9%
Simplified98.9%
[Start]98.9 | \[ {x}^{2} + 0.08333333333333333 \cdot {x}^{4}
\] |
|---|---|
unpow2 [=>]98.9 | \[ \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4}
\] |
Applied egg-rr98.6%
[Start]98.9 | \[ x \cdot x + 0.08333333333333333 \cdot {x}^{4}
\] |
|---|---|
expm1-log1p-u [=>]98.9 | \[ x \cdot x + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.08333333333333333 \cdot {x}^{4}\right)\right)}
\] |
expm1-udef [=>]98.6 | \[ x \cdot x + \color{blue}{\left(e^{\mathsf{log1p}\left(0.08333333333333333 \cdot {x}^{4}\right)} - 1\right)}
\] |
log1p-udef [=>]98.6 | \[ x \cdot x + \left(e^{\color{blue}{\log \left(1 + 0.08333333333333333 \cdot {x}^{4}\right)}} - 1\right)
\] |
add-exp-log [<=]98.6 | \[ x \cdot x + \left(\color{blue}{\left(1 + 0.08333333333333333 \cdot {x}^{4}\right)} - 1\right)
\] |
Applied egg-rr98.9%
[Start]98.6 | \[ x \cdot x + \left(\left(1 + 0.08333333333333333 \cdot {x}^{4}\right) - 1\right)
\] |
|---|---|
add-exp-log [=>]98.6 | \[ x \cdot x + \left(\color{blue}{e^{\log \left(1 + 0.08333333333333333 \cdot {x}^{4}\right)}} - 1\right)
\] |
log1p-udef [<=]98.6 | \[ x \cdot x + \left(e^{\color{blue}{\mathsf{log1p}\left(0.08333333333333333 \cdot {x}^{4}\right)}} - 1\right)
\] |
expm1-udef [<=]98.9 | \[ x \cdot x + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.08333333333333333 \cdot {x}^{4}\right)\right)}
\] |
expm1-log1p-u [<=]98.9 | \[ x \cdot x + \color{blue}{0.08333333333333333 \cdot {x}^{4}}
\] |
*-commutative [=>]98.9 | \[ x \cdot x + \color{blue}{{x}^{4} \cdot 0.08333333333333333}
\] |
sqr-pow [=>]98.9 | \[ x \cdot x + \color{blue}{\left({x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}\right)} \cdot 0.08333333333333333
\] |
metadata-eval [=>]98.9 | \[ x \cdot x + \left({x}^{\color{blue}{2}} \cdot {x}^{\left(\frac{4}{2}\right)}\right) \cdot 0.08333333333333333
\] |
pow2 [<=]98.9 | \[ x \cdot x + \left(\color{blue}{\left(x \cdot x\right)} \cdot {x}^{\left(\frac{4}{2}\right)}\right) \cdot 0.08333333333333333
\] |
metadata-eval [=>]98.9 | \[ x \cdot x + \left(\left(x \cdot x\right) \cdot {x}^{\color{blue}{2}}\right) \cdot 0.08333333333333333
\] |
pow2 [<=]98.9 | \[ x \cdot x + \left(\left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot 0.08333333333333333
\] |
associate-*l* [=>]98.9 | \[ x \cdot x + \color{blue}{\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.08333333333333333\right)}
\] |
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 704 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 192 |
| Alternative 3 | |
|---|---|
| Accuracy | 51.6% |
| Cost | 64 |
herbie shell --seed 2023151
(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))))