Average Error: 19.8 → 5.1
Time: 12.0s
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.3381309335657303 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.0184496907077957 \cdot 10^{-153}:\\ \;\;\;\;\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.4681229867935913 \cdot 10^{-162}:\\ \;\;\;\;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.3381309335657303 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.0184496907077957 \cdot 10^{-153}:\\
\;\;\;\;\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.4681229867935913 \cdot 10^{-162}:\\
\;\;\;\;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 r2499004 = x;
        double r2499005 = y;
        double r2499006 = r2499004 - r2499005;
        double r2499007 = r2499004 + r2499005;
        double r2499008 = r2499006 * r2499007;
        double r2499009 = r2499004 * r2499004;
        double r2499010 = r2499005 * r2499005;
        double r2499011 = r2499009 + r2499010;
        double r2499012 = r2499008 / r2499011;
        return r2499012;
}

double f(double x, double y) {
        double r2499013 = y;
        double r2499014 = -1.3381309335657303e+154;
        bool r2499015 = r2499013 <= r2499014;
        double r2499016 = -1.0;
        double r2499017 = -1.0184496907077957e-153;
        bool r2499018 = r2499013 <= r2499017;
        double r2499019 = x;
        double r2499020 = r2499019 * r2499019;
        double r2499021 = r2499013 * r2499013;
        double r2499022 = r2499020 + r2499021;
        double r2499023 = r2499020 / r2499022;
        double r2499024 = r2499021 / r2499022;
        double r2499025 = r2499023 - r2499024;
        double r2499026 = 3.4681229867935913e-162;
        bool r2499027 = r2499013 <= r2499026;
        double r2499028 = 1.0;
        double r2499029 = r2499027 ? r2499028 : r2499025;
        double r2499030 = r2499018 ? r2499025 : r2499029;
        double r2499031 = r2499015 ? r2499016 : r2499030;
        return r2499031;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.8
Target0.0
Herbie5.1
\[\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.3381309335657303e+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 -inf 63.6

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{\color{blue}{{y}^{2} + {x}^{2}}}\]
    4. Simplified63.6

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

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

    if -1.3381309335657303e+154 < y < -1.0184496907077957e-153 or 3.4681229867935913e-162 < y

    1. Initial program 0.0

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

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

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{\color{blue}{{y}^{2} + {x}^{2}}}\]
    4. Simplified0.0

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

    if -1.0184496907077957e-153 < y < 3.4681229867935913e-162

    1. Initial program 28.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified28.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 -inf 28.6

      \[\leadsto \frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{\color{blue}{{y}^{2} + {x}^{2}}}\]
    4. Simplified28.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3381309335657303 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.0184496907077957 \cdot 10^{-153}:\\ \;\;\;\;\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.4681229867935913 \cdot 10^{-162}:\\ \;\;\;\;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 2019151 
(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))))