Average Error: 20.2 → 5.2
Time: 10.2s
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.3255253403345302 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.9802794932900194 \cdot 10^{-182}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -8.125759275196955 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.6484923373755113 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{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 -1.3255253403345302 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.9802794932900194 \cdot 10^{-182}:\\
\;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le -8.125759275196955 \cdot 10^{-201}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r3827295 = x;
        double r3827296 = y;
        double r3827297 = r3827295 - r3827296;
        double r3827298 = r3827295 + r3827296;
        double r3827299 = r3827297 * r3827298;
        double r3827300 = r3827295 * r3827295;
        double r3827301 = r3827296 * r3827296;
        double r3827302 = r3827300 + r3827301;
        double r3827303 = r3827299 / r3827302;
        return r3827303;
}

double f(double x, double y) {
        double r3827304 = y;
        double r3827305 = -1.3255253403345302e+154;
        bool r3827306 = r3827304 <= r3827305;
        double r3827307 = -1.0;
        double r3827308 = -1.9802794932900194e-182;
        bool r3827309 = r3827304 <= r3827308;
        double r3827310 = r3827304 * r3827304;
        double r3827311 = x;
        double r3827312 = r3827311 * r3827311;
        double r3827313 = r3827310 - r3827312;
        double r3827314 = r3827312 + r3827310;
        double r3827315 = r3827313 / r3827314;
        double r3827316 = -r3827315;
        double r3827317 = -8.125759275196955e-201;
        bool r3827318 = r3827304 <= r3827317;
        double r3827319 = 1.6484923373755113e-162;
        bool r3827320 = r3827304 <= r3827319;
        double r3827321 = 1.0;
        double r3827322 = r3827320 ? r3827321 : r3827316;
        double r3827323 = r3827318 ? r3827307 : r3827322;
        double r3827324 = r3827309 ? r3827316 : r3827323;
        double r3827325 = r3827306 ? r3827307 : r3827324;
        return r3827325;
}

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.2
\[\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.3255253403345302e+154 or -1.9802794932900194e-182 < y < -8.125759275196955e-201

    1. Initial program 60.4

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

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

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

    if -1.3255253403345302e+154 < y < -1.9802794932900194e-182 or 1.6484923373755113e-162 < y

    1. Initial program 1.1

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

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

    if -8.125759275196955e-201 < y < 1.6484923373755113e-162

    1. Initial program 29.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3255253403345302 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.9802794932900194 \cdot 10^{-182}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -8.125759275196955 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.6484923373755113 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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