Average Error: 20.6 → 5.3
Time: 16.3s
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 -7.97560835483767313443274064459131142554 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.033522684534884437001190823053512215602 \cdot 10^{-155}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \mathbf{elif}\;y \le 1.497237818899669451923578244569587493317 \cdot 10^{-159}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \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 -7.97560835483767313443274064459131142554 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.033522684534884437001190823053512215602 \cdot 10^{-155}:\\
\;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\

\mathbf{elif}\;y \le 1.497237818899669451923578244569587493317 \cdot 10^{-159}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\

\end{array}
double f(double x, double y) {
        double r4649140 = x;
        double r4649141 = y;
        double r4649142 = r4649140 - r4649141;
        double r4649143 = r4649140 + r4649141;
        double r4649144 = r4649142 * r4649143;
        double r4649145 = r4649140 * r4649140;
        double r4649146 = r4649141 * r4649141;
        double r4649147 = r4649145 + r4649146;
        double r4649148 = r4649144 / r4649147;
        return r4649148;
}

double f(double x, double y) {
        double r4649149 = y;
        double r4649150 = -7.975608354837673e+153;
        bool r4649151 = r4649149 <= r4649150;
        double r4649152 = -1.0;
        double r4649153 = -1.0335226845348844e-155;
        bool r4649154 = r4649149 <= r4649153;
        double r4649155 = x;
        double r4649156 = r4649155 * r4649155;
        double r4649157 = r4649149 * r4649149;
        double r4649158 = r4649156 + r4649157;
        double r4649159 = r4649157 - r4649156;
        double r4649160 = r4649158 / r4649159;
        double r4649161 = r4649152 / r4649160;
        double r4649162 = 1.4972378188996695e-159;
        bool r4649163 = r4649149 <= r4649162;
        double r4649164 = 1.0;
        double r4649165 = r4649163 ? r4649164 : r4649161;
        double r4649166 = r4649154 ? r4649161 : r4649165;
        double r4649167 = r4649151 ? r4649152 : r4649166;
        return r4649167;
}

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.6
Target0.0
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 < -7.975608354837673e+153

    1. Initial program 63.9

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

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

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

    if -7.975608354837673e+153 < y < -1.0335226845348844e-155 or 1.4972378188996695e-159 < 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{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied difference-of-squares0.0

      \[\leadsto -\frac{\color{blue}{\left(y + x\right) \cdot \left(y - x\right)}}{x \cdot x + y \cdot y}\]
    5. Applied associate-/l*0.2

      \[\leadsto -\color{blue}{\frac{y + x}{\frac{x \cdot x + y \cdot y}{y - x}}}\]
    6. Using strategy rm
    7. Applied clear-num0.2

      \[\leadsto -\color{blue}{\frac{1}{\frac{\frac{x \cdot x + y \cdot y}{y - x}}{y + x}}}\]
    8. Simplified0.0

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

    if -1.0335226845348844e-155 < y < 1.4972378188996695e-159

    1. Initial program 29.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.97560835483767313443274064459131142554 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.033522684534884437001190823053512215602 \cdot 10^{-155}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \mathbf{elif}\;y \le 1.497237818899669451923578244569587493317 \cdot 10^{-159}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019170 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))