Average Error: 19.7 → 5.0
Time: 4.8s
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.3386474296726014 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.572350587881258 \cdot 10^{-188}:\\ \;\;\;\;\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.6548784939791494 \cdot 10^{-199}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.0258790624487682 \cdot 10^{-176}:\\ \;\;\;\;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.3386474296726014 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -5.572350587881258 \cdot 10^{-188}:\\
\;\;\;\;\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.6548784939791494 \cdot 10^{-199}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 2.0258790624487682 \cdot 10^{-176}:\\
\;\;\;\;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 r1338226 = x;
        double r1338227 = y;
        double r1338228 = r1338226 - r1338227;
        double r1338229 = r1338226 + r1338227;
        double r1338230 = r1338228 * r1338229;
        double r1338231 = r1338226 * r1338226;
        double r1338232 = r1338227 * r1338227;
        double r1338233 = r1338231 + r1338232;
        double r1338234 = r1338230 / r1338233;
        return r1338234;
}

double f(double x, double y) {
        double r1338235 = y;
        double r1338236 = -1.3386474296726014e+154;
        bool r1338237 = r1338235 <= r1338236;
        double r1338238 = -1.0;
        double r1338239 = -5.572350587881258e-188;
        bool r1338240 = r1338235 <= r1338239;
        double r1338241 = x;
        double r1338242 = r1338241 * r1338241;
        double r1338243 = r1338235 * r1338235;
        double r1338244 = r1338242 + r1338243;
        double r1338245 = r1338242 / r1338244;
        double r1338246 = r1338243 / r1338244;
        double r1338247 = r1338245 - r1338246;
        double r1338248 = -3.6548784939791494e-199;
        bool r1338249 = r1338235 <= r1338248;
        double r1338250 = 2.0258790624487682e-176;
        bool r1338251 = r1338235 <= r1338250;
        double r1338252 = 1.0;
        double r1338253 = r1338251 ? r1338252 : r1338247;
        double r1338254 = r1338249 ? r1338238 : r1338253;
        double r1338255 = r1338240 ? r1338247 : r1338254;
        double r1338256 = r1338237 ? r1338238 : r1338255;
        return r1338256;
}

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.7
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.3386474296726014e+154 or -5.572350587881258e-188 < y < -3.6548784939791494e-199

    1. Initial program 61.1

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

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

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

    if -1.3386474296726014e+154 < y < -5.572350587881258e-188 or 2.0258790624487682e-176 < y

    1. Initial program 2.1

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

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

    if -3.6548784939791494e-199 < y < 2.0258790624487682e-176

    1. Initial program 28.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3386474296726014 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.572350587881258 \cdot 10^{-188}:\\ \;\;\;\;\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.6548784939791494 \cdot 10^{-199}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.0258790624487682 \cdot 10^{-176}:\\ \;\;\;\;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 2019156 
(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))))