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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{5}{16}, \sqrt{\frac{1}{{x}^{7}}}, \sqrt{\frac{1}{\left(x \cdot x\right) \cdot x}} \cdot \frac{1}{2}\right) - \sqrt{\frac{1}{{x}^{5}}} \cdot \frac{3}{8}\\

\end{array}
double f(double x) {
        double r5216534 = 1.0;
        double r5216535 = x;
        double r5216536 = sqrt(r5216535);
        double r5216537 = r5216534 / r5216536;
        double r5216538 = r5216535 + r5216534;
        double r5216539 = sqrt(r5216538);
        double r5216540 = r5216534 / r5216539;
        double r5216541 = r5216537 - r5216540;
        return r5216541;
}

double f(double x) {
        double r5216542 = x;
        double r5216543 = 7517.51302646943;
        bool r5216544 = r5216542 <= r5216543;
        double r5216545 = -1.0;
        double r5216546 = 1.0;
        double r5216547 = r5216546 + r5216542;
        double r5216548 = sqrt(r5216547);
        double r5216549 = sqrt(r5216548);
        double r5216550 = r5216545 / r5216549;
        double r5216551 = r5216546 / r5216549;
        double r5216552 = r5216551 * r5216551;
        double r5216553 = fma(r5216550, r5216551, r5216552);
        double r5216554 = -0.5;
        double r5216555 = pow(r5216542, r5216554);
        double r5216556 = -r5216552;
        double r5216557 = fma(r5216546, r5216555, r5216556);
        double r5216558 = r5216553 + r5216557;
        double r5216559 = 0.3125;
        double r5216560 = 7.0;
        double r5216561 = pow(r5216542, r5216560);
        double r5216562 = r5216546 / r5216561;
        double r5216563 = sqrt(r5216562);
        double r5216564 = r5216542 * r5216542;
        double r5216565 = r5216564 * r5216542;
        double r5216566 = r5216546 / r5216565;
        double r5216567 = sqrt(r5216566);
        double r5216568 = 0.5;
        double r5216569 = r5216567 * r5216568;
        double r5216570 = fma(r5216559, r5216563, r5216569);
        double r5216571 = 5.0;
        double r5216572 = pow(r5216542, r5216571);
        double r5216573 = r5216546 / r5216572;
        double r5216574 = sqrt(r5216573);
        double r5216575 = 0.375;
        double r5216576 = r5216574 * r5216575;
        double r5216577 = r5216570 - r5216576;
        double r5216578 = r5216544 ? r5216558 : r5216577;
        return r5216578;
}

Error

Bits error versus x

Target

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

Derivation

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

    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.1

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

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

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

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

      \[\leadsto {x}^{\frac{-1}{2}} - \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}\]
    10. Applied times-frac0.1

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

      \[\leadsto \color{blue}{1 \cdot {x}^{\frac{-1}{2}}} - \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}} \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\]
    12. Applied prod-diff0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, {x}^{\frac{-1}{2}}, -\frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}} \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\right) + \mathsf{fma}\left(-\frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}, \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}, \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}} \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\right)}\]

    if 7517.51302646943 < x

    1. Initial program 39.6

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

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

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

      \[\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. Taylor expanded around inf 21.7

      \[\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}}}}\]
    7. Simplified21.7

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

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

Reproduce

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