Average Error: 20.4 → 5.1
Time: 6.3s
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.3308054258701725 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.1512930280169555 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}} \cdot \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 8.250332507489211 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}} \cdot \sqrt{\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.3308054258701725 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 8.250332507489211 \cdot 10^{-160}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r1481486 = x;
        double r1481487 = y;
        double r1481488 = r1481486 - r1481487;
        double r1481489 = r1481486 + r1481487;
        double r1481490 = r1481488 * r1481489;
        double r1481491 = r1481486 * r1481486;
        double r1481492 = r1481487 * r1481487;
        double r1481493 = r1481491 + r1481492;
        double r1481494 = r1481490 / r1481493;
        return r1481494;
}

double f(double x, double y) {
        double r1481495 = y;
        double r1481496 = -1.3308054258701725e+154;
        bool r1481497 = r1481495 <= r1481496;
        double r1481498 = -1.0;
        double r1481499 = -3.1512930280169555e-162;
        bool r1481500 = r1481495 <= r1481499;
        double r1481501 = x;
        double r1481502 = r1481501 * r1481501;
        double r1481503 = r1481495 * r1481495;
        double r1481504 = r1481502 + r1481503;
        double r1481505 = r1481502 / r1481504;
        double r1481506 = r1481503 / r1481504;
        double r1481507 = sqrt(r1481506);
        double r1481508 = r1481507 * r1481507;
        double r1481509 = r1481505 - r1481508;
        double r1481510 = 8.250332507489211e-160;
        bool r1481511 = r1481495 <= r1481510;
        double r1481512 = 1.0;
        double r1481513 = r1481511 ? r1481512 : r1481509;
        double r1481514 = r1481500 ? r1481509 : r1481513;
        double r1481515 = r1481497 ? r1481498 : r1481514;
        return r1481515;
}

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.4
Target0.1
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.3308054258701725e+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.3308054258701725e+154 < y < -3.1512930280169555e-162 or 8.250332507489211e-160 < 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. Using strategy rm
    4. Applied add-sqr-sqrt0.0

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

    if -3.1512930280169555e-162 < y < 8.250332507489211e-160

    1. Initial program 29.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3308054258701725 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.1512930280169555 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}} \cdot \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 8.250332507489211 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}} \cdot \sqrt{\frac{y \cdot y}{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

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