Average Error: 20.2 → 5.2
Time: 5.5s
Precision: 64
\[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.3483719131786158 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.3662280950353905 \cdot 10^{-155}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 3.1003292371794966 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \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.3483719131786158 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -6.3662280950353905 \cdot 10^{-155}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 3.1003292371794966 \cdot 10^{-168}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\

\end{array}
double f(double x, double y) {
        double r1490580 = x;
        double r1490581 = y;
        double r1490582 = r1490580 - r1490581;
        double r1490583 = r1490580 + r1490581;
        double r1490584 = r1490582 * r1490583;
        double r1490585 = r1490580 * r1490580;
        double r1490586 = r1490581 * r1490581;
        double r1490587 = r1490585 + r1490586;
        double r1490588 = r1490584 / r1490587;
        return r1490588;
}

double f(double x, double y) {
        double r1490589 = y;
        double r1490590 = -1.3483719131786158e+154;
        bool r1490591 = r1490589 <= r1490590;
        double r1490592 = -1.0;
        double r1490593 = -6.3662280950353905e-155;
        bool r1490594 = r1490589 <= r1490593;
        double r1490595 = x;
        double r1490596 = r1490595 * r1490595;
        double r1490597 = r1490589 * r1490589;
        double r1490598 = r1490596 + r1490597;
        double r1490599 = r1490596 / r1490598;
        double r1490600 = r1490597 / r1490598;
        double r1490601 = r1490599 - r1490600;
        double r1490602 = 3.1003292371794966e-168;
        bool r1490603 = r1490589 <= r1490602;
        double r1490604 = 1.0;
        double r1490605 = r1490603 ? r1490604 : r1490601;
        double r1490606 = r1490594 ? r1490601 : r1490605;
        double r1490607 = r1490591 ? r1490592 : r1490606;
        return r1490607;
}

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.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 3 regimes
  2. if y < -1.3483719131786158e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified63.6

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around 0 0

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

    if -1.3483719131786158e+154 < y < -6.3662280950353905e-155 or 3.1003292371794966e-168 < y

    1. Initial program 0.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified0.3

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]

    if -6.3662280950353905e-155 < y < 3.1003292371794966e-168

    1. Initial program 28.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified28.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 16.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3483719131786158 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.3662280950353905 \cdot 10^{-155}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 3.1003292371794966 \cdot 10^{-168}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019153 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 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))))