Average Error: 20.2 → 5.0
Time: 14.8s
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.082274284195729575558840081904180391227 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.525836621341174380993007144208805388616 \cdot 10^{-161} \lor \neg \left(y \le 2.03127253257456944718278947981499411723 \cdot 10^{-162}\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 -1.082274284195729575558840081904180391227 \cdot 10^{154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.525836621341174380993007144208805388616 \cdot 10^{-161} \lor \neg \left(y \le 2.03127253257456944718278947981499411723 \cdot 10^{-162}\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 r72688 = x;
        double r72689 = y;
        double r72690 = r72688 - r72689;
        double r72691 = r72688 + r72689;
        double r72692 = r72690 * r72691;
        double r72693 = r72688 * r72688;
        double r72694 = r72689 * r72689;
        double r72695 = r72693 + r72694;
        double r72696 = r72692 / r72695;
        return r72696;
}

double f(double x, double y) {
        double r72697 = y;
        double r72698 = -1.0822742841957296e+154;
        bool r72699 = r72697 <= r72698;
        double r72700 = -1.0;
        double r72701 = -3.5258366213411744e-161;
        bool r72702 = r72697 <= r72701;
        double r72703 = 2.0312725325745694e-162;
        bool r72704 = r72697 <= r72703;
        double r72705 = !r72704;
        bool r72706 = r72702 || r72705;
        double r72707 = x;
        double r72708 = r72707 - r72697;
        double r72709 = r72707 + r72697;
        double r72710 = r72708 * r72709;
        double r72711 = r72707 * r72707;
        double r72712 = r72697 * r72697;
        double r72713 = r72711 + r72712;
        double r72714 = r72710 / r72713;
        double r72715 = 3.0;
        double r72716 = pow(r72714, r72715);
        double r72717 = cbrt(r72716);
        double r72718 = 1.0;
        double r72719 = r72706 ? r72717 : r72718;
        double r72720 = r72699 ? r72700 : r72719;
        return r72720;
}

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.2
Target0.0
Herbie5.0
\[\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.0822742841957296e+154

    1. Initial program 64.0

      \[\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 -1.0822742841957296e+154 < y < -3.5258366213411744e-161 or 2.0312725325745694e-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}}}\]
    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 -3.5258366213411744e-161 < y < 2.0312725325745694e-162

    1. Initial program 30.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.082274284195729575558840081904180391227 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.525836621341174380993007144208805388616 \cdot 10^{-161} \lor \neg \left(y \le 2.03127253257456944718278947981499411723 \cdot 10^{-162}\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 2019212 
(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))))