Average Error: 19.8 → 5.6
Time: 12.3s
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.3311533934439168 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.50265526585485 \cdot 10^{-162}:\\ \;\;\;\;\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 2.0115899741754227 \cdot 10^{-215}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x - 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 -1.3311533934439168 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.50265526585485 \cdot 10^{-162}:\\
\;\;\;\;\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 2.0115899741754227 \cdot 10^{-215}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r4181065 = x;
        double r4181066 = y;
        double r4181067 = r4181065 - r4181066;
        double r4181068 = r4181065 + r4181066;
        double r4181069 = r4181067 * r4181068;
        double r4181070 = r4181065 * r4181065;
        double r4181071 = r4181066 * r4181066;
        double r4181072 = r4181070 + r4181071;
        double r4181073 = r4181069 / r4181072;
        return r4181073;
}

double f(double x, double y) {
        double r4181074 = y;
        double r4181075 = -1.3311533934439168e+154;
        bool r4181076 = r4181074 <= r4181075;
        double r4181077 = -1.0;
        double r4181078 = -3.50265526585485e-162;
        bool r4181079 = r4181074 <= r4181078;
        double r4181080 = x;
        double r4181081 = r4181080 * r4181080;
        double r4181082 = r4181074 * r4181074;
        double r4181083 = r4181081 + r4181082;
        double r4181084 = r4181081 / r4181083;
        double r4181085 = r4181082 / r4181083;
        double r4181086 = r4181084 - r4181085;
        double r4181087 = exp(r4181086);
        double r4181088 = log(r4181087);
        double r4181089 = 2.0115899741754227e-215;
        bool r4181090 = r4181074 <= r4181089;
        double r4181091 = 1.0;
        double r4181092 = r4181074 + r4181080;
        double r4181093 = sqrt(r4181083);
        double r4181094 = r4181092 / r4181093;
        double r4181095 = r4181080 - r4181074;
        double r4181096 = r4181095 / r4181093;
        double r4181097 = r4181094 * r4181096;
        double r4181098 = r4181090 ? r4181091 : r4181097;
        double r4181099 = r4181079 ? r4181088 : r4181098;
        double r4181100 = r4181076 ? r4181077 : r4181099;
        return r4181100;
}

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.8
Target0.0
Herbie5.6
\[\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.3311533934439168e+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.3311533934439168e+154 < y < -3.50265526585485e-162

    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 add-log-exp0.0

      \[\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.0

      \[\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 -3.50265526585485e-162 < y < 2.0115899741754227e-215

    1. Initial program 29.4

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

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

    if 2.0115899741754227e-215 < y

    1. Initial program 8.2

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

      \[\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-frac8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3311533934439168 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.50265526585485 \cdot 10^{-162}:\\ \;\;\;\;\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 2.0115899741754227 \cdot 10^{-215}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x - y}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

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