Average Error: 20.1 → 5.0
Time: 12.0s
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 -5.797856225877881060769082412965027708037 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.329253761175223739159446383274506990081 \cdot 10^{-158}:\\ \;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 7.961862811311691246218405838467989119993 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\ \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 -5.797856225877881060769082412965027708037 \cdot 10^{150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.329253761175223739159446383274506990081 \cdot 10^{-158}:\\
\;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\

\mathbf{elif}\;y \le 7.961862811311691246218405838467989119993 \cdot 10^{-164}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\

\end{array}
double f(double x, double y) {
        double r5592129 = x;
        double r5592130 = y;
        double r5592131 = r5592129 - r5592130;
        double r5592132 = r5592129 + r5592130;
        double r5592133 = r5592131 * r5592132;
        double r5592134 = r5592129 * r5592129;
        double r5592135 = r5592130 * r5592130;
        double r5592136 = r5592134 + r5592135;
        double r5592137 = r5592133 / r5592136;
        return r5592137;
}

double f(double x, double y) {
        double r5592138 = y;
        double r5592139 = -5.797856225877881e+150;
        bool r5592140 = r5592138 <= r5592139;
        double r5592141 = -1.0;
        double r5592142 = -1.3292537611752237e-158;
        bool r5592143 = r5592138 <= r5592142;
        double r5592144 = x;
        double r5592145 = r5592144 * r5592144;
        double r5592146 = r5592138 * r5592138;
        double r5592147 = r5592145 + r5592146;
        double r5592148 = sqrt(r5592147);
        double r5592149 = r5592145 / r5592148;
        double r5592150 = r5592138 / r5592148;
        double r5592151 = r5592150 * r5592138;
        double r5592152 = r5592149 - r5592151;
        double r5592153 = r5592152 / r5592148;
        double r5592154 = 7.961862811311691e-164;
        bool r5592155 = r5592138 <= r5592154;
        double r5592156 = 1.0;
        double r5592157 = r5592155 ? r5592156 : r5592153;
        double r5592158 = r5592143 ? r5592153 : r5592157;
        double r5592159 = r5592140 ? r5592141 : r5592158;
        return r5592159;
}

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.1
Target0.0
Herbie5.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 3 regimes
  2. if y < -5.797856225877881e+150

    1. Initial program 62.3

      \[\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 -5.797856225877881e+150 < y < -1.3292537611752237e-158 or 7.961862811311691e-164 < y

    1. Initial program 0.1

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied associate-/r*0.2

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Simplified0.2

      \[\leadsto \frac{\color{blue}{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y \cdot y}{\sqrt{x \cdot x + y \cdot y}}}}{\sqrt{x \cdot x + y \cdot y}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity0.2

      \[\leadsto \frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y \cdot y}{\sqrt{\color{blue}{1 \cdot \left(x \cdot x + y \cdot y\right)}}}}{\sqrt{x \cdot x + y \cdot y}}\]
    8. Applied sqrt-prod0.2

      \[\leadsto \frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y \cdot y}{\color{blue}{\sqrt{1} \cdot \sqrt{x \cdot x + y \cdot y}}}}{\sqrt{x \cdot x + y \cdot y}}\]
    9. Applied times-frac0.4

      \[\leadsto \frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \color{blue}{\frac{y}{\sqrt{1}} \cdot \frac{y}{\sqrt{x \cdot x + y \cdot y}}}}{\sqrt{x \cdot x + y \cdot y}}\]
    10. Simplified0.4

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

    if -1.3292537611752237e-158 < y < 7.961862811311691e-164

    1. Initial program 29.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -5.797856225877881060769082412965027708037 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.329253761175223739159446383274506990081 \cdot 10^{-158}:\\ \;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\ \mathbf{elif}\;y \le 7.961862811311691246218405838467989119993 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot x}{\sqrt{x \cdot x + y \cdot y}} - \frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot y}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))