Average Error: 29.5 → 0.3
Time: 3.9s
Precision: 64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \le -0.003423216791116969:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(e^{a \cdot x}\right)\right) - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, {\left(x \cdot a\right)}^{2}, \mathsf{fma}\left(\frac{1}{6}, {\left(x \cdot a\right)}^{3}, a \cdot x\right)\right)\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \le -0.003423216791116969:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(e^{a \cdot x}\right)\right) - 1\\

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

\end{array}
double f(double a, double x) {
        double r130791 = a;
        double r130792 = x;
        double r130793 = r130791 * r130792;
        double r130794 = exp(r130793);
        double r130795 = 1.0;
        double r130796 = r130794 - r130795;
        return r130796;
}

double f(double a, double x) {
        double r130797 = a;
        double r130798 = x;
        double r130799 = r130797 * r130798;
        double r130800 = -0.003423216791116969;
        bool r130801 = r130799 <= r130800;
        double r130802 = exp(r130799);
        double r130803 = log1p(r130802);
        double r130804 = expm1(r130803);
        double r130805 = 1.0;
        double r130806 = r130804 - r130805;
        double r130807 = 0.5;
        double r130808 = r130798 * r130797;
        double r130809 = 2.0;
        double r130810 = pow(r130808, r130809);
        double r130811 = 0.16666666666666666;
        double r130812 = 3.0;
        double r130813 = pow(r130808, r130812);
        double r130814 = fma(r130811, r130813, r130799);
        double r130815 = fma(r130807, r130810, r130814);
        double r130816 = r130801 ? r130806 : r130815;
        return r130816;
}

Error

Bits error versus a

Bits error versus x

Target

Original29.5
Target0.2
Herbie0.3
\[\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) < -0.003423216791116969

    1. Initial program 0.0

      \[e^{a \cdot x} - 1\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.0

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{a \cdot x}\right)\right)} - 1\]

    if -0.003423216791116969 < (* a x)

    1. Initial program 44.2

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

      \[\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. Simplified14.5

      \[\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. Using strategy rm
    5. Applied pow-prod-down8.4

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, {a}^{2} \cdot {x}^{2}, \mathsf{fma}\left(\frac{1}{6}, {\color{blue}{\left(x \cdot a\right)}}^{3}, a \cdot x\right)\right)\]
    7. Using strategy rm
    8. Applied pow-prod-down0.5

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

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

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

Reproduce

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