Average Error: 20.5 → 5.2
Time: 13.4s
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.3561015051531283 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.0295842870860447 \cdot 10^{-160}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \mathbf{elif}\;y \le 1.5669239890129575 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \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.3561015051531283 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.0295842870860447 \cdot 10^{-160}:\\
\;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\

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

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

\end{array}
double f(double x, double y) {
        double r2154700 = x;
        double r2154701 = y;
        double r2154702 = r2154700 - r2154701;
        double r2154703 = r2154700 + r2154701;
        double r2154704 = r2154702 * r2154703;
        double r2154705 = r2154700 * r2154700;
        double r2154706 = r2154701 * r2154701;
        double r2154707 = r2154705 + r2154706;
        double r2154708 = r2154704 / r2154707;
        return r2154708;
}

double f(double x, double y) {
        double r2154709 = y;
        double r2154710 = -1.3561015051531283e+154;
        bool r2154711 = r2154709 <= r2154710;
        double r2154712 = -1.0;
        double r2154713 = -2.0295842870860447e-160;
        bool r2154714 = r2154709 <= r2154713;
        double r2154715 = x;
        double r2154716 = r2154715 * r2154715;
        double r2154717 = r2154709 * r2154709;
        double r2154718 = r2154716 + r2154717;
        double r2154719 = r2154716 / r2154718;
        double r2154720 = r2154717 / r2154718;
        double r2154721 = r2154719 - r2154720;
        double r2154722 = r2154721 * r2154721;
        double r2154723 = r2154722 * r2154721;
        double r2154724 = cbrt(r2154723);
        double r2154725 = 1.5669239890129575e-162;
        bool r2154726 = r2154709 <= r2154725;
        double r2154727 = 1.0;
        double r2154728 = r2154726 ? r2154727 : r2154724;
        double r2154729 = r2154714 ? r2154724 : r2154728;
        double r2154730 = r2154711 ? r2154712 : r2154729;
        return r2154730;
}

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.5
Target0.1
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.3561015051531283e+154

    1. Initial program 63.6

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

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

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

    if -1.3561015051531283e+154 < y < -2.0295842870860447e-160 or 1.5669239890129575e-162 < y

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{y \cdot y + x \cdot x} - \frac{y \cdot y}{y \cdot y + x \cdot x}}\]
    3. Using strategy rm
    4. Applied add-cbrt-cube0.1

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

    if -2.0295842870860447e-160 < y < 1.5669239890129575e-162

    1. Initial program 30.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3561015051531283 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.0295842870860447 \cdot 10^{-160}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \mathbf{elif}\;y \le 1.5669239890129575 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\right)}\\ \end{array}\]

Reproduce

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