Average Error: 20.1 → 19.9
Time: 31.5s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 9.993638768580708575728490299319521227813 \cdot 10^{79}:\\ \;\;\;\;\left(\frac{1}{\sqrt{x}} - \frac{\frac{1}{\sqrt{\sqrt{1 + x}}}}{\sqrt{\sqrt{1 + x}}}\right) + \mathsf{fma}\left(\frac{1}{\sqrt{\sqrt{1 + x}}}, \frac{-1}{\sqrt{\sqrt{1 + x}}}, \frac{\frac{1}{\sqrt{\sqrt{1 + x}}}}{\sqrt{\sqrt{1 + x}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}}\right) \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \cdot \left(\frac{1}{\sqrt{1 + x}} \cdot \frac{1}{\sqrt{1 + x}}\right)}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + x}}, \frac{1}{\sqrt{1 + x}} + \frac{1}{\sqrt{x}}, \frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}}\right)}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 9.993638768580708575728490299319521227813 \cdot 10^{79}:\\
\;\;\;\;\left(\frac{1}{\sqrt{x}} - \frac{\frac{1}{\sqrt{\sqrt{1 + x}}}}{\sqrt{\sqrt{1 + x}}}\right) + \mathsf{fma}\left(\frac{1}{\sqrt{\sqrt{1 + x}}}, \frac{-1}{\sqrt{\sqrt{1 + x}}}, \frac{\frac{1}{\sqrt{\sqrt{1 + x}}}}{\sqrt{\sqrt{1 + x}}}\right)\\

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

\end{array}
double f(double x) {
        double r5978813 = 1.0;
        double r5978814 = x;
        double r5978815 = sqrt(r5978814);
        double r5978816 = r5978813 / r5978815;
        double r5978817 = r5978814 + r5978813;
        double r5978818 = sqrt(r5978817);
        double r5978819 = r5978813 / r5978818;
        double r5978820 = r5978816 - r5978819;
        return r5978820;
}

double f(double x) {
        double r5978821 = x;
        double r5978822 = 9.993638768580709e+79;
        bool r5978823 = r5978821 <= r5978822;
        double r5978824 = 1.0;
        double r5978825 = sqrt(r5978821);
        double r5978826 = r5978824 / r5978825;
        double r5978827 = r5978824 + r5978821;
        double r5978828 = sqrt(r5978827);
        double r5978829 = sqrt(r5978828);
        double r5978830 = r5978824 / r5978829;
        double r5978831 = r5978830 / r5978829;
        double r5978832 = r5978826 - r5978831;
        double r5978833 = -1.0;
        double r5978834 = r5978833 / r5978829;
        double r5978835 = fma(r5978830, r5978834, r5978831);
        double r5978836 = r5978832 + r5978835;
        double r5978837 = r5978826 * r5978826;
        double r5978838 = r5978837 * r5978826;
        double r5978839 = r5978824 / r5978828;
        double r5978840 = r5978839 * r5978839;
        double r5978841 = r5978839 * r5978840;
        double r5978842 = r5978838 - r5978841;
        double r5978843 = r5978839 + r5978826;
        double r5978844 = fma(r5978839, r5978843, r5978837);
        double r5978845 = r5978842 / r5978844;
        double r5978846 = r5978823 ? r5978836 : r5978845;
        return r5978846;
}

Error

Bits error versus x

Target

Original20.1
Target0.6
Herbie19.9
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < 9.993638768580709e+79

    1. Initial program 11.5

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

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

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}}\]
    5. Applied *-un-lft-identity11.5

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{\color{blue}{1 \cdot 1}}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}\]
    6. Applied times-frac11.4

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

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{x}}} \cdot \sqrt{\frac{1}{\sqrt{x}}}} - \frac{1}{\sqrt{\sqrt{x + 1}}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}\]
    8. Applied prod-diff11.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{1}{\sqrt{x}}}, \sqrt{\frac{1}{\sqrt{x}}}, -\frac{1}{\sqrt{\sqrt{x + 1}}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}\right) + \mathsf{fma}\left(-\frac{1}{\sqrt{\sqrt{x + 1}}}, \frac{1}{\sqrt{\sqrt{x + 1}}}, \frac{1}{\sqrt{\sqrt{x + 1}}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}\right)}\]
    9. Simplified11.3

      \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{x}} - \frac{\frac{1}{\sqrt{\sqrt{x + 1}}}}{\sqrt{\sqrt{x + 1}}}\right)} + \mathsf{fma}\left(-\frac{1}{\sqrt{\sqrt{x + 1}}}, \frac{1}{\sqrt{\sqrt{x + 1}}}, \frac{1}{\sqrt{\sqrt{x + 1}}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}\right)\]
    10. Simplified11.3

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

    if 9.993638768580709e+79 < x

    1. Initial program 34.3

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

      \[\leadsto \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)}}\]
    4. Simplified34.3

      \[\leadsto \frac{\color{blue}{\left(\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}}\right) \cdot \frac{1}{\sqrt{x}} - \left(\frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}\right) \cdot \frac{1}{\sqrt{x + 1}}}}{\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)}\]
    5. Simplified34.3

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

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

Reproduce

herbie shell --seed 2019192 +o rules:numerics
(FPCore (x)
  :name "2isqrt (example 3.6)"

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))