Average Error: 20.5 → 5.2
Time: 1.2m
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.3259028745370529 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2836496369311533 \cdot 10^{-167}:\\ \;\;\;\;\frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}}\\ \mathbf{elif}\;y \le 4.004001196571373 \cdot 10^{-181}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{y + x}{\sqrt{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.3259028745370529 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.2836496369311533 \cdot 10^{-167}:\\
\;\;\;\;\frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}}\\

\mathbf{elif}\;y \le 4.004001196571373 \cdot 10^{-181}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r11084539 = x;
        double r11084540 = y;
        double r11084541 = r11084539 - r11084540;
        double r11084542 = r11084539 + r11084540;
        double r11084543 = r11084541 * r11084542;
        double r11084544 = r11084539 * r11084539;
        double r11084545 = r11084540 * r11084540;
        double r11084546 = r11084544 + r11084545;
        double r11084547 = r11084543 / r11084546;
        return r11084547;
}

double f(double x, double y) {
        double r11084548 = y;
        double r11084549 = -1.3259028745370529e+154;
        bool r11084550 = r11084548 <= r11084549;
        double r11084551 = -1.0;
        double r11084552 = -1.2836496369311533e-167;
        bool r11084553 = r11084548 <= r11084552;
        double r11084554 = x;
        double r11084555 = r11084554 - r11084548;
        double r11084556 = r11084554 * r11084554;
        double r11084557 = r11084548 * r11084548;
        double r11084558 = r11084556 + r11084557;
        double r11084559 = sqrt(r11084558);
        double r11084560 = r11084548 + r11084554;
        double r11084561 = r11084560 / r11084559;
        double r11084562 = r11084559 / r11084561;
        double r11084563 = r11084555 / r11084562;
        double r11084564 = 4.004001196571373e-181;
        bool r11084565 = r11084548 <= r11084564;
        double r11084566 = 1.0;
        double r11084567 = r11084565 ? r11084566 : r11084563;
        double r11084568 = r11084553 ? r11084563 : r11084567;
        double r11084569 = r11084550 ? r11084551 : r11084568;
        return r11084569;
}

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.0
Herbie5.2
\[\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.3259028745370529e+154

    1. Initial program 63.6

      \[\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.3259028745370529e+154 < y < -1.2836496369311533e-167 or 4.004001196571373e-181 < y

    1. Initial program 1.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*1.8

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt1.8

      \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{x + y}}\]
    6. Applied associate-/l*1.7

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

    if -1.2836496369311533e-167 < y < 4.004001196571373e-181

    1. Initial program 30.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3259028745370529 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2836496369311533 \cdot 10^{-167}:\\ \;\;\;\;\frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}}\\ \mathbf{elif}\;y \le 4.004001196571373 \cdot 10^{-181}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\frac{\sqrt{x \cdot x + y \cdot y}}{\frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}}\\ \end{array}\]

Reproduce

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