Average Error: 20.2 → 5.1
Time: 19.3s
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.3740657909060598 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.2764103459019323 \cdot 10^{-152}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 7.647705034433286 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \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.3740657909060598 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.2764103459019323 \cdot 10^{-152}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\

\end{array}
double f(double x, double y) {
        double r7256952 = x;
        double r7256953 = y;
        double r7256954 = r7256952 - r7256953;
        double r7256955 = r7256952 + r7256953;
        double r7256956 = r7256954 * r7256955;
        double r7256957 = r7256952 * r7256952;
        double r7256958 = r7256953 * r7256953;
        double r7256959 = r7256957 + r7256958;
        double r7256960 = r7256956 / r7256959;
        return r7256960;
}

double f(double x, double y) {
        double r7256961 = y;
        double r7256962 = -1.3740657909060598e+154;
        bool r7256963 = r7256961 <= r7256962;
        double r7256964 = -1.0;
        double r7256965 = -3.2764103459019323e-152;
        bool r7256966 = r7256961 <= r7256965;
        double r7256967 = x;
        double r7256968 = r7256967 - r7256961;
        double r7256969 = r7256961 + r7256967;
        double r7256970 = r7256968 * r7256969;
        double r7256971 = r7256961 * r7256961;
        double r7256972 = r7256967 * r7256967;
        double r7256973 = r7256971 + r7256972;
        double r7256974 = r7256970 / r7256973;
        double r7256975 = 7.647705034433286e-163;
        bool r7256976 = r7256961 <= r7256975;
        double r7256977 = 1.0;
        double r7256978 = r7256976 ? r7256977 : r7256974;
        double r7256979 = r7256966 ? r7256974 : r7256978;
        double r7256980 = r7256963 ? r7256964 : r7256979;
        return r7256980;
}

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.1
Herbie5.1
\[\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.3740657909060598e+154

    1. Initial program 63.6

      \[\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.3740657909060598e+154 < y < -3.2764103459019323e-152 or 7.647705034433286e-163 < y

    1. Initial program 0.1

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

    if -3.2764103459019323e-152 < y < 7.647705034433286e-163

    1. Initial program 29.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt29.1

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac29.8

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Taylor expanded around inf 15.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3740657909060598 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.2764103459019323 \cdot 10^{-152}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 7.647705034433286 \cdot 10^{-163}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \end{array}\]

Reproduce

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