Average Error: 20.6 → 11.0
Time: 924.0ms
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.35356263340194646 \cdot 10^{-113}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 7.03047708396554176 \cdot 10^{-131}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \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.35356263340194646 \cdot 10^{-113}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 7.03047708396554176 \cdot 10^{-131}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
double f(double x, double y) {
        double r116448 = x;
        double r116449 = y;
        double r116450 = r116448 - r116449;
        double r116451 = r116448 + r116449;
        double r116452 = r116450 * r116451;
        double r116453 = r116448 * r116448;
        double r116454 = r116449 * r116449;
        double r116455 = r116453 + r116454;
        double r116456 = r116452 / r116455;
        return r116456;
}

double f(double __attribute__((unused)) x, double y) {
        double r116457 = y;
        double r116458 = -2.3535626334019465e-113;
        bool r116459 = r116457 <= r116458;
        double r116460 = -1.0;
        double r116461 = 7.030477083965542e-131;
        bool r116462 = r116457 <= r116461;
        double r116463 = 1.0;
        double r116464 = r116462 ? r116463 : r116460;
        double r116465 = r116459 ? r116460 : r116464;
        return r116465;
}

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.6
Target0.0
Herbie11.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 2 regimes
  2. if y < -2.3535626334019465e-113 or 7.030477083965542e-131 < y

    1. Initial program 18.5

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

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

    if -2.3535626334019465e-113 < y < 7.030477083965542e-131

    1. Initial program 23.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.35356263340194646 \cdot 10^{-113}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 7.03047708396554176 \cdot 10^{-131}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020046 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.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))))