Average Error: 19.5 → 5.2
Time: 12.5s
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.367949010508958 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.564256890674104 \cdot 10^{-158}:\\ \;\;\;\;-\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}\right)\\ \mathbf{elif}\;y \le 1.8050510261731553 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}\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.367949010508958 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.8050510261731553 \cdot 10^{-162}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r4106106 = x;
        double r4106107 = y;
        double r4106108 = r4106106 - r4106107;
        double r4106109 = r4106106 + r4106107;
        double r4106110 = r4106108 * r4106109;
        double r4106111 = r4106106 * r4106106;
        double r4106112 = r4106107 * r4106107;
        double r4106113 = r4106111 + r4106112;
        double r4106114 = r4106110 / r4106113;
        return r4106114;
}

double f(double x, double y) {
        double r4106115 = y;
        double r4106116 = -1.367949010508958e+154;
        bool r4106117 = r4106115 <= r4106116;
        double r4106118 = -1.0;
        double r4106119 = -3.564256890674104e-158;
        bool r4106120 = r4106115 <= r4106119;
        double r4106121 = r4106115 * r4106115;
        double r4106122 = x;
        double r4106123 = r4106122 * r4106122;
        double r4106124 = r4106123 + r4106121;
        double r4106125 = r4106121 / r4106124;
        double r4106126 = 1.0;
        double r4106127 = r4106124 / r4106123;
        double r4106128 = r4106126 / r4106127;
        double r4106129 = r4106125 - r4106128;
        double r4106130 = -r4106129;
        double r4106131 = 1.8050510261731553e-162;
        bool r4106132 = r4106115 <= r4106131;
        double r4106133 = r4106132 ? r4106126 : r4106130;
        double r4106134 = r4106120 ? r4106130 : r4106133;
        double r4106135 = r4106117 ? r4106118 : r4106134;
        return r4106135;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.5
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 3 regimes
  2. if y < -1.367949010508958e+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{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 0

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

    if -1.367949010508958e+154 < y < -3.564256890674104e-158 or 1.8050510261731553e-162 < y

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied div-sub0.0

      \[\leadsto -\color{blue}{\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \frac{x \cdot x}{x \cdot x + y \cdot y}\right)}\]
    5. Using strategy rm
    6. Applied clear-num0.0

      \[\leadsto -\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}}\right)\]

    if -3.564256890674104e-158 < y < 1.8050510261731553e-162

    1. Initial program 29.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.367949010508958 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.564256890674104 \cdot 10^{-158}:\\ \;\;\;\;-\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}\right)\\ \mathbf{elif}\;y \le 1.8050510261731553 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\left(\frac{y \cdot y}{x \cdot x + y \cdot y} - \frac{1}{\frac{x \cdot x + y \cdot y}{x \cdot x}}\right)\\ \end{array}\]

Reproduce

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