\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := {x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
t_1 := \sqrt{\frac{1}{x}}\\
t_2 := \mathsf{fma}\left(2, t_1, t_1\right)\\
t_3 := {\left({x}^{-0.25}\right)}^{2}\\
\mathbf{if}\;x \leq 386923.8565851494:\\
\;\;\;\;\left|t_0\right|\\
\mathbf{elif}\;x \leq 1.1577094350749208 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(1.125, \sqrt{\frac{1}{{x}^{7}}} \cdot \frac{1}{{t_2}^{2}}, 1.5 \cdot \frac{1}{\left(x \cdot x\right) \cdot t_2}\right) - 1.5 \cdot \frac{1}{{x}^{3} \cdot t_2}\\
\mathbf{elif}\;x \leq 3.3300363174486925 \cdot 10^{+201}:\\
\;\;\;\;t_0 + \left(\mathsf{fma}\left(0.5, \frac{t_3}{x}, \mathsf{fma}\left(0.375, \frac{{x}^{-0.5}}{x \cdot x}, 0.3125 \cdot \frac{t_3}{{x}^{3}}\right)\right) - \left(\mathsf{fma}\left(0.3125, \frac{{x}^{-0.5}}{{x}^{3}}, \mathsf{fma}\left(0.375, \frac{t_3}{x \cdot x}, t_3\right)\right) - \frac{{x}^{-0.5}}{x} \cdot \left(x - 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right)}\\
\end{array}
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (- (pow x -0.5) (pow (+ x 1.0) -0.5)))
(t_1 (sqrt (/ 1.0 x)))
(t_2 (fma 2.0 t_1 t_1))
(t_3 (pow (pow x -0.25) 2.0)))
(if (<= x 386923.8565851494)
(fabs t_0)
(if (<= x 1.1577094350749208e+154)
(-
(fma
1.125
(* (sqrt (/ 1.0 (pow x 7.0))) (/ 1.0 (pow t_2 2.0)))
(* 1.5 (/ 1.0 (* (* x x) t_2))))
(* 1.5 (/ 1.0 (* (pow x 3.0) t_2))))
(if (<= x 3.3300363174486925e+201)
(+
t_0
(-
(fma
0.5
(/ t_3 x)
(fma
0.375
(/ (pow x -0.5) (* x x))
(* 0.3125 (/ t_3 (pow x 3.0)))))
(-
(fma
0.3125
(/ (pow x -0.5) (pow x 3.0))
(fma 0.375 (/ t_3 (* x x)) t_3))
(* (/ (pow x -0.5) x) (- x 0.5)))))
(exp (log (- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double t_0 = pow(x, -0.5) - pow((x + 1.0), -0.5);
double t_1 = sqrt((1.0 / x));
double t_2 = fma(2.0, t_1, t_1);
double t_3 = pow(pow(x, -0.25), 2.0);
double tmp;
if (x <= 386923.8565851494) {
tmp = fabs(t_0);
} else if (x <= 1.1577094350749208e+154) {
tmp = fma(1.125, (sqrt((1.0 / pow(x, 7.0))) * (1.0 / pow(t_2, 2.0))), (1.5 * (1.0 / ((x * x) * t_2)))) - (1.5 * (1.0 / (pow(x, 3.0) * t_2)));
} else if (x <= 3.3300363174486925e+201) {
tmp = t_0 + (fma(0.5, (t_3 / x), fma(0.375, (pow(x, -0.5) / (x * x)), (0.3125 * (t_3 / pow(x, 3.0))))) - (fma(0.3125, (pow(x, -0.5) / pow(x, 3.0)), fma(0.375, (t_3 / (x * x)), t_3)) - ((pow(x, -0.5) / x) * (x - 0.5))));
} else {
tmp = exp(log((pow(x, -0.5) - pow((1.0 + x), -0.5))));
}
return tmp;
}




Bits error versus x
| Original | 19.4 |
|---|---|
| Target | 0.7 |
| Herbie | 3.3 |
if x < 386923.85658514942Initial program 0.4
Applied egg-rr0.7
Applied egg-rr0.2
if 386923.85658514942 < x < 1.1577094350749208e154Initial program 59.4
Applied egg-rr59.5
Applied egg-rr59.3
Taylor expanded in x around inf 0.7
Simplified0.7
if 1.1577094350749208e154 < x < 3.33003631744869248e201Initial program 58.8
Applied egg-rr58.8
Applied egg-rr61.4
Taylor expanded in x around -inf 64.0
Simplified30.6
if 3.33003631744869248e201 < x Initial program 4.5
Applied egg-rr4.5
Final simplification3.3
herbie shell --seed 2022127
(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)))))