Average Error: 20.1 → 0.8
Time: 9.8s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\frac{1}{\left(\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right) \cdot x\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right)}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1}{\left(\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right) \cdot x\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right)}
double f(double x) {
        double r151284 = 1.0;
        double r151285 = x;
        double r151286 = sqrt(r151285);
        double r151287 = r151284 / r151286;
        double r151288 = r151285 + r151284;
        double r151289 = sqrt(r151288);
        double r151290 = r151284 / r151289;
        double r151291 = r151287 - r151290;
        return r151291;
}

double f(double x) {
        double r151292 = 1.0;
        double r151293 = 1.0;
        double r151294 = x;
        double r151295 = r151294 + r151292;
        double r151296 = sqrt(r151295);
        double r151297 = r151293 / r151296;
        double r151298 = sqrt(r151294);
        double r151299 = r151292 / r151298;
        double r151300 = fma(r151297, r151292, r151299);
        double r151301 = r151300 * r151294;
        double r151302 = r151296 / r151292;
        double r151303 = r151302 * r151302;
        double r151304 = r151301 * r151303;
        double r151305 = r151292 / r151304;
        return r151305;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 20.1

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

    \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\frac{\sqrt{x + 1}}{1}}}\]
  4. Using strategy rm
  5. Applied flip--20.1

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

    \[\leadsto \frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\frac{\sqrt{x + 1}}{1}} \cdot \frac{1}{\frac{\sqrt{x + 1}}{1}}}{\color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right)}}\]
  7. Using strategy rm
  8. Applied frac-times25.2

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

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

    \[\leadsto \frac{\color{blue}{\frac{\left(1 \cdot 1\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right) - \left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(1 \cdot 1\right)}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right)}}}{\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right)}\]
  11. Applied associate-/l/19.9

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

    \[\leadsto \frac{\left(1 \cdot 1\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right) - \left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(1 \cdot 1\right)}{\color{blue}{\left(\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right) \cdot x\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right)}}\]
  13. Taylor expanded around 0 0.8

    \[\leadsto \frac{\color{blue}{1}}{\left(\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, 1, \frac{1}{\sqrt{x}}\right) \cdot x\right) \cdot \left(\frac{\sqrt{x + 1}}{1} \cdot \frac{\sqrt{x + 1}}{1}\right)}\]
  14. Final simplification0.8

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

Reproduce

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