Average Error: 20.6 → 5.2
Time: 10.6s
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.6930748104447922 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.91773166521773073 \cdot 10^{-160}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \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.6930748104447922 \cdot 10^{150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.91773166521773073 \cdot 10^{-160}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\

\end{array}
double f(double x, double y) {
        double r101160 = x;
        double r101161 = y;
        double r101162 = r101160 - r101161;
        double r101163 = r101160 + r101161;
        double r101164 = r101162 * r101163;
        double r101165 = r101160 * r101160;
        double r101166 = r101161 * r101161;
        double r101167 = r101165 + r101166;
        double r101168 = r101164 / r101167;
        return r101168;
}

double f(double x, double y) {
        double r101169 = y;
        double r101170 = -1.693074810444792e+150;
        bool r101171 = r101169 <= r101170;
        double r101172 = -1.0;
        double r101173 = -1.9177316652177307e-160;
        bool r101174 = r101169 <= r101173;
        double r101175 = x;
        double r101176 = r101175 - r101169;
        double r101177 = r101175 + r101169;
        double r101178 = r101176 * r101177;
        double r101179 = r101175 * r101175;
        double r101180 = r101169 * r101169;
        double r101181 = r101179 + r101180;
        double r101182 = r101178 / r101181;
        double r101183 = 2.87578004264954e-160;
        bool r101184 = r101169 <= r101183;
        double r101185 = 1.0;
        double r101186 = r101181 / r101178;
        double r101187 = r101185 / r101186;
        double r101188 = r101184 ? r101185 : r101187;
        double r101189 = r101174 ? r101182 : r101188;
        double r101190 = r101171 ? r101172 : r101189;
        return r101190;
}

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.1
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 4 regimes
  2. if y < -1.693074810444792e+150

    1. Initial program 62.1

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

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

    if -1.693074810444792e+150 < y < -1.9177316652177307e-160

    1. Initial program 0.0

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

    if -1.9177316652177307e-160 < y < 2.87578004264954e-160

    1. Initial program 30.6

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

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

    if 2.87578004264954e-160 < y

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num0.1

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.6930748104447922 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.91773166521773073 \cdot 10^{-160}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.87578004264953974 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \end{array}\]

Reproduce

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