Average Error: 20.2 → 0.0
Time: 3.8s
Precision: 64
\[0.0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{1}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}\right)\right)\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{1}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}\right)\right)
double f(double x, double y) {
        double r87284 = x;
        double r87285 = y;
        double r87286 = r87284 - r87285;
        double r87287 = r87284 + r87285;
        double r87288 = r87286 * r87287;
        double r87289 = r87284 * r87284;
        double r87290 = r87285 * r87285;
        double r87291 = r87289 + r87290;
        double r87292 = r87288 / r87291;
        return r87292;
}

double f(double x, double y) {
        double r87293 = x;
        double r87294 = y;
        double r87295 = r87293 - r87294;
        double r87296 = hypot(r87293, r87294);
        double r87297 = 1.0;
        double r87298 = r87293 + r87294;
        double r87299 = r87298 / r87296;
        double r87300 = r87297 / r87299;
        double r87301 = r87296 * r87300;
        double r87302 = r87295 / r87301;
        double r87303 = expm1(r87302);
        double r87304 = log1p(r87303);
        return r87304;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.2
Target0.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Initial program 20.2

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Simplified20.3

    \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}}\]
  3. Using strategy rm
  4. Applied *-un-lft-identity20.3

    \[\leadsto \frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{\color{blue}{1 \cdot \left(x + y\right)}}}\]
  5. Applied add-sqr-sqrt20.3

    \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}}{1 \cdot \left(x + y\right)}}\]
  6. Applied times-frac20.2

    \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}}}\]
  7. Simplified20.2

    \[\leadsto \frac{x - y}{\color{blue}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}}\]
  8. Simplified0.0

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}}\]
  9. Using strategy rm
  10. Applied log1p-expm1-u0.0

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x + y}}\right)\right)}\]
  11. Using strategy rm
  12. Applied clear-num0.0

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\frac{1}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}}\right)\right)\]
  13. Final simplification0.0

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{1}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}\right)\right)\]

Reproduce

herbie shell --seed 2020057 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))