| Alternative 1 | |
|---|---|
| Accuracy | 79.5% |
| Cost | 26180 |
\[\begin{array}{l}
\mathbf{if}\;\frac{e^{x}}{e^{x} + -1} \leq 10000:\\
\;\;\;\;\frac{e^{x}}{\mathsf{expm1}\left(x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + 0.5\\
\end{array}
\]

(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x) :precision binary64 (if (<= (/ (exp x) (+ (exp x) -1.0)) 10000.0) (/ (exp x) (expm1 x)) (+ (/ 1.0 x) 0.5)))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
double tmp;
if ((exp(x) / (exp(x) + -1.0)) <= 10000.0) {
tmp = exp(x) / expm1(x);
} else {
tmp = (1.0 / x) + 0.5;
}
return tmp;
}
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
double tmp;
if ((Math.exp(x) / (Math.exp(x) + -1.0)) <= 10000.0) {
tmp = Math.exp(x) / Math.expm1(x);
} else {
tmp = (1.0 / x) + 0.5;
}
return tmp;
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
def code(x): tmp = 0 if (math.exp(x) / (math.exp(x) + -1.0)) <= 10000.0: tmp = math.exp(x) / math.expm1(x) else: tmp = (1.0 / x) + 0.5 return tmp
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function code(x) tmp = 0.0 if (Float64(exp(x) / Float64(exp(x) + -1.0)) <= 10000.0) tmp = Float64(exp(x) / expm1(x)); else tmp = Float64(Float64(1.0 / x) + 0.5); end return tmp end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 10000.0], N[(N[Exp[x], $MachinePrecision] / N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;\frac{e^{x}}{e^{x} + -1} \leq 10000:\\
\;\;\;\;\frac{e^{x}}{\mathsf{expm1}\left(x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + 0.5\\
\end{array}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 28.1% |
|---|---|
| Target | 53.3% |
| Herbie | 79.5% |
if (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1)) < 1e4Initial program 95.5%
Simplified100.0%
[Start]95.5% | \[ \frac{e^{x}}{e^{x} - 1}
\] |
|---|---|
expm1-def [=>]100.0% | \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}}
\] |
if 1e4 < (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1)) Initial program 2.9%
Simplified70.3%
[Start]2.9% | \[ \frac{e^{x}}{e^{x} - 1}
\] |
|---|---|
expm1-def [=>]70.3% | \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}}
\] |
Taylor expanded in x around 0 75.8%
Simplified75.8%
[Start]75.8% | \[ 0.5 + \frac{1}{x}
\] |
|---|---|
+-commutative [=>]75.8% | \[ \color{blue}{\frac{1}{x} + 0.5}
\] |
Final simplification82.5%
| Alternative 1 | |
|---|---|
| Accuracy | 79.5% |
| Cost | 26180 |
| Alternative 2 | |
|---|---|
| Accuracy | 54.8% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 192 |
herbie shell --seed 2023271
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))