?

Average Error: 58.6 → 0.0
Time: 7.9s
Precision: binary64
Cost: 26756

?

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

\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.5
Herbie0.0
\[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.01000000000000001

    1. Initial program 59.1

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

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

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

      [Start]0.0

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

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

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

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

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

      rational.json-simplify-41 [=>]0.0

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

      rational.json-simplify-41 [=>]0.0

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

    if 1.01000000000000001 < (exp.f64 x)

    1. Initial program 0.8

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

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

Alternatives

Alternative 1
Error0.1
Cost20036
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.01:\\ \;\;\;\;x + \left(0.5 \cdot {x}^{2} + 0.16666666666666666 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]
Alternative 2
Error0.1
Cost20036
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.01:\\ \;\;\;\;0.5 \cdot {x}^{2} + \left(x + 0.16666666666666666 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]
Alternative 3
Error0.2
Cost13316
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.00001:\\ \;\;\;\;0.5 \cdot {x}^{2} + x\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]
Alternative 4
Error0.7
Cost13124
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.00000001:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;e^{x} - 1\\ \end{array} \]
Alternative 5
Error1.3
Cost64
\[x \]

Error

Reproduce?

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