Average Error: 39.9 → 0.4
Time: 2.4s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.069605297074794643787457038008881227142 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{e^{x} - 1}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, \mathsf{fma}\left(\frac{1}{6}, {x}^{3}, x\right)\right)}{x}\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -1.069605297074794643787457038008881227142 \cdot 10^{-4}:\\
\;\;\;\;\frac{\log \left(e^{e^{x} - 1}\right)}{x}\\

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

\end{array}
double f(double x) {
        double r79306 = x;
        double r79307 = exp(r79306);
        double r79308 = 1.0;
        double r79309 = r79307 - r79308;
        double r79310 = r79309 / r79306;
        return r79310;
}

double f(double x) {
        double r79311 = x;
        double r79312 = -0.00010696052970747946;
        bool r79313 = r79311 <= r79312;
        double r79314 = exp(r79311);
        double r79315 = 1.0;
        double r79316 = r79314 - r79315;
        double r79317 = exp(r79316);
        double r79318 = log(r79317);
        double r79319 = r79318 / r79311;
        double r79320 = 0.5;
        double r79321 = 2.0;
        double r79322 = pow(r79311, r79321);
        double r79323 = 0.16666666666666666;
        double r79324 = 3.0;
        double r79325 = pow(r79311, r79324);
        double r79326 = fma(r79323, r79325, r79311);
        double r79327 = fma(r79320, r79322, r79326);
        double r79328 = r79327 / r79311;
        double r79329 = r79313 ? r79319 : r79328;
        return r79329;
}

Error

Bits error versus x

Target

Original39.9
Target40.4
Herbie0.4
\[\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.00010696052970747946

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \frac{e^{x} - \color{blue}{\log \left(e^{1}\right)}}{x}\]
    4. Applied add-log-exp0.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}{x}\]
    5. Applied diff-log0.1

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}{x}\]
    6. Simplified0.0

      \[\leadsto \frac{\log \color{blue}{\left(e^{e^{x} - 1}\right)}}{x}\]

    if -0.00010696052970747946 < x

    1. Initial program 60.2

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

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

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

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

Reproduce

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

  :herbie-target
  (if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))

  (/ (- (exp x) 1) x))