Average Error: 19.5 → 19.4
Time: 2.4m
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 2.668373493906622370467320990724522581671 \cdot 10^{101}:\\ \;\;\;\;\frac{\sqrt{1}}{\sqrt{\sqrt[3]{1 + x}}} \cdot \left(\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|} + \left(-\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|}\right)\right) + \mathsf{fma}\left(-\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|}, \frac{\sqrt{1}}{\sqrt{\sqrt[3]{1 + x}}}, \frac{1}{\sqrt{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}}\right)} \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}}\right)}}\right)}^{\left(\sqrt[3]{\log \left(\frac{{\left(\frac{1}{\sqrt{x}}\right)}^{3} - {\left(\frac{1}{\sqrt{1 + x}}\right)}^{3}}{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, \frac{1}{\sqrt{x}}, \left(\frac{1}{\sqrt{1 + x}} + \frac{1}{\sqrt{x}}\right) \cdot \frac{1}{\sqrt{1 + x}}\right)}\right)}\right)}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 2.668373493906622370467320990724522581671 \cdot 10^{101}:\\
\;\;\;\;\frac{\sqrt{1}}{\sqrt{\sqrt[3]{1 + x}}} \cdot \left(\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|} + \left(-\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|}\right)\right) + \mathsf{fma}\left(-\frac{\sqrt{1}}{\left|\sqrt[3]{1 + x}\right|}, \frac{\sqrt{1}}{\sqrt{\sqrt[3]{1 + x}}}, \frac{1}{\sqrt{x}}\right)\\

\mathbf{else}:\\
\;\;\;\;{\left(e^{\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}}\right)} \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}}\right)}}\right)}^{\left(\sqrt[3]{\log \left(\frac{{\left(\frac{1}{\sqrt{x}}\right)}^{3} - {\left(\frac{1}{\sqrt{1 + x}}\right)}^{3}}{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, \frac{1}{\sqrt{x}}, \left(\frac{1}{\sqrt{1 + x}} + \frac{1}{\sqrt{x}}\right) \cdot \frac{1}{\sqrt{1 + x}}\right)}\right)}\right)}\\

\end{array}
double f(double x) {
        double r619111 = 1.0;
        double r619112 = x;
        double r619113 = sqrt(r619112);
        double r619114 = r619111 / r619113;
        double r619115 = r619112 + r619111;
        double r619116 = sqrt(r619115);
        double r619117 = r619111 / r619116;
        double r619118 = r619114 - r619117;
        return r619118;
}

double f(double x) {
        double r619119 = x;
        double r619120 = 2.6683734939066224e+101;
        bool r619121 = r619119 <= r619120;
        double r619122 = 1.0;
        double r619123 = sqrt(r619122);
        double r619124 = r619122 + r619119;
        double r619125 = cbrt(r619124);
        double r619126 = sqrt(r619125);
        double r619127 = r619123 / r619126;
        double r619128 = fabs(r619125);
        double r619129 = r619123 / r619128;
        double r619130 = -r619129;
        double r619131 = r619129 + r619130;
        double r619132 = r619127 * r619131;
        double r619133 = sqrt(r619119);
        double r619134 = r619122 / r619133;
        double r619135 = fma(r619130, r619127, r619134);
        double r619136 = r619132 + r619135;
        double r619137 = sqrt(r619124);
        double r619138 = r619122 / r619137;
        double r619139 = r619134 - r619138;
        double r619140 = log(r619139);
        double r619141 = cbrt(r619140);
        double r619142 = r619141 * r619141;
        double r619143 = exp(r619142);
        double r619144 = 3.0;
        double r619145 = pow(r619134, r619144);
        double r619146 = pow(r619138, r619144);
        double r619147 = r619145 - r619146;
        double r619148 = r619138 + r619134;
        double r619149 = r619148 * r619138;
        double r619150 = fma(r619134, r619134, r619149);
        double r619151 = r619147 / r619150;
        double r619152 = log(r619151);
        double r619153 = cbrt(r619152);
        double r619154 = pow(r619143, r619153);
        double r619155 = r619121 ? r619136 : r619154;
        return r619155;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < 2.6683734939066224e+101

    1. Initial program 14.2

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

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{\color{blue}{\left(\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1}\right) \cdot \sqrt[3]{x + 1}}}}\]
    4. Applied sqrt-prod14.1

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

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

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

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

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

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

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

    if 2.6683734939066224e+101 < x

    1. Initial program 30.4

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

      \[\leadsto \color{blue}{e^{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt30.4

      \[\leadsto e^{\color{blue}{\left(\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)} \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}\right) \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}}}\]
    6. Applied exp-prod30.4

      \[\leadsto \color{blue}{{\left(e^{\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)} \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}}\right)}^{\left(\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}\right)}}\]
    7. Using strategy rm
    8. Applied flip3--30.4

      \[\leadsto {\left(e^{\sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)} \cdot \sqrt[3]{\log \left(\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)}}\right)}^{\left(\sqrt[3]{\log \color{blue}{\left(\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)}\right)}}\right)}\]
    9. Simplified30.4

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

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

Reproduce

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