Average Error: 20.0 → 0.3
Time: 5.1m
Precision: 64
Internal Precision: 1088
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;{x}^{\left(-\frac{1}{2}\right)} - \frac{1}{\sqrt{1 + x}} \le 1.2189914808529811 \cdot 10^{-94}:\\ \;\;\;\;\frac{\sqrt{1}}{\sqrt{1 + x} + \sqrt{x}} \cdot \left(\left(\frac{1}{x} + \frac{1}{{x}^{3}} \cdot \frac{3}{8}\right) - \frac{1}{2} \cdot \frac{1}{{x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{(x \cdot x + x)_*}} \cdot \left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(-\frac{1}{2}\right)} \cdot {\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(-\frac{1}{2}\right)}\right)\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (- (pow x (- 1/2)) (/ 1 (sqrt (+ x 1)))) < 1.2189914808529811e-94

    1. Initial program 38.9

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

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

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

      \[\leadsto \frac{\sqrt{x + 1} - \sqrt{x}}{\color{blue}{\sqrt{x + x \cdot x}}}\]
    6. Using strategy rm
    7. Applied flip--38.9

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x + x \cdot x}}\]
    8. Applied associate-/l/38.9

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

      \[\leadsto \frac{\color{blue}{\left(1 + x\right) - x}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt38.9

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

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

      \[\leadsto \color{blue}{\sqrt{\frac{1 + 0}{(x \cdot x + x)_*}}} \cdot \frac{\sqrt{\left(1 + x\right) - x}}{\sqrt{x + 1} + \sqrt{x}}\]
    14. Simplified12.2

      \[\leadsto \sqrt{\frac{1 + 0}{(x \cdot x + x)_*}} \cdot \color{blue}{\frac{\sqrt{1 + 0}}{\sqrt{x + 1} + \sqrt{x}}}\]
    15. Taylor expanded around inf 0.3

      \[\leadsto \color{blue}{\left(\left(\frac{3}{8} \cdot \frac{1}{{x}^{3}} + \frac{1}{x}\right) - \frac{1}{2} \cdot \frac{1}{{x}^{2}}\right)} \cdot \frac{\sqrt{1 + 0}}{\sqrt{x + 1} + \sqrt{x}}\]

    if 1.2189914808529811e-94 < (- (pow x (- 1/2)) (/ 1 (sqrt (+ x 1))))

    1. Initial program 4.6

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

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

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

      \[\leadsto \frac{\sqrt{x + 1} - \sqrt{x}}{\color{blue}{\sqrt{x + x \cdot x}}}\]
    6. Using strategy rm
    7. Applied flip--4.2

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x + x \cdot x}}\]
    8. Applied associate-/l/4.2

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

      \[\leadsto \frac{\color{blue}{\left(1 + x\right) - x}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt3.5

      \[\leadsto \frac{\color{blue}{\sqrt{\left(1 + x\right) - x} \cdot \sqrt{\left(1 + x\right) - x}}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}\]
    12. Applied times-frac3.5

      \[\leadsto \color{blue}{\frac{\sqrt{\left(1 + x\right) - x}}{\sqrt{x + x \cdot x}} \cdot \frac{\sqrt{\left(1 + x\right) - x}}{\sqrt{x + 1} + \sqrt{x}}}\]
    13. Simplified3.4

      \[\leadsto \color{blue}{\sqrt{\frac{1 + 0}{(x \cdot x + x)_*}}} \cdot \frac{\sqrt{\left(1 + x\right) - x}}{\sqrt{x + 1} + \sqrt{x}}\]
    14. Simplified0.3

      \[\leadsto \sqrt{\frac{1 + 0}{(x \cdot x + x)_*}} \cdot \color{blue}{\frac{\sqrt{1 + 0}}{\sqrt{x + 1} + \sqrt{x}}}\]
    15. Using strategy rm
    16. Applied add-sqr-sqrt0.3

      \[\leadsto \sqrt{\frac{1 + 0}{(x \cdot x + x)_*}} \cdot \frac{\sqrt{1 + 0}}{\color{blue}{\sqrt{\sqrt{x + 1} + \sqrt{x}} \cdot \sqrt{\sqrt{x + 1} + \sqrt{x}}}}\]
    17. Applied add-cube-cbrt0.3

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

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

      \[\leadsto \sqrt{\frac{1 + 0}{(x \cdot x + x)_*}} \cdot \left(\color{blue}{{\left(\sqrt{x} + \sqrt{1 + x}\right)}^{\left(-\frac{1}{2}\right)}} \cdot \frac{\sqrt[3]{\sqrt{1 + 0}}}{\sqrt{\sqrt{x + 1} + \sqrt{x}}}\right)\]
    20. Simplified0.3

      \[\leadsto \sqrt{\frac{1 + 0}{(x \cdot x + x)_*}} \cdot \left({\left(\sqrt{x} + \sqrt{1 + x}\right)}^{\left(-\frac{1}{2}\right)} \cdot \color{blue}{{\left(\sqrt{x} + \sqrt{1 + x}\right)}^{\left(-\frac{1}{2}\right)}}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;{x}^{\left(-\frac{1}{2}\right)} - \frac{1}{\sqrt{1 + x}} \le 1.2189914808529811 \cdot 10^{-94}:\\ \;\;\;\;\frac{\sqrt{1}}{\sqrt{1 + x} + \sqrt{x}} \cdot \left(\left(\frac{1}{x} + \frac{1}{{x}^{3}} \cdot \frac{3}{8}\right) - \frac{1}{2} \cdot \frac{1}{{x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{(x \cdot x + x)_*}} \cdot \left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(-\frac{1}{2}\right)} \cdot {\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(-\frac{1}{2}\right)}\right)\\ \end{array}\]

Runtime

Time bar (total: 5.1m)Debug logProfile

herbie shell --seed 2018214 +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)))))