Average Error: 20.1 → 5.2
Time: 1.8m
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.3730354842790037 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.534922755068586 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 3.053717103568057 \cdot 10^{-167}:\\ \;\;\;\;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.3730354842790037 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 3.053717103568057 \cdot 10^{-167}:\\
\;\;\;\;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 r25378236 = x;
        double r25378237 = y;
        double r25378238 = r25378236 - r25378237;
        double r25378239 = r25378236 + r25378237;
        double r25378240 = r25378238 * r25378239;
        double r25378241 = r25378236 * r25378236;
        double r25378242 = r25378237 * r25378237;
        double r25378243 = r25378241 + r25378242;
        double r25378244 = r25378240 / r25378243;
        return r25378244;
}

double f(double x, double y) {
        double r25378245 = y;
        double r25378246 = -1.3730354842790037e+154;
        bool r25378247 = r25378245 <= r25378246;
        double r25378248 = -1.0;
        double r25378249 = -4.534922755068586e-162;
        bool r25378250 = r25378245 <= r25378249;
        double r25378251 = x;
        double r25378252 = r25378251 - r25378245;
        double r25378253 = r25378245 + r25378251;
        double r25378254 = r25378252 * r25378253;
        double r25378255 = r25378245 * r25378245;
        double r25378256 = r25378251 * r25378251;
        double r25378257 = r25378255 + r25378256;
        double r25378258 = r25378254 / r25378257;
        double r25378259 = 3.053717103568057e-167;
        bool r25378260 = r25378245 <= r25378259;
        double r25378261 = 1.0;
        double r25378262 = r25378260 ? r25378261 : r25378258;
        double r25378263 = r25378250 ? r25378258 : r25378262;
        double r25378264 = r25378247 ? r25378248 : r25378263;
        return r25378264;
}

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.2
\[\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.3730354842790037e+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.3730354842790037e+154 < y < -4.534922755068586e-162 or 3.053717103568057e-167 < y

    1. Initial program 0.5

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

    if -4.534922755068586e-162 < y < 3.053717103568057e-167

    1. Initial program 29.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3730354842790037 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.534922755068586 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 3.053717103568057 \cdot 10^{-167}:\\ \;\;\;\;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 2019107 
(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))))