Average Error: 20.9 → 0.0
Time: 2.6s
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{\mathsf{hypot}\left(x, y\right)}{\left(x + y\right) \cdot 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{\mathsf{hypot}\left(x, y\right)}{\left(x + y\right) \cdot 1}}
double f(double x, double y) {
        double r86685 = x;
        double r86686 = y;
        double r86687 = r86685 - r86686;
        double r86688 = r86685 + r86686;
        double r86689 = r86687 * r86688;
        double r86690 = r86685 * r86685;
        double r86691 = r86686 * r86686;
        double r86692 = r86690 + r86691;
        double r86693 = r86689 / r86692;
        return r86693;
}

double f(double x, double y) {
        double r86694 = x;
        double r86695 = y;
        double r86696 = r86694 - r86695;
        double r86697 = hypot(r86694, r86695);
        double r86698 = r86694 + r86695;
        double r86699 = 1.0;
        double r86700 = r86698 * r86699;
        double r86701 = r86697 / r86700;
        double r86702 = r86697 * r86701;
        double r86703 = r86696 / r86702;
        return r86703;
}

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

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Using strategy rm
  3. Applied associate-/l*21.0

    \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
  4. Using strategy rm
  5. Applied *-un-lft-identity21.0

    \[\leadsto \frac{x - y}{\frac{x \cdot x + y \cdot y}{\color{blue}{1 \cdot \left(x + y\right)}}}\]
  6. Applied add-sqr-sqrt21.0

    \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{1 \cdot \left(x + y\right)}}\]
  7. Applied times-frac21.0

    \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{1} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{x + y}}}\]
  8. Simplified21.0

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

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

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

Reproduce

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