Average Error: 29.8 → 0.3
Time: 3.5s
Precision: 64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \le -4.1023891212148034 \cdot 10^{-4}:\\ \;\;\;\;\left(\sqrt{e^{a \cdot x}} + \sqrt{1}\right) \cdot \left(\sqrt{e^{a \cdot x}} - \sqrt{1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{6}, {\left(x \cdot a\right)}^{3}, \mathsf{fma}\left(\frac{1}{2}, {\left(x \cdot a\right)}^{2}, x \cdot a\right)\right)\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \le -4.1023891212148034 \cdot 10^{-4}:\\
\;\;\;\;\left(\sqrt{e^{a \cdot x}} + \sqrt{1}\right) \cdot \left(\sqrt{e^{a \cdot x}} - \sqrt{1}\right)\\

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

\end{array}
double code(double a, double x) {
	return (exp((a * x)) - 1.0);
}
double code(double a, double x) {
	double temp;
	if (((a * x) <= -0.00041023891212148034)) {
		temp = ((sqrt(exp((a * x))) + sqrt(1.0)) * (sqrt(exp((a * x))) - sqrt(1.0)));
	} else {
		temp = fma(0.16666666666666666, pow((x * a), 3.0), fma(0.5, pow((x * a), 2.0), (x * a)));
	}
	return temp;
}

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.8
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.00041023891212148034

    1. Initial program 0.0

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

      \[\leadsto e^{a \cdot x} - \color{blue}{\sqrt{1} \cdot \sqrt{1}}\]
    4. Applied add-sqr-sqrt0.0

      \[\leadsto \color{blue}{\sqrt{e^{a \cdot x}} \cdot \sqrt{e^{a \cdot x}}} - \sqrt{1} \cdot \sqrt{1}\]
    5. Applied difference-of-squares0.0

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

    if -0.00041023891212148034 < (* a x)

    1. Initial program 44.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.6

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

      \[\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. Taylor expanded around inf 14.6

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

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

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

Reproduce

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