Average Error: 19.5 → 4.8
Time: 12.4s
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.369677616151796 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.3534166982027225 \cdot 10^{-177}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \mathbf{elif}\;y \le -1.8586020041360913 \cdot 10^{-183}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 8.42369621266438 \cdot 10^{-175}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{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 -1.369677616151796 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.3534166982027225 \cdot 10^{-177}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\

\mathbf{elif}\;y \le -1.8586020041360913 \cdot 10^{-183}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 8.42369621266438 \cdot 10^{-175}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r3483794 = x;
        double r3483795 = y;
        double r3483796 = r3483794 - r3483795;
        double r3483797 = r3483794 + r3483795;
        double r3483798 = r3483796 * r3483797;
        double r3483799 = r3483794 * r3483794;
        double r3483800 = r3483795 * r3483795;
        double r3483801 = r3483799 + r3483800;
        double r3483802 = r3483798 / r3483801;
        return r3483802;
}

double f(double x, double y) {
        double r3483803 = y;
        double r3483804 = -1.369677616151796e+154;
        bool r3483805 = r3483803 <= r3483804;
        double r3483806 = -1.0;
        double r3483807 = -3.3534166982027225e-177;
        bool r3483808 = r3483803 <= r3483807;
        double r3483809 = x;
        double r3483810 = r3483809 * r3483809;
        double r3483811 = r3483803 * r3483803;
        double r3483812 = r3483810 + r3483811;
        double r3483813 = r3483810 / r3483812;
        double r3483814 = r3483811 / r3483812;
        double r3483815 = r3483813 - r3483814;
        double r3483816 = exp(r3483815);
        double r3483817 = log(r3483816);
        double r3483818 = -1.8586020041360913e-183;
        bool r3483819 = r3483803 <= r3483818;
        double r3483820 = 8.42369621266438e-175;
        bool r3483821 = r3483803 <= r3483820;
        double r3483822 = 1.0;
        double r3483823 = r3483809 - r3483803;
        double r3483824 = r3483803 + r3483809;
        double r3483825 = r3483823 * r3483824;
        double r3483826 = r3483825 / r3483812;
        double r3483827 = r3483821 ? r3483822 : r3483826;
        double r3483828 = r3483819 ? r3483806 : r3483827;
        double r3483829 = r3483808 ? r3483817 : r3483828;
        double r3483830 = r3483805 ? r3483806 : r3483829;
        return r3483830;
}

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.0
Herbie4.8
\[\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.369677616151796e+154 or -3.3534166982027225e-177 < y < -1.8586020041360913e-183

    1. Initial program 61.9

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

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

    if -1.369677616151796e+154 < y < -3.3534166982027225e-177

    1. Initial program 1.3

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Simplified1.3

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

    if -1.8586020041360913e-183 < y < 8.42369621266438e-175

    1. Initial program 28.9

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Simplified28.9

      \[\leadsto \log \color{blue}{\left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)}\]
    5. Taylor expanded around -inf 13.4

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

    if 8.42369621266438e-175 < y

    1. Initial program 2.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification4.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.369677616151796 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.3534166982027225 \cdot 10^{-177}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \mathbf{elif}\;y \le -1.8586020041360913 \cdot 10^{-183}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 8.42369621266438 \cdot 10^{-175}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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