Average Error: 29.1 → 0.4
Time: 3.4s
Precision: 64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \le -0.26310033146711964:\\ \;\;\;\;\log \left(e^{e^{a \cdot x} - 1}\right)\\ \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.26310033146711964:\\
\;\;\;\;\log \left(e^{e^{a \cdot x} - 1}\right)\\

\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 code(double a, double x) {
	return ((double) (((double) exp(((double) (a * x)))) - 1.0));
}
double code(double a, double x) {
	double VAR;
	if ((((double) (a * x)) <= -0.26310033146711964)) {
		VAR = ((double) log(((double) exp(((double) (((double) exp(((double) (a * x)))) - 1.0))))));
	} else {
		VAR = ((double) fma(0.5, ((double) pow(((double) (x * a)), 2.0)), ((double) fma(0.16666666666666666, ((double) pow(((double) (x * a)), 3.0)), ((double) (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

Original29.1
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.26310033146711964

    1. Initial program 0.0

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

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

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

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

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

    if -0.26310033146711964 < (* a x)

    1. Initial program 43.6

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

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

      \[\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.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \le -0.26310033146711964:\\ \;\;\;\;\log \left(e^{e^{a \cdot x} - 1}\right)\\ \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 2020121 +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))