Average Error: 20.3 → 5.3
Time: 12.5s
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}:\\ \;\;\;\;\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.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}:\\
\;\;\;\;\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 r3590255 = x;
        double r3590256 = y;
        double r3590257 = r3590255 - r3590256;
        double r3590258 = r3590255 + r3590256;
        double r3590259 = r3590257 * r3590258;
        double r3590260 = r3590255 * r3590255;
        double r3590261 = r3590256 * r3590256;
        double r3590262 = r3590260 + r3590261;
        double r3590263 = r3590259 / r3590262;
        return r3590263;
}

double f(double x, double y) {
        double r3590264 = y;
        double r3590265 = -1.3379792666689724e+154;
        bool r3590266 = r3590264 <= r3590265;
        double r3590267 = -1.0;
        double r3590268 = -6.704752375070274e-156;
        bool r3590269 = r3590264 <= r3590268;
        double r3590270 = x;
        double r3590271 = r3590270 * r3590270;
        double r3590272 = r3590264 * r3590264;
        double r3590273 = r3590271 + r3590272;
        double r3590274 = r3590271 / r3590273;
        double r3590275 = r3590272 / r3590273;
        double r3590276 = r3590274 - r3590275;
        double r3590277 = exp(r3590276);
        double r3590278 = log(r3590277);
        double r3590279 = 4.0567724911730275e-165;
        bool r3590280 = r3590264 <= r3590279;
        double r3590281 = 1.0;
        double r3590282 = r3590270 - r3590264;
        double r3590283 = r3590264 + r3590270;
        double r3590284 = r3590282 * r3590283;
        double r3590285 = r3590284 / r3590273;
        double r3590286 = r3590280 ? r3590281 : r3590285;
        double r3590287 = r3590269 ? r3590278 : r3590286;
        double r3590288 = r3590266 ? r3590267 : r3590287;
        return r3590288;
}

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 4 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

    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 -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. Taylor expanded around inf 16.4

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

    if 4.0567724911730275e-165 < y

    1. Initial program 0.6

      \[\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 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}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\\ \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))))