Average Error: 19.4 → 19.3
Time: 17.2s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 8.343787893268626 \cdot 10^{+200}:\\ \;\;\;\;{x}^{\frac{-1}{2}} - \frac{1}{\sqrt{1 + x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\frac{-1}{2}} \cdot \frac{1}{x} - \frac{\frac{1}{1 + x}}{\sqrt{1 + x}}}{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{{x}^{\frac{-1}{2}}}{\sqrt{1 + x}}\right) + \frac{1}{1 + x}}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 8.343787893268626 \cdot 10^{+200}:\\
\;\;\;\;{x}^{\frac{-1}{2}} - \frac{1}{\sqrt{1 + x}}\\

\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\frac{-1}{2}} \cdot \frac{1}{x} - \frac{\frac{1}{1 + x}}{\sqrt{1 + x}}}{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{{x}^{\frac{-1}{2}}}{\sqrt{1 + x}}\right) + \frac{1}{1 + x}}\\

\end{array}
double f(double x) {
        double r5506535 = 1.0;
        double r5506536 = x;
        double r5506537 = sqrt(r5506536);
        double r5506538 = r5506535 / r5506537;
        double r5506539 = r5506536 + r5506535;
        double r5506540 = sqrt(r5506539);
        double r5506541 = r5506535 / r5506540;
        double r5506542 = r5506538 - r5506541;
        return r5506542;
}

double f(double x) {
        double r5506543 = x;
        double r5506544 = 8.343787893268626e+200;
        bool r5506545 = r5506543 <= r5506544;
        double r5506546 = -0.5;
        double r5506547 = pow(r5506543, r5506546);
        double r5506548 = 1.0;
        double r5506549 = r5506548 + r5506543;
        double r5506550 = sqrt(r5506549);
        double r5506551 = r5506548 / r5506550;
        double r5506552 = r5506547 - r5506551;
        double r5506553 = r5506548 / r5506543;
        double r5506554 = r5506547 * r5506553;
        double r5506555 = r5506548 / r5506549;
        double r5506556 = r5506555 / r5506550;
        double r5506557 = r5506554 - r5506556;
        double r5506558 = r5506547 / r5506550;
        double r5506559 = fma(r5506547, r5506547, r5506558);
        double r5506560 = r5506559 + r5506555;
        double r5506561 = r5506557 / r5506560;
        double r5506562 = r5506545 ? r5506552 : r5506561;
        return r5506562;
}

Error

Bits error versus x

Target

Original19.4
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 x < 8.343787893268626e+200

    1. Initial program 22.5

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

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

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

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

    if 8.343787893268626e+200 < x

    1. Initial program 4.8

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 8.343787893268626 \cdot 10^{+200}:\\ \;\;\;\;{x}^{\frac{-1}{2}} - \frac{1}{\sqrt{1 + x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\frac{-1}{2}} \cdot \frac{1}{x} - \frac{\frac{1}{1 + x}}{\sqrt{1 + x}}}{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{{x}^{\frac{-1}{2}}}{\sqrt{1 + x}}\right) + \frac{1}{1 + x}}\\ \end{array}\]

Reproduce

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