\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\begin{array}{l}
\mathbf{if}\;x \leq 72052.32713768836:\\
\;\;\;\;\frac{\frac{1}{x + \sqrt{x \cdot \left(x + 1\right)}}}{\sqrt{x + 1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\
\end{array}(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 72052.32713768836) (/ (/ 1.0 (+ x (sqrt (* x (+ x 1.0))))) (sqrt (+ x 1.0))) (/ (/ 1.0 (- (+ 0.5 (* x 2.0)) (/ 0.125 x))) (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt(x + 1.0));
}
double code(double x) {
double tmp;
if (x <= 72052.32713768836) {
tmp = (1.0 / (x + sqrt(x * (x + 1.0)))) / sqrt(x + 1.0);
} else {
tmp = (1.0 / ((0.5 + (x * 2.0)) - (0.125 / x))) / sqrt(x + 1.0);
}
return tmp;
}













Bits error versus x
Results
| Original | 19.9 |
|---|---|
| Target | 0.7 |
| Herbie | 0.3 |
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 20032 |
| Alternative 2 | |
|---|---|
| Error | 0.7 |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 13633 |
| Alternative 4 | |
|---|---|
| Error | 0.8 |
| Cost | 7681 |
| Alternative 5 | |
|---|---|
| Error | 0.9 |
| Cost | 7425 |
| Alternative 6 | |
|---|---|
| Error | 1.2 |
| Cost | 7169 |
| Alternative 7 | |
|---|---|
| Error | 21.3 |
| Cost | 7041 |
| Alternative 8 | |
|---|---|
| Error | 50.0 |
| Cost | 385 |
| Alternative 9 | |
|---|---|
| Error | 60.3 |
| Cost | 64 |

if x < 72052.327137688364Initial program 0.4
rmApplied frac-sub_binary64_17920.4
Simplified0.4
Simplified0.4
rmApplied flip--_binary64_17580.4
Simplified0.3
rmApplied associate-/r*_binary64_17270.3
Simplified0.3
rmApplied sqrt-unprod_binary64_18030.3
Simplified0.3
if 72052.327137688364 < x Initial program 39.7
rmApplied frac-sub_binary64_179239.7
Simplified39.7
Simplified39.7
rmApplied flip--_binary64_175839.2
Simplified0.5
rmApplied associate-/r*_binary64_17270.5
Simplified0.4
Taylor expanded around inf 0.2
Simplified0.2
Simplified0.2
Final simplification0.3
herbie shell --seed 2021044
(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)))))