Average Error: 20.0 → 4.8
Time: 2.2s
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.14178066733525963 \cdot 10^{154}:\\ \;\;\;\;\sqrt[3]{-1}\\ \mathbf{elif}\;y \le -1.6515932751816961 \cdot 10^{-162}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \mathbf{elif}\;y \le 7.8035108112990794 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \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.14178066733525963 \cdot 10^{154}:\\
\;\;\;\;\sqrt[3]{-1}\\

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

\mathbf{elif}\;y \le 7.8035108112990794 \cdot 10^{-163}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r68123 = x;
        double r68124 = y;
        double r68125 = r68123 - r68124;
        double r68126 = r68123 + r68124;
        double r68127 = r68125 * r68126;
        double r68128 = r68123 * r68123;
        double r68129 = r68124 * r68124;
        double r68130 = r68128 + r68129;
        double r68131 = r68127 / r68130;
        return r68131;
}

double f(double x, double y) {
        double r68132 = y;
        double r68133 = -1.1417806673352596e+154;
        bool r68134 = r68132 <= r68133;
        double r68135 = -1.0;
        double r68136 = cbrt(r68135);
        double r68137 = -1.651593275181696e-162;
        bool r68138 = r68132 <= r68137;
        double r68139 = x;
        double r68140 = r68139 - r68132;
        double r68141 = r68139 + r68132;
        double r68142 = r68140 * r68141;
        double r68143 = r68139 * r68139;
        double r68144 = r68132 * r68132;
        double r68145 = r68143 + r68144;
        double r68146 = r68142 / r68145;
        double r68147 = 3.0;
        double r68148 = pow(r68146, r68147);
        double r68149 = cbrt(r68148);
        double r68150 = 7.80351081129908e-163;
        bool r68151 = r68132 <= r68150;
        double r68152 = 1.0;
        double r68153 = r68151 ? r68152 : r68149;
        double r68154 = r68138 ? r68149 : r68153;
        double r68155 = r68134 ? r68136 : r68154;
        return r68155;
}

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.0
Target0.1
Herbie4.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.1417806673352596e+154

    1. Initial program 64.0

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    4. Applied add-cbrt-cube64.0

      \[\leadsto \frac{\left(x - y\right) \cdot \color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    5. Applied add-cbrt-cube64.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)}} \cdot \sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    6. Applied cbrt-unprod64.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    7. Applied cbrt-undiv64.0

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

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

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

    if -1.1417806673352596e+154 < y < -1.651593275181696e-162 or 7.80351081129908e-163 < y

    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 add-cbrt-cube37.2

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    4. Applied add-cbrt-cube37.5

      \[\leadsto \frac{\left(x - y\right) \cdot \color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    5. Applied add-cbrt-cube37.7

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)}} \cdot \sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    6. Applied cbrt-unprod37.2

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    7. Applied cbrt-undiv37.1

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

      \[\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 -1.651593275181696e-162 < y < 7.80351081129908e-163

    1. Initial program 29.4

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

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

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

Reproduce

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