\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5.459127345053966 \cdot 10^{-19}:\\
\;\;\;\;{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := {\left(1 + x\right)}^{-0.5}\\
t_2 := {t_0}^{-0.5}\\
\left({x}^{-0.5} - t_1\right) + \mathsf{fma}\left(-t_2, t_2, t_1\right)
\end{array}\\
\end{array}
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 5.459127345053966e-19)
(* (pow x -1.5) (+ 0.5 (/ -0.375 x)))
(let* ((t_1 (pow (+ 1.0 x) -0.5)) (t_2 (pow t_0 -0.5)))
(+ (- (pow x -0.5) t_1) (fma (- t_2) t_2 t_1))))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt(x + 1.0));
}
double code(double x) {
double t_0 = sqrt(1.0 + x);
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 5.459127345053966e-19) {
tmp = pow(x, -1.5) * (0.5 + (-0.375 / x));
} else {
double t_1 = pow((1.0 + x), -0.5);
double t_2 = pow(t_0, -0.5);
tmp = (pow(x, -0.5) - t_1) + fma(-t_2, t_2, t_1);
}
return tmp;
}




Bits error versus x
| Original | 20.3 |
|---|---|
| Target | 0.7 |
| Herbie | 0.4 |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 5.45913e-19Initial program 41.0
Applied egg41.0
Taylor expanded in x around -inf 64.0
Simplified0.2
Applied egg0.0
if 5.45913e-19 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 1.0
Applied egg0.7
Applied egg0.8
Final simplification0.4
herbie shell --seed 2022125
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))