Average Error: 20.2 → 5.8
Time: 3.3s
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.326706575340792247837315389343616804379 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.402534282322308160462177343677727580266 \cdot 10^{-146}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 8.08684968258849881560228236305205528229 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot 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.326706575340792247837315389343616804379 \cdot 10^{154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -6.402534282322308160462177343677727580266 \cdot 10^{-146}:\\
\;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\\

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

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

\end{array}
double f(double x, double y) {
        double r105919 = x;
        double r105920 = y;
        double r105921 = r105919 - r105920;
        double r105922 = r105919 + r105920;
        double r105923 = r105921 * r105922;
        double r105924 = r105919 * r105919;
        double r105925 = r105920 * r105920;
        double r105926 = r105924 + r105925;
        double r105927 = r105923 / r105926;
        return r105927;
}

double f(double x, double y) {
        double r105928 = y;
        double r105929 = -1.3267065753407922e+154;
        bool r105930 = r105928 <= r105929;
        double r105931 = -1.0;
        double r105932 = -6.402534282322308e-146;
        bool r105933 = r105928 <= r105932;
        double r105934 = x;
        double r105935 = r105934 - r105928;
        double r105936 = r105934 * r105934;
        double r105937 = r105928 * r105928;
        double r105938 = r105936 + r105937;
        double r105939 = sqrt(r105938);
        double r105940 = r105935 / r105939;
        double r105941 = r105934 + r105928;
        double r105942 = r105941 / r105939;
        double r105943 = r105940 * r105942;
        double r105944 = 8.086849682588499e-165;
        bool r105945 = r105928 <= r105944;
        double r105946 = 1.0;
        double r105947 = r105945 ? r105946 : r105943;
        double r105948 = r105933 ? r105943 : r105947;
        double r105949 = r105930 ? r105931 : r105948;
        return r105949;
}

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.2
Target0.1
Herbie5.8
\[\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 < -1.3267065753407922e+154

    1. Initial program 64.0

      \[\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.3267065753407922e+154 < y < -6.402534282322308e-146 or 8.086849682588499e-165 < 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 add-sqr-sqrt0.1

      \[\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}}}\]

    if -6.402534282322308e-146 < y < 8.086849682588499e-165

    1. Initial program 28.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.326706575340792247837315389343616804379 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.402534282322308160462177343677727580266 \cdot 10^{-146}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 8.08684968258849881560228236305205528229 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

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