Average Error: 20.6 → 5.9
Time: 11.3s
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.553125844209864019349205574997414631362 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.262962472101785089653746326381466961868 \cdot 10^{-159}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 4.982414937133197896822437436552107699435 \cdot 10^{-223}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.744541337219421296708284469703238777066 \cdot 10^{-178}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}\\ \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.553125844209864019349205574997414631362 \cdot 10^{153}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 4.982414937133197896822437436552107699435 \cdot 10^{-223}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 4.744541337219421296708284469703238777066 \cdot 10^{-178}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r4280385 = x;
        double r4280386 = y;
        double r4280387 = r4280385 - r4280386;
        double r4280388 = r4280385 + r4280386;
        double r4280389 = r4280387 * r4280388;
        double r4280390 = r4280385 * r4280385;
        double r4280391 = r4280386 * r4280386;
        double r4280392 = r4280390 + r4280391;
        double r4280393 = r4280389 / r4280392;
        return r4280393;
}

double f(double x, double y) {
        double r4280394 = y;
        double r4280395 = -9.553125844209864e+153;
        bool r4280396 = r4280394 <= r4280395;
        double r4280397 = -1.0;
        double r4280398 = -2.262962472101785e-159;
        bool r4280399 = r4280394 <= r4280398;
        double r4280400 = x;
        double r4280401 = r4280400 * r4280400;
        double r4280402 = r4280394 * r4280394;
        double r4280403 = r4280402 + r4280401;
        double r4280404 = r4280401 / r4280403;
        double r4280405 = r4280402 / r4280403;
        double r4280406 = r4280404 - r4280405;
        double r4280407 = 4.982414937133198e-223;
        bool r4280408 = r4280394 <= r4280407;
        double r4280409 = 1.0;
        double r4280410 = 4.7445413372194213e-178;
        bool r4280411 = r4280394 <= r4280410;
        double r4280412 = r4280411 ? r4280397 : r4280406;
        double r4280413 = r4280408 ? r4280409 : r4280412;
        double r4280414 = r4280399 ? r4280406 : r4280413;
        double r4280415 = r4280396 ? r4280397 : r4280414;
        return r4280415;
}

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.6
Target0.1
Herbie5.9
\[\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.553125844209864e+153 or 4.982414937133198e-223 < y < 4.7445413372194213e-178

    1. Initial program 57.1

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

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

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

    if -9.553125844209864e+153 < y < -2.262962472101785e-159 or 4.7445413372194213e-178 < y

    1. Initial program 1.0

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

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

    if -2.262962472101785e-159 < y < 4.982414937133198e-223

    1. Initial program 30.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.553125844209864019349205574997414631362 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.262962472101785089653746326381466961868 \cdot 10^{-159}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 4.982414937133197896822437436552107699435 \cdot 10^{-223}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.744541337219421296708284469703238777066 \cdot 10^{-178}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019200 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))