Average Error: 19.8 → 5.1
Time: 8.7s
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 r1276211 = x;
        double r1276212 = y;
        double r1276213 = r1276211 - r1276212;
        double r1276214 = r1276211 + r1276212;
        double r1276215 = r1276213 * r1276214;
        double r1276216 = r1276211 * r1276211;
        double r1276217 = r1276212 * r1276212;
        double r1276218 = r1276216 + r1276217;
        double r1276219 = r1276215 / r1276218;
        return r1276219;
}

double f(double x, double y) {
        double r1276220 = y;
        double r1276221 = -1.3381309335657303e+154;
        bool r1276222 = r1276220 <= r1276221;
        double r1276223 = -1.0;
        double r1276224 = -1.0184496907077957e-153;
        bool r1276225 = r1276220 <= r1276224;
        double r1276226 = x;
        double r1276227 = r1276226 * r1276226;
        double r1276228 = r1276220 * r1276220;
        double r1276229 = r1276227 + r1276228;
        double r1276230 = r1276227 / r1276229;
        double r1276231 = r1276228 / r1276229;
        double r1276232 = r1276230 - r1276231;
        double r1276233 = 3.4681229867935913e-162;
        bool r1276234 = r1276220 <= r1276233;
        double r1276235 = 1.0;
        double r1276236 = r1276234 ? r1276235 : r1276232;
        double r1276237 = r1276225 ? r1276232 : r1276236;
        double r1276238 = r1276222 ? r1276223 : r1276237;
        return r1276238;
}

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 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))))