Average Error: 39.1 → 0.3
Time: 32.4s
Precision: 64
\[\frac{e^{x} - 1.0}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00017882867482842777:\\ \;\;\;\;\frac{\left(\sqrt{1.0} + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} - \sqrt{1.0}}{2} + \log \left(\sqrt{e^{e^{x} - 1.0}}\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.0}{x}
\begin{array}{l}
\mathbf{if}\;x \le -0.00017882867482842777:\\
\;\;\;\;\frac{\left(\sqrt{1.0} + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} - \sqrt{1.0}}{2} + \log \left(\sqrt{e^{e^{x} - 1.0}}\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 r3114255 = x;
        double r3114256 = exp(r3114255);
        double r3114257 = 1.0;
        double r3114258 = r3114256 - r3114257;
        double r3114259 = r3114258 / r3114255;
        return r3114259;
}

double f(double x) {
        double r3114260 = x;
        double r3114261 = -0.00017882867482842777;
        bool r3114262 = r3114260 <= r3114261;
        double r3114263 = 1.0;
        double r3114264 = sqrt(r3114263);
        double r3114265 = exp(r3114260);
        double r3114266 = sqrt(r3114265);
        double r3114267 = r3114264 + r3114266;
        double r3114268 = r3114266 - r3114264;
        double r3114269 = 2.0;
        double r3114270 = r3114268 / r3114269;
        double r3114271 = r3114267 * r3114270;
        double r3114272 = r3114265 - r3114263;
        double r3114273 = exp(r3114272);
        double r3114274 = sqrt(r3114273);
        double r3114275 = log(r3114274);
        double r3114276 = r3114271 + r3114275;
        double r3114277 = r3114276 / r3114260;
        double r3114278 = 0.16666666666666666;
        double r3114279 = 0.5;
        double r3114280 = fma(r3114260, r3114278, r3114279);
        double r3114281 = 1.0;
        double r3114282 = fma(r3114260, r3114280, r3114281);
        double r3114283 = r3114262 ? r3114277 : r3114282;
        return r3114283;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{\left(e^{e^{x} - 1.0}\right)}}{x}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\log \color{blue}{\left(\sqrt{e^{e^{x} - 1.0}} \cdot \sqrt{e^{e^{x} - 1.0}}\right)}}{x}\]
    9. Applied log-prod0.1

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \left(\sqrt{e^{e^{x} - 1.0}}\right)}}{x}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \left(\sqrt{e^{e^{x} - \color{blue}{\sqrt{1.0} \cdot \sqrt{1.0}}}}\right)}{x}\]
    12. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \left(\sqrt{e^{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - \sqrt{1.0} \cdot \sqrt{1.0}}}\right)}{x}\]
    13. Applied difference-of-squares0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \left(\sqrt{e^{\color{blue}{\left(\sqrt{e^{x}} + \sqrt{1.0}\right) \cdot \left(\sqrt{e^{x}} - \sqrt{1.0}\right)}}}\right)}{x}\]
    14. Applied exp-prod0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \left(\sqrt{\color{blue}{{\left(e^{\sqrt{e^{x}} + \sqrt{1.0}}\right)}^{\left(\sqrt{e^{x}} - \sqrt{1.0}\right)}}}\right)}{x}\]
    15. Applied sqrt-pow10.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \log \color{blue}{\left({\left(e^{\sqrt{e^{x}} + \sqrt{1.0}}\right)}^{\left(\frac{\sqrt{e^{x}} - \sqrt{1.0}}{2}\right)}\right)}}{x}\]
    16. Applied log-pow0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \color{blue}{\frac{\sqrt{e^{x}} - \sqrt{1.0}}{2} \cdot \log \left(e^{\sqrt{e^{x}} + \sqrt{1.0}}\right)}}{x}\]
    17. Simplified0.1

      \[\leadsto \frac{\log \left(\sqrt{e^{e^{x} - 1.0}}\right) + \frac{\sqrt{e^{x}} - \sqrt{1.0}}{2} \cdot \color{blue}{\left(\sqrt{e^{x}} + \sqrt{1.0}\right)}}{x}\]

    if -0.00017882867482842777 < x

    1. Initial program 60.0

      \[\frac{e^{x} - 1.0}{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 -0.00017882867482842777:\\ \;\;\;\;\frac{\left(\sqrt{1.0} + \sqrt{e^{x}}\right) \cdot \frac{\sqrt{e^{x}} - \sqrt{1.0}}{2} + \log \left(\sqrt{e^{e^{x} - 1.0}}\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 2019165 +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))