Average Error: 20.6 → 11.0
Time: 2.4s
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 r54022 = x;
        double r54023 = y;
        double r54024 = r54022 - r54023;
        double r54025 = r54022 + r54023;
        double r54026 = r54024 * r54025;
        double r54027 = r54022 * r54022;
        double r54028 = r54023 * r54023;
        double r54029 = r54027 + r54028;
        double r54030 = r54026 / r54029;
        return r54030;
}

double f(double __attribute__((unused)) x, double y) {
        double r54031 = y;
        double r54032 = -2.3535626334019465e-113;
        bool r54033 = r54031 <= r54032;
        double r54034 = -1.0;
        double r54035 = 7.030477083965542e-131;
        bool r54036 = r54031 <= r54035;
        double r54037 = 1.0;
        double r54038 = r54036 ? r54037 : r54034;
        double r54039 = r54033 ? r54034 : r54038;
        return r54039;
}

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. Simplified18.1

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}}\]
    3. 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. Simplified24.7

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}}\]
    3. 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))))