Average Error: 20.3 → 5.0
Time: 14.7s
Precision: 64
\[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.334219986648209 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.6696225172636794 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.7320534110029677 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \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.334219986648209 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.6696225172636794 \cdot 10^{-156}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 1.7320534110029677 \cdot 10^{-177}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\

\end{array}
double f(double x, double y) {
        double r3712846 = x;
        double r3712847 = y;
        double r3712848 = r3712846 - r3712847;
        double r3712849 = r3712846 + r3712847;
        double r3712850 = r3712848 * r3712849;
        double r3712851 = r3712846 * r3712846;
        double r3712852 = r3712847 * r3712847;
        double r3712853 = r3712851 + r3712852;
        double r3712854 = r3712850 / r3712853;
        return r3712854;
}

double f(double x, double y) {
        double r3712855 = y;
        double r3712856 = -1.334219986648209e+154;
        bool r3712857 = r3712855 <= r3712856;
        double r3712858 = -1.0;
        double r3712859 = -3.6696225172636794e-156;
        bool r3712860 = r3712855 <= r3712859;
        double r3712861 = 1.0;
        double r3712862 = x;
        double r3712863 = r3712862 * r3712862;
        double r3712864 = r3712855 * r3712855;
        double r3712865 = r3712863 + r3712864;
        double r3712866 = r3712865 / r3712863;
        double r3712867 = r3712861 / r3712866;
        double r3712868 = r3712864 / r3712865;
        double r3712869 = r3712867 - r3712868;
        double r3712870 = 1.7320534110029677e-177;
        bool r3712871 = r3712855 <= r3712870;
        double r3712872 = r3712871 ? r3712861 : r3712869;
        double r3712873 = r3712860 ? r3712869 : r3712872;
        double r3712874 = r3712857 ? r3712858 : r3712873;
        return r3712874;
}

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.3
Target0.1
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.334219986648209e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified63.6

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around 0 0

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

    if -1.334219986648209e+154 < y < -3.6696225172636794e-156 or 1.7320534110029677e-177 < y

    1. Initial program 0.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified0.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied clear-num0.9

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\]

    if -3.6696225172636794e-156 < y < 1.7320534110029677e-177

    1. Initial program 29.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified29.2

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 15.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.334219986648209 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.6696225172636794 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.7320534110029677 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019165 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 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))))