Average Error: 19.9 → 10.6
Time: 1.1m
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 7495.91023062866:\\ \;\;\;\;{x}^{\frac{-1}{2}} - \sqrt{\frac{1}{\sqrt{1 + x}}} \cdot \sqrt{\frac{1}{\sqrt{1 + x}}}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{\frac{1}{\left(x \cdot x\right) \cdot x}} \cdot \frac{1}{2} - \sqrt{\frac{1}{{x}^{5}}} \cdot \frac{3}{8}\right) - \frac{-5}{16} \cdot \sqrt{\frac{1}{{x}^{7}}}\\ \end{array}\]

Error

Bits error versus x

Target

Original19.9
Target0.7
Herbie10.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 < 7495.91023062866

    1. Initial program 0.3

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{{x}^{1}}}} - \frac{1}{\sqrt{x + 1}}\]
    4. Applied sqrt-pow10.3

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

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

      \[\leadsto {x}^{\color{blue}{\frac{-1}{2}}} - \frac{1}{\sqrt{x + 1}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

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

    if 7495.91023062866 < x

    1. Initial program 40.0

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

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

      \[\leadsto \frac{1}{\color{blue}{{x}^{\left(\frac{1}{2}\right)}}} - \frac{1}{\sqrt{x + 1}}\]
    5. Applied pow-flip44.7

      \[\leadsto \color{blue}{{x}^{\left(-\frac{1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\]
    6. Simplified44.7

      \[\leadsto {x}^{\color{blue}{\frac{-1}{2}}} - \frac{1}{\sqrt{x + 1}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt50.9

      \[\leadsto {x}^{\frac{-1}{2}} - \color{blue}{\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}}\]
    9. Applied add-sqr-sqrt42.4

      \[\leadsto \color{blue}{\sqrt{{x}^{\frac{-1}{2}}} \cdot \sqrt{{x}^{\frac{-1}{2}}}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\]
    10. Applied difference-of-squares42.4

      \[\leadsto \color{blue}{\left(\sqrt{{x}^{\frac{-1}{2}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \left(\sqrt{{x}^{\frac{-1}{2}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}\]
    11. Using strategy rm
    12. Applied add-log-exp42.4

      \[\leadsto \left(\sqrt{{x}^{\frac{-1}{2}}} + \sqrt{\color{blue}{\log \left(e^{\frac{1}{\sqrt{x + 1}}}\right)}}\right) \cdot \left(\sqrt{{x}^{\frac{-1}{2}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)\]
    13. Taylor expanded around inf 21.3

      \[\leadsto \color{blue}{\left(\frac{5}{16} \cdot \sqrt{\frac{1}{{x}^{7}}} + \frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}}\right) - \frac{3}{8} \cdot \sqrt{\frac{1}{{x}^{5}}}}\]
    14. Simplified21.3

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \frac{1}{2} - \frac{3}{8} \cdot \sqrt{\frac{1}{{x}^{5}}}\right) - \sqrt{\frac{1}{{x}^{7}}} \cdot \frac{-5}{16}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification10.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 7495.91023062866:\\ \;\;\;\;{x}^{\frac{-1}{2}} - \sqrt{\frac{1}{\sqrt{1 + x}}} \cdot \sqrt{\frac{1}{\sqrt{1 + x}}}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{\frac{1}{\left(x \cdot x\right) \cdot x}} \cdot \frac{1}{2} - \sqrt{\frac{1}{{x}^{5}}} \cdot \frac{3}{8}\right) - \frac{-5}{16} \cdot \sqrt{\frac{1}{{x}^{7}}}\\ \end{array}\]

Reproduce

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