Average Error: 20.3 → 5.3
Time: 9.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.3379792666689724 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.704752375070274 \cdot 10^{-156}:\\ \;\;\;\;\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 4.0567724911730275 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot 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 -1.3379792666689724 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -6.704752375070274 \cdot 10^{-156}:\\
\;\;\;\;\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 4.0567724911730275 \cdot 10^{-165}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r1249013 = x;
        double r1249014 = y;
        double r1249015 = r1249013 - r1249014;
        double r1249016 = r1249013 + r1249014;
        double r1249017 = r1249015 * r1249016;
        double r1249018 = r1249013 * r1249013;
        double r1249019 = r1249014 * r1249014;
        double r1249020 = r1249018 + r1249019;
        double r1249021 = r1249017 / r1249020;
        return r1249021;
}

double f(double x, double y) {
        double r1249022 = y;
        double r1249023 = -1.3379792666689724e+154;
        bool r1249024 = r1249022 <= r1249023;
        double r1249025 = -1.0;
        double r1249026 = -6.704752375070274e-156;
        bool r1249027 = r1249022 <= r1249026;
        double r1249028 = x;
        double r1249029 = r1249028 * r1249028;
        double r1249030 = r1249022 * r1249022;
        double r1249031 = r1249029 + r1249030;
        double r1249032 = r1249029 / r1249031;
        double r1249033 = r1249030 / r1249031;
        double r1249034 = r1249032 - r1249033;
        double r1249035 = exp(r1249034);
        double r1249036 = log(r1249035);
        double r1249037 = 4.0567724911730275e-165;
        bool r1249038 = r1249022 <= r1249037;
        double r1249039 = 1.0;
        double r1249040 = r1249038 ? r1249039 : r1249036;
        double r1249041 = r1249027 ? r1249036 : r1249040;
        double r1249042 = r1249024 ? r1249025 : r1249041;
        return r1249042;
}

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.1
Herbie5.3
\[\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.3379792666689724e+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.3379792666689724e+154 < y < -6.704752375070274e-156 or 4.0567724911730275e-165 < y

    1. Initial program 0.2

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

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

      \[\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 -6.704752375070274e-156 < y < 4.0567724911730275e-165

    1. Initial program 30.5

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

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

      \[\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 16.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3379792666689724 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.704752375070274 \cdot 10^{-156}:\\ \;\;\;\;\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 4.0567724911730275 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]

Reproduce

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