Average Error: 20.4 → 5.4
Time: 4.0s
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 -3.289979231242187938780435609932311249764 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.562289755990830357227294343969921773158 \cdot 10^{-143}:\\ \;\;\;\;\frac{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}}{x - y}\\ \mathbf{elif}\;y \le 7.409492782297067496240750121255910787268 \cdot 10^{-170}:\\ \;\;\;\;\frac{\frac{x - y}{1}}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{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 -3.289979231242187938780435609932311249764 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.562289755990830357227294343969921773158 \cdot 10^{-143}:\\
\;\;\;\;\frac{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}}{x - y}\\

\mathbf{elif}\;y \le 7.409492782297067496240750121255910787268 \cdot 10^{-170}:\\
\;\;\;\;\frac{\frac{x - y}{1}}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r84243 = x;
        double r84244 = y;
        double r84245 = r84243 - r84244;
        double r84246 = r84243 + r84244;
        double r84247 = r84245 * r84246;
        double r84248 = r84243 * r84243;
        double r84249 = r84244 * r84244;
        double r84250 = r84248 + r84249;
        double r84251 = r84247 / r84250;
        return r84251;
}

double f(double x, double y) {
        double r84252 = y;
        double r84253 = -3.289979231242188e+153;
        bool r84254 = r84252 <= r84253;
        double r84255 = -1.0;
        double r84256 = -1.5622897559908304e-143;
        bool r84257 = r84252 <= r84256;
        double r84258 = x;
        double r84259 = r84258 - r84252;
        double r84260 = r84258 * r84258;
        double r84261 = r84252 * r84252;
        double r84262 = r84260 + r84261;
        double r84263 = r84260 - r84261;
        double r84264 = r84262 / r84263;
        double r84265 = r84259 / r84264;
        double r84266 = r84265 / r84259;
        double r84267 = 7.409492782297067e-170;
        bool r84268 = r84252 <= r84267;
        double r84269 = 1.0;
        double r84270 = r84259 / r84269;
        double r84271 = r84270 / r84259;
        double r84272 = r84258 + r84252;
        double r84273 = r84259 * r84272;
        double r84274 = r84273 / r84262;
        double r84275 = r84268 ? r84271 : r84274;
        double r84276 = r84257 ? r84266 : r84275;
        double r84277 = r84254 ? r84255 : r84276;
        return r84277;
}

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.4
Target0.0
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 < -3.289979231242188e+153

    1. Initial program 63.8

      \[\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 -3.289979231242188e+153 < y < -1.5622897559908304e-143

    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. Using strategy rm
    5. Applied flip-+0.0

      \[\leadsto \frac{x - y}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied associate-/r/0.0

      \[\leadsto \frac{x - y}{\color{blue}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y} \cdot \left(x - y\right)}}\]
    7. Applied associate-/r*0.0

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

    if -1.5622897559908304e-143 < y < 7.409492782297067e-170

    1. Initial program 28.6

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Using strategy rm
    5. Applied flip-+28.6

      \[\leadsto \frac{x - y}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied associate-/r/28.6

      \[\leadsto \frac{x - y}{\color{blue}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y} \cdot \left(x - y\right)}}\]
    7. Applied associate-/r*28.6

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

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

    if 7.409492782297067e-170 < y

    1. Initial program 1.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.289979231242187938780435609932311249764 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.562289755990830357227294343969921773158 \cdot 10^{-143}:\\ \;\;\;\;\frac{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}}{x - y}\\ \mathbf{elif}\;y \le 7.409492782297067496240750121255910787268 \cdot 10^{-170}:\\ \;\;\;\;\frac{\frac{x - y}{1}}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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