Average Error: 29.4 → 0.2
Time: 6.2s
Precision: binary64
\[[a, x]=\mathsf{sort}([a, x])\]
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.00467310360191573:\\ \;\;\;\;\sqrt{e^{a \cdot x}} \cdot \sqrt{e^{a \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(x + 0.5 \cdot \left(x \cdot \left(a \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)\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -0.00467310360191573:\\
\;\;\;\;\sqrt{e^{a \cdot x}} \cdot \sqrt{e^{a \cdot x}} - 1\\

\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + 0.5 \cdot \left(x \cdot \left(a \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)\\

\end{array}
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -0.00467310360191573)
   (- (* (sqrt (exp (* a x))) (sqrt (exp (* a x)))) 1.0)
   (+
    (* a (+ x (* 0.5 (* x (* a x)))))
    (+
     (* 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.00467310360191573) {
		tmp = (sqrt(exp(a * x)) * sqrt(exp(a * x))) - 1.0;
	} else {
		tmp = (a * (x + (0.5 * (x * (a * x))))) + ((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.4
Target0.2
Herbie0.2
\[\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.0046731036019157304

    1. Initial program 0.0

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

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

    if -0.0046731036019157304 < (*.f64 a x)

    1. Initial program 44.6

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

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

      \[\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. Using strategy rm
    5. Applied associate-*r*_binary64_17230.4

      \[\leadsto a \cdot \left(x + 0.5 \cdot \color{blue}{\left(\left(a \cdot x\right) \cdot x\right)}\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.00467310360191573:\\ \;\;\;\;\sqrt{e^{a \cdot x}} \cdot \sqrt{e^{a \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(x + 0.5 \cdot \left(x \cdot \left(a \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)\\ \end{array}\]

Reproduce

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