Average Error: 30.2 → 0.2
Time: 21.4s
Precision: 64
\[\sqrt{x + 1} - \sqrt{x}\]
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}}\]
double f(double x) {
        double r12434734 = x;
        double r12434735 = 1.0;
        double r12434736 = r12434734 + r12434735;
        double r12434737 = sqrt(r12434736);
        double r12434738 = sqrt(r12434734);
        double r12434739 = r12434737 - r12434738;
        return r12434739;
}

double f(double x) {
        double r12434740 = 1.0;
        double r12434741 = x;
        double r12434742 = r12434741 + r12434740;
        double r12434743 = sqrt(r12434742);
        double r12434744 = sqrt(r12434741);
        double r12434745 = r12434743 + r12434744;
        double r12434746 = r12434740 / r12434745;
        return r12434746;
}

\sqrt{x + 1} - \sqrt{x}
\frac{1}{\sqrt{x + 1} + \sqrt{x}}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 30.2

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

    \[\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. Final simplification0.2

    \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}}\]

Reproduce

herbie shell --seed 2019101 
(FPCore (x)
  :name "2sqrt (example 3.1)"

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

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