Average Error: 39.8 → 0.3
Time: 29.3s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.078685598347373564200729623152597014268 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}} \cdot \frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -1.078685598347373564200729623152597014268 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}} \cdot \frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)\\

\end{array}
double f(double x) {
        double r4046133 = x;
        double r4046134 = exp(r4046133);
        double r4046135 = 1.0;
        double r4046136 = r4046134 - r4046135;
        double r4046137 = r4046136 / r4046133;
        return r4046137;
}

double f(double x) {
        double r4046138 = x;
        double r4046139 = -0.00010786855983473736;
        bool r4046140 = r4046138 <= r4046139;
        double r4046141 = 1.0;
        double r4046142 = exp(r4046138);
        double r4046143 = 1.0;
        double r4046144 = r4046143 + r4046142;
        double r4046145 = r4046143 * r4046144;
        double r4046146 = fma(r4046142, r4046142, r4046145);
        double r4046147 = sqrt(r4046146);
        double r4046148 = r4046141 / r4046147;
        double r4046149 = 2.0;
        double r4046150 = fma(r4046138, r4046149, r4046138);
        double r4046151 = exp(r4046150);
        double r4046152 = r4046143 * r4046143;
        double r4046153 = r4046152 * r4046143;
        double r4046154 = r4046151 - r4046153;
        double r4046155 = r4046154 / r4046147;
        double r4046156 = r4046148 * r4046155;
        double r4046157 = r4046156 / r4046138;
        double r4046158 = 0.16666666666666666;
        double r4046159 = 0.5;
        double r4046160 = fma(r4046138, r4046158, r4046159);
        double r4046161 = fma(r4046138, r4046160, r4046141);
        double r4046162 = r4046140 ? r4046157 : r4046161;
        return r4046162;
}

Error

Bits error versus x

Target

Original39.8
Target40.3
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt 1 \land x \gt -1:\\ \;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.00010786855983473736

    1. Initial program 0.1

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied flip3--0.1

      \[\leadsto \frac{\color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}}{x}\]
    4. Simplified0.1

      \[\leadsto \frac{\frac{\color{blue}{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}}{e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)}}{x}\]
    5. Simplified0.1

      \[\leadsto \frac{\frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\color{blue}{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}{x}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\color{blue}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)} \cdot \sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}}{x}\]
    8. Applied *-un-lft-identity0.1

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1\right)}}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)} \cdot \sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}{x}\]
    9. Applied times-frac0.1

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}} \cdot \frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}}{x}\]

    if -0.00010786855983473736 < x

    1. Initial program 60.2

      \[\frac{e^{x} - 1}{x}\]
    2. Taylor expanded around 0 0.5

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{6} \cdot {x}^{2} + 1\right)}\]
    3. Simplified0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.078685598347373564200729623152597014268 \cdot 10^{-4}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}} \cdot \frac{e^{\mathsf{fma}\left(x, 2, x\right)} - \left(1 \cdot 1\right) \cdot 1}{\sqrt{\mathsf{fma}\left(e^{x}, e^{x}, 1 \cdot \left(1 + e^{x}\right)\right)}}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{6}, \frac{1}{2}\right), 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x)
  :name "Kahan's exp quotient"

  :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))