| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 13120 |
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x) :precision binary64 (if (<= x -0.00155) (/ 1.0 (- 1.0 (exp (- x)))) (+ 0.5 (/ 1.0 (* x (+ 1.0 (* -0.08333333333333333 (* x x))))))))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
double tmp;
if (x <= -0.00155) {
tmp = 1.0 / (1.0 - exp(-x));
} else {
tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.00155d0)) then
tmp = 1.0d0 / (1.0d0 - exp(-x))
else
tmp = 0.5d0 + (1.0d0 / (x * (1.0d0 + ((-0.08333333333333333d0) * (x * x)))))
end if
code = tmp
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
double tmp;
if (x <= -0.00155) {
tmp = 1.0 / (1.0 - Math.exp(-x));
} else {
tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))));
}
return tmp;
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
def code(x): tmp = 0 if x <= -0.00155: tmp = 1.0 / (1.0 - math.exp(-x)) else: tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x))))) return tmp
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function code(x) tmp = 0.0 if (x <= -0.00155) tmp = Float64(1.0 / Float64(1.0 - exp(Float64(-x)))); else tmp = Float64(0.5 + Float64(1.0 / Float64(x * Float64(1.0 + Float64(-0.08333333333333333 * Float64(x * x)))))); end return tmp end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.00155) tmp = 1.0 / (1.0 - exp(-x)); else tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x))))); end tmp_2 = tmp; end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -0.00155], N[(1.0 / N[(1.0 - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(1.0 / N[(x * N[(1.0 + N[(-0.08333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -0.00155:\\
\;\;\;\;\frac{1}{1 - e^{-x}}\\
\mathbf{else}:\\
\;\;\;\;0.5 + \frac{1}{x \cdot \left(1 + -0.08333333333333333 \cdot \left(x \cdot x\right)\right)}\\
\end{array}
Results
| Original | 35.1% |
|---|---|
| Target | 35.8% |
| Herbie | 98.9% |
if x < -0.00154999999999999995Initial program 99.9%
Simplified100.0%
[Start]99.9 | \[ \frac{e^{x}}{e^{x} - 1}
\] |
|---|---|
expm1-def [=>]100.0 | \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ \frac{e^{x}}{\mathsf{expm1}\left(x\right)}
\] |
|---|---|
clear-num [=>]100.0 | \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}}
\] |
inv-pow [=>]100.0 | \[ \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1}}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ {\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1}
\] |
|---|---|
unpow-1 [=>]100.0 | \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}}
\] |
Taylor expanded in x around inf 99.9%
Simplified99.9%
[Start]99.9 | \[ \frac{1}{\frac{e^{x} - 1}{e^{x}}}
\] |
|---|---|
div-sub [=>]1.8 | \[ \frac{1}{\color{blue}{\frac{e^{x}}{e^{x}} - \frac{1}{e^{x}}}}
\] |
*-inverses [=>]99.9 | \[ \frac{1}{\color{blue}{1} - \frac{1}{e^{x}}}
\] |
exp-neg [<=]99.9 | \[ \frac{1}{1 - \color{blue}{e^{-x}}}
\] |
if -0.00154999999999999995 < x Initial program 3.4%
Simplified98.9%
[Start]3.4 | \[ \frac{e^{x}}{e^{x} - 1}
\] |
|---|---|
expm1-def [=>]98.9 | \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}}
\] |
Taylor expanded in x around 0 98.4%
Applied egg-rr48.6%
[Start]98.4 | \[ 0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)
\] |
|---|---|
flip-+ [=>]48.7 | \[ 0.5 + \color{blue}{\frac{\left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right) - \frac{1}{x} \cdot \frac{1}{x}}{0.08333333333333333 \cdot x - \frac{1}{x}}}
\] |
clear-num [=>]48.7 | \[ 0.5 + \color{blue}{\frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{\left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right) - \frac{1}{x} \cdot \frac{1}{x}}}}
\] |
swap-sqr [=>]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{\color{blue}{\left(0.08333333333333333 \cdot 0.08333333333333333\right) \cdot \left(x \cdot x\right)} - \frac{1}{x} \cdot \frac{1}{x}}}
\] |
metadata-eval [=>]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{\color{blue}{0.006944444444444444} \cdot \left(x \cdot x\right) - \frac{1}{x} \cdot \frac{1}{x}}}
\] |
inv-pow [=>]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - \color{blue}{{x}^{-1}} \cdot \frac{1}{x}}}
\] |
metadata-eval [<=]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\color{blue}{\left(-1\right)}} \cdot \frac{1}{x}}}
\] |
inv-pow [=>]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\left(-1\right)} \cdot \color{blue}{{x}^{-1}}}}
\] |
metadata-eval [<=]48.7 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\left(-1\right)} \cdot {x}^{\color{blue}{\left(-1\right)}}}}
\] |
pow-sqr [=>]48.6 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - \color{blue}{{x}^{\left(2 \cdot \left(-1\right)\right)}}}}
\] |
metadata-eval [=>]48.6 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\left(2 \cdot \color{blue}{-1}\right)}}}
\] |
metadata-eval [=>]48.6 | \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\color{blue}{-2}}}}
\] |
Taylor expanded in x around 0 98.4%
Applied egg-rr98.4%
[Start]98.4 | \[ 0.5 + \frac{1}{-0.08333333333333333 \cdot {x}^{3} + x}
\] |
|---|---|
unpow3 [=>]98.4 | \[ 0.5 + \frac{1}{-0.08333333333333333 \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} + x}
\] |
associate-*r* [=>]98.4 | \[ 0.5 + \frac{1}{\color{blue}{\left(-0.08333333333333333 \cdot \left(x \cdot x\right)\right) \cdot x} + x}
\] |
distribute-lft1-in [=>]98.4 | \[ 0.5 + \frac{1}{\color{blue}{\left(-0.08333333333333333 \cdot \left(x \cdot x\right) + 1\right) \cdot x}}
\] |
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 13120 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 12992 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.3% |
| Cost | 832 |
| Alternative 4 | |
|---|---|
| Accuracy | 66.9% |
| Cost | 192 |
herbie shell --seed 2023135
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))