Average Error: 20.5 → 0.0
Time: 1.2m
Precision: 64
\[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{x - y}{\sqrt{x^2 + y^2}^*}}{\frac{\sqrt{x^2 + y^2}^*}{y + x}}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{\frac{x - y}{\sqrt{x^2 + y^2}^*}}{\frac{\sqrt{x^2 + y^2}^*}{y + x}}
double f(double x, double y) {
        double r6750176 = x;
        double r6750177 = y;
        double r6750178 = r6750176 - r6750177;
        double r6750179 = r6750176 + r6750177;
        double r6750180 = r6750178 * r6750179;
        double r6750181 = r6750176 * r6750176;
        double r6750182 = r6750177 * r6750177;
        double r6750183 = r6750181 + r6750182;
        double r6750184 = r6750180 / r6750183;
        return r6750184;
}

double f(double x, double y) {
        double r6750185 = x;
        double r6750186 = y;
        double r6750187 = r6750185 - r6750186;
        double r6750188 = hypot(r6750185, r6750186);
        double r6750189 = r6750187 / r6750188;
        double r6750190 = r6750186 + r6750185;
        double r6750191 = r6750188 / r6750190;
        double r6750192 = r6750189 / r6750191;
        return r6750192;
}

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

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

    \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt20.5

    \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{x + y}}\]
  6. Applied associate-/l*20.4

    \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}}}\]
  7. Using strategy rm
  8. Applied add-sqr-sqrt20.8

    \[\leadsto \frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{x + y}{\color{blue}{\sqrt{\sqrt{x \cdot x + y \cdot y}} \cdot \sqrt{\sqrt{x \cdot x + y \cdot y}}}}}}\]
  9. Applied *-un-lft-identity20.8

    \[\leadsto \frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{\color{blue}{1 \cdot \left(x + y\right)}}{\sqrt{\sqrt{x \cdot x + y \cdot y}} \cdot \sqrt{\sqrt{x \cdot x + y \cdot y}}}}}\]
  10. Applied times-frac20.8

    \[\leadsto \frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\color{blue}{\frac{1}{\sqrt{\sqrt{x \cdot x + y \cdot y}}} \cdot \frac{x + y}{\sqrt{\sqrt{x \cdot x + y \cdot y}}}}}}\]
  11. Applied add-sqr-sqrt21.0

    \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{\sqrt{x \cdot x + y \cdot y}} \cdot \sqrt{\sqrt{x \cdot x + y \cdot y}}}}{\frac{1}{\sqrt{\sqrt{x \cdot x + y \cdot y}}} \cdot \frac{x + y}{\sqrt{\sqrt{x \cdot x + y \cdot y}}}}}\]
  12. Applied times-frac21.1

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

    \[\leadsto \frac{x - y}{\color{blue}{\sqrt{x^2 + y^2}^*} \cdot \frac{\sqrt{\sqrt{x \cdot x + y \cdot y}}}{\frac{x + y}{\sqrt{\sqrt{x \cdot x + y \cdot y}}}}}\]
  14. Simplified0.0

    \[\leadsto \frac{x - y}{\sqrt{x^2 + y^2}^* \cdot \color{blue}{\frac{\sqrt{x^2 + y^2}^*}{x + y}}}\]
  15. Using strategy rm
  16. Applied associate-/r*0.0

    \[\leadsto \color{blue}{\frac{\frac{x - y}{\sqrt{x^2 + y^2}^*}}{\frac{\sqrt{x^2 + y^2}^*}{x + y}}}\]
  17. Final simplification0.0

    \[\leadsto \frac{\frac{x - y}{\sqrt{x^2 + y^2}^*}}{\frac{\sqrt{x^2 + y^2}^*}{y + x}}\]

Reproduce

herbie shell --seed 2019119 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 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))))