Average Error: 29.6 → 0.3
Time: 3.6s
Precision: binary64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.34231484842688326:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\right) + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + 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.34231484842688326:\\
\;\;\;\;e^{a \cdot x} - 1\\

\mathbf{else}:\\
\;\;\;\;\left(a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\right) + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + 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.34231484842688326)
   (- (exp (* a x)) 1.0)
   (+
    (+ (* a x) (* 0.5 (pow (* a x) 2.0)))
    (+
     (* 0.16666666666666666 (pow (* a x) 3.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.34231484842688326) {
		tmp = exp(a * x) - 1.0;
	} else {
		tmp = ((a * x) + (0.5 * pow((a * x), 2.0))) + ((0.16666666666666666 * pow((a * x), 3.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.6
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.342314848426883256

    1. Initial program 0.0

      \[e^{a \cdot x} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary640.0

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

    if -0.342314848426883256 < (*.f64 a x)

    1. Initial program 44.2

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

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

      \[\leadsto \color{blue}{a \cdot \left(x + 0.5 \cdot \left(a \cdot \left(x \cdot x\right)\right)\right) + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)}\]
    4. Taylor expanded around 0 8.6

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

      \[\leadsto \color{blue}{\left(a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\right)} + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + 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.34231484842688326:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\right) + \left(0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3} + 0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4}\right)\\ \end{array}\]

Alternatives

Reproduce

herbie shell --seed 2021110 
(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))