Average Error: 29.1 → 0.3
Time: 3.5s
Precision: binary64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.006267703910975944:\\ \;\;\;\;\frac{e^{\left(a \cdot x\right) \cdot 2} + -1}{e^{a \cdot x} + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\right) + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -0.006267703910975944:\\
\;\;\;\;\frac{e^{\left(a \cdot x\right) \cdot 2} + -1}{e^{a \cdot x} + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(a \cdot x + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\right) + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)\\

\end{array}
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -0.006267703910975944)
   (/ (+ (exp (* (* a x) 2.0)) -1.0) (+ (exp (* a x)) 1.0))
   (+
    (+ (* a x) (* 0.16666666666666666 (pow (* a x) 3.0)))
    (+ (* 0.5 (pow (* a x) 2.0)) (* 0.041666666666666664 (pow (* a x) 4.0))))))
double code(double a, double x) {
	return exp(a * x) - 1.0;
}
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -0.006267703910975944) {
		tmp = (exp((a * x) * 2.0) + -1.0) / (exp(a * x) + 1.0);
	} else {
		tmp = ((a * x) + (0.16666666666666666 * pow((a * x), 3.0))) + ((0.5 * pow((a * x), 2.0)) + (0.041666666666666664 * pow((a * x), 4.0)));
	}
	return tmp;
}

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.3
\[\begin{array}{l} \mathbf{if}\;\left|a \cdot x\right| < 0.1:\\ \;\;\;\;\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 (*.f64 a x) < -0.00626770391097594432

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{e^{a \cdot x} \cdot e^{a \cdot x} - 1 \cdot 1}{e^{a \cdot x} + 1}}\]
    4. Simplified0.0

      \[\leadsto \frac{\color{blue}{{\left(e^{a \cdot x}\right)}^{2} + -1}}{e^{a \cdot x} + 1}\]
    5. Using strategy rm
    6. Applied pow-exp_binary640.0

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

    if -0.00626770391097594432 < (*.f64 a x)

    1. Initial program 44.3

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

      \[\leadsto \color{blue}{a \cdot x + \left(0.16666666666666666 \cdot \left({a}^{3} \cdot {x}^{3}\right) + \left(0.5 \cdot \left({a}^{2} \cdot {x}^{2}\right) + 0.041666666666666664 \cdot \left({a}^{4} \cdot {x}^{4}\right)\right)\right)}\]
    3. Simplified0.4

      \[\leadsto \color{blue}{a \cdot x + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)\right)}\]
    4. Using strategy rm
    5. Applied associate-+r+_binary640.4

      \[\leadsto \color{blue}{\left(a \cdot x + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\right) + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.006267703910975944:\\ \;\;\;\;\frac{e^{\left(a \cdot x\right) \cdot 2} + -1}{e^{a \cdot x} + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\right) + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021176 
(FPCore (a x)
  :name "expax (section 3.5)"
  :precision binary64

  :herbie-target
  (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))

  (- (exp (* a x)) 1.0))