| Alternative 1 | |
|---|---|
| Error | 17.4 |
| Cost | 452 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.6:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 0.5\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x) :precision binary64 (/ (expm1 x) x))
double code(double x) {
return (exp(x) - 1.0) / x;
}
double code(double x) {
return expm1(x) / x;
}
public static double code(double x) {
return (Math.exp(x) - 1.0) / x;
}
public static double code(double x) {
return Math.expm1(x) / x;
}
def code(x): return (math.exp(x) - 1.0) / x
def code(x): return math.expm1(x) / x
function code(x) return Float64(Float64(exp(x) - 1.0) / x) end
function code(x) return Float64(expm1(x) / x) end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision]
code[x_] := N[(N[(Exp[x] - 1), $MachinePrecision] / x), $MachinePrecision]
\frac{e^{x} - 1}{x}
\frac{\mathsf{expm1}\left(x\right)}{x}
Results
| Original | 40.5 |
|---|---|
| Target | 41.1 |
| Herbie | 0.0 |
Initial program 40.5
Simplified0.0
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 17.4 |
| Cost | 452 |
| Alternative 2 | |
|---|---|
| Error | 17.4 |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 17.8 |
| Cost | 324 |
| Alternative 4 | |
|---|---|
| Error | 20.6 |
| Cost | 64 |

herbie shell --seed 2022296
(FPCore (x)
:name "Kahan's exp quotient"
:precision binary64
:herbie-target
(if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))
(/ (- (exp x) 1.0) x))