Average Error: 20.0 → 5.2
Time: 7.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 -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \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 -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \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 r5763935 = x;
        double r5763936 = y;
        double r5763937 = r5763935 - r5763936;
        double r5763938 = r5763935 + r5763936;
        double r5763939 = r5763937 * r5763938;
        double r5763940 = r5763935 * r5763935;
        double r5763941 = r5763936 * r5763936;
        double r5763942 = r5763940 + r5763941;
        double r5763943 = r5763939 / r5763942;
        return r5763943;
}

double f(double x, double y) {
        double r5763944 = y;
        double r5763945 = -6.379960110729306e+150;
        bool r5763946 = r5763944 <= r5763945;
        double r5763947 = -1.0;
        double r5763948 = -1.5016765466948683e-155;
        bool r5763949 = r5763944 <= r5763948;
        double r5763950 = r5763944 * r5763944;
        double r5763951 = x;
        double r5763952 = r5763951 * r5763951;
        double r5763953 = r5763950 - r5763952;
        double r5763954 = r5763952 + r5763950;
        double r5763955 = r5763953 / r5763954;
        double r5763956 = -r5763955;
        double r5763957 = 1.6656408088991096e-162;
        bool r5763958 = r5763944 <= r5763957;
        double r5763959 = 1.0;
        double r5763960 = r5763958 ? r5763959 : r5763956;
        double r5763961 = r5763949 ? r5763956 : r5763960;
        double r5763962 = r5763946 ? r5763947 : r5763961;
        return r5763962;
}

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.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 < -6.379960110729306e+150

    1. Initial program 62.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified62.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 -6.379960110729306e+150 < y < -1.5016765466948683e-155 or 1.6656408088991096e-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{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]

    if -1.5016765466948683e-155 < y < 1.6656408088991096e-162

    1. Initial program 29.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \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 2019172 
(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))))