Average Error: 20.0 → 8.0
Time: 11.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 -2.92690375472246175352160983946616260701 \cdot 10^{-134}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 5.816163962969591972156246782697755183642 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x - 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 -2.92690375472246175352160983946616260701 \cdot 10^{-134}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r5151313 = x;
        double r5151314 = y;
        double r5151315 = r5151313 - r5151314;
        double r5151316 = r5151313 + r5151314;
        double r5151317 = r5151315 * r5151316;
        double r5151318 = r5151313 * r5151313;
        double r5151319 = r5151314 * r5151314;
        double r5151320 = r5151318 + r5151319;
        double r5151321 = r5151317 / r5151320;
        return r5151321;
}

double f(double x, double y) {
        double r5151322 = y;
        double r5151323 = -2.9269037547224618e-134;
        bool r5151324 = r5151322 <= r5151323;
        double r5151325 = -1.0;
        double r5151326 = 5.816163962969592e-162;
        bool r5151327 = r5151322 <= r5151326;
        double r5151328 = 1.0;
        double r5151329 = x;
        double r5151330 = r5151329 * r5151329;
        double r5151331 = r5151322 * r5151322;
        double r5151332 = r5151330 - r5151331;
        double r5151333 = r5151330 + r5151331;
        double r5151334 = r5151332 / r5151333;
        double r5151335 = r5151327 ? r5151328 : r5151334;
        double r5151336 = r5151324 ? r5151325 : r5151335;
        return r5151336;
}

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.0
Target0.1
Herbie8.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 < -2.9269037547224618e-134

    1. Initial program 22.1

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

      \[\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 4.2

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

    if -2.9269037547224618e-134 < y < 5.816163962969592e-162

    1. Initial program 27.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified27.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 17.2

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

    if 5.816163962969592e-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{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 sub-div0.0

      \[\leadsto \color{blue}{\frac{x \cdot x - y \cdot y}{x \cdot x + y \cdot y}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.92690375472246175352160983946616260701 \cdot 10^{-134}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 5.816163962969591972156246782697755183642 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x - y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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