Average Error: 19.6 → 0.6
Time: 39.1s
Precision: 64
Internal Precision: 128
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 0.029564513659296528:\\ \;\;\;\;{x}^{\frac{-1}{2}} - \frac{1}{\sqrt{1 + x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{(x \cdot \left(\frac{\frac{1 + x}{\sqrt{x}}}{x}\right) + \left(\frac{x}{\sqrt{1 + x}}\right))_*}{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} + \left(\frac{1}{\sqrt{1 + x}} \cdot \frac{1}{\sqrt{1 + x}} - \frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{1 + x}}\right)}}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < 0.029564513659296528

    1. Initial program 0.3

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
    2. Using strategy rm
    3. Applied pow1/20.3

      \[\leadsto \frac{1}{\color{blue}{{x}^{\frac{1}{2}}}} - \frac{1}{\sqrt{x + 1}}\]
    4. Applied pow-flip0.0

      \[\leadsto \color{blue}{{x}^{\left(-\frac{1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\]
    5. Simplified0.0

      \[\leadsto {x}^{\color{blue}{\frac{-1}{2}}} - \frac{1}{\sqrt{x + 1}}\]

    if 0.029564513659296528 < x

    1. Initial program 39.0

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

      \[\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-times48.9

      \[\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-times39.0

      \[\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-sub38.6

      \[\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. Simplified10.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. Simplified10.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 associate-/l/10.7

      \[\leadsto \color{blue}{\frac{1}{\left(\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}\right) \cdot (x \cdot x + x)_*}}\]
    12. Using strategy rm
    13. Applied flip3-+29.8

      \[\leadsto \frac{1}{\color{blue}{\frac{{\left(\frac{1}{\sqrt{x}}\right)}^{3} + {\left(\frac{1}{\sqrt{x + 1}}\right)}^{3}}{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} + \left(\frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}} - \frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x + 1}}\right)}} \cdot (x \cdot x + x)_*}\]
    14. Applied associate-*l/29.9

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

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

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

Runtime

Time bar (total: 39.1s)Debug logProfile

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