Average Error: 20.2 → 5.2
Time: 8.5s
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 -1.133041248169889485704928868462676821371 \cdot 10^{154}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le -6.692220829649749294501672462795840344495 \cdot 10^{-158} \lor \neg \left(y \le 1.219697898657824473673616108359575531018 \cdot 10^{-167}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \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 -1.133041248169889485704928868462676821371 \cdot 10^{154}:\\
\;\;\;\;\frac{x - y}{y - x}\\

\mathbf{elif}\;y \le -6.692220829649749294501672462795840344495 \cdot 10^{-158} \lor \neg \left(y \le 1.219697898657824473673616108359575531018 \cdot 10^{-167}\right):\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r135033 = x;
        double r135034 = y;
        double r135035 = r135033 - r135034;
        double r135036 = r135033 + r135034;
        double r135037 = r135035 * r135036;
        double r135038 = r135033 * r135033;
        double r135039 = r135034 * r135034;
        double r135040 = r135038 + r135039;
        double r135041 = r135037 / r135040;
        return r135041;
}

double f(double x, double y) {
        double r135042 = y;
        double r135043 = -1.1330412481698895e+154;
        bool r135044 = r135042 <= r135043;
        double r135045 = x;
        double r135046 = r135045 - r135042;
        double r135047 = r135042 - r135045;
        double r135048 = r135046 / r135047;
        double r135049 = -6.692220829649749e-158;
        bool r135050 = r135042 <= r135049;
        double r135051 = 1.2196978986578245e-167;
        bool r135052 = r135042 <= r135051;
        double r135053 = !r135052;
        bool r135054 = r135050 || r135053;
        double r135055 = r135045 + r135042;
        double r135056 = r135046 * r135055;
        double r135057 = r135045 * r135045;
        double r135058 = r135042 * r135042;
        double r135059 = r135057 + r135058;
        double r135060 = r135056 / r135059;
        double r135061 = 1.0;
        double r135062 = r135054 ? r135060 : r135061;
        double r135063 = r135044 ? r135048 : r135062;
        return r135063;
}

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.2
Target0.0
Herbie5.2
\[\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.1330412481698895e+154

    1. Initial program 64.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*62.0

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

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

    if -1.1330412481698895e+154 < y < -6.692220829649749e-158 or 1.2196978986578245e-167 < y

    1. Initial program 0.4

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

    if -6.692220829649749e-158 < y < 1.2196978986578245e-167

    1. Initial program 30.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.133041248169889485704928868462676821371 \cdot 10^{154}:\\ \;\;\;\;\frac{x - y}{y - x}\\ \mathbf{elif}\;y \le -6.692220829649749294501672462795840344495 \cdot 10^{-158} \lor \neg \left(y \le 1.219697898657824473673616108359575531018 \cdot 10^{-167}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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