Average Error: 19.9 → 4.6
Time: 12.5s
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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\ \mathbf{elif}\;y \le 1.828260016637030233456157191815862132037 \cdot 10^{-162}:\\ \;\;\;\;1\\ \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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\

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

\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 r60254 = x;
        double r60255 = y;
        double r60256 = r60254 - r60255;
        double r60257 = r60254 + r60255;
        double r60258 = r60256 * r60257;
        double r60259 = r60254 * r60254;
        double r60260 = r60255 * r60255;
        double r60261 = r60259 + r60260;
        double r60262 = r60258 / r60261;
        return r60262;
}

double f(double x, double y) {
        double r60263 = y;
        double r60264 = -9.82178231331464e+153;
        bool r60265 = r60263 <= r60264;
        double r60266 = -1.0;
        double r60267 = -1.937646393364571e-161;
        bool r60268 = r60263 <= r60267;
        double r60269 = x;
        double r60270 = r60269 * r60269;
        double r60271 = r60263 * r60263;
        double r60272 = r60270 - r60271;
        double r60273 = r60270 + r60271;
        double r60274 = r60269 - r60263;
        double r60275 = r60269 + r60263;
        double r60276 = r60274 * r60275;
        double r60277 = r60273 / r60276;
        double r60278 = r60272 / r60277;
        double r60279 = r60275 * r60274;
        double r60280 = r60278 / r60279;
        double r60281 = 1.8282600166370302e-162;
        bool r60282 = r60263 <= r60281;
        double r60283 = 1.0;
        double r60284 = r60276 / r60273;
        double r60285 = r60282 ? r60283 : r60284;
        double r60286 = r60268 ? r60280 : r60285;
        double r60287 = r60265 ? r60266 : r60286;
        return r60287;
}

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.9
Target0.1
Herbie4.6
\[\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 < -9.82178231331464e+153

    1. Initial program 63.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num63.9

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Using strategy rm
    5. Applied flip-+63.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied flip--63.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \cdot \frac{x \cdot x - y \cdot y}{x - y}}}\]
    7. Applied frac-times64.0

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}{\left(x + y\right) \cdot \left(x - y\right)}}}}\]
    8. Applied associate-/r/64.0

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

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}}\]
    10. Simplified63.9

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

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

    if -9.82178231331464e+153 < y < -1.937646393364571e-161

    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)}}}\]
    4. Using strategy rm
    5. Applied flip-+0.0

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied flip--0.1

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \cdot \frac{x \cdot x - y \cdot y}{x - y}}}\]
    7. Applied frac-times27.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}{\left(x + y\right) \cdot \left(x - y\right)}}}}\]
    8. Applied associate-/r/28.0

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

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}}\]
    10. Simplified0.0

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

    if -1.937646393364571e-161 < y < 1.8282600166370302e-162

    1. Initial program 29.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num29.7

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Taylor expanded around inf 14.6

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

    if 1.8282600166370302e-162 < y

    1. Initial program 0.1

      \[\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 simplification4.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\ \mathbf{elif}\;y \le 1.828260016637030233456157191815862132037 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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