Average Error: 20.0 → 0.3
Time: 7.3s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\frac{1}{\sqrt{x}} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1}{\sqrt{x}} \cdot \frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)}
double code(double x) {
	return ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))));
}
double code(double x) {
	return ((1.0 / sqrt(x)) * (1.0 / fma(sqrt((x + 1.0)), sqrt(x), (x + 1.0))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target0.7
Herbie0.3
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]

Derivation

  1. Initial program 20.0

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
  2. Using strategy rm
  3. Applied frac-sub19.9

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

    \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{x + 1} - \sqrt{x}\right)}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  5. Using strategy rm
  6. Applied flip--19.7

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

    \[\leadsto \frac{1 \cdot \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  8. Taylor expanded around 0 0.4

    \[\leadsto \frac{1 \cdot \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  9. Using strategy rm
  10. Applied times-frac0.4

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

    \[\leadsto \frac{1}{\sqrt{x}} \cdot \color{blue}{\frac{1}{\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x}, x + 1\right)}}\]
  12. Final simplification0.3

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

Reproduce

herbie shell --seed 2020057 +o rules:numerics
(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)))))