Average Error: 19.6 → 4.9
Time: 27.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 -2.177668980432744910801239047230540451852 \cdot 10^{151}:\\ \;\;\;\;\sqrt[3]{-1}\\ \mathbf{elif}\;y \le -5.072088037283406952673541392243906788651 \cdot 10^{-162} \lor \neg \left(y \le 3.359239716448135408912382006946129864167 \cdot 10^{-163}\right):\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \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 -2.177668980432744910801239047230540451852 \cdot 10^{151}:\\
\;\;\;\;\sqrt[3]{-1}\\

\mathbf{elif}\;y \le -5.072088037283406952673541392243906788651 \cdot 10^{-162} \lor \neg \left(y \le 3.359239716448135408912382006946129864167 \cdot 10^{-163}\right):\\
\;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r84300 = x;
        double r84301 = y;
        double r84302 = r84300 - r84301;
        double r84303 = r84300 + r84301;
        double r84304 = r84302 * r84303;
        double r84305 = r84300 * r84300;
        double r84306 = r84301 * r84301;
        double r84307 = r84305 + r84306;
        double r84308 = r84304 / r84307;
        return r84308;
}

double f(double x, double y) {
        double r84309 = y;
        double r84310 = -2.177668980432745e+151;
        bool r84311 = r84309 <= r84310;
        double r84312 = -1.0;
        double r84313 = cbrt(r84312);
        double r84314 = -5.072088037283407e-162;
        bool r84315 = r84309 <= r84314;
        double r84316 = 3.3592397164481354e-163;
        bool r84317 = r84309 <= r84316;
        double r84318 = !r84317;
        bool r84319 = r84315 || r84318;
        double r84320 = x;
        double r84321 = r84320 - r84309;
        double r84322 = r84320 + r84309;
        double r84323 = r84321 * r84322;
        double r84324 = r84320 * r84320;
        double r84325 = r84309 * r84309;
        double r84326 = r84324 + r84325;
        double r84327 = r84323 / r84326;
        double r84328 = 3.0;
        double r84329 = pow(r84327, r84328);
        double r84330 = cbrt(r84329);
        double r84331 = 1.0;
        double r84332 = r84319 ? r84330 : r84331;
        double r84333 = r84311 ? r84313 : r84332;
        return r84333;
}

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.6
Target0.0
Herbie4.9
\[\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 < -2.177668980432745e+151

    1. Initial program 62.8

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

      \[\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. Simplified62.8

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

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

    if -2.177668980432745e+151 < y < -5.072088037283407e-162 or 3.3592397164481354e-163 < 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}}}\]
    4. Simplified0.1

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

    if -5.072088037283407e-162 < y < 3.3592397164481354e-163

    1. Initial program 30.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-cube30.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}}}\]
    4. Simplified30.1

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

      \[\leadsto \sqrt[3]{\color{blue}{1}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.177668980432744910801239047230540451852 \cdot 10^{151}:\\ \;\;\;\;\sqrt[3]{-1}\\ \mathbf{elif}\;y \le -5.072088037283406952673541392243906788651 \cdot 10^{-162} \lor \neg \left(y \le 3.359239716448135408912382006946129864167 \cdot 10^{-163}\right):\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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