| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 576 |
\[x - \left(0.5 + 0.125 \cdot \frac{1}{x}\right)
\]
(FPCore (x) :precision binary64 (* (sqrt (- x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (- x (+ (+ 0.5 (* 0.125 (/ 1.0 x))) (* 0.0625 (/ 1.0 (pow x 2.0))))))
double code(double x) {
return sqrt((x - 1.0)) * sqrt(x);
}
double code(double x) {
return x - ((0.5 + (0.125 * (1.0 / x))) + (0.0625 * (1.0 / pow(x, 2.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x - 1.0d0)) * sqrt(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = x - ((0.5d0 + (0.125d0 * (1.0d0 / x))) + (0.0625d0 * (1.0d0 / (x ** 2.0d0))))
end function
public static double code(double x) {
return Math.sqrt((x - 1.0)) * Math.sqrt(x);
}
public static double code(double x) {
return x - ((0.5 + (0.125 * (1.0 / x))) + (0.0625 * (1.0 / Math.pow(x, 2.0))));
}
def code(x): return math.sqrt((x - 1.0)) * math.sqrt(x)
def code(x): return x - ((0.5 + (0.125 * (1.0 / x))) + (0.0625 * (1.0 / math.pow(x, 2.0))))
function code(x) return Float64(sqrt(Float64(x - 1.0)) * sqrt(x)) end
function code(x) return Float64(x - Float64(Float64(0.5 + Float64(0.125 * Float64(1.0 / x))) + Float64(0.0625 * Float64(1.0 / (x ^ 2.0))))) end
function tmp = code(x) tmp = sqrt((x - 1.0)) * sqrt(x); end
function tmp = code(x) tmp = x - ((0.5 + (0.125 * (1.0 / x))) + (0.0625 * (1.0 / (x ^ 2.0)))); end
code[x_] := N[(N[Sqrt[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x - N[(N[(0.5 + N[(0.125 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.0625 * N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x - 1} \cdot \sqrt{x}
x - \left(\left(0.5 + 0.125 \cdot \frac{1}{x}\right) + 0.0625 \cdot \frac{1}{{x}^{2}}\right)
Results
Initial program 0.5
Taylor expanded in x around inf 0.3
Simplified0.3
[Start]0.3 | \[ x - \left(0.5 + \left(0.0625 \cdot \frac{1}{{x}^{2}} + 0.125 \cdot \frac{1}{x}\right)\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.3 | \[ x - \color{blue}{\left(0.0625 \cdot \frac{1}{{x}^{2}} + \left(0.5 + 0.125 \cdot \frac{1}{x}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.3 | \[ x - \color{blue}{\left(\left(0.5 + 0.125 \cdot \frac{1}{x}\right) + 0.0625 \cdot \frac{1}{{x}^{2}}\right)}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 192 |
| Alternative 3 | |
|---|---|
| Error | 1.4 |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x)
:name "sqrt times"
:precision binary64
(* (sqrt (- x 1.0)) (sqrt x)))