Average Error: 20.3 → 5.0
Time: 3.9s
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 -9.7481688320642468 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.8249914759998345 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 1.576932748768084 \cdot 10^{-162}:\\ \;\;\;\;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 -9.7481688320642468 \cdot 10^{142}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.576932748768084 \cdot 10^{-162}:\\
\;\;\;\;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 r90598 = x;
        double r90599 = y;
        double r90600 = r90598 - r90599;
        double r90601 = r90598 + r90599;
        double r90602 = r90600 * r90601;
        double r90603 = r90598 * r90598;
        double r90604 = r90599 * r90599;
        double r90605 = r90603 + r90604;
        double r90606 = r90602 / r90605;
        return r90606;
}

double f(double x, double y) {
        double r90607 = y;
        double r90608 = -9.748168832064247e+142;
        bool r90609 = r90607 <= r90608;
        double r90610 = -1.0;
        double r90611 = -2.8249914759998345e-162;
        bool r90612 = r90607 <= r90611;
        double r90613 = 1.0;
        double r90614 = x;
        double r90615 = r90614 * r90614;
        double r90616 = r90607 * r90607;
        double r90617 = r90615 + r90616;
        double r90618 = r90614 - r90607;
        double r90619 = r90614 + r90607;
        double r90620 = r90618 * r90619;
        double r90621 = r90617 / r90620;
        double r90622 = r90613 / r90621;
        double r90623 = 1.576932748768084e-162;
        bool r90624 = r90607 <= r90623;
        double r90625 = r90624 ? r90613 : r90622;
        double r90626 = r90612 ? r90622 : r90625;
        double r90627 = r90609 ? r90610 : r90626;
        return r90627;
}

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.3
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 < -9.748168832064247e+142

    1. Initial program 59.9

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

      \[\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 times-frac58.1

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

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

    if -9.748168832064247e+142 < y < -2.8249914759998345e-162 or 1.576932748768084e-162 < 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.0

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

    if -2.8249914759998345e-162 < y < 1.576932748768084e-162

    1. Initial program 31.0

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

      \[\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 times-frac31.6

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Taylor expanded around inf 16.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.7481688320642468 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.8249914759998345 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le 1.576932748768084 \cdot 10^{-162}:\\ \;\;\;\;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 2020020 
(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))))