Average Error: 20.2 → 0.0
Time: 11.9s
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 r88863 = x;
        double r88864 = y;
        double r88865 = r88863 - r88864;
        double r88866 = r88863 + r88864;
        double r88867 = r88865 * r88866;
        double r88868 = r88863 * r88863;
        double r88869 = r88864 * r88864;
        double r88870 = r88868 + r88869;
        double r88871 = r88867 / r88870;
        return r88871;
}

double f(double x, double y) {
        double r88872 = x;
        double r88873 = y;
        double r88874 = r88872 - r88873;
        double r88875 = hypot(r88872, r88873);
        double r88876 = r88874 / r88875;
        double r88877 = 1.0;
        double r88878 = r88872 + r88873;
        double r88879 = r88875 / r88878;
        double r88880 = r88877 / r88879;
        double r88881 = r88876 * r88880;
        return r88881;
}

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. 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 2019351 +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))))