Average Error: 30.0 → 0.2
Time: 27.9s
Precision: 64
\[\sqrt{x + 1} - \sqrt{x}\]
\[\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{\mathsf{fma}\left(\left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{x}\right)\right)}\right)\right)\right)\right)\]
\sqrt{x + 1} - \sqrt{x}
\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{\mathsf{fma}\left(\left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{x}\right)\right)}\right)\right)\right)\right)
double f(double x) {
        double r7103732 = x;
        double r7103733 = 1.0;
        double r7103734 = r7103732 + r7103733;
        double r7103735 = sqrt(r7103734);
        double r7103736 = sqrt(r7103732);
        double r7103737 = r7103735 - r7103736;
        return r7103737;
}

double f(double x) {
        double r7103738 = 1.0;
        double r7103739 = x;
        double r7103740 = r7103739 + r7103738;
        double r7103741 = sqrt(r7103740);
        double r7103742 = sqrt(r7103741);
        double r7103743 = sqrt(r7103739);
        double r7103744 = fma(r7103742, r7103742, r7103743);
        double r7103745 = r7103738 / r7103744;
        double r7103746 = log1p(r7103745);
        double r7103747 = expm1(r7103746);
        return r7103747;
}

Error

Bits error versus x

Target

Original30.0
Target0.2
Herbie0.2
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}}\]

Derivation

  1. Initial program 30.0

    \[\sqrt{x + 1} - \sqrt{x}\]
  2. Using strategy rm
  3. Applied flip--29.8

    \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}\]
  4. Taylor expanded around inf 0.2

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt0.2

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

    \[\leadsto \frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}} + \sqrt{x}}\]
  8. Applied fma-def0.2

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{x}\right)\right)}}\]
  9. Using strategy rm
  10. Applied expm1-log1p-u0.2

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{\mathsf{fma}\left(\left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{\sqrt{x + 1}}\right), \left(\sqrt{x}\right)\right)}\right)\right)\right)\right)}\]
  11. Final simplification0.2

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

Reproduce

herbie shell --seed 2019124 +o rules:numerics
(FPCore (x)
  :name "2sqrt (example 3.1)"

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

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