Average Error: 19.5 → 5.2
Time: 32.2s
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 r8070753 = x;
        double r8070754 = y;
        double r8070755 = r8070753 - r8070754;
        double r8070756 = r8070753 + r8070754;
        double r8070757 = r8070755 * r8070756;
        double r8070758 = r8070753 * r8070753;
        double r8070759 = r8070754 * r8070754;
        double r8070760 = r8070758 + r8070759;
        double r8070761 = r8070757 / r8070760;
        return r8070761;
}

double f(double x, double y) {
        double r8070762 = y;
        double r8070763 = -1.367949010508958e+154;
        bool r8070764 = r8070762 <= r8070763;
        double r8070765 = -1.0;
        double r8070766 = -3.564256890674104e-158;
        bool r8070767 = r8070762 <= r8070766;
        double r8070768 = r8070762 * r8070762;
        double r8070769 = x;
        double r8070770 = r8070769 * r8070769;
        double r8070771 = r8070770 + r8070768;
        double r8070772 = r8070768 / r8070771;
        double r8070773 = 1.0;
        double r8070774 = r8070771 / r8070770;
        double r8070775 = r8070773 / r8070774;
        double r8070776 = r8070772 - r8070775;
        double r8070777 = -r8070776;
        double r8070778 = 1.8050510261731553e-162;
        bool r8070779 = r8070762 <= r8070778;
        double r8070780 = r8070779 ? r8070773 : r8070777;
        double r8070781 = r8070767 ? r8070777 : r8070780;
        double r8070782 = r8070764 ? r8070765 : r8070781;
        return r8070782;
}

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))))