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