?

Average Error: 29.1 → 0.4
Time: 9.1s
Precision: binary64
Cost: 20996

?

\[e^{a \cdot x} - 1 \]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -50:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x + \left(0.5 \cdot {\left(a \cdot x\right)}^{2} + \left(0.041666666666666664 \cdot {\left(a \cdot x\right)}^{4} - {\left(a \cdot x\right)}^{3} \cdot -0.16666666666666666\right)\right)\\ \end{array} \]
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -50.0)
   (- (exp (* a x)) 1.0)
   (+
    (* a x)
    (+
     (* 0.5 (pow (* a x) 2.0))
     (-
      (* 0.041666666666666664 (pow (* a x) 4.0))
      (* (pow (* a x) 3.0) -0.16666666666666666))))))
double code(double a, double x) {
	return exp((a * x)) - 1.0;
}
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -50.0) {
		tmp = exp((a * x)) - 1.0;
	} else {
		tmp = (a * x) + ((0.5 * pow((a * x), 2.0)) + ((0.041666666666666664 * pow((a * x), 4.0)) - (pow((a * x), 3.0) * -0.16666666666666666)));
	}
	return tmp;
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    code = exp((a * x)) - 1.0d0
end function
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((a * x) <= (-50.0d0)) then
        tmp = exp((a * x)) - 1.0d0
    else
        tmp = (a * x) + ((0.5d0 * ((a * x) ** 2.0d0)) + ((0.041666666666666664d0 * ((a * x) ** 4.0d0)) - (((a * x) ** 3.0d0) * (-0.16666666666666666d0))))
    end if
    code = tmp
end function
public static double code(double a, double x) {
	return Math.exp((a * x)) - 1.0;
}
public static double code(double a, double x) {
	double tmp;
	if ((a * x) <= -50.0) {
		tmp = Math.exp((a * x)) - 1.0;
	} else {
		tmp = (a * x) + ((0.5 * Math.pow((a * x), 2.0)) + ((0.041666666666666664 * Math.pow((a * x), 4.0)) - (Math.pow((a * x), 3.0) * -0.16666666666666666)));
	}
	return tmp;
}
def code(a, x):
	return math.exp((a * x)) - 1.0
def code(a, x):
	tmp = 0
	if (a * x) <= -50.0:
		tmp = math.exp((a * x)) - 1.0
	else:
		tmp = (a * x) + ((0.5 * math.pow((a * x), 2.0)) + ((0.041666666666666664 * math.pow((a * x), 4.0)) - (math.pow((a * x), 3.0) * -0.16666666666666666)))
	return tmp
function code(a, x)
	return Float64(exp(Float64(a * x)) - 1.0)
end
function code(a, x)
	tmp = 0.0
	if (Float64(a * x) <= -50.0)
		tmp = Float64(exp(Float64(a * x)) - 1.0);
	else
		tmp = Float64(Float64(a * x) + Float64(Float64(0.5 * (Float64(a * x) ^ 2.0)) + Float64(Float64(0.041666666666666664 * (Float64(a * x) ^ 4.0)) - Float64((Float64(a * x) ^ 3.0) * -0.16666666666666666))));
	end
	return tmp
end
function tmp = code(a, x)
	tmp = exp((a * x)) - 1.0;
end
function tmp_2 = code(a, x)
	tmp = 0.0;
	if ((a * x) <= -50.0)
		tmp = exp((a * x)) - 1.0;
	else
		tmp = (a * x) + ((0.5 * ((a * x) ^ 2.0)) + ((0.041666666666666664 * ((a * x) ^ 4.0)) - (((a * x) ^ 3.0) * -0.16666666666666666)));
	end
	tmp_2 = tmp;
end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(a * x), $MachinePrecision] + N[(N[(0.5 * N[Power[N[(a * x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.041666666666666664 * N[Power[N[(a * x), $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[(a * x), $MachinePrecision], 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;e^{a \cdot x} - 1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.1
Target0.2
Herbie0.4
\[\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) < -50

    1. Initial program 0

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

    if -50 < (*.f64 a x)

    1. Initial program 44.0

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

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

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

      [Start]18.6

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

      rational_best-simplify-115 [=>]18.6

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

      rational_best-simplify-1 [=>]18.6

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

      exponential-simplify-29 [=>]18.6

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

      rational_best-simplify-1 [=>]18.6

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

      rational_best-simplify-62 [=>]18.6

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

      exponential-simplify-29 [=>]14.9

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

      rational_best-simplify-52 [=>]14.9

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

      exponential-simplify-29 [=>]0.6

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

      metadata-eval [=>]0.6

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

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

Alternatives

Alternative 1
Error0.5
Cost14148
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -50:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x - {\left(a \cdot x\right)}^{2} \cdot -0.5\right) + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\\ \end{array} \]
Alternative 2
Error0.5
Cost6980
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -1 \cdot 10^{-5}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{elif}\;a \cdot x + 2 \ne 0:\\ \;\;\;\;a \cdot \left(\left(x \cdot \left(-2 - a \cdot x\right)\right) \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
Alternative 3
Error18.3
Cost1352
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -50:\\ \;\;\;\;-2\\ \mathbf{elif}\;a \cdot x + 2 \ne 0:\\ \;\;\;\;a \cdot \left(\left(x \cdot \left(-2 - a \cdot x\right)\right) \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
Alternative 4
Error18.8
Cost452
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -50:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
Alternative 5
Error58.3
Cost64
\[-2 \]

Error

Reproduce?

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