Average Error: 19.9 → 4.6
Time: 14.0s
Precision: 64
\[0.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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\ \mathbf{elif}\;y \le 1.828260016637030233456157191815862132037 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\

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

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

\end{array}
double f(double x, double y) {
        double r97003 = x;
        double r97004 = y;
        double r97005 = r97003 - r97004;
        double r97006 = r97003 + r97004;
        double r97007 = r97005 * r97006;
        double r97008 = r97003 * r97003;
        double r97009 = r97004 * r97004;
        double r97010 = r97008 + r97009;
        double r97011 = r97007 / r97010;
        return r97011;
}

double f(double x, double y) {
        double r97012 = y;
        double r97013 = -9.82178231331464e+153;
        bool r97014 = r97012 <= r97013;
        double r97015 = -1.0;
        double r97016 = -1.937646393364571e-161;
        bool r97017 = r97012 <= r97016;
        double r97018 = x;
        double r97019 = r97018 * r97018;
        double r97020 = r97012 * r97012;
        double r97021 = r97019 - r97020;
        double r97022 = r97019 + r97020;
        double r97023 = r97018 - r97012;
        double r97024 = r97018 + r97012;
        double r97025 = r97023 * r97024;
        double r97026 = r97022 / r97025;
        double r97027 = r97021 / r97026;
        double r97028 = r97024 * r97023;
        double r97029 = r97027 / r97028;
        double r97030 = 1.8282600166370302e-162;
        bool r97031 = r97012 <= r97030;
        double r97032 = 1.0;
        double r97033 = r97025 / r97022;
        double r97034 = r97031 ? r97032 : r97033;
        double r97035 = r97017 ? r97029 : r97034;
        double r97036 = r97014 ? r97015 : r97035;
        return r97036;
}

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.9
Target0.1
Herbie4.6
\[\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 < -9.82178231331464e+153

    1. Initial program 63.9

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

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Using strategy rm
    5. Applied flip-+63.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied flip--63.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \cdot \frac{x \cdot x - y \cdot y}{x - y}}}\]
    7. Applied frac-times64.0

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}{\left(x + y\right) \cdot \left(x - y\right)}}}}\]
    8. Applied associate-/r/64.0

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \cdot \left(\left(x + y\right) \cdot \left(x - y\right)\right)}}\]
    9. Applied associate-/r*64.0

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}}\]
    10. Simplified63.9

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

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

    if -9.82178231331464e+153 < y < -1.937646393364571e-161

    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 clear-num0.0

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Using strategy rm
    5. Applied flip-+0.0

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied flip--0.1

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \cdot \frac{x \cdot x - y \cdot y}{x - y}}}\]
    7. Applied frac-times27.9

      \[\leadsto \frac{1}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}{\left(x + y\right) \cdot \left(x - y\right)}}}}\]
    8. Applied associate-/r/28.0

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \cdot \left(\left(x + y\right) \cdot \left(x - y\right)\right)}}\]
    9. Applied associate-/r*28.0

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}}\]
    10. Simplified0.0

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

    if -1.937646393364571e-161 < y < 1.8282600166370302e-162

    1. Initial program 29.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num29.7

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

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

    if 1.8282600166370302e-162 < y

    1. Initial program 0.1

      \[\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 simplification4.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.937646393364570937539099703487067921288 \cdot 10^{-161}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot y}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}{\left(x + y\right) \cdot \left(x - y\right)}\\ \mathbf{elif}\;y \le 1.828260016637030233456157191815862132037 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.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))))