Average Error: 20.5 → 5.5
Time: 2.0m
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.3384733654556106 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.5675314538252927 \cdot 10^{-162}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \mathbf{elif}\;y \le 1.3055224462810883 \cdot 10^{-161}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y \cdot y + x \cdot x}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \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.3384733654556106 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.3055224462810883 \cdot 10^{-161}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{y \cdot y + x \cdot x}{\left(x - y\right) \cdot \left(y + x\right)}}\\

\end{array}
double f(double x, double y) {
        double r20555569 = x;
        double r20555570 = y;
        double r20555571 = r20555569 - r20555570;
        double r20555572 = r20555569 + r20555570;
        double r20555573 = r20555571 * r20555572;
        double r20555574 = r20555569 * r20555569;
        double r20555575 = r20555570 * r20555570;
        double r20555576 = r20555574 + r20555575;
        double r20555577 = r20555573 / r20555576;
        return r20555577;
}

double f(double x, double y) {
        double r20555578 = y;
        double r20555579 = -1.3384733654556106e+154;
        bool r20555580 = r20555578 <= r20555579;
        double r20555581 = -1.0;
        double r20555582 = -1.5675314538252927e-162;
        bool r20555583 = r20555578 <= r20555582;
        double r20555584 = x;
        double r20555585 = r20555584 - r20555578;
        double r20555586 = r20555578 + r20555584;
        double r20555587 = r20555585 * r20555586;
        double r20555588 = r20555578 * r20555578;
        double r20555589 = r20555584 * r20555584;
        double r20555590 = r20555588 + r20555589;
        double r20555591 = r20555587 / r20555590;
        double r20555592 = cbrt(r20555591);
        double r20555593 = r20555592 * r20555592;
        double r20555594 = r20555593 * r20555592;
        double r20555595 = 1.3055224462810883e-161;
        bool r20555596 = r20555578 <= r20555595;
        double r20555597 = 1.0;
        double r20555598 = r20555590 / r20555587;
        double r20555599 = r20555597 / r20555598;
        double r20555600 = r20555596 ? r20555597 : r20555599;
        double r20555601 = r20555583 ? r20555594 : r20555600;
        double r20555602 = r20555580 ? r20555581 : r20555601;
        return r20555602;
}

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.5
Target0.1
Herbie5.5
\[\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.3384733654556106e+154

    1. Initial program 63.6

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

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

    if -1.3384733654556106e+154 < y < -1.5675314538252927e-162

    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-cube-cbrt0.0

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

    if -1.5675314538252927e-162 < y < 1.3055224462810883e-161

    1. Initial program 30.4

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

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

    if 1.3055224462810883e-161 < y

    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 clear-num0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3384733654556106 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.5675314538252927 \cdot 10^{-162}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \mathbf{elif}\;y \le 1.3055224462810883 \cdot 10^{-161}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y \cdot y + x \cdot x}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \end{array}\]

Reproduce

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