Average Error: 19.9 → 5.5
Time: 23.5s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 7911.288097968324:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{\left(\frac{\frac{1}{x \cdot x}}{x \cdot x} + \frac{1}{x \cdot x}\right) - \frac{\frac{1}{x \cdot x}}{x}}{{x}^{\frac{-1}{2}} + \frac{1}{\sqrt{1 + x}}}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 7911.288097968324:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{\left(\frac{\frac{1}{x \cdot x}}{x \cdot x} + \frac{1}{x \cdot x}\right) - \frac{\frac{1}{x \cdot x}}{x}}{{x}^{\frac{-1}{2}} + \frac{1}{\sqrt{1 + x}}}\\

\end{array}
double f(double x) {
        double r3157799 = 1.0;
        double r3157800 = x;
        double r3157801 = sqrt(r3157800);
        double r3157802 = r3157799 / r3157801;
        double r3157803 = r3157800 + r3157799;
        double r3157804 = sqrt(r3157803);
        double r3157805 = r3157799 / r3157804;
        double r3157806 = r3157802 - r3157805;
        return r3157806;
}

double f(double x) {
        double r3157807 = x;
        double r3157808 = 7911.288097968324;
        bool r3157809 = r3157807 <= r3157808;
        double r3157810 = -1.0;
        double r3157811 = 1.0;
        double r3157812 = r3157811 + r3157807;
        double r3157813 = sqrt(r3157812);
        double r3157814 = sqrt(r3157813);
        double r3157815 = r3157810 / r3157814;
        double r3157816 = r3157811 / r3157814;
        double r3157817 = r3157816 * r3157816;
        double r3157818 = fma(r3157815, r3157816, r3157817);
        double r3157819 = -0.5;
        double r3157820 = pow(r3157807, r3157819);
        double r3157821 = -r3157817;
        double r3157822 = fma(r3157811, r3157820, r3157821);
        double r3157823 = r3157818 + r3157822;
        double r3157824 = r3157807 * r3157807;
        double r3157825 = r3157811 / r3157824;
        double r3157826 = r3157825 / r3157824;
        double r3157827 = r3157826 + r3157825;
        double r3157828 = r3157825 / r3157807;
        double r3157829 = r3157827 - r3157828;
        double r3157830 = r3157811 / r3157813;
        double r3157831 = r3157820 + r3157830;
        double r3157832 = r3157829 / r3157831;
        double r3157833 = r3157809 ? r3157823 : r3157832;
        return r3157833;
}

Error

Bits error versus x

Target

Original19.9
Target0.7
Herbie5.5
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]

Derivation

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

    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 7911.288097968324 < x

    1. Initial program 39.6

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

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\frac{-1}{2}} \cdot {x}^{\frac{-1}{2}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{{x}^{\frac{-1}{2}} + \frac{1}{\sqrt{x + 1}}}}\]
    8. Taylor expanded around inf 10.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 7911.288097968324:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{\left(\frac{\frac{1}{x \cdot x}}{x \cdot x} + \frac{1}{x \cdot x}\right) - \frac{\frac{1}{x \cdot x}}{x}}{{x}^{\frac{-1}{2}} + \frac{1}{\sqrt{1 + x}}}\\ \end{array}\]

Reproduce

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