Average Error: 20.5 → 5.3
Time: 12.6s
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 -1.510563131011509312029961642974820488385 \cdot 10^{145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.381918288171490541810968390394686030288 \cdot 10^{-146}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}\\ \mathbf{elif}\;y \le 8.251127577565226646325837783638255523843 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + 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.510563131011509312029961642974820488385 \cdot 10^{145}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -4.381918288171490541810968390394686030288 \cdot 10^{-146}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}\\

\mathbf{elif}\;y \le 8.251127577565226646325837783638255523843 \cdot 10^{-164}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r5639399 = x;
        double r5639400 = y;
        double r5639401 = r5639399 - r5639400;
        double r5639402 = r5639399 + r5639400;
        double r5639403 = r5639401 * r5639402;
        double r5639404 = r5639399 * r5639399;
        double r5639405 = r5639400 * r5639400;
        double r5639406 = r5639404 + r5639405;
        double r5639407 = r5639403 / r5639406;
        return r5639407;
}

double f(double x, double y) {
        double r5639408 = y;
        double r5639409 = -1.5105631310115093e+145;
        bool r5639410 = r5639408 <= r5639409;
        double r5639411 = -1.0;
        double r5639412 = -4.3819182881714905e-146;
        bool r5639413 = r5639408 <= r5639412;
        double r5639414 = 1.0;
        double r5639415 = x;
        double r5639416 = r5639415 * r5639415;
        double r5639417 = r5639408 * r5639408;
        double r5639418 = r5639416 + r5639417;
        double r5639419 = r5639416 - r5639417;
        double r5639420 = r5639418 / r5639419;
        double r5639421 = r5639414 / r5639420;
        double r5639422 = 8.251127577565227e-164;
        bool r5639423 = r5639408 <= r5639422;
        double r5639424 = r5639423 ? r5639414 : r5639421;
        double r5639425 = r5639413 ? r5639421 : r5639424;
        double r5639426 = r5639410 ? r5639411 : r5639425;
        return r5639426;
}

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.5
Target0.1
Herbie5.3
\[\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.5105631310115093e+145

    1. Initial program 60.5

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

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

    if -1.5105631310115093e+145 < y < -4.3819182881714905e-146 or 8.251127577565227e-164 < y

    1. Initial program 0.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num0.1

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Simplified0.1

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

    if -4.3819182881714905e-146 < y < 8.251127577565227e-164

    1. Initial program 29.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 16.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.510563131011509312029961642974820488385 \cdot 10^{145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.381918288171490541810968390394686030288 \cdot 10^{-146}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}\\ \mathbf{elif}\;y \le 8.251127577565226646325837783638255523843 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 
(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))))