Average Error: 20.4 → 5.0
Time: 16.5s
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.8362219082959398974708165042102336884:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160} \lor \neg \left(y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}\right):\\ \;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\ \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.8362219082959398974708165042102336884:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160} \lor \neg \left(y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}\right):\\
\;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\

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

\end{array}
double f(double x, double y) {
        double r65550 = x;
        double r65551 = y;
        double r65552 = r65550 - r65551;
        double r65553 = r65550 + r65551;
        double r65554 = r65552 * r65553;
        double r65555 = r65550 * r65550;
        double r65556 = r65551 * r65551;
        double r65557 = r65555 + r65556;
        double r65558 = r65554 / r65557;
        return r65558;
}

double f(double x, double y) {
        double r65559 = y;
        double r65560 = -106.83622190829594;
        bool r65561 = r65559 <= r65560;
        double r65562 = -1.0;
        double r65563 = -7.718474411270338e-160;
        bool r65564 = r65559 <= r65563;
        double r65565 = 2.1155504904828537e-166;
        bool r65566 = r65559 <= r65565;
        double r65567 = !r65566;
        bool r65568 = r65564 || r65567;
        double r65569 = x;
        double r65570 = r65569 - r65559;
        double r65571 = r65569 + r65559;
        double r65572 = r65570 * r65571;
        double r65573 = r65569 * r65569;
        double r65574 = r65559 * r65559;
        double r65575 = r65573 + r65574;
        double r65576 = sqrt(r65575);
        double r65577 = r65572 / r65576;
        double r65578 = r65577 / r65576;
        double r65579 = 1.0;
        double r65580 = r65568 ? r65578 : r65579;
        double r65581 = r65561 ? r65562 : r65580;
        return r65581;
}

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.0
\[\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.83622190829594

    1. Initial program 33.1

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

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

    if -106.83622190829594 < y < -7.718474411270338e-160 or 2.1155504904828537e-166 < y

    1. Initial program 0.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.3

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied associate-/r*0.3

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

    if -7.718474411270338e-160 < y < 2.1155504904828537e-166

    1. Initial program 29.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -106.8362219082959398974708165042102336884:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.718474411270338072989398491487506383281 \cdot 10^{-160} \lor \neg \left(y \le 2.115550490482853735977870448972948077296 \cdot 10^{-166}\right):\\ \;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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