Average Error: 20.4 → 5.0
Time: 3.1s
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}\]
\[\begin{array}{l} \mathbf{if}\;y \le -5.000545272256956163196117207287515182782 \cdot 10^{152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -5.000545272256956163196117207287515182782 \cdot 10^{152}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\

\mathbf{elif}\;y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\

\end{array}
double f(double x, double y) {
        double r89272 = x;
        double r89273 = y;
        double r89274 = r89272 - r89273;
        double r89275 = r89272 + r89273;
        double r89276 = r89274 * r89275;
        double r89277 = r89272 * r89272;
        double r89278 = r89273 * r89273;
        double r89279 = r89277 + r89278;
        double r89280 = r89276 / r89279;
        return r89280;
}

double f(double x, double y) {
        double r89281 = y;
        double r89282 = -5.000545272256956e+152;
        bool r89283 = r89281 <= r89282;
        double r89284 = -1.0;
        double r89285 = -7.718474411270338e-160;
        bool r89286 = r89281 <= r89285;
        double r89287 = 1.0;
        double r89288 = x;
        double r89289 = r89288 * r89288;
        double r89290 = r89281 * r89281;
        double r89291 = r89289 + r89290;
        double r89292 = r89288 - r89281;
        double r89293 = r89288 + r89281;
        double r89294 = r89292 * r89293;
        double r89295 = r89291 / r89294;
        double r89296 = r89287 / r89295;
        double r89297 = 2.1155504904828537e-166;
        bool r89298 = r89281 <= r89297;
        double r89299 = r89298 ? r89287 : r89296;
        double r89300 = r89286 ? r89296 : r89299;
        double r89301 = r89283 ? r89284 : r89300;
        return r89301;
}

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.4
Target0.1
Herbie5.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. Split input into 3 regimes
  2. if y < -5.000545272256956e+152

    1. Initial program 63.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 0

      \[\leadsto \color{blue}{-1}\]

    if -5.000545272256956e+152 < y < -7.718474411270338e-160 or 2.1155504904828537e-166 < y

    1. Initial program 0.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num0.2

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]

    if -7.718474411270338e-160 < y < 2.1155504904828537e-166

    1. Initial program 29.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 15.3

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -5.000545272256956163196117207287515182782 \cdot 10^{152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019322 
(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))))