Average Error: 19.5 → 19.3
Time: 33.7s
Precision: 64
Internal Precision: 1152
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{x + 1}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}} \le 4.381860511644953 \cdot 10^{-78}:\\ \;\;\;\;\left(\sqrt{\frac{1}{\sqrt{x}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot e^{\log \left(\sqrt{\frac{1}{\sqrt{x}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{x + 1}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}\\ \end{array}\]

Error

Bits error versus x

Target

Original19.5
Target0.7
Herbie19.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)) (pow x (- 1/2))) (/ 1 (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1))))) < 4.381860511644953e-78

    1. Initial program 37.5

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

      \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}}\]
    4. Applied add-sqr-sqrt37.5

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{x}}} \cdot \sqrt{\frac{1}{\sqrt{x}}}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\]
    5. Applied difference-of-squares37.5

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

      \[\leadsto \left(\sqrt{\frac{1}{\sqrt{x}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \color{blue}{e^{\log \left(\sqrt{\frac{1}{\sqrt{x}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}}\]

    if 4.381860511644953e-78 < (/ (- (* (pow x (- 1/2)) (pow x (- 1/2))) (/ 1 (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1)))))

    1. Initial program 6.2

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}}\]
    7. Applied simplify5.8

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

Runtime

Time bar (total: 33.7s)Debug logProfile

herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)' 
(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)))))