Average Error: 19.9 → 5.2
Time: 13.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 -106.3060688461918488201263244263827800751:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151} \lor \neg \left(y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \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 -106.3060688461918488201263244263827800751:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151} \lor \neg \left(y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}\right):\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r72515 = x;
        double r72516 = y;
        double r72517 = r72515 - r72516;
        double r72518 = r72515 + r72516;
        double r72519 = r72517 * r72518;
        double r72520 = r72515 * r72515;
        double r72521 = r72516 * r72516;
        double r72522 = r72520 + r72521;
        double r72523 = r72519 / r72522;
        return r72523;
}

double f(double x, double y) {
        double r72524 = y;
        double r72525 = -106.30606884619185;
        bool r72526 = r72524 <= r72525;
        double r72527 = -1.0;
        double r72528 = -1.1129546130770477e-151;
        bool r72529 = r72524 <= r72528;
        double r72530 = 7.168109854324842e-160;
        bool r72531 = r72524 <= r72530;
        double r72532 = !r72531;
        bool r72533 = r72529 || r72532;
        double r72534 = x;
        double r72535 = r72534 - r72524;
        double r72536 = r72534 + r72524;
        double r72537 = r72535 * r72536;
        double r72538 = r72534 * r72534;
        double r72539 = 2.0;
        double r72540 = pow(r72524, r72539);
        double r72541 = r72538 + r72540;
        double r72542 = r72537 / r72541;
        double r72543 = 1.0;
        double r72544 = r72533 ? r72542 : r72543;
        double r72545 = r72526 ? r72527 : r72544;
        return r72545;
}

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.9
Target0.1
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 < -106.30606884619185

    1. Initial program 31.8

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{{x}^{2} + {y}^{2}}}\]
    3. Simplified31.8

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]
    4. Using strategy rm
    5. Applied clear-num31.8

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + {y}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    6. Taylor expanded around 0 0

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

    if -106.30606884619185 < y < -1.1129546130770477e-151 or 7.168109854324842e-160 < y

    1. Initial program 0.0

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{{x}^{2} + {y}^{2}}}\]
    3. Simplified0.0

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]

    if -1.1129546130770477e-151 < y < 7.168109854324842e-160

    1. Initial program 28.5

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{{x}^{2} + {y}^{2}}}\]
    3. Simplified28.5

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]
    4. Using strategy rm
    5. Applied clear-num28.5

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + {y}^{2}}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    6. Taylor expanded around inf 15.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -106.3060688461918488201263244263827800751:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151} \lor \neg \left(y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019323 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.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))))