Average Error: 19.7 → 5.7
Time: 12.8s
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.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{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 -1.3691694056010857 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r4423054 = x;
        double r4423055 = y;
        double r4423056 = r4423054 - r4423055;
        double r4423057 = r4423054 + r4423055;
        double r4423058 = r4423056 * r4423057;
        double r4423059 = r4423054 * r4423054;
        double r4423060 = r4423055 * r4423055;
        double r4423061 = r4423059 + r4423060;
        double r4423062 = r4423058 / r4423061;
        return r4423062;
}

double f(double x, double y) {
        double r4423063 = y;
        double r4423064 = -1.3691694056010857e+154;
        bool r4423065 = r4423063 <= r4423064;
        double r4423066 = -1.0;
        double r4423067 = -1.2013518175407308e-161;
        bool r4423068 = r4423063 <= r4423067;
        double r4423069 = x;
        double r4423070 = r4423069 - r4423063;
        double r4423071 = r4423063 + r4423069;
        double r4423072 = r4423070 * r4423071;
        double r4423073 = r4423063 * r4423063;
        double r4423074 = r4423069 * r4423069;
        double r4423075 = r4423073 + r4423074;
        double r4423076 = r4423072 / r4423075;
        double r4423077 = exp(r4423076);
        double r4423078 = log(r4423077);
        double r4423079 = 2.9860065638011237e-218;
        bool r4423080 = r4423063 <= r4423079;
        double r4423081 = 1.0;
        double r4423082 = 1.2966442305400266e-202;
        bool r4423083 = r4423063 <= r4423082;
        double r4423084 = sqrt(r4423075);
        double r4423085 = r4423071 / r4423084;
        double r4423086 = r4423070 / r4423084;
        double r4423087 = r4423085 * r4423086;
        double r4423088 = r4423083 ? r4423066 : r4423087;
        double r4423089 = r4423080 ? r4423081 : r4423088;
        double r4423090 = r4423068 ? r4423078 : r4423089;
        double r4423091 = r4423065 ? r4423066 : r4423090;
        return r4423091;
}

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.7
Target0.0
Herbie5.7
\[\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 < -1.3691694056010857e+154 or 2.9860065638011237e-218 < y < 1.2966442305400266e-202

    1. Initial program 60.1

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

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

    if -1.3691694056010857e+154 < y < -1.2013518175407308e-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 add-sqr-sqrt0.0

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac0.3

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.3

      \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)}\]
    7. Simplified0.0

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

    if -1.2013518175407308e-161 < y < 2.9860065638011237e-218

    1. Initial program 28.8

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

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

    if 1.2966442305400266e-202 < y

    1. Initial program 6.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt6.3

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac6.9

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\ \end{array}\]

Reproduce

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