Average Error: 20.2 → 0.0
Time: 26.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}\]
\[\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
double f(double x, double y) {
        double r78734 = x;
        double r78735 = y;
        double r78736 = r78734 - r78735;
        double r78737 = r78734 + r78735;
        double r78738 = r78736 * r78737;
        double r78739 = r78734 * r78734;
        double r78740 = r78735 * r78735;
        double r78741 = r78739 + r78740;
        double r78742 = r78738 / r78741;
        return r78742;
}

double f(double x, double y) {
        double r78743 = x;
        double r78744 = y;
        double r78745 = r78743 - r78744;
        double r78746 = hypot(r78743, r78744);
        double r78747 = r78745 / r78746;
        double r78748 = 1.0;
        double r78749 = r78743 + r78744;
        double r78750 = r78746 / r78749;
        double r78751 = r78748 / r78750;
        double r78752 = r78747 * r78751;
        return r78752;
}

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.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.2

    \[\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.2

    \[\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.3

    \[\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.2

    \[\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 clear-num0.0

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

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

Reproduce

herbie shell --seed 2019199 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

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