\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\frac{1 \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}}{\left(\sqrt{x} \cdot \sqrt{\sqrt{x + 1}}\right) \cdot \sqrt{\sqrt{x + 1}}}double code(double x) {
return ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))));
}
double code(double x) {
return ((1.0 * (1.0 / (sqrt((x + 1.0)) + sqrt(x)))) / ((sqrt(x) * sqrt(sqrt((x + 1.0)))) * sqrt(sqrt((x + 1.0)))));
}




Bits error versus x
Results
| Original | 18.8 |
|---|---|
| Target | 0.7 |
| Herbie | 0.4 |
Initial program 18.8
rmApplied frac-sub18.8
Simplified18.8
rmApplied flip--18.6
Simplified18.2
Taylor expanded around 0 0.4
rmApplied add-sqr-sqrt0.4
Applied sqrt-prod0.4
Applied associate-*r*0.4
Final simplification0.4
herbie shell --seed 2020053
(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)))))