Average Error: 20.2 → 5.0
Time: 3.8s
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.05517634643658878 \cdot 10^{154}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le -2.5188680969543457 \cdot 10^{-164}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le -3.9254647910815149 \cdot 10^{-187}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{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 -1.05517634643658878 \cdot 10^{154}:\\
\;\;\;\;\frac{1}{-1}\\

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

\mathbf{elif}\;y \le -3.9254647910815149 \cdot 10^{-187}:\\
\;\;\;\;\frac{1}{-1}\\

\mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\
\;\;\;\;\frac{1}{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 r90528 = x;
        double r90529 = y;
        double r90530 = r90528 - r90529;
        double r90531 = r90528 + r90529;
        double r90532 = r90530 * r90531;
        double r90533 = r90528 * r90528;
        double r90534 = r90529 * r90529;
        double r90535 = r90533 + r90534;
        double r90536 = r90532 / r90535;
        return r90536;
}

double f(double x, double y) {
        double r90537 = y;
        double r90538 = -1.0551763464365888e+154;
        bool r90539 = r90537 <= r90538;
        double r90540 = 1.0;
        double r90541 = -1.0;
        double r90542 = r90540 / r90541;
        double r90543 = -2.5188680969543457e-164;
        bool r90544 = r90537 <= r90543;
        double r90545 = x;
        double r90546 = r90545 * r90545;
        double r90547 = r90537 * r90537;
        double r90548 = r90546 + r90547;
        double r90549 = r90545 - r90537;
        double r90550 = r90545 + r90537;
        double r90551 = r90549 * r90550;
        double r90552 = r90548 / r90551;
        double r90553 = r90540 / r90552;
        double r90554 = -3.925464791081515e-187;
        bool r90555 = r90537 <= r90554;
        double r90556 = 2.1854699112047555e-162;
        bool r90557 = r90537 <= r90556;
        double r90558 = r90540 / r90540;
        double r90559 = r90557 ? r90558 : r90553;
        double r90560 = r90555 ? r90542 : r90559;
        double r90561 = r90544 ? r90553 : r90560;
        double r90562 = r90539 ? r90542 : r90561;
        return r90562;
}

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
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 < -1.0551763464365888e+154 or -2.5188680969543457e-164 < y < -3.925464791081515e-187

    1. Initial program 60.2

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

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

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

    if -1.0551763464365888e+154 < y < -2.5188680969543457e-164 or 2.1854699112047555e-162 < 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 -3.925464791081515e-187 < y < 2.1854699112047555e-162

    1. Initial program 29.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.05517634643658878 \cdot 10^{154}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le -2.5188680969543457 \cdot 10^{-164}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le -3.9254647910815149 \cdot 10^{-187}:\\ \;\;\;\;\frac{1}{-1}\\ \mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{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 2020062 
(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))))