Average Error: 20.2 → 0.0
Time: 21.2s
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{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\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{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}
double f(double x, double y) {
        double r5930056 = x;
        double r5930057 = y;
        double r5930058 = r5930056 - r5930057;
        double r5930059 = r5930056 + r5930057;
        double r5930060 = r5930058 * r5930059;
        double r5930061 = r5930056 * r5930056;
        double r5930062 = r5930057 * r5930057;
        double r5930063 = r5930061 + r5930062;
        double r5930064 = r5930060 / r5930063;
        return r5930064;
}

double f(double x, double y) {
        double r5930065 = y;
        double r5930066 = x;
        double r5930067 = r5930065 + r5930066;
        double r5930068 = hypot(r5930066, r5930065);
        double r5930069 = r5930067 / r5930068;
        double r5930070 = r5930066 - r5930065;
        double r5930071 = r5930068 / r5930070;
        double r5930072 = r5930069 / r5930071;
        return r5930072;
}

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

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

    \[\leadsto \frac{\left(x - y\right) \cdot \left(y + x\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-frac20.3

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}} \cdot \frac{y + x}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}}\]
  6. Using strategy rm
  7. Applied *-un-lft-identity20.3

    \[\leadsto \color{blue}{\left(1 \cdot \frac{x - y}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}\right)} \cdot \frac{y + x}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}\]
  8. Applied associate-*l*20.3

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

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

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

Reproduce

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