Average Error: 28.9 → 0.4
Time: 3.2s
Precision: 64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \le -0.369328679075431043:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \left(x \cdot a\right) \cdot \left(x \cdot a\right), \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.369328679075431043:\\
\;\;\;\;e^{a \cdot x} - 1\\

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

\end{array}
double code(double a, double x) {
	return (exp((a * x)) - 1.0);
}
double code(double a, double x) {
	double VAR;
	if (((a * x) <= -0.36932867907543104)) {
		VAR = (exp((a * x)) - 1.0);
	} else {
		VAR = fma(0.5, ((x * a) * (x * a)), fma(0.16666666666666666, pow((x * a), 3.0), (a * x)));
	}
	return VAR;
}

Error

Bits error versus a

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original28.9
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) < -0.36932867907543104

    1. Initial program 0.0

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

    if -0.36932867907543104 < (* a x)

    1. Initial program 43.8

      \[e^{a \cdot x} - 1\]
    2. Taylor expanded around 0 14.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. Simplified14.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. 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 unpow28.4

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{\left(a \cdot a\right)} \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{1}{6}, {\left(x \cdot a\right)}^{3}, a \cdot x\right)\right)\]
    10. Applied unswap-sqr0.7

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left(x \cdot a\right) \cdot \color{blue}{\left(x \cdot a\right)}, \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.4

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

Reproduce

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