| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 20224 |
\[0.16666666666666666 \cdot {x}^{3} + \left(x + \left(0.5 \cdot {x}^{2} + 0.041666666666666664 \cdot {x}^{4}\right)\right)
\]
(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}
Results
| Original | 58.6 |
|---|---|
| Target | 0.4 |
| Herbie | 0.2 |
if (exp.f64 x) < 1.00049999999999994Initial program 59.1
Taylor expanded in x around 0 0.2
if 1.00049999999999994 < (exp.f64 x) Initial program 1.4
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 20224 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 13504 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 13124 |
| Alternative 4 | |
|---|---|
| Error | 1.3 |
| Cost | 64 |
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))