\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \le 3.2859459478 \cdot 10^{-8}:\\
\;\;\;\;\frac{\frac{\left(0.5 \cdot \frac{1}{x} + 0.171875 \cdot \frac{1}{{x}^{3}}\right) - 0.25 \cdot \frac{1}{{x}^{2}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\\
\end{array}double code(double x) {
return ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))));
}
double code(double x) {
double temp;
if ((((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)))) <= 3.2859459478049025e-08)) {
temp = (((((0.5 * (1.0 / x)) + (0.171875 * (1.0 / pow(x, 3.0)))) - (0.25 * (1.0 / pow(x, 2.0)))) / sqrt((sqrt(sqrt(x)) * sqrt(sqrt((x + 1.0)))))) / sqrt((sqrt(sqrt(x)) * sqrt(sqrt((x + 1.0))))));
} else {
temp = ((1.0 / sqrt(x)) - (sqrt((1.0 / sqrt((x + 1.0)))) * sqrt((1.0 / sqrt((x + 1.0))))));
}
return temp;
}




Bits error versus x
Results
| Original | 19.8 |
|---|---|
| Target | 0.6 |
| Herbie | 0.4 |
if (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))) < 3.2859459478049025e-08Initial program 40.7
rmApplied add-sqr-sqrt40.7
Applied sqrt-prod48.6
Applied associate-/r*51.1
Applied add-sqr-sqrt51.1
Applied sqrt-prod47.4
Applied associate-/r*40.8
Applied frac-sub40.8
rmApplied add-sqr-sqrt40.8
Applied associate-/r*40.8
Taylor expanded around inf 0.4
if 3.2859459478049025e-08 < (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))) Initial program 0.4
rmApplied add-sqr-sqrt0.4
Final simplification0.4
herbie shell --seed 2020066
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1)))))
(- (/ 1 (sqrt x)) (/ 1 (sqrt (+ x 1)))))