(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (/ -1.0 (- (- (sqrt (+ 1.0 x))) (sqrt x))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return -1.0 / (-sqrt((1.0 + x)) - sqrt(x));
}
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 = (-1.0d0) / (-sqrt((1.0d0 + x)) - sqrt(x))
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
return -1.0 / (-Math.sqrt((1.0 + x)) - Math.sqrt(x));
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return -1.0 / (-math.sqrt((1.0 + x)) - math.sqrt(x))
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return Float64(-1.0 / Float64(Float64(-sqrt(Float64(1.0 + x))) - sqrt(x))) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp = code(x) tmp = -1.0 / (-sqrt((1.0 + x)) - sqrt(x)); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(-1.0 / N[((-N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]) - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{-1}{\left(-\sqrt{1 + x}\right) - \sqrt{x}}




Bits error versus x
Results
| Original | 29.7 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
Initial program 29.7
Applied egg-rr29.1
Taylor expanded in x around 0 0.2
Applied egg-rr0.2
Applied egg-rr0.2
Final simplification0.2
herbie shell --seed 2022160
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))