| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 13124 |

(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x) :precision binary64 (/ -1.0 (expm1 (- x))))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
return -1.0 / expm1(-x);
}
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
return -1.0 / Math.expm1(-x);
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
def code(x): return -1.0 / math.expm1(-x)
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function code(x) return Float64(-1.0 / expm1(Float64(-x))) end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(-1.0 / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\frac{e^{x}}{e^{x} - 1}
\frac{-1}{\mathsf{expm1}\left(-x\right)}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 37.5% |
|---|---|
| Target | 38.1% |
| Herbie | 100.0% |
Initial program 34.8%
Simplified98.8%
[Start]34.8 | \[ \frac{e^{x}}{e^{x} - 1}
\] |
|---|---|
expm1-def [=>]98.8 | \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}}
\] |
Applied egg-rr98.8%
[Start]98.8 | \[ \frac{e^{x}}{\mathsf{expm1}\left(x\right)}
\] |
|---|---|
clear-num [=>]98.8 | \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}}
\] |
associate-/r/ [=>]98.8 | \[ \color{blue}{\frac{1}{\mathsf{expm1}\left(x\right)} \cdot e^{x}}
\] |
Applied egg-rr98.8%
[Start]98.8 | \[ \frac{1}{\mathsf{expm1}\left(x\right)} \cdot e^{x}
\] |
|---|---|
associate-*l/ [=>]98.8 | \[ \color{blue}{\frac{1 \cdot e^{x}}{\mathsf{expm1}\left(x\right)}}
\] |
associate-/l* [=>]98.8 | \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}}
\] |
Taylor expanded in x around inf 34.8%
Simplified100.0%
[Start]34.8 | \[ \frac{1}{\frac{e^{x} - 1}{e^{x}}}
\] |
|---|---|
expm1-def [=>]98.8 | \[ \frac{1}{\frac{\color{blue}{\mathsf{expm1}\left(x\right)}}{e^{x}}}
\] |
*-rgt-identity [<=]98.8 | \[ \frac{1}{\frac{\color{blue}{\mathsf{expm1}\left(x\right) \cdot 1}}{e^{x}}}
\] |
associate-*r/ [<=]98.8 | \[ \frac{1}{\color{blue}{\mathsf{expm1}\left(x\right) \cdot \frac{1}{e^{x}}}}
\] |
exp-neg [<=]98.8 | \[ \frac{1}{\mathsf{expm1}\left(x\right) \cdot \color{blue}{e^{-x}}}
\] |
remove-double-neg [<=]98.8 | \[ \frac{1}{\mathsf{expm1}\left(x\right) \cdot \color{blue}{\left(-\left(-e^{-x}\right)\right)}}
\] |
distribute-rgt-neg-in [<=]98.8 | \[ \frac{1}{\color{blue}{-\mathsf{expm1}\left(x\right) \cdot \left(-e^{-x}\right)}}
\] |
distribute-lft-neg-in [=>]98.8 | \[ \frac{1}{\color{blue}{\left(-\mathsf{expm1}\left(x\right)\right) \cdot \left(-e^{-x}\right)}}
\] |
distribute-rgt-neg-out [=>]98.8 | \[ \frac{1}{\color{blue}{-\left(-\mathsf{expm1}\left(x\right)\right) \cdot e^{-x}}}
\] |
distribute-lft-neg-in [<=]98.8 | \[ \frac{1}{-\color{blue}{\left(-\mathsf{expm1}\left(x\right) \cdot e^{-x}\right)}}
\] |
exp-neg [=>]98.8 | \[ \frac{1}{-\left(-\mathsf{expm1}\left(x\right) \cdot \color{blue}{\frac{1}{e^{x}}}\right)}
\] |
associate-*r/ [=>]98.8 | \[ \frac{1}{-\left(-\color{blue}{\frac{\mathsf{expm1}\left(x\right) \cdot 1}{e^{x}}}\right)}
\] |
*-rgt-identity [=>]98.8 | \[ \frac{1}{-\left(-\frac{\color{blue}{\mathsf{expm1}\left(x\right)}}{e^{x}}\right)}
\] |
expm1-def [<=]34.8 | \[ \frac{1}{-\left(-\frac{\color{blue}{e^{x} - 1}}{e^{x}}\right)}
\] |
div-sub [=>]6.3 | \[ \frac{1}{-\left(-\color{blue}{\left(\frac{e^{x}}{e^{x}} - \frac{1}{e^{x}}\right)}\right)}
\] |
exp-neg [<=]6.3 | \[ \frac{1}{-\left(-\left(\frac{e^{x}}{e^{x}} - \color{blue}{e^{-x}}\right)\right)}
\] |
sub-neg [=>]6.3 | \[ \frac{1}{-\left(-\color{blue}{\left(\frac{e^{x}}{e^{x}} + \left(-e^{-x}\right)\right)}\right)}
\] |
*-inverses [=>]36.0 | \[ \frac{1}{-\left(-\left(\color{blue}{1} + \left(-e^{-x}\right)\right)\right)}
\] |
+-commutative [=>]36.0 | \[ \frac{1}{-\left(-\color{blue}{\left(\left(-e^{-x}\right) + 1\right)}\right)}
\] |
distribute-neg-in [=>]35.9 | \[ \frac{1}{-\color{blue}{\left(\left(-\left(-e^{-x}\right)\right) + \left(-1\right)\right)}}
\] |
remove-double-neg [=>]35.9 | \[ \frac{1}{-\left(\color{blue}{e^{-x}} + \left(-1\right)\right)}
\] |
Taylor expanded in x around inf 35.9%
Simplified100.0%
[Start]35.9 | \[ \frac{-1}{e^{-x} - 1}
\] |
|---|---|
expm1-def [=>]100.0 | \[ \frac{-1}{\color{blue}{\mathsf{expm1}\left(-x\right)}}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 13124 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 708 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 452 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 324 |
| Alternative 5 | |
|---|---|
| Accuracy | 3.3% |
| Cost | 64 |
| Alternative 6 | |
|---|---|
| Accuracy | 34.4% |
| Cost | 64 |
herbie shell --seed 2023160
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))