Average Error: 19.7 → 5.2
Time: 12.8s
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 -1.366208359764161784440446370856263249991 \cdot 10^{154}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le -7.512106064144896311879552836863591950545 \cdot 10^{-163}:\\ \;\;\;\;\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}}\right)\\ \mathbf{elif}\;y \le -9.739334495050348959786376614389218616652 \cdot 10^{-187}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le 7.425329178057676654436511729281516473593 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{x \cdot x + y \cdot y}{x - y}}{x + 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.366208359764161784440446370856263249991 \cdot 10^{154}:\\
\;\;\;\;\frac{x - y}{y - x}\\

\mathbf{elif}\;y \le -7.512106064144896311879552836863591950545 \cdot 10^{-163}:\\
\;\;\;\;\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}}\right)\\

\mathbf{elif}\;y \le -9.739334495050348959786376614389218616652 \cdot 10^{-187}:\\
\;\;\;\;\frac{x - y}{y - x}\\

\mathbf{elif}\;y \le 7.425329178057676654436511729281516473593 \cdot 10^{-165}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r191492 = x;
        double r191493 = y;
        double r191494 = r191492 - r191493;
        double r191495 = r191492 + r191493;
        double r191496 = r191494 * r191495;
        double r191497 = r191492 * r191492;
        double r191498 = r191493 * r191493;
        double r191499 = r191497 + r191498;
        double r191500 = r191496 / r191499;
        return r191500;
}

double f(double x, double y) {
        double r191501 = y;
        double r191502 = -1.3662083597641618e+154;
        bool r191503 = r191501 <= r191502;
        double r191504 = x;
        double r191505 = r191504 - r191501;
        double r191506 = r191501 - r191504;
        double r191507 = r191505 / r191506;
        double r191508 = -7.512106064144896e-163;
        bool r191509 = r191501 <= r191508;
        double r191510 = r191504 + r191501;
        double r191511 = r191504 * r191504;
        double r191512 = r191501 * r191501;
        double r191513 = r191511 + r191512;
        double r191514 = r191505 / r191513;
        double r191515 = r191510 * r191514;
        double r191516 = cbrt(r191515);
        double r191517 = r191516 * r191516;
        double r191518 = r191516 * r191517;
        double r191519 = -9.739334495050349e-187;
        bool r191520 = r191501 <= r191519;
        double r191521 = 7.425329178057677e-165;
        bool r191522 = r191501 <= r191521;
        double r191523 = 1.0;
        double r191524 = r191513 / r191505;
        double r191525 = r191524 / r191510;
        double r191526 = r191523 / r191525;
        double r191527 = r191522 ? r191523 : r191526;
        double r191528 = r191520 ? r191507 : r191527;
        double r191529 = r191509 ? r191518 : r191528;
        double r191530 = r191503 ? r191507 : r191529;
        return r191530;
}

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.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 4 regimes
  2. if y < -1.3662083597641618e+154 or -7.512106064144896e-163 < y < -9.739334495050349e-187

    1. Initial program 59.7

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]
    3. Taylor expanded around 0 4.6

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

    if -1.3662083597641618e+154 < y < -7.512106064144896e-163

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt0.3

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

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

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

    if -9.739334495050349e-187 < y < 7.425329178057677e-165

    1. Initial program 28.7

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]
    3. Taylor expanded around inf 13.9

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

    if 7.425329178057677e-165 < y

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]
    3. Using strategy rm
    4. Applied clear-num1.2

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x \cdot x + y \cdot y}{y + x}}{x - y}}}\]
    5. Simplified1.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.366208359764161784440446370856263249991 \cdot 10^{154}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le -7.512106064144896311879552836863591950545 \cdot 10^{-163}:\\ \;\;\;\;\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\left(x + y\right) \cdot \frac{x - y}{x \cdot x + y \cdot y}}\right)\\ \mathbf{elif}\;y \le -9.739334495050348959786376614389218616652 \cdot 10^{-187}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le 7.425329178057676654436511729281516473593 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{x \cdot x + y \cdot y}{x - y}}{x + y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))