Average Error: 19.6 → 5.3
Time: 13.6s
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.364714454837564 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.2241936526231514 \cdot 10^{-170}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{1}{\frac{x \cdot x + y \cdot y}{y \cdot y}}}\right)\\ \mathbf{elif}\;y \le -1.0663270652980943 \cdot 10^{-198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 6.518473908454177 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{1}{\frac{x \cdot x + y \cdot y}{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.364714454837564 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.2241936526231514 \cdot 10^{-170}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{1}{\frac{x \cdot x + y \cdot y}{y \cdot y}}}\right)\\

\mathbf{elif}\;y \le -1.0663270652980943 \cdot 10^{-198}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 6.518473908454177 \cdot 10^{-162}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r3058123 = x;
        double r3058124 = y;
        double r3058125 = r3058123 - r3058124;
        double r3058126 = r3058123 + r3058124;
        double r3058127 = r3058125 * r3058126;
        double r3058128 = r3058123 * r3058123;
        double r3058129 = r3058124 * r3058124;
        double r3058130 = r3058128 + r3058129;
        double r3058131 = r3058127 / r3058130;
        return r3058131;
}

double f(double x, double y) {
        double r3058132 = y;
        double r3058133 = -1.364714454837564e+154;
        bool r3058134 = r3058132 <= r3058133;
        double r3058135 = -1.0;
        double r3058136 = -3.2241936526231514e-170;
        bool r3058137 = r3058132 <= r3058136;
        double r3058138 = x;
        double r3058139 = r3058138 * r3058138;
        double r3058140 = r3058132 * r3058132;
        double r3058141 = r3058139 + r3058140;
        double r3058142 = r3058139 / r3058141;
        double r3058143 = 1.0;
        double r3058144 = r3058141 / r3058140;
        double r3058145 = r3058143 / r3058144;
        double r3058146 = exp(r3058145);
        double r3058147 = log(r3058146);
        double r3058148 = r3058142 - r3058147;
        double r3058149 = -1.0663270652980943e-198;
        bool r3058150 = r3058132 <= r3058149;
        double r3058151 = 6.518473908454177e-162;
        bool r3058152 = r3058132 <= r3058151;
        double r3058153 = r3058152 ? r3058143 : r3058148;
        double r3058154 = r3058150 ? r3058135 : r3058153;
        double r3058155 = r3058137 ? r3058148 : r3058154;
        double r3058156 = r3058134 ? r3058135 : r3058155;
        return r3058156;
}

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.6
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.364714454837564e+154 or -3.2241936526231514e-170 < y < -1.0663270652980943e-198

    1. Initial program 58.3

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

      \[\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 add-log-exp58.3

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

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

    if -1.364714454837564e+154 < y < -3.2241936526231514e-170 or 6.518473908454177e-162 < y

    1. Initial program 0.4

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

      \[\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 add-log-exp0.4

      \[\leadsto \frac{x \cdot x}{y \cdot y + x \cdot x} - \color{blue}{\log \left(e^{\frac{y \cdot y}{y \cdot y + x \cdot x}}\right)}\]
    5. Using strategy rm
    6. Applied clear-num0.4

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

    if -1.0663270652980943e-198 < y < 6.518473908454177e-162

    1. Initial program 28.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.364714454837564 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.2241936526231514 \cdot 10^{-170}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{1}{\frac{x \cdot x + y \cdot y}{y \cdot y}}}\right)\\ \mathbf{elif}\;y \le -1.0663270652980943 \cdot 10^{-198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 6.518473908454177 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \log \left(e^{\frac{1}{\frac{x \cdot x + y \cdot y}{y \cdot y}}}\right)\\ \end{array}\]

Reproduce

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