Average Error: 20.6 → 5.2
Time: 8.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 -1.6930748104447922 \cdot 10^{150}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le -1.91773166521773073 \cdot 10^{-160}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{{y}^{2} + {x}^{2}}{\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 -1.6930748104447922 \cdot 10^{150}:\\
\;\;\;\;\frac{1}{-1}\\

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

\mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r89358 = x;
        double r89359 = y;
        double r89360 = r89358 - r89359;
        double r89361 = r89358 + r89359;
        double r89362 = r89360 * r89361;
        double r89363 = r89358 * r89358;
        double r89364 = r89359 * r89359;
        double r89365 = r89363 + r89364;
        double r89366 = r89362 / r89365;
        return r89366;
}

double f(double x, double y) {
        double r89367 = y;
        double r89368 = -1.693074810444792e+150;
        bool r89369 = r89367 <= r89368;
        double r89370 = 1.0;
        double r89371 = -1.0;
        double r89372 = r89370 / r89371;
        double r89373 = -1.9177316652177307e-160;
        bool r89374 = r89367 <= r89373;
        double r89375 = x;
        double r89376 = r89375 - r89367;
        double r89377 = r89375 + r89367;
        double r89378 = r89376 * r89377;
        double r89379 = r89375 * r89375;
        double r89380 = r89367 * r89367;
        double r89381 = r89379 + r89380;
        double r89382 = sqrt(r89381);
        double r89383 = r89382 * r89382;
        double r89384 = r89378 / r89383;
        double r89385 = 2.87578004264954e-160;
        bool r89386 = r89367 <= r89385;
        double r89387 = 2.0;
        double r89388 = pow(r89367, r89387);
        double r89389 = pow(r89375, r89387);
        double r89390 = r89388 + r89389;
        double r89391 = r89390 / r89378;
        double r89392 = r89370 / r89391;
        double r89393 = r89386 ? r89370 : r89392;
        double r89394 = r89374 ? r89384 : r89393;
        double r89395 = r89369 ? r89372 : r89394;
        return r89395;
}

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.6
Target0.1
Herbie5.2
\[\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 4 regimes
  2. if y < -1.693074810444792e+150

    1. Initial program 62.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.1

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Using strategy rm
    5. Applied clear-num62.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{{y}^{2} + {x}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    7. Taylor expanded around inf 0

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

    if -1.693074810444792e+150 < y < -1.9177316652177307e-160

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.0

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

    if -1.9177316652177307e-160 < y < 2.87578004264954e-160

    1. Initial program 30.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt30.6

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Using strategy rm
    5. Applied clear-num30.6

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

      \[\leadsto \frac{1}{\color{blue}{\frac{{y}^{2} + {x}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    7. Taylor expanded around 0 16.2

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

    if 2.87578004264954e-160 < y

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Using strategy rm
    5. Applied clear-num0.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{{y}^{2} + {x}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.6930748104447922 \cdot 10^{150}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le -1.91773166521773073 \cdot 10^{-160}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{{y}^{2} + {x}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \end{array}\]

Reproduce

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