Average Error: 19.8 → 0.6
Time: 2.4m
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\frac{1}{\mathsf{fma}\left(\left(x + 1\right), \left(\sqrt{x}\right), \left(x \cdot \sqrt{x + 1}\right)\right)}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1}{\mathsf{fma}\left(\left(x + 1\right), \left(\sqrt{x}\right), \left(x \cdot \sqrt{x + 1}\right)\right)}
double f(double x) {
        double r11009495 = 1.0;
        double r11009496 = x;
        double r11009497 = sqrt(r11009496);
        double r11009498 = r11009495 / r11009497;
        double r11009499 = r11009496 + r11009495;
        double r11009500 = sqrt(r11009499);
        double r11009501 = r11009495 / r11009500;
        double r11009502 = r11009498 - r11009501;
        return r11009502;
}

double f(double x) {
        double r11009503 = 1.0;
        double r11009504 = x;
        double r11009505 = r11009504 + r11009503;
        double r11009506 = sqrt(r11009504);
        double r11009507 = sqrt(r11009505);
        double r11009508 = r11009504 * r11009507;
        double r11009509 = fma(r11009505, r11009506, r11009508);
        double r11009510 = r11009503 / r11009509;
        return r11009510;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 19.8

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

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

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

    \[\leadsto \frac{\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-/l/19.6

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

    \[\leadsto \frac{\color{blue}{1}}{\left(\sqrt{x} \cdot \sqrt{x + 1}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}\]
  9. Using strategy rm
  10. Applied pow10.8

    \[\leadsto \frac{1}{\left(\sqrt{x} \cdot \sqrt{x + 1}\right) \cdot \color{blue}{{\left(\sqrt{x + 1} + \sqrt{x}\right)}^{1}}}\]
  11. Applied pow10.8

    \[\leadsto \frac{1}{\left(\sqrt{x} \cdot \color{blue}{{\left(\sqrt{x + 1}\right)}^{1}}\right) \cdot {\left(\sqrt{x + 1} + \sqrt{x}\right)}^{1}}\]
  12. Applied pow10.8

    \[\leadsto \frac{1}{\left(\color{blue}{{\left(\sqrt{x}\right)}^{1}} \cdot {\left(\sqrt{x + 1}\right)}^{1}\right) \cdot {\left(\sqrt{x + 1} + \sqrt{x}\right)}^{1}}\]
  13. Applied pow-prod-down0.8

    \[\leadsto \frac{1}{\color{blue}{{\left(\sqrt{x} \cdot \sqrt{x + 1}\right)}^{1}} \cdot {\left(\sqrt{x + 1} + \sqrt{x}\right)}^{1}}\]
  14. Applied pow-prod-down0.8

    \[\leadsto \frac{1}{\color{blue}{{\left(\left(\sqrt{x} \cdot \sqrt{x + 1}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)\right)}^{1}}}\]
  15. Simplified0.6

    \[\leadsto \frac{1}{{\color{blue}{\left(\sqrt{x + 1} \cdot \mathsf{fma}\left(\left(\sqrt{x}\right), \left(\sqrt{x + 1}\right), x\right)\right)}}^{1}}\]
  16. Using strategy rm
  17. Applied *-un-lft-identity0.6

    \[\leadsto \frac{1}{\color{blue}{1 \cdot {\left(\sqrt{x + 1} \cdot \mathsf{fma}\left(\left(\sqrt{x}\right), \left(\sqrt{x + 1}\right), x\right)\right)}^{1}}}\]
  18. Applied add-sqr-sqrt0.6

    \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot {\left(\sqrt{x + 1} \cdot \mathsf{fma}\left(\left(\sqrt{x}\right), \left(\sqrt{x + 1}\right), x\right)\right)}^{1}}\]
  19. Applied times-frac0.6

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

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

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

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

Reproduce

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