Average Error: 29.0 → 0.2
Time: 16.8s
Precision: 64
\[\sqrt{x + 1} - \sqrt{x}\]
\[\mathsf{log1p}\left(\left(\mathsf{expm1}\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{log1p}\left(\left(\mathsf{expm1}\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 r3440319 = x;
        double r3440320 = 1.0;
        double r3440321 = r3440319 + r3440320;
        double r3440322 = sqrt(r3440321);
        double r3440323 = sqrt(r3440319);
        double r3440324 = r3440322 - r3440323;
        return r3440324;
}

double f(double x) {
        double r3440325 = 1.0;
        double r3440326 = x;
        double r3440327 = r3440326 + r3440325;
        double r3440328 = sqrt(r3440327);
        double r3440329 = sqrt(r3440328);
        double r3440330 = sqrt(r3440326);
        double r3440331 = fma(r3440329, r3440329, r3440330);
        double r3440332 = r3440325 / r3440331;
        double r3440333 = expm1(r3440332);
        double r3440334 = log1p(r3440333);
        return r3440334;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.0

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

    \[\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}}{\sqrt{x + 1} + \sqrt{x}}\]
  5. Using strategy rm
  6. Applied log1p-expm1-u0.2

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

    \[\leadsto \mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}} + \sqrt{x}}\right)\right)\right)\right)\]
  9. Applied fma-def0.2

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

    \[\leadsto \mathsf{log1p}\left(\left(\mathsf{expm1}\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 2019130 +o rules:numerics
(FPCore (x)
  :name "2sqrt (example 3.1)"

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

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