Average Error: 19.2 → 0.2
Time: 7.2s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[{x}^{-0.5} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)} \]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
{x}^{-0.5} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)}
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (* (pow x -0.5) (/ 1.0 (fma (sqrt (+ x 1.0)) (sqrt x) (+ x 1.0)))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt(x + 1.0));
}
double code(double x) {
	return pow(x, -0.5) * (1.0 / fma(sqrt(x + 1.0), sqrt(x), (x + 1.0)));
}

Error

Bits error versus x

Target

Original19.2
Target0.6
Herbie0.2
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 19.2

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied frac-sub_binary6419.2

    \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
  3. Simplified19.2

    \[\leadsto \frac{\color{blue}{\sqrt{1 + x} - \sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
  4. Simplified19.2

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x} \cdot \sqrt{1 + x}}} \]
  5. Applied flip--_binary6419.0

    \[\leadsto \frac{\color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  6. Simplified0.4

    \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  7. Applied *-un-lft-identity_binary640.4

    \[\leadsto \frac{\frac{1}{\color{blue}{1 \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  8. Applied add-cube-cbrt_binary640.4

    \[\leadsto \frac{\frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{1 \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  9. Applied times-frac_binary640.4

    \[\leadsto \frac{\color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1} \cdot \frac{\sqrt[3]{1}}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  10. Applied times-frac_binary640.4

    \[\leadsto \color{blue}{\frac{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1}}{\sqrt{x}} \cdot \frac{\frac{\sqrt[3]{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{1 + x}}} \]
  11. Simplified0.4

    \[\leadsto \color{blue}{\frac{1}{\sqrt{x}}} \cdot \frac{\frac{\sqrt[3]{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{1 + x}} \]
  12. Simplified0.3

    \[\leadsto \frac{1}{\sqrt{x}} \cdot \color{blue}{\frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right)}} \]
  13. Applied pow1/2_binary640.3

    \[\leadsto \frac{1}{\color{blue}{{x}^{0.5}}} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right)} \]
  14. Applied pow-flip_binary640.2

    \[\leadsto \color{blue}{{x}^{\left(-0.5\right)}} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right)} \]
  15. Simplified0.2

    \[\leadsto {x}^{\color{blue}{-0.5}} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right)} \]
  16. Final simplification0.2

    \[\leadsto {x}^{-0.5} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)} \]

Reproduce

herbie shell --seed 2021329 
(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)))))