Average Error: 20.0 → 5.0
Time: 37.1s
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.3369907459246656 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8149485600284774 \cdot 10^{-162}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} - 1)^*)\\ \mathbf{elif}\;y \le 8.57058787857935 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} - 1)^*)\\ \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.3369907459246656 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.8149485600284774 \cdot 10^{-162}:\\
\;\;\;\;\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} - 1)^*)\\

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

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

\end{array}
double f(double x, double y) {
        double r33081182 = x;
        double r33081183 = y;
        double r33081184 = r33081182 - r33081183;
        double r33081185 = r33081182 + r33081183;
        double r33081186 = r33081184 * r33081185;
        double r33081187 = r33081182 * r33081182;
        double r33081188 = r33081183 * r33081183;
        double r33081189 = r33081187 + r33081188;
        double r33081190 = r33081186 / r33081189;
        return r33081190;
}

double f(double x, double y) {
        double r33081191 = y;
        double r33081192 = -1.3369907459246656e+154;
        bool r33081193 = r33081191 <= r33081192;
        double r33081194 = -1.0;
        double r33081195 = -1.8149485600284774e-162;
        bool r33081196 = r33081191 <= r33081195;
        double r33081197 = x;
        double r33081198 = r33081197 - r33081191;
        double r33081199 = r33081191 + r33081197;
        double r33081200 = r33081198 * r33081199;
        double r33081201 = r33081191 * r33081191;
        double r33081202 = r33081197 * r33081197;
        double r33081203 = r33081201 + r33081202;
        double r33081204 = r33081200 / r33081203;
        double r33081205 = expm1(r33081204);
        double r33081206 = log1p(r33081205);
        double r33081207 = 8.57058787857935e-162;
        bool r33081208 = r33081191 <= r33081207;
        double r33081209 = 1.0;
        double r33081210 = r33081208 ? r33081209 : r33081206;
        double r33081211 = r33081196 ? r33081206 : r33081210;
        double r33081212 = r33081193 ? r33081194 : r33081211;
        return r33081212;
}

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.0
Target0.0
Herbie5.0
\[\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.3369907459246656e+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.3369907459246656e+154 < y < -1.8149485600284774e-162 or 8.57058787857935e-162 < y

    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 log1p-expm1-u0.0

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

    if -1.8149485600284774e-162 < y < 8.57058787857935e-162

    1. Initial program 28.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied log1p-expm1-u28.9

      \[\leadsto \color{blue}{\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} - 1)^*)}\]
    4. Taylor expanded around -inf 15.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3369907459246656 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8149485600284774 \cdot 10^{-162}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} - 1)^*)\\ \mathbf{elif}\;y \le 8.57058787857935 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} - 1)^*)\\ \end{array}\]

Reproduce

herbie shell --seed 2019112 +o rules:numerics
(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))))