Average Error: 20.2 → 5.1
Time: 12.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}\;y \le -1.3434000592863123 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -8.556032821094931 \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 2.1804237440776019 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + 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.3434000592863123 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r1604143 = x;
        double r1604144 = y;
        double r1604145 = r1604143 - r1604144;
        double r1604146 = r1604143 + r1604144;
        double r1604147 = r1604145 * r1604146;
        double r1604148 = r1604143 * r1604143;
        double r1604149 = r1604144 * r1604144;
        double r1604150 = r1604148 + r1604149;
        double r1604151 = r1604147 / r1604150;
        return r1604151;
}

double f(double x, double y) {
        double r1604152 = y;
        double r1604153 = -1.3434000592863123e+154;
        bool r1604154 = r1604152 <= r1604153;
        double r1604155 = -1.0;
        double r1604156 = -8.556032821094931e-156;
        bool r1604157 = r1604152 <= r1604156;
        double r1604158 = x;
        double r1604159 = r1604158 * r1604158;
        double r1604160 = r1604152 * r1604152;
        double r1604161 = r1604159 + r1604160;
        double r1604162 = r1604159 / r1604161;
        double r1604163 = r1604160 / r1604161;
        double r1604164 = r1604162 - r1604163;
        double r1604165 = exp(r1604164);
        double r1604166 = log(r1604165);
        double r1604167 = 2.1804237440776019e-162;
        bool r1604168 = r1604152 <= r1604167;
        double r1604169 = 1.0;
        double r1604170 = r1604168 ? r1604169 : r1604166;
        double r1604171 = r1604157 ? r1604166 : r1604170;
        double r1604172 = r1604154 ? r1604155 : r1604171;
        return r1604172;
}

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.2
Target0.0
Herbie5.1
\[\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.3434000592863123e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified63.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. Using strategy rm
    4. Applied add-log-exp63.6

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

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

    if -1.3434000592863123e+154 < y < -8.556032821094931e-156 or 2.1804237440776019e-162 < y

    1. Initial program 0.0

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

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

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

    if -8.556032821094931e-156 < y < 2.1804237440776019e-162

    1. Initial program 29.2

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

      \[\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 15.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3434000592863123 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -8.556032821094931 \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 2.1804237440776019 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]

Reproduce

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