Average Error: 20.5 → 0.3
Time: 4.0m
Precision: 64
Internal Precision: 128
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\frac{\frac{1}{x + 1}}{\sqrt{x} \cdot \left(\frac{\sqrt{x}}{\sqrt{x}} + \frac{\sqrt{x}}{\sqrt{x + 1}}\right)}\]

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 20.5

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

    \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}}\]
  4. Using strategy rm
  5. Applied frac-times25.5

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

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

    \[\leadsto \frac{\color{blue}{\frac{\left(1 \cdot 1\right) \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right) - \left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(1 \cdot 1\right)}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right)}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\]
  8. Simplified5.9

    \[\leadsto \frac{\frac{\color{blue}{1}}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right)}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\]
  9. Simplified5.7

    \[\leadsto \frac{\frac{1}{\color{blue}{(x \cdot x + x)_*}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\]
  10. Using strategy rm
  11. Applied *-un-lft-identity5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{\color{blue}{1 \cdot \left(x + 1\right)}}}}\]
  12. Applied sqrt-prod5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \frac{1}{\color{blue}{\sqrt{1} \cdot \sqrt{x + 1}}}}\]
  13. Applied *-un-lft-identity5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \frac{\color{blue}{1 \cdot 1}}{\sqrt{1} \cdot \sqrt{x + 1}}}\]
  14. Applied times-frac5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \color{blue}{\frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x + 1}}}}\]
  15. Applied *-un-lft-identity5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{\color{blue}{1 \cdot x}}} + \frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x + 1}}}\]
  16. Applied sqrt-prod5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{1}{\color{blue}{\sqrt{1} \cdot \sqrt{x}}} + \frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x + 1}}}\]
  17. Applied *-un-lft-identity5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\frac{\color{blue}{1 \cdot 1}}{\sqrt{1} \cdot \sqrt{x}} + \frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x + 1}}}\]
  18. Applied times-frac5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\color{blue}{\frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x}}} + \frac{1}{\sqrt{1}} \cdot \frac{1}{\sqrt{x + 1}}}\]
  19. Applied distribute-lft-out5.7

    \[\leadsto \frac{\frac{1}{(x \cdot x + x)_*}}{\color{blue}{\frac{1}{\sqrt{1}} \cdot \left(\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}\right)}}\]
  20. Applied *-un-lft-identity5.7

    \[\leadsto \frac{\frac{1}{\color{blue}{1 \cdot (x \cdot x + x)_*}}}{\frac{1}{\sqrt{1}} \cdot \left(\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}\right)}\]
  21. Applied add-cube-cbrt5.7

    \[\leadsto \frac{\frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{1 \cdot (x \cdot x + x)_*}}{\frac{1}{\sqrt{1}} \cdot \left(\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}\right)}\]
  22. Applied times-frac5.7

    \[\leadsto \frac{\color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1} \cdot \frac{\sqrt[3]{1}}{(x \cdot x + x)_*}}}{\frac{1}{\sqrt{1}} \cdot \left(\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}\right)}\]
  23. Applied times-frac5.7

    \[\leadsto \color{blue}{\frac{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1}}{\frac{1}{\sqrt{1}}} \cdot \frac{\frac{\sqrt[3]{1}}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}}\]
  24. Simplified5.7

    \[\leadsto \color{blue}{1} \cdot \frac{\frac{\sqrt[3]{1}}{(x \cdot x + x)_*}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\]
  25. Simplified0.4

    \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{1 + x}}{\frac{x}{\sqrt{1 + x}} + \frac{x}{\sqrt{x}}}}\]
  26. Using strategy rm
  27. Applied *-un-lft-identity0.4

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\frac{x}{\sqrt{1 + x}} + \frac{x}{\color{blue}{1 \cdot \sqrt{x}}}}\]
  28. Applied add-sqr-sqrt0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\frac{x}{\sqrt{1 + x}} + \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{1 \cdot \sqrt{x}}}\]
  29. Applied times-frac0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\frac{x}{\sqrt{1 + x}} + \color{blue}{\frac{\sqrt{x}}{1} \cdot \frac{\sqrt{x}}{\sqrt{x}}}}\]
  30. Applied *-un-lft-identity0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\frac{x}{\color{blue}{1 \cdot \sqrt{1 + x}}} + \frac{\sqrt{x}}{1} \cdot \frac{\sqrt{x}}{\sqrt{x}}}\]
  31. Applied add-sqr-sqrt0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{1 \cdot \sqrt{1 + x}} + \frac{\sqrt{x}}{1} \cdot \frac{\sqrt{x}}{\sqrt{x}}}\]
  32. Applied times-frac0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\color{blue}{\frac{\sqrt{x}}{1} \cdot \frac{\sqrt{x}}{\sqrt{1 + x}}} + \frac{\sqrt{x}}{1} \cdot \frac{\sqrt{x}}{\sqrt{x}}}\]
  33. Applied distribute-lft-out0.3

    \[\leadsto 1 \cdot \frac{\frac{1}{1 + x}}{\color{blue}{\frac{\sqrt{x}}{1} \cdot \left(\frac{\sqrt{x}}{\sqrt{1 + x}} + \frac{\sqrt{x}}{\sqrt{x}}\right)}}\]
  34. Simplified0.3

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

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

Reproduce

herbie shell --seed 2019089 +o rules:numerics
(FPCore (x)
  :name "2isqrt (example 3.6)"

  :herbie-target
  (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1)))))

  (- (/ 1 (sqrt x)) (/ 1 (sqrt (+ x 1)))))