Average Error: 20.3 → 5.2
Time: 14.8s
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}\;x \le 3.23474552151853 \cdot 10^{-205}:\\ \;\;\;\;\frac{-y}{\frac{x \cdot x}{y} + y}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right)\right) - \frac{y}{\frac{x \cdot x}{y} + y}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le 3.23474552151853 \cdot 10^{-205}:\\
\;\;\;\;\frac{-y}{\frac{x \cdot x}{y} + y}\\

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

\end{array}
double f(double x, double y) {
        double r2954233 = x;
        double r2954234 = y;
        double r2954235 = r2954233 - r2954234;
        double r2954236 = r2954233 + r2954234;
        double r2954237 = r2954235 * r2954236;
        double r2954238 = r2954233 * r2954233;
        double r2954239 = r2954234 * r2954234;
        double r2954240 = r2954238 + r2954239;
        double r2954241 = r2954237 / r2954240;
        return r2954241;
}

double f(double x, double y) {
        double r2954242 = x;
        double r2954243 = 3.23474552151853e-205;
        bool r2954244 = r2954242 <= r2954243;
        double r2954245 = y;
        double r2954246 = -r2954245;
        double r2954247 = r2954242 * r2954242;
        double r2954248 = r2954247 / r2954245;
        double r2954249 = r2954248 + r2954245;
        double r2954250 = r2954246 / r2954249;
        double r2954251 = r2954245 * r2954245;
        double r2954252 = r2954251 + r2954247;
        double r2954253 = r2954247 / r2954252;
        double r2954254 = exp(r2954253);
        double r2954255 = sqrt(r2954254);
        double r2954256 = log(r2954255);
        double r2954257 = r2954256 + r2954256;
        double r2954258 = r2954245 / r2954249;
        double r2954259 = r2954257 - r2954258;
        double r2954260 = r2954244 ? r2954250 : r2954259;
        return r2954260;
}

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.0
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 2 regimes
  2. if x < 3.23474552151853e-205

    1. Initial program 30.8

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified30.8

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}}\]
    3. Using strategy rm
    4. Applied associate-/l*30.9

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \color{blue}{\frac{y}{\frac{y \cdot y + x \cdot x}{y}}}\]
    5. Taylor expanded around 0 20.3

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y}{\color{blue}{y + \frac{{x}^{2}}{y}}}\]
    6. Simplified20.3

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y}{\color{blue}{\frac{x \cdot x}{y} + y}}\]
    7. Taylor expanded around inf 7.7

      \[\leadsto \color{blue}{0} - \frac{y}{\frac{x \cdot x}{y} + y}\]

    if 3.23474552151853e-205 < x

    1. Initial program 14.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified14.7

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}}\]
    3. Using strategy rm
    4. Applied associate-/l*14.6

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \color{blue}{\frac{y}{\frac{y \cdot y + x \cdot x}{y}}}\]
    5. Taylor expanded around 0 3.8

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y}{\color{blue}{y + \frac{{x}^{2}}{y}}}\]
    6. Simplified3.8

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y}{\color{blue}{\frac{x \cdot x}{y} + y}}\]
    7. Using strategy rm
    8. Applied add-log-exp3.8

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}\right)} - \frac{y}{\frac{x \cdot x}{y} + y}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt3.8

      \[\leadsto \log \color{blue}{\left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}} \cdot \sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right)} - \frac{y}{\frac{x \cdot x}{y} + y}\]
    11. Applied log-prod3.8

      \[\leadsto \color{blue}{\left(\log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right)\right)} - \frac{y}{\frac{x \cdot x}{y} + y}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 3.23474552151853 \cdot 10^{-205}:\\ \;\;\;\;\frac{-y}{\frac{x \cdot x}{y} + y}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x}{y \cdot y + x \cdot x}}}\right)\right) - \frac{y}{\frac{x \cdot x}{y} + y}\\ \end{array}\]

Reproduce

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