Average Error: 39.9 → 0.3
Time: 4.8s
Precision: binary64
Cost: 26497
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.0014603342715462273:\\
\;\;\;\;\left(1 + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} + -1}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\\
\end{array}\]
\frac{e^{x} - 1}{x}↓
\begin{array}{l}
\mathbf{if}\;x \leq -0.0014603342715462273:\\
\;\;\;\;\left(1 + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} + -1}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\\
\end{array}(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
↓
(FPCore (x)
:precision binary64
(if (<= x -0.0014603342715462273)
(* (+ 1.0 (sqrt (exp x))) (/ (+ (sqrt (exp x)) -1.0) x))
(+
1.0
(* x (+ 0.5 (* x (+ 0.16666666666666666 (* x 0.041666666666666664))))))))double code(double x) {
return (exp(x) - 1.0) / x;
}
↓
double code(double x) {
double tmp;
if (x <= -0.0014603342715462273) {
tmp = (1.0 + sqrt(exp(x))) * ((sqrt(exp(x)) + -1.0) / x);
} else {
tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664)))));
}
return tmp;
}
Try it out
Enter valid numbers for all inputs
Target
| Original | 39.9 |
|---|
| Target | 40.3 |
|---|
| Herbie | 0.3 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x < 1 \land x > -1:\\
\;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x} - 1}{x}\\
\end{array}\]
Alternatives
| Alternative 1 |
|---|
| Error | 60.5 |
|---|
| Cost | 71488 |
|---|
\[\frac{\sqrt[3]{e^{x} + -1} \cdot \sqrt[3]{e^{x} + -1}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt[3]{e^{x} + -1}}{\log \left(e^{\sqrt[3]{x}}\right)}\]
| Alternative 2 |
|---|
| Error | 40.3 |
|---|
| Cost | 58688 |
|---|
\[\frac{\sqrt[3]{e^{x} + -1} \cdot \sqrt[3]{e^{x} + -1}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt[3]{e^{x} + -1}}{\sqrt[3]{x}}\]
| Alternative 3 |
|---|
| Error | 40.3 |
|---|
| Cost | 45632 |
|---|
\[\frac{1 + \sqrt{e^{x}}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt{e^{x}} + -1}{\sqrt[3]{x}}\]
| Alternative 4 |
|---|
| Error | 39.9 |
|---|
| Cost | 39232 |
|---|
\[\frac{\sqrt[3]{e^{x} + -1} \cdot \left(\sqrt[3]{e^{x} + -1} \cdot \sqrt[3]{e^{x} + -1}\right)}{x}\]
| Alternative 5 |
|---|
| Error | 39.9 |
|---|
| Cost | 26496 |
|---|
\[\frac{\frac{-1 + {\left(e^{x}\right)}^{3}}{1 + e^{x} \cdot \left(e^{x} + 1\right)}}{x}\]
| Alternative 6 |
|---|
| Error | 40.3 |
|---|
| Cost | 26304 |
|---|
\[\frac{1}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{e^{x} + -1}{\sqrt[3]{x}}\]
| Alternative 7 |
|---|
| Error | 39.9 |
|---|
| Cost | 26176 |
|---|
\[\left(1 + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} + -1}{x}\]
| Alternative 8 |
|---|
| Error | 39.9 |
|---|
| Cost | 26176 |
|---|
\[\frac{\left(1 + \sqrt{e^{x}}\right) \cdot \left(\sqrt{e^{x}} + -1\right)}{x}\]
| Alternative 9 |
|---|
| Error | 61.8 |
|---|
| Cost | 26176 |
|---|
\[\frac{\sqrt{e^{x} + -1} \cdot \sqrt{e^{x} + -1}}{x}\]
| Alternative 10 |
|---|
| Error | 53.1 |
|---|
| Cost | 19584 |
|---|
\[\sqrt[3]{{\left(\frac{e^{x} + -1}{x}\right)}^{3}}\]
| Alternative 11 |
|---|
| Error | 39.9 |
|---|
| Cost | 19584 |
|---|
\[\frac{\sqrt[3]{{\left(e^{x} + -1\right)}^{3}}}{x}\]
| Alternative 12 |
|---|
| Error | 61.8 |
|---|
| Cost | 19520 |
|---|
\[\frac{e^{\log \left(e^{x} + -1\right)}}{x}\]
| Alternative 13 |
|---|
| Error | 40.0 |
|---|
| Cost | 19520 |
|---|
\[\frac{\log \left(e^{e^{x} + -1}\right)}{x}\]
| Alternative 14 |
|---|
| Error | 39.6 |
|---|
| Cost | 6848 |
|---|
\[\frac{e^{x}}{x} - \frac{1}{x}\]
| Alternative 15 |
|---|
| Error | 39.9 |
|---|
| Cost | 6720 |
|---|
\[\frac{e^{x} + -1}{x}\]
| Alternative 16 |
|---|
| Error | 21.6 |
|---|
| Cost | 1088 |
|---|
\[\frac{x + \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)}{x}\]
| Alternative 17 |
|---|
| Error | 21.5 |
|---|
| Cost | 832 |
|---|
\[1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\]
| Alternative 18 |
|---|
| Error | 21.3 |
|---|
| Cost | 832 |
|---|
\[\frac{x + \left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.16666666666666666\right)}{x}\]
| Alternative 19 |
|---|
| Error | 21.2 |
|---|
| Cost | 576 |
|---|
\[1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\]
| Alternative 20 |
|---|
| Error | 21.7 |
|---|
| Cost | 576 |
|---|
\[\frac{x + 0.5 \cdot \left(x \cdot x\right)}{x}\]
| Alternative 21 |
|---|
| Error | 21.5 |
|---|
| Cost | 320 |
|---|
\[1 + x \cdot 0.5\]
| Alternative 22 |
|---|
| Error | 21.2 |
|---|
| Cost | 192 |
|---|
\[\frac{x}{x}\]
| Alternative 23 |
|---|
| Error | 21.2 |
|---|
| Cost | 64 |
|---|
\[1\]
| Alternative 24 |
|---|
| Error | 61.5 |
|---|
| Cost | 64 |
|---|
\[0\]
| Alternative 25 |
|---|
| Error | 62.9 |
|---|
| Cost | 64 |
|---|
\[-1\]
Error

