Average Error: 20.2 → 5.0
Time: 3.5s
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}:\\ \;\;\;\;-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}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\ \;\;\;\;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}:\\
\;\;\;\;-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}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\
\;\;\;\;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 r112632 = x;
        double r112633 = y;
        double r112634 = r112632 - r112633;
        double r112635 = r112632 + r112633;
        double r112636 = r112634 * r112635;
        double r112637 = r112632 * r112632;
        double r112638 = r112633 * r112633;
        double r112639 = r112637 + r112638;
        double r112640 = r112636 / r112639;
        return r112640;
}

double f(double x, double y) {
        double r112641 = y;
        double r112642 = -1.0551763464365888e+154;
        bool r112643 = r112641 <= r112642;
        double r112644 = -1.0;
        double r112645 = -2.5188680969543457e-164;
        bool r112646 = r112641 <= r112645;
        double r112647 = 1.0;
        double r112648 = x;
        double r112649 = r112648 * r112648;
        double r112650 = r112641 * r112641;
        double r112651 = r112649 + r112650;
        double r112652 = r112648 - r112641;
        double r112653 = r112648 + r112641;
        double r112654 = r112652 * r112653;
        double r112655 = r112651 / r112654;
        double r112656 = r112647 / r112655;
        double r112657 = -3.925464791081515e-187;
        bool r112658 = r112641 <= r112657;
        double r112659 = 2.1854699112047555e-162;
        bool r112660 = r112641 <= r112659;
        double r112661 = r112660 ? r112647 : r112656;
        double r112662 = r112658 ? r112644 : r112661;
        double r112663 = r112646 ? r112656 : r112662;
        double r112664 = r112643 ? r112644 : r112663;
        return r112664;
}

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. Taylor expanded around 0 4.1

      \[\leadsto \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. Taylor expanded around inf 14.0

      \[\leadsto \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}:\\ \;\;\;\;-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}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.18546991120475549 \cdot 10^{-162}:\\ \;\;\;\;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))))