Average Error: 19.7 → 5.4
Time: 4.4s
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.33482155704522383 \cdot 10^{154}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le -2.3154031063993499 \cdot 10^{-154}:\\ \;\;\;\;\frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}\\ \mathbf{elif}\;y \le 2.69542421539970603 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\sqrt[3]{{\left(\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}\right)}^{3}}}\\ \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.33482155704522383 \cdot 10^{154}:\\
\;\;\;\;\frac{x - y}{y - x}\\

\mathbf{elif}\;y \le -2.3154031063993499 \cdot 10^{-154}:\\
\;\;\;\;\frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}\\

\mathbf{elif}\;y \le 2.69542421539970603 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\sqrt[3]{{\left(\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}\right)}^{3}}}\\

\end{array}
double f(double x, double y) {
        double r89929 = x;
        double r89930 = y;
        double r89931 = r89929 - r89930;
        double r89932 = r89929 + r89930;
        double r89933 = r89931 * r89932;
        double r89934 = r89929 * r89929;
        double r89935 = r89930 * r89930;
        double r89936 = r89934 + r89935;
        double r89937 = r89933 / r89936;
        return r89937;
}

double f(double x, double y) {
        double r89938 = y;
        double r89939 = -1.3348215570452238e+154;
        bool r89940 = r89938 <= r89939;
        double r89941 = x;
        double r89942 = r89941 - r89938;
        double r89943 = r89938 - r89941;
        double r89944 = r89942 / r89943;
        double r89945 = -2.31540310639935e-154;
        bool r89946 = r89938 <= r89945;
        double r89947 = 2.0;
        double r89948 = pow(r89941, r89947);
        double r89949 = pow(r89938, r89947);
        double r89950 = r89948 + r89949;
        double r89951 = sqrt(r89950);
        double r89952 = r89942 / r89951;
        double r89953 = r89941 + r89938;
        double r89954 = r89951 / r89953;
        double r89955 = r89952 / r89954;
        double r89956 = 2.695424215399706e-162;
        bool r89957 = r89938 <= r89956;
        double r89958 = 1.0;
        double r89959 = 3.0;
        double r89960 = pow(r89954, r89959);
        double r89961 = cbrt(r89960);
        double r89962 = r89952 / r89961;
        double r89963 = r89957 ? r89958 : r89962;
        double r89964 = r89946 ? r89955 : r89963;
        double r89965 = r89940 ? r89944 : r89964;
        return r89965;
}

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.4
\[\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.3348215570452238e+154

    1. Initial program 64.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*62.0

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Simplified62.0

      \[\leadsto \frac{x - y}{\color{blue}{\frac{{x}^{2} + {y}^{2}}{x + y}}}\]
    5. Taylor expanded around 0 0

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

    if -1.3348215570452238e+154 < y < -2.31540310639935e-154

    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 associate-/l*0.1

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Simplified0.1

      \[\leadsto \frac{x - y}{\color{blue}{\frac{{x}^{2} + {y}^{2}}{x + y}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.1

      \[\leadsto \frac{x - y}{\frac{{x}^{2} + {y}^{2}}{\color{blue}{1 \cdot \left(x + y\right)}}}\]
    7. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{{x}^{2} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}}}{1 \cdot \left(x + y\right)}}\]
    8. Applied times-frac0.0

      \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{1} \cdot \frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}}\]
    9. Applied associate-/r*0.0

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{1}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}}\]
    10. Simplified0.0

      \[\leadsto \frac{\color{blue}{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}\]

    if -2.31540310639935e-154 < y < 2.695424215399706e-162

    1. Initial program 28.7

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

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

    if 2.695424215399706e-162 < y

    1. Initial program 0.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*0.5

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Simplified0.5

      \[\leadsto \frac{x - y}{\color{blue}{\frac{{x}^{2} + {y}^{2}}{x + y}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.5

      \[\leadsto \frac{x - y}{\frac{{x}^{2} + {y}^{2}}{\color{blue}{1 \cdot \left(x + y\right)}}}\]
    7. Applied add-sqr-sqrt0.5

      \[\leadsto \frac{x - y}{\frac{\color{blue}{\sqrt{{x}^{2} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}}}{1 \cdot \left(x + y\right)}}\]
    8. Applied times-frac0.5

      \[\leadsto \frac{x - y}{\color{blue}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{1} \cdot \frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}}\]
    9. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{1}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}}\]
    10. Simplified0.5

      \[\leadsto \frac{\color{blue}{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{x + y}}\]
    11. Using strategy rm
    12. Applied add-cbrt-cube14.5

      \[\leadsto \frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\frac{\sqrt{{x}^{2} + {y}^{2}}}{\color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}}\]
    13. Applied add-cbrt-cube13.6

      \[\leadsto \frac{\frac{x - y}{\sqrt{{x}^{2} + {y}^{2}}}}{\frac{\color{blue}{\sqrt[3]{\left(\sqrt{{x}^{2} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}\right) \cdot \sqrt{{x}^{2} + {y}^{2}}}}}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}\]
    14. Applied cbrt-undiv13.6

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

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

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

Reproduce

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