Derivation
- Split input into 2 regimes
if x < -0.00146033427154622733
Initial program 0.0
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied *-un-lft-identity_binary64_21240.0
\[\leadsto \frac{e^{x} - 1}{\color{blue}{1 \cdot x}}\]
Applied add-sqr-sqrt_binary64_21460.0
\[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - 1}{1 \cdot x}\]
Applied difference-of-sqr-1_binary64_20940.0
\[\leadsto \frac{\color{blue}{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}}{1 \cdot x}\]
Applied times-frac_binary64_21300.0
\[\leadsto \color{blue}{\frac{\sqrt{e^{x}} + 1}{1} \cdot \frac{\sqrt{e^{x}} - 1}{x}}\]
Simplified0.0
\[\leadsto \color{blue}{\left(1 + \sqrt{e^{x}}\right)} \cdot \frac{\sqrt{e^{x}} - 1}{x}\]
Simplified0.0
\[\leadsto \left(1 + \sqrt{e^{x}}\right) \cdot \color{blue}{\frac{-1 + \sqrt{e^{x}}}{x}}\]
Simplified0.0
\[\leadsto \color{blue}{\left(1 + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} + -1}{x}}\]
if -0.00146033427154622733 < x
Initial program 60.0
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.4
\[\leadsto \color{blue}{0.5 \cdot x + \left(0.16666666666666666 \cdot {x}^{2} + \left(0.041666666666666664 \cdot {x}^{3} + 1\right)\right)}\]
Simplified0.4
\[\leadsto \color{blue}{1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)}\]
Simplified0.4
\[\leadsto \color{blue}{1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)}\]
- Recombined 2 regimes into one program.
Final simplification0.3
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \leq -0.0014603342715462273:\\
\;\;\;\;\left(1 + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} + -1}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\\
\end{array}\]
Reproduce
herbie shell --seed 2021022
(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))