Average Error: 20.1 → 5.8
Time: 13.1s
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.331422128540074531478604803697494380994 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.442199717490925538211935056920460457484 \cdot 10^{-141} \lor \neg \left(y \le 4.132147070209029551225717614816463605085 \cdot 10^{-169}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}} \cdot \sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\right) \cdot \sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\\ \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.331422128540074531478604803697494380994 \cdot 10^{154}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r66153 = x;
        double r66154 = y;
        double r66155 = r66153 - r66154;
        double r66156 = r66153 + r66154;
        double r66157 = r66155 * r66156;
        double r66158 = r66153 * r66153;
        double r66159 = r66154 * r66154;
        double r66160 = r66158 + r66159;
        double r66161 = r66157 / r66160;
        return r66161;
}

double f(double x, double y) {
        double r66162 = y;
        double r66163 = -1.3314221285400745e+154;
        bool r66164 = r66162 <= r66163;
        double r66165 = -1.0;
        double r66166 = -1.4421997174909255e-141;
        bool r66167 = r66162 <= r66166;
        double r66168 = 4.1321470702090296e-169;
        bool r66169 = r66162 <= r66168;
        double r66170 = !r66169;
        bool r66171 = r66167 || r66170;
        double r66172 = x;
        double r66173 = r66172 - r66162;
        double r66174 = r66172 * r66172;
        double r66175 = r66162 * r66162;
        double r66176 = r66174 + r66175;
        double r66177 = r66162 + r66172;
        double r66178 = r66176 / r66177;
        double r66179 = r66173 / r66178;
        double r66180 = cbrt(r66179);
        double r66181 = r66180 * r66180;
        double r66182 = r66181 * r66180;
        double r66183 = 1.0;
        double r66184 = r66171 ? r66182 : r66183;
        double r66185 = r66164 ? r66165 : r66184;
        return r66185;
}

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.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.3314221285400745e+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.3314221285400745e+154 < y < -1.4421997174909255e-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}}}\]
    4. Simplified0.7

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

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

    if -1.4421997174909255e-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.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.331422128540074531478604803697494380994 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.442199717490925538211935056920460457484 \cdot 10^{-141} \lor \neg \left(y \le 4.132147070209029551225717614816463605085 \cdot 10^{-169}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}} \cdot \sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\right) \cdot \sqrt[3]{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\\ \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))))