Average Error: 19.4 → 4.7
Time: 33.5s
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.3274516788363714 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.1787343740722824 \cdot 10^{-157}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 3.804078574192898 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x} \cdot \frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\right) \cdot \frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \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.3274516788363714 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

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

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

\end{array}
double f(double x, double y) {
        double r12688337 = x;
        double r12688338 = y;
        double r12688339 = r12688337 - r12688338;
        double r12688340 = r12688337 + r12688338;
        double r12688341 = r12688339 * r12688340;
        double r12688342 = r12688337 * r12688337;
        double r12688343 = r12688338 * r12688338;
        double r12688344 = r12688342 + r12688343;
        double r12688345 = r12688341 / r12688344;
        return r12688345;
}

double f(double x, double y) {
        double r12688346 = y;
        double r12688347 = -1.3274516788363714e+154;
        bool r12688348 = r12688346 <= r12688347;
        double r12688349 = -1.0;
        double r12688350 = -2.1787343740722824e-157;
        bool r12688351 = r12688346 <= r12688350;
        double r12688352 = x;
        double r12688353 = r12688352 - r12688346;
        double r12688354 = r12688346 + r12688352;
        double r12688355 = r12688353 * r12688354;
        double r12688356 = r12688346 * r12688346;
        double r12688357 = r12688352 * r12688352;
        double r12688358 = r12688356 + r12688357;
        double r12688359 = r12688355 / r12688358;
        double r12688360 = 3.804078574192898e-162;
        bool r12688361 = r12688346 <= r12688360;
        double r12688362 = 1.0;
        double r12688363 = r12688359 * r12688359;
        double r12688364 = r12688363 * r12688359;
        double r12688365 = cbrt(r12688364);
        double r12688366 = r12688361 ? r12688362 : r12688365;
        double r12688367 = r12688351 ? r12688359 : r12688366;
        double r12688368 = r12688348 ? r12688349 : r12688367;
        return r12688368;
}

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.4
Target0.0
Herbie4.7
\[\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.3274516788363714e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube63.6

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

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

    if -1.3274516788363714e+154 < y < -2.1787343740722824e-157

    1. Initial program 0.0

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

    if -2.1787343740722824e-157 < y < 3.804078574192898e-162

    1. Initial program 27.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt27.3

      \[\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-frac27.7

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Taylor expanded around -inf 15.0

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

    if 3.804078574192898e-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 add-cbrt-cube0.1

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \cdot \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right) \cdot \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.7

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

Reproduce

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