Average Error: 29.6 → 0.2
Time: 18.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 r5856883 = x;
        double r5856884 = 1.0;
        double r5856885 = r5856883 + r5856884;
        double r5856886 = sqrt(r5856885);
        double r5856887 = sqrt(r5856883);
        double r5856888 = r5856886 - r5856887;
        return r5856888;
}

double f(double x) {
        double r5856889 = 1.0;
        double r5856890 = x;
        double r5856891 = r5856890 + r5856889;
        double r5856892 = sqrt(r5856891);
        double r5856893 = sqrt(r5856890);
        double r5856894 = r5856892 + r5856893;
        double r5856895 = r5856889 / r5856894;
        double r5856896 = log1p(r5856895);
        double r5856897 = expm1(r5856896);
        return r5856897;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 29.6

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

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

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

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

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

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

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

Reproduce

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