Average Error: 29.3 → 0.5
Time: 2.0s
Precision: binary64
\[e^{a \cdot x} - 1\]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -4.5898218916979556 \cdot 10^{-06}:\\ \;\;\;\;\left(1 + \sqrt{e^{a \cdot x}}\right) \cdot \left(\sqrt{e^{a \cdot x}} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\\ \end{array}\]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4.5898218916979556 \cdot 10^{-06}:\\
\;\;\;\;\left(1 + \sqrt{e^{a \cdot x}}\right) \cdot \left(\sqrt{e^{a \cdot x}} + -1\right)\\

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

\end{array}
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -4.5898218916979556e-06)
   (* (+ 1.0 (sqrt (exp (* a x)))) (+ (sqrt (exp (* a x))) -1.0))
   (+ (* a x) (* 0.5 (pow (* a x) 2.0)))))
double code(double a, double x) {
	return exp(a * x) - 1.0;
}
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -4.5898218916979556e-06) {
		tmp = (1.0 + sqrt(exp(a * x))) * (sqrt(exp(a * x)) + -1.0);
	} else {
		tmp = (a * x) + (0.5 * pow((a * x), 2.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.3
Target0.2
Herbie0.5
\[\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) < -4.5898218916979556e-6

    1. Initial program 0.1

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

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

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

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

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

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

    if -4.5898218916979556e-6 < (*.f64 a x)

    1. Initial program 44.4

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left({a}^{2} \cdot {x}^{2}\right) + a \cdot x}\]
    5. Simplified8.6

      \[\leadsto \color{blue}{a \cdot x + 0.5 \cdot \left(\left(a \cdot a\right) \cdot \left(x \cdot x\right)\right)}\]
    6. Using strategy rm
    7. Applied pow2_binary648.6

      \[\leadsto a \cdot x + 0.5 \cdot \left(\left(a \cdot a\right) \cdot \color{blue}{{x}^{2}}\right)\]
    8. Applied pow2_binary648.6

      \[\leadsto a \cdot x + 0.5 \cdot \left(\color{blue}{{a}^{2}} \cdot {x}^{2}\right)\]
    9. Applied pow-prod-down_binary640.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -4.5898218916979556 \cdot 10^{-06}:\\ \;\;\;\;\left(1 + \sqrt{e^{a \cdot x}}\right) \cdot \left(\sqrt{e^{a \cdot x}} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\\ \end{array}\]

Reproduce

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

  :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))