Average Error: 19.6 → 0.7
Time: 6.6s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\frac{1 \cdot \log \left(e^{1} \cdot e^{x - x}\right)}{\mathsf{fma}\left(\sqrt{x}, x + 1, \sqrt{x \cdot \sqrt{x + 1}} \cdot \sqrt{x \cdot \sqrt{x + 1}}\right)}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1 \cdot \log \left(e^{1} \cdot e^{x - x}\right)}{\mathsf{fma}\left(\sqrt{x}, x + 1, \sqrt{x \cdot \sqrt{x + 1}} \cdot \sqrt{x \cdot \sqrt{x + 1}}\right)}
double f(double x) {
        double r161758 = 1.0;
        double r161759 = x;
        double r161760 = sqrt(r161759);
        double r161761 = r161758 / r161760;
        double r161762 = r161759 + r161758;
        double r161763 = sqrt(r161762);
        double r161764 = r161758 / r161763;
        double r161765 = r161761 - r161764;
        return r161765;
}

double f(double x) {
        double r161766 = 1.0;
        double r161767 = exp(r161766);
        double r161768 = x;
        double r161769 = r161768 - r161768;
        double r161770 = exp(r161769);
        double r161771 = r161767 * r161770;
        double r161772 = log(r161771);
        double r161773 = r161766 * r161772;
        double r161774 = sqrt(r161768);
        double r161775 = r161768 + r161766;
        double r161776 = sqrt(r161775);
        double r161777 = r161768 * r161776;
        double r161778 = sqrt(r161777);
        double r161779 = r161778 * r161778;
        double r161780 = fma(r161774, r161775, r161779);
        double r161781 = r161773 / r161780;
        return r161781;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 19.6

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

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

    \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{x + 1} - \sqrt{x}\right)}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  5. Using strategy rm
  6. Applied flip--19.4

    \[\leadsto \frac{1 \cdot \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  7. Applied associate-*r/19.4

    \[\leadsto \frac{\color{blue}{\frac{1 \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right)}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{x + 1}}\]
  8. Applied associate-/l/19.4

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

    \[\leadsto \frac{1 \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right)}{\color{blue}{\mathsf{fma}\left(\sqrt{x}, x + 1, x \cdot \sqrt{x + 1}\right)}}\]
  10. Using strategy rm
  11. Applied add-log-exp31.6

    \[\leadsto \frac{1 \cdot \left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \color{blue}{\log \left(e^{\sqrt{x} \cdot \sqrt{x}}\right)}\right)}{\mathsf{fma}\left(\sqrt{x}, x + 1, x \cdot \sqrt{x + 1}\right)}\]
  12. Applied add-log-exp31.6

    \[\leadsto \frac{1 \cdot \left(\color{blue}{\log \left(e^{\sqrt{x + 1} \cdot \sqrt{x + 1}}\right)} - \log \left(e^{\sqrt{x} \cdot \sqrt{x}}\right)\right)}{\mathsf{fma}\left(\sqrt{x}, x + 1, x \cdot \sqrt{x + 1}\right)}\]
  13. Applied diff-log31.6

    \[\leadsto \frac{1 \cdot \color{blue}{\log \left(\frac{e^{\sqrt{x + 1} \cdot \sqrt{x + 1}}}{e^{\sqrt{x} \cdot \sqrt{x}}}\right)}}{\mathsf{fma}\left(\sqrt{x}, x + 1, x \cdot \sqrt{x + 1}\right)}\]
  14. Simplified0.7

    \[\leadsto \frac{1 \cdot \log \color{blue}{\left(e^{1} \cdot e^{x - x}\right)}}{\mathsf{fma}\left(\sqrt{x}, x + 1, x \cdot \sqrt{x + 1}\right)}\]
  15. Using strategy rm
  16. Applied add-sqr-sqrt0.7

    \[\leadsto \frac{1 \cdot \log \left(e^{1} \cdot e^{x - x}\right)}{\mathsf{fma}\left(\sqrt{x}, x + 1, \color{blue}{\sqrt{x \cdot \sqrt{x + 1}} \cdot \sqrt{x \cdot \sqrt{x + 1}}}\right)}\]
  17. Final simplification0.7

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

Reproduce

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

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

  (- (/ 1 (sqrt x)) (/ 1 (sqrt (+ x 1)))))