Average Error: 19.9 → 5.2
Time: 12.5s
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 -106.3060688461918488201263244263827800751:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\ \mathbf{elif}\;y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}}\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 -106.3060688461918488201263244263827800751:\\
\;\;\;\;\log \left(e^{-1}\right)\\

\mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\

\mathbf{elif}\;y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r75276 = x;
        double r75277 = y;
        double r75278 = r75276 - r75277;
        double r75279 = r75276 + r75277;
        double r75280 = r75278 * r75279;
        double r75281 = r75276 * r75276;
        double r75282 = r75277 * r75277;
        double r75283 = r75281 + r75282;
        double r75284 = r75280 / r75283;
        return r75284;
}

double f(double x, double y) {
        double r75285 = y;
        double r75286 = -106.30606884619185;
        bool r75287 = r75285 <= r75286;
        double r75288 = -1.0;
        double r75289 = exp(r75288);
        double r75290 = log(r75289);
        double r75291 = -1.1129546130770477e-151;
        bool r75292 = r75285 <= r75291;
        double r75293 = x;
        double r75294 = r75293 - r75285;
        double r75295 = r75293 + r75285;
        double r75296 = r75294 * r75295;
        double r75297 = r75293 * r75293;
        double r75298 = 2.0;
        double r75299 = pow(r75285, r75298);
        double r75300 = r75297 + r75299;
        double r75301 = r75296 / r75300;
        double r75302 = 7.168109854324842e-160;
        bool r75303 = r75285 <= r75302;
        double r75304 = 1.0;
        double r75305 = exp(r75301);
        double r75306 = log(r75305);
        double r75307 = r75303 ? r75304 : r75306;
        double r75308 = r75292 ? r75301 : r75307;
        double r75309 = r75287 ? r75290 : r75308;
        return r75309;
}

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.9
Target0.1
Herbie5.2
\[\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 < -106.30606884619185

    1. Initial program 31.8

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{{x}^{2} + {y}^{2}}}\]
    3. Simplified31.8

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]
    4. Using strategy rm
    5. Applied add-log-exp31.8

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

      \[\leadsto \log \left(e^{\color{blue}{-1}}\right)\]

    if -106.30606884619185 < y < -1.1129546130770477e-151

    1. Initial program 0.0

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

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

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

    if -1.1129546130770477e-151 < y < 7.168109854324842e-160

    1. Initial program 28.5

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{{x}^{2} + {y}^{2}}}\]
    3. Simplified28.5

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]
    4. Using strategy rm
    5. Applied add-log-exp28.5

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

      \[\leadsto \log \left(e^{\color{blue}{1}}\right)\]

    if 7.168109854324842e-160 < y

    1. Initial program 0.0

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

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{x \cdot x + {y}^{2}}}\]
    4. Using strategy rm
    5. 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}^{2}}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -106.3060688461918488201263244263827800751:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;y \le -1.112954613077047722664131657642916967389 \cdot 10^{-151}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}\\ \mathbf{elif}\;y \le 7.168109854324841883368591954908086893719 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + {y}^{2}}}\right)\\ \end{array}\]

Reproduce

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