?

Average Error: 58.6 → 0.2
Time: 2.2s
Precision: binary64
Cost: 13316

?

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

\mathbf{else}:\\
\;\;\;\;e^{x} - 1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.6
Target0.4
Herbie0.2
\[x \cdot \left(\left(1 + \frac{x}{2}\right) + \frac{x \cdot x}{6}\right) \]

Derivation?

  1. Split input into 2 regimes
  2. if (exp.f64 x) < 1.00049999999999994

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{0.5 \cdot {x}^{2} + x} \]

    if 1.00049999999999994 < (exp.f64 x)

    1. Initial program 1.4

      \[e^{x} - 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \leq 1.0005:\\ \;\;\;\;0.5 \cdot {x}^{2} + x\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost20224
\[0.16666666666666666 \cdot {x}^{3} + \left(x + \left(0.5 \cdot {x}^{2} + 0.041666666666666664 \cdot {x}^{4}\right)\right) \]
Alternative 2
Error0.4
Cost13504
\[0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + x\right) \]
Alternative 3
Error0.9
Cost13124
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.0005:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]
Alternative 4
Error1.3
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023097 
(FPCore (x)
  :name "expm1 (example 3.7)"
  :precision binary64
  :pre (< -0.00017 x)

  :herbie-target
  (* x (+ (+ 1.0 (/ x 2.0)) (/ (* x x) 6.0)))

  (- (exp x) 1.0))