| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13504 |
\[0.5 \cdot {x}^{2} + \left(x + 0.16666666666666666 \cdot {x}^{3}\right)
\]
(FPCore (x) :precision binary64 (- (exp x) 1.0))
(FPCore (x) :precision binary64 (+ (* 0.5 (pow x 2.0)) (+ (+ x (* 0.16666666666666666 (pow x 3.0))) (* 0.041666666666666664 (pow x 4.0)))))
double code(double x) {
return exp(x) - 1.0;
}
double code(double x) {
return (0.5 * pow(x, 2.0)) + ((x + (0.16666666666666666 * pow(x, 3.0))) + (0.041666666666666664 * pow(x, 4.0)));
}
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
code = (0.5d0 * (x ** 2.0d0)) + ((x + (0.16666666666666666d0 * (x ** 3.0d0))) + (0.041666666666666664d0 * (x ** 4.0d0)))
end function
public static double code(double x) {
return Math.exp(x) - 1.0;
}
public static double code(double x) {
return (0.5 * Math.pow(x, 2.0)) + ((x + (0.16666666666666666 * Math.pow(x, 3.0))) + (0.041666666666666664 * Math.pow(x, 4.0)));
}
def code(x): return math.exp(x) - 1.0
def code(x): return (0.5 * math.pow(x, 2.0)) + ((x + (0.16666666666666666 * math.pow(x, 3.0))) + (0.041666666666666664 * math.pow(x, 4.0)))
function code(x) return Float64(exp(x) - 1.0) end
function code(x) return Float64(Float64(0.5 * (x ^ 2.0)) + Float64(Float64(x + Float64(0.16666666666666666 * (x ^ 3.0))) + Float64(0.041666666666666664 * (x ^ 4.0)))) end
function tmp = code(x) tmp = exp(x) - 1.0; end
function tmp = code(x) tmp = (0.5 * (x ^ 2.0)) + ((x + (0.16666666666666666 * (x ^ 3.0))) + (0.041666666666666664 * (x ^ 4.0))); end
code[x_] := N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]
code[x_] := N[(N[(0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x + N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.041666666666666664 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
e^{x} - 1
0.5 \cdot {x}^{2} + \left(\left(x + 0.16666666666666666 \cdot {x}^{3}\right) + 0.041666666666666664 \cdot {x}^{4}\right)
Results
| Original | 58.6 |
|---|---|
| Target | 0.5 |
| Herbie | 0.4 |
Initial program 58.6
Taylor expanded in x around 0 0.4
Simplified0.4
[Start]0.4 | \[ 0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + \left(0.041666666666666664 \cdot {x}^{4} + x\right)\right)
\] |
|---|---|
rational.json-simplify-41 [=>]0.4 | \[ \color{blue}{0.5 \cdot {x}^{2} + \left(\left(0.041666666666666664 \cdot {x}^{4} + x\right) + 0.16666666666666666 \cdot {x}^{3}\right)}
\] |
rational.json-simplify-1 [=>]0.4 | \[ 0.5 \cdot {x}^{2} + \color{blue}{\left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + x\right)\right)}
\] |
rational.json-simplify-41 [=>]0.4 | \[ 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-1 [=>]0.4 | \[ 0.5 \cdot {x}^{2} + \color{blue}{\left(\left(x + 0.16666666666666666 \cdot {x}^{3}\right) + 0.041666666666666664 \cdot {x}^{4}\right)}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13504 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 13124 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 6784 |
| Alternative 4 | |
|---|---|
| Error | 1.4 |
| Cost | 64 |
herbie shell --seed 2023073
(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))