| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 20036 |
\[\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}
\]
(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}
Results
| Original | 58.6 |
|---|---|
| Target | 0.5 |
| Herbie | 0.0 |
if (exp.f64 x) < 1.01000000000000001Initial program 59.1
Taylor expanded in x around 0 0.0
Simplified0.0
[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) Initial program 0.8
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 20036 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 20036 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 13316 |
| Alternative 4 | |
|---|---|
| Error | 0.7 |
| Cost | 13124 |
| Alternative 5 | |
|---|---|
| Error | 1.3 |
| Cost | 64 |
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))