Average Error: 19.7 → 5.7
Time: 12.6s
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.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(y + x\right) \cdot \left(x - y\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\ \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.3691694056010857 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\
\;\;\;\;\log \left(e^{\frac{\left(y + x\right) \cdot \left(x - y\right)}{y \cdot y + x \cdot x}}\right)\\

\mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r3881520 = x;
        double r3881521 = y;
        double r3881522 = r3881520 - r3881521;
        double r3881523 = r3881520 + r3881521;
        double r3881524 = r3881522 * r3881523;
        double r3881525 = r3881520 * r3881520;
        double r3881526 = r3881521 * r3881521;
        double r3881527 = r3881525 + r3881526;
        double r3881528 = r3881524 / r3881527;
        return r3881528;
}

double f(double x, double y) {
        double r3881529 = y;
        double r3881530 = -1.3691694056010857e+154;
        bool r3881531 = r3881529 <= r3881530;
        double r3881532 = -1.0;
        double r3881533 = -1.2013518175407308e-161;
        bool r3881534 = r3881529 <= r3881533;
        double r3881535 = x;
        double r3881536 = r3881529 + r3881535;
        double r3881537 = r3881535 - r3881529;
        double r3881538 = r3881536 * r3881537;
        double r3881539 = r3881529 * r3881529;
        double r3881540 = r3881535 * r3881535;
        double r3881541 = r3881539 + r3881540;
        double r3881542 = r3881538 / r3881541;
        double r3881543 = exp(r3881542);
        double r3881544 = log(r3881543);
        double r3881545 = 2.9860065638011237e-218;
        bool r3881546 = r3881529 <= r3881545;
        double r3881547 = 1.0;
        double r3881548 = 1.2966442305400266e-202;
        bool r3881549 = r3881529 <= r3881548;
        double r3881550 = sqrt(r3881541);
        double r3881551 = r3881536 / r3881550;
        double r3881552 = r3881537 / r3881550;
        double r3881553 = r3881551 * r3881552;
        double r3881554 = r3881549 ? r3881532 : r3881553;
        double r3881555 = r3881546 ? r3881547 : r3881554;
        double r3881556 = r3881534 ? r3881544 : r3881555;
        double r3881557 = r3881531 ? r3881532 : r3881556;
        return r3881557;
}

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.7
Target0.0
Herbie5.7
\[\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 4 regimes
  2. if y < -1.3691694056010857e+154 or 2.9860065638011237e-218 < y < 1.2966442305400266e-202

    1. Initial program 60.1

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

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

    if -1.3691694056010857e+154 < y < -1.2013518175407308e-161

    1. Initial program 0.0

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

      \[\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 times-frac0.3

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.3

      \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)}\]
    7. Simplified0.0

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

    if -1.2013518175407308e-161 < y < 2.9860065638011237e-218

    1. Initial program 28.8

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

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

    if 1.2966442305400266e-202 < y

    1. Initial program 6.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt6.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 times-frac6.9

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(y + x\right) \cdot \left(x - y\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\ \end{array}\]

Reproduce

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