Average Error: 20.1 → 5.7
Time: 12.7s
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.42434775145189198 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.34847619210042794 \cdot 10^{-141} \lor \neg \left(y \le 4.1321470702090296 \cdot 10^{-169}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\\ \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.42434775145189198 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.34847619210042794 \cdot 10^{-141} \lor \neg \left(y \le 4.1321470702090296 \cdot 10^{-169}\right):\\
\;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\\

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

\end{array}
double f(double x, double y) {
        double r58934 = x;
        double r58935 = y;
        double r58936 = r58934 - r58935;
        double r58937 = r58934 + r58935;
        double r58938 = r58936 * r58937;
        double r58939 = r58934 * r58934;
        double r58940 = r58935 * r58935;
        double r58941 = r58939 + r58940;
        double r58942 = r58938 / r58941;
        return r58942;
}

double f(double x, double y) {
        double r58943 = y;
        double r58944 = -1.424347751451892e+153;
        bool r58945 = r58943 <= r58944;
        double r58946 = -1.0;
        double r58947 = -2.348476192100428e-141;
        bool r58948 = r58943 <= r58947;
        double r58949 = 4.1321470702090296e-169;
        bool r58950 = r58943 <= r58949;
        double r58951 = !r58950;
        bool r58952 = r58948 || r58951;
        double r58953 = x;
        double r58954 = r58953 - r58943;
        double r58955 = r58953 + r58943;
        double r58956 = r58954 * r58955;
        double r58957 = r58953 * r58953;
        double r58958 = r58943 * r58943;
        double r58959 = r58957 + r58958;
        double r58960 = r58956 / r58959;
        double r58961 = cbrt(r58960);
        double r58962 = r58961 * r58961;
        double r58963 = r58962 * r58961;
        double r58964 = 1.0;
        double r58965 = r58952 ? r58963 : r58964;
        double r58966 = r58945 ? r58946 : r58965;
        return r58966;
}

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.1
Target0.1
Herbie5.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 3 regimes
  2. if y < -1.424347751451892e+153

    1. Initial program 63.8

      \[\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.424347751451892e+153 < y < -2.348476192100428e-141 or 4.1321470702090296e-169 < y

    1. Initial program 0.5

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

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

    if -2.348476192100428e-141 < y < 4.1321470702090296e-169

    1. Initial program 27.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.42434775145189198 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.34847619210042794 \cdot 10^{-141} \lor \neg \left(y \le 4.1321470702090296 \cdot 10^{-169}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019195 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))