Average Error: 30.0 → 0.2
Time: 33.7s
Precision: 64
\[\sqrt{x + 1} - \sqrt{x}\]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1} + \sqrt{x}}\right)\right)\]
\sqrt{x + 1} - \sqrt{x}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1} + \sqrt{x}}\right)\right)
double f(double x) {
        double r5620418 = x;
        double r5620419 = 1.0;
        double r5620420 = r5620418 + r5620419;
        double r5620421 = sqrt(r5620420);
        double r5620422 = sqrt(r5620418);
        double r5620423 = r5620421 - r5620422;
        return r5620423;
}

double f(double x) {
        double r5620424 = 1.0;
        double r5620425 = x;
        double r5620426 = r5620425 + r5620424;
        double r5620427 = sqrt(r5620426);
        double r5620428 = sqrt(r5620425);
        double r5620429 = r5620427 + r5620428;
        double r5620430 = r5620424 / r5620429;
        double r5620431 = log1p(r5620430);
        double r5620432 = expm1(r5620431);
        return r5620432;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.9

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

    \[\leadsto \frac{\color{blue}{\left(x + 1\right) - x}}{\sqrt{x + 1} + \sqrt{x}}\]
  5. Taylor expanded around 0 0.2

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}\]
  6. Using strategy rm
  7. Applied expm1-log1p-u0.2

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

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

Reproduce

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

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

  (- (sqrt (+ x 1.0)) (sqrt x)))