Average Error: 19.9 → 0.0
Time: 11.3s
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(y, x\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y, x\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(y, x\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y, x\right)}{x + y}}
double f(double x, double y) {
        double r96464 = x;
        double r96465 = y;
        double r96466 = r96464 - r96465;
        double r96467 = r96464 + r96465;
        double r96468 = r96466 * r96467;
        double r96469 = r96464 * r96464;
        double r96470 = r96465 * r96465;
        double r96471 = r96469 + r96470;
        double r96472 = r96468 / r96471;
        return r96472;
}

double f(double x, double y) {
        double r96473 = x;
        double r96474 = y;
        double r96475 = r96473 - r96474;
        double r96476 = hypot(r96474, r96473);
        double r96477 = r96475 / r96476;
        double r96478 = 1.0;
        double r96479 = r96473 + r96474;
        double r96480 = r96476 / r96479;
        double r96481 = r96478 / r96480;
        double r96482 = r96477 * r96481;
        return r96482;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

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

    \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{fma}\left(x, x, y \cdot y\right)}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt19.9

    \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}}\]
  5. Applied times-frac19.9

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}} \cdot \frac{x + y}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}}\]
  6. Simplified19.9

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

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

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

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

Reproduce

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