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

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

\end{array}
double f(double x) {
        double r107444 = x;
        double r107445 = exp(r107444);
        double r107446 = 1.0;
        double r107447 = r107445 - r107446;
        double r107448 = r107447 / r107444;
        return r107448;
}

double f(double x) {
        double r107449 = x;
        double r107450 = -0.00010392522358541646;
        bool r107451 = r107449 <= r107450;
        double r107452 = 1.0;
        double r107453 = -r107452;
        double r107454 = r107449 + r107449;
        double r107455 = exp(r107454);
        double r107456 = fma(r107453, r107452, r107455);
        double r107457 = exp(r107456);
        double r107458 = log(r107457);
        double r107459 = cbrt(r107458);
        double r107460 = r107459 * r107459;
        double r107461 = exp(r107449);
        double r107462 = r107461 + r107452;
        double r107463 = cbrt(r107462);
        double r107464 = r107463 * r107463;
        double r107465 = r107460 / r107464;
        double r107466 = r107449 * r107463;
        double r107467 = cbrt(r107456);
        double r107468 = r107466 / r107467;
        double r107469 = r107465 / r107468;
        double r107470 = 0.16666666666666666;
        double r107471 = 2.0;
        double r107472 = pow(r107449, r107471);
        double r107473 = 0.5;
        double r107474 = 1.0;
        double r107475 = fma(r107473, r107449, r107474);
        double r107476 = fma(r107470, r107472, r107475);
        double r107477 = r107451 ? r107469 : r107476;
        return r107477;
}

Error

Bits error versus x

Target

Original39.6
Target40.1
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.00010392522358541646

    1. Initial program 0.1

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

      \[\leadsto \frac{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}{x}\]
    4. Simplified0.0

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}{e^{x} + 1}}{x}\]
    5. Using strategy rm
    6. Applied add-log-exp0.1

      \[\leadsto \frac{\frac{\color{blue}{\log \left(e^{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right)}}{e^{x} + 1}}{x}\]
    7. Using strategy rm
    8. Applied add-cube-cbrt0.1

      \[\leadsto \frac{\frac{\log \left(e^{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right)}{\color{blue}{\left(\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}\right) \cdot \sqrt[3]{e^{x} + 1}}}}{x}\]
    9. Applied add-cube-cbrt0.1

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt[3]{\log \left(e^{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right)} \cdot \sqrt[3]{\log \left(e^{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right)}}{\sqrt[3]{e^{x} + 1} \cdot \sqrt[3]{e^{x} + 1}} \cdot \frac{\sqrt[3]{\log \left(e^{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right)}}{\sqrt[3]{e^{x} + 1}}}}{x}\]
    11. Applied associate-/l*0.1

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

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

    if -0.00010392522358541646 < x

    1. Initial program 60.0

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

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

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

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

Reproduce

herbie shell --seed 2020056 +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))