Average Error: 29.8 → 0.4
Time: 3.1s
Precision: 64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \le -1.45020641556337332 \cdot 10^{-5}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \left|x \cdot a\right| \cdot \left|x \cdot a\right|, x \cdot a\right)\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \le -1.45020641556337332 \cdot 10^{-5}:\\
\;\;\;\;e^{a \cdot x} - 1\\

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

\end{array}
double f(double a, double x) {
        double r94647 = a;
        double r94648 = x;
        double r94649 = r94647 * r94648;
        double r94650 = exp(r94649);
        double r94651 = 1.0;
        double r94652 = r94650 - r94651;
        return r94652;
}

double f(double a, double x) {
        double r94653 = a;
        double r94654 = x;
        double r94655 = r94653 * r94654;
        double r94656 = -1.4502064155633733e-05;
        bool r94657 = r94655 <= r94656;
        double r94658 = exp(r94655);
        double r94659 = 1.0;
        double r94660 = r94658 - r94659;
        double r94661 = 0.5;
        double r94662 = r94654 * r94653;
        double r94663 = fabs(r94662);
        double r94664 = r94663 * r94663;
        double r94665 = fma(r94661, r94664, r94662);
        double r94666 = r94657 ? r94660 : r94665;
        return r94666;
}

Error

Bits error versus a

Bits error versus x

Target

Original29.8
Target0.2
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;\left|a \cdot x\right| \lt 0.10000000000000001:\\ \;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^{2}}{6}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (* a x) < -1.4502064155633733e-05

    1. Initial program 0.1

      \[e^{a \cdot x} - 1\]

    if -1.4502064155633733e-05 < (* a x)

    1. Initial program 44.9

      \[e^{a \cdot x} - 1\]
    2. Taylor expanded around 0 13.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, {a}^{2} \cdot {x}^{2}, \mathsf{fma}\left(\frac{1}{6}, {a}^{3} \cdot {x}^{3}, a \cdot x\right)\right)}\]
    4. Taylor expanded around 0 8.1

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, {a}^{2} \cdot {x}^{2}, \color{blue}{a \cdot x}\right)\]
    5. Simplified8.1

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{\sqrt{{a}^{2} \cdot {x}^{2}} \cdot \sqrt{{a}^{2} \cdot {x}^{2}}}, x \cdot a\right)\]
    8. Simplified8.1

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{\left|x \cdot a\right|} \cdot \sqrt{{a}^{2} \cdot {x}^{2}}, x \cdot a\right)\]
    9. Simplified0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \le -1.45020641556337332 \cdot 10^{-5}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \left|x \cdot a\right| \cdot \left|x \cdot a\right|, x \cdot a\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020027 +o rules:numerics
(FPCore (a x)
  :name "expax (section 3.5)"
  :precision binary64
  :herbie-expected 14

  :herbie-target
  (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1 (+ (/ (* a x) 2) (/ (pow (* a x) 2) 6)))) (- (exp (* a x)) 1))

  (- (exp (* a x)) 1))