Average Error: 20.8 → 6.5
Time: 11.9s
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.267281322841902807987182678972058939928 \cdot 10^{-36}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -9.045484095441608795936674401022833043021 \cdot 10^{-169}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -3.929967420140984020120019708943131362955 \cdot 10^{-215}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.041177474800958309147430071459428044927 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{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.267281322841902807987182678972058939928 \cdot 10^{-36}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le -3.929967420140984020120019708943131362955 \cdot 10^{-215}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 2.041177474800958309147430071459428044927 \cdot 10^{-167}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r65222 = x;
        double r65223 = y;
        double r65224 = r65222 - r65223;
        double r65225 = r65222 + r65223;
        double r65226 = r65224 * r65225;
        double r65227 = r65222 * r65222;
        double r65228 = r65223 * r65223;
        double r65229 = r65227 + r65228;
        double r65230 = r65226 / r65229;
        return r65230;
}

double f(double x, double y) {
        double r65231 = y;
        double r65232 = -6.267281322841903e-36;
        bool r65233 = r65231 <= r65232;
        double r65234 = -1.0;
        double r65235 = -9.045484095441609e-169;
        bool r65236 = r65231 <= r65235;
        double r65237 = x;
        double r65238 = r65237 - r65231;
        double r65239 = r65237 + r65231;
        double r65240 = r65237 * r65237;
        double r65241 = r65231 * r65231;
        double r65242 = r65240 + r65241;
        double r65243 = r65239 / r65242;
        double r65244 = r65238 * r65243;
        double r65245 = -3.929967420140984e-215;
        bool r65246 = r65231 <= r65245;
        double r65247 = 2.0411774748009583e-167;
        bool r65248 = r65231 <= r65247;
        double r65249 = 1.0;
        double r65250 = r65248 ? r65249 : r65244;
        double r65251 = r65246 ? r65234 : r65250;
        double r65252 = r65236 ? r65244 : r65251;
        double r65253 = r65233 ? r65234 : r65252;
        return r65253;
}

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.8
Target0.1
Herbie6.5
\[\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.267281322841903e-36 or -9.045484095441609e-169 < y < -3.929967420140984e-215

    1. Initial program 29.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 5.4

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

    if -6.267281322841903e-36 < y < -9.045484095441609e-169 or 2.0411774748009583e-167 < y

    1. Initial program 1.4

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

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

    if -3.929967420140984e-215 < y < 2.0411774748009583e-167

    1. Initial program 30.8

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 13.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.267281322841902807987182678972058939928 \cdot 10^{-36}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -9.045484095441608795936674401022833043021 \cdot 10^{-169}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -3.929967420140984020120019708943131362955 \cdot 10^{-215}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.041177474800958309147430071459428044927 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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