Average Error: 30.8 → 0.2
Time: 5.8s
Precision: 64
\[\sqrt{x + 1} - \sqrt{x}\]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1 + 0}{\sqrt{x + 1} + \sqrt{x}}\right)\right)\]
\sqrt{x + 1} - \sqrt{x}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1 + 0}{\sqrt{x + 1} + \sqrt{x}}\right)\right)
double f(double x) {
        double r137091 = x;
        double r137092 = 1.0;
        double r137093 = r137091 + r137092;
        double r137094 = sqrt(r137093);
        double r137095 = sqrt(r137091);
        double r137096 = r137094 - r137095;
        return r137096;
}

double f(double x) {
        double r137097 = 1.0;
        double r137098 = 0.0;
        double r137099 = r137097 + r137098;
        double r137100 = x;
        double r137101 = r137100 + r137097;
        double r137102 = sqrt(r137101);
        double r137103 = sqrt(r137100);
        double r137104 = r137102 + r137103;
        double r137105 = r137099 / r137104;
        double r137106 = log1p(r137105);
        double r137107 = expm1(r137106);
        return r137107;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 30.8

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1 + 0}{\sqrt{x + 1} + \sqrt{x}}\right)\right)\right)\right)}\]
  9. Simplified0.2

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

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

Reproduce

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

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

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