?

Average Error: 29.7 → 0.3
Time: 11.7s
Precision: binary64
Cost: 14148

?

\[e^{a \cdot x} - 1 \]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.002:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\right) + 0.16666666666666666 \cdot {\left(a \cdot x\right)}^{3}\\ \end{array} \]
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -0.002)
   (- (exp (* a x)) 1.0)
   (+
    (+ (* a x) (* 0.5 (pow (* a x) 2.0)))
    (* 0.16666666666666666 (pow (* a x) 3.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.002) {
		tmp = exp((a * x)) - 1.0;
	} else {
		tmp = ((a * x) + (0.5 * pow((a * x), 2.0))) + (0.16666666666666666 * pow((a * x), 3.0));
	}
	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) <= (-0.002d0)) then
        tmp = exp((a * x)) - 1.0d0
    else
        tmp = ((a * x) + (0.5d0 * ((a * x) ** 2.0d0))) + (0.16666666666666666d0 * ((a * x) ** 3.0d0))
    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) <= -0.002) {
		tmp = Math.exp((a * x)) - 1.0;
	} else {
		tmp = ((a * x) + (0.5 * Math.pow((a * x), 2.0))) + (0.16666666666666666 * Math.pow((a * x), 3.0));
	}
	return tmp;
}
def code(a, x):
	return math.exp((a * x)) - 1.0
def code(a, x):
	tmp = 0
	if (a * x) <= -0.002:
		tmp = math.exp((a * x)) - 1.0
	else:
		tmp = ((a * x) + (0.5 * math.pow((a * x), 2.0))) + (0.16666666666666666 * math.pow((a * x), 3.0))
	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) <= -0.002)
		tmp = Float64(exp(Float64(a * x)) - 1.0);
	else
		tmp = Float64(Float64(Float64(a * x) + Float64(0.5 * (Float64(a * x) ^ 2.0))) + Float64(0.16666666666666666 * (Float64(a * x) ^ 3.0)));
	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) <= -0.002)
		tmp = exp((a * x)) - 1.0;
	else
		tmp = ((a * x) + (0.5 * ((a * x) ^ 2.0))) + (0.16666666666666666 * ((a * x) ^ 3.0));
	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], -0.002], N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(a * x), $MachinePrecision] + N[(0.5 * N[Power[N[(a * x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[Power[N[(a * x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -0.002:\\
\;\;\;\;e^{a \cdot x} - 1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.7
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) < -2e-3

    1. Initial program 0.0

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

    if -2e-3 < (*.f64 a x)

    1. Initial program 44.5

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

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

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

      [Start]14.8

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

      rational.json-simplify-41 [<=]14.8

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

      rational.json-simplify-1 [=>]14.8

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

      rational.json-simplify-1 [=>]14.8

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

      exponential.json-simplify-27 [=>]14.8

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

      exponential.json-simplify-27 [=>]0.4

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

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

Alternatives

Alternative 1
Error0.5
Cost7300
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -0.002:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x + 0.5 \cdot {\left(a \cdot x\right)}^{2}\\ \end{array} \]
Alternative 2
Error0.8
Cost6980
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -2 \cdot 10^{-8}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
Alternative 3
Error21.2
Cost192
\[a \cdot x \]

Error

Reproduce?

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