Average Error: 39.9 → 0.4
Time: 2.5s
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}:\\ \;\;\;\;\log \left(e^{\frac{1}{6} \cdot {x}^{2}}\right) + \left(\frac{1}{2} \cdot x + 1\right)\\ \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}:\\
\;\;\;\;\log \left(e^{\frac{1}{6} \cdot {x}^{2}}\right) + \left(\frac{1}{2} \cdot x + 1\right)\\

\end{array}
double f(double x) {
        double r77214 = x;
        double r77215 = exp(r77214);
        double r77216 = 1.0;
        double r77217 = r77215 - r77216;
        double r77218 = r77217 / r77214;
        return r77218;
}

double f(double x) {
        double r77219 = x;
        double r77220 = -0.00010696052970747946;
        bool r77221 = r77219 <= r77220;
        double r77222 = exp(r77219);
        double r77223 = 1.0;
        double r77224 = r77222 - r77223;
        double r77225 = exp(r77224);
        double r77226 = log(r77225);
        double r77227 = r77226 / r77219;
        double r77228 = 0.16666666666666666;
        double r77229 = 2.0;
        double r77230 = pow(r77219, r77229);
        double r77231 = r77228 * r77230;
        double r77232 = exp(r77231);
        double r77233 = log(r77232);
        double r77234 = 0.5;
        double r77235 = r77234 * r77219;
        double r77236 = 1.0;
        double r77237 = r77235 + r77236;
        double r77238 = r77233 + r77237;
        double r77239 = r77221 ? r77227 : r77238;
        return r77239;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 \color{blue}{\frac{1}{6} \cdot {x}^{2} + \left(\frac{1}{2} \cdot x + 1\right)}\]
    3. Using strategy rm
    4. Applied add-log-exp0.5

      \[\leadsto \color{blue}{\log \left(e^{\frac{1}{6} \cdot {x}^{2}}\right)} + \left(\frac{1}{2} \cdot x + 1\right)\]
  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}:\\ \;\;\;\;\log \left(e^{\frac{1}{6} \cdot {x}^{2}}\right) + \left(\frac{1}{2} \cdot x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020001 
(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))