Average Error: 20.1 → 4.9
Time: 10.2s
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.3341061642710286 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.1638085591132404 \cdot 10^{-160}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.5708400865028228 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{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.3341061642710286 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.1638085591132404 \cdot 10^{-160}:\\
\;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 1.5708400865028228 \cdot 10^{-162}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r3736254 = x;
        double r3736255 = y;
        double r3736256 = r3736254 - r3736255;
        double r3736257 = r3736254 + r3736255;
        double r3736258 = r3736256 * r3736257;
        double r3736259 = r3736254 * r3736254;
        double r3736260 = r3736255 * r3736255;
        double r3736261 = r3736259 + r3736260;
        double r3736262 = r3736258 / r3736261;
        return r3736262;
}

double f(double x, double y) {
        double r3736263 = y;
        double r3736264 = -1.3341061642710286e+154;
        bool r3736265 = r3736263 <= r3736264;
        double r3736266 = -1.0;
        double r3736267 = -1.1638085591132404e-160;
        bool r3736268 = r3736263 <= r3736267;
        double r3736269 = r3736263 * r3736263;
        double r3736270 = x;
        double r3736271 = r3736270 * r3736270;
        double r3736272 = r3736269 - r3736271;
        double r3736273 = r3736271 + r3736269;
        double r3736274 = r3736272 / r3736273;
        double r3736275 = -r3736274;
        double r3736276 = 1.5708400865028228e-162;
        bool r3736277 = r3736263 <= r3736276;
        double r3736278 = 1.0;
        double r3736279 = r3736277 ? r3736278 : r3736275;
        double r3736280 = r3736268 ? r3736275 : r3736279;
        double r3736281 = r3736265 ? r3736266 : r3736280;
        return r3736281;
}

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
Herbie4.9
\[\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.3341061642710286e+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{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 0

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

    if -1.3341061642710286e+154 < y < -1.1638085591132404e-160 or 1.5708400865028228e-162 < y

    1. Initial program 0.0

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

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

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

    if -1.1638085591132404e-160 < y < 1.5708400865028228e-162

    1. Initial program 30.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3341061642710286 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.1638085591132404 \cdot 10^{-160}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.5708400865028228 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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