Average Error: 20.5 → 5.5
Time: 1.7m
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.3363011022663002 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.452451271730543 \cdot 10^{-154}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \mathbf{elif}\;y \le 2.6338497742796816 \cdot 10^{-188}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{1}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - 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 -1.3363011022663002 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 2.6338497742796816 \cdot 10^{-188}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r14610732 = x;
        double r14610733 = y;
        double r14610734 = r14610732 - r14610733;
        double r14610735 = r14610732 + r14610733;
        double r14610736 = r14610734 * r14610735;
        double r14610737 = r14610732 * r14610732;
        double r14610738 = r14610733 * r14610733;
        double r14610739 = r14610737 + r14610738;
        double r14610740 = r14610736 / r14610739;
        return r14610740;
}

double f(double x, double y) {
        double r14610741 = y;
        double r14610742 = -1.3363011022663002e+154;
        bool r14610743 = r14610741 <= r14610742;
        double r14610744 = -1.0;
        double r14610745 = -4.452451271730543e-154;
        bool r14610746 = r14610741 <= r14610745;
        double r14610747 = 1.0;
        double r14610748 = x;
        double r14610749 = r14610748 * r14610748;
        double r14610750 = r14610741 * r14610741;
        double r14610751 = r14610749 + r14610750;
        double r14610752 = r14610748 - r14610741;
        double r14610753 = r14610741 + r14610748;
        double r14610754 = r14610752 * r14610753;
        double r14610755 = r14610751 / r14610754;
        double r14610756 = r14610747 / r14610755;
        double r14610757 = 2.6338497742796816e-188;
        bool r14610758 = r14610741 <= r14610757;
        double r14610759 = sqrt(r14610751);
        double r14610760 = r14610753 / r14610759;
        double r14610761 = r14610759 / r14610752;
        double r14610762 = r14610747 / r14610761;
        double r14610763 = r14610760 * r14610762;
        double r14610764 = r14610758 ? r14610747 : r14610763;
        double r14610765 = r14610746 ? r14610756 : r14610764;
        double r14610766 = r14610743 ? r14610744 : r14610765;
        return r14610766;
}

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.5
Target0.1
Herbie5.5
\[\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.3363011022663002e+154

    1. Initial program 63.6

      \[\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.3363011022663002e+154 < y < -4.452451271730543e-154

    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 -4.452451271730543e-154 < y < 2.6338497742796816e-188

    1. Initial program 29.1

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

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

    if 2.6338497742796816e-188 < y

    1. Initial program 4.5

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

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt4.5

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{\left(x - y\right) \cdot \left(x + y\right)}}\]
    6. Applied times-frac4.9

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - y} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{x + y}}}\]
    7. Applied add-cube-cbrt4.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - y} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{x + y}}\]
    8. Applied times-frac4.9

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - y}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{x \cdot x + y \cdot y}}{x + y}}}\]
    9. Simplified4.9

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - y}} \cdot \color{blue}{\frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3363011022663002 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.452451271730543 \cdot 10^{-154}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \mathbf{elif}\;y \le 2.6338497742796816 \cdot 10^{-188}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{1}{\frac{\sqrt{x \cdot x + y \cdot y}}{x - y}}\\ \end{array}\]

Reproduce

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