Average Error: 20.8 → 0.0
Time: 17.4s
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}\]
\[\log \left(e^{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}\right)\right)}\right)\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\log \left(e^{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}\right)\right)}\right)
double f(double x, double y) {
        double r127563 = x;
        double r127564 = y;
        double r127565 = r127563 - r127564;
        double r127566 = r127563 + r127564;
        double r127567 = r127565 * r127566;
        double r127568 = r127563 * r127563;
        double r127569 = r127564 * r127564;
        double r127570 = r127568 + r127569;
        double r127571 = r127567 / r127570;
        return r127571;
}

double f(double x, double y) {
        double r127572 = x;
        double r127573 = y;
        double r127574 = r127572 - r127573;
        double r127575 = r127572 + r127573;
        double r127576 = hypot(r127572, r127573);
        double r127577 = r127575 / r127576;
        double r127578 = r127577 / r127576;
        double r127579 = r127574 * r127578;
        double r127580 = expm1(r127579);
        double r127581 = log1p(r127580);
        double r127582 = exp(r127581);
        double r127583 = log(r127582);
        return r127583;
}

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.8
Target0.1
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.8

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt20.8

    \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
  4. Applied times-frac20.8

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  5. Simplified20.8

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

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}\]
  7. Using strategy rm
  8. Applied add-log-exp0.0

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

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

    \[\leadsto \log \left(e^{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\left(\left(x - y\right) \cdot \frac{1}{\mathsf{hypot}\left(x, y\right)}\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)\right)}\right)\]
  13. Applied associate-*l*0.0

    \[\leadsto \log \left(e^{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\left(x - y\right) \cdot \left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)}\right)\right)}\right)\]
  14. Simplified0.0

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

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

Reproduce

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