Average Error: 20.3 → 5.5
Time: 7.9s
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.3472849343494396 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.1717566453158604 \cdot 10^{-152}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.0973588853044266 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \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.3472849343494396 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 2.0973588853044266 \cdot 10^{-164}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r2809409 = x;
        double r2809410 = y;
        double r2809411 = r2809409 - r2809410;
        double r2809412 = r2809409 + r2809410;
        double r2809413 = r2809411 * r2809412;
        double r2809414 = r2809409 * r2809409;
        double r2809415 = r2809410 * r2809410;
        double r2809416 = r2809414 + r2809415;
        double r2809417 = r2809413 / r2809416;
        return r2809417;
}

double f(double x, double y) {
        double r2809418 = y;
        double r2809419 = -1.3472849343494396e+154;
        bool r2809420 = r2809418 <= r2809419;
        double r2809421 = -1.0;
        double r2809422 = -2.1717566453158604e-152;
        bool r2809423 = r2809418 <= r2809422;
        double r2809424 = x;
        double r2809425 = r2809424 * r2809424;
        double r2809426 = r2809418 * r2809418;
        double r2809427 = r2809425 + r2809426;
        double r2809428 = r2809425 / r2809427;
        double r2809429 = r2809426 / r2809427;
        double r2809430 = r2809428 - r2809429;
        double r2809431 = 2.0973588853044266e-164;
        bool r2809432 = r2809418 <= r2809431;
        double r2809433 = 1.0;
        double r2809434 = r2809432 ? r2809433 : r2809430;
        double r2809435 = r2809423 ? r2809430 : r2809434;
        double r2809436 = r2809420 ? r2809421 : r2809435;
        return r2809436;
}

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.0
Herbie5.5
\[\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.3472849343494396e+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.3472849343494396e+154 < y < -2.1717566453158604e-152 or 2.0973588853044266e-164 < y

    1. Initial program 0.1

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

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

    if -2.1717566453158604e-152 < y < 2.0973588853044266e-164

    1. Initial program 29.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified29.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. Taylor expanded around -inf 16.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3472849343494396 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.1717566453158604 \cdot 10^{-152}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.0973588853044266 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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