Average Error: 20.9 → 5.0
Time: 2.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 -9.561120846059961 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.89985753242773941 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 3.23597648055595592 \cdot 10^{-171}:\\ \;\;\;\;\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 -9.561120846059961 \cdot 10^{153}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 3.23597648055595592 \cdot 10^{-171}:\\
\;\;\;\;\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 r70259 = x;
        double r70260 = y;
        double r70261 = r70259 - r70260;
        double r70262 = r70259 + r70260;
        double r70263 = r70261 * r70262;
        double r70264 = r70259 * r70259;
        double r70265 = r70260 * r70260;
        double r70266 = r70264 + r70265;
        double r70267 = r70263 / r70266;
        return r70267;
}

double f(double x, double y) {
        double r70268 = y;
        double r70269 = -9.561120846059961e+153;
        bool r70270 = r70268 <= r70269;
        double r70271 = -1.0;
        double r70272 = -1.8998575324277394e-162;
        bool r70273 = r70268 <= r70272;
        double r70274 = 1.0;
        double r70275 = x;
        double r70276 = r70275 * r70275;
        double r70277 = r70268 * r70268;
        double r70278 = r70276 + r70277;
        double r70279 = r70275 - r70268;
        double r70280 = r70275 + r70268;
        double r70281 = r70279 * r70280;
        double r70282 = r70278 / r70281;
        double r70283 = r70274 / r70282;
        double r70284 = 3.235976480555956e-171;
        bool r70285 = r70268 <= r70284;
        double r70286 = r70274 / r70274;
        double r70287 = r70285 ? r70286 : r70283;
        double r70288 = r70273 ? r70283 : r70287;
        double r70289 = r70270 ? r70271 : r70288;
        return r70289;
}

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.9
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 < -9.561120846059961e+153

    1. Initial program 64.0

      \[\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 -9.561120846059961e+153 < y < -1.8998575324277394e-162 or 3.235976480555956e-171 < y

    1. Initial program 0.5

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

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

    if -1.8998575324277394e-162 < y < 3.235976480555956e-171

    1. Initial program 31.1

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

      \[\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 15.5

      \[\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 -9.561120846059961 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.89985753242773941 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 3.23597648055595592 \cdot 10^{-171}:\\ \;\;\;\;\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 2020039 
(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))))