Average Error: 20.3 → 5.7
Time: 8.3s
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.3330097877511057 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.406936418392987 \cdot 10^{-189}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}}\right) - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -1.4153860890433093 \cdot 10^{-211}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 5.33062675147924 \cdot 10^{-161}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}}\right) - \frac{y \cdot 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 -1.3330097877511057 \cdot 10^{+154}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le -1.4153860890433093 \cdot 10^{-211}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 5.33062675147924 \cdot 10^{-161}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r1287630 = x;
        double r1287631 = y;
        double r1287632 = r1287630 - r1287631;
        double r1287633 = r1287630 + r1287631;
        double r1287634 = r1287632 * r1287633;
        double r1287635 = r1287630 * r1287630;
        double r1287636 = r1287631 * r1287631;
        double r1287637 = r1287635 + r1287636;
        double r1287638 = r1287634 / r1287637;
        return r1287638;
}

double f(double x, double y) {
        double r1287639 = y;
        double r1287640 = -1.3330097877511057e+154;
        bool r1287641 = r1287639 <= r1287640;
        double r1287642 = -1.0;
        double r1287643 = -2.406936418392987e-189;
        bool r1287644 = r1287639 <= r1287643;
        double r1287645 = x;
        double r1287646 = r1287645 * r1287645;
        double r1287647 = r1287639 * r1287639;
        double r1287648 = r1287646 + r1287647;
        double r1287649 = r1287646 / r1287648;
        double r1287650 = cbrt(r1287649);
        double r1287651 = r1287650 * r1287650;
        double r1287652 = r1287650 * r1287651;
        double r1287653 = r1287647 / r1287648;
        double r1287654 = r1287652 - r1287653;
        double r1287655 = -1.4153860890433093e-211;
        bool r1287656 = r1287639 <= r1287655;
        double r1287657 = 5.33062675147924e-161;
        bool r1287658 = r1287639 <= r1287657;
        double r1287659 = 1.0;
        double r1287660 = r1287658 ? r1287659 : r1287654;
        double r1287661 = r1287656 ? r1287642 : r1287660;
        double r1287662 = r1287644 ? r1287654 : r1287661;
        double r1287663 = r1287641 ? r1287642 : r1287662;
        return r1287663;
}

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.3
Target0.1
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 3 regimes
  2. if y < -1.3330097877511057e+154 or -2.406936418392987e-189 < y < -1.4153860890433093e-211

    1. Initial program 59.3

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

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

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

    if -1.3330097877511057e+154 < y < -2.406936418392987e-189 or 5.33062675147924e-161 < y

    1. Initial program 1.7

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt1.7

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

    if -1.4153860890433093e-211 < y < 5.33062675147924e-161

    1. Initial program 30.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3330097877511057 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.406936418392987 \cdot 10^{-189}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}}\right) - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le -1.4153860890433093 \cdot 10^{-211}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 5.33062675147924 \cdot 10^{-161}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x}{x \cdot x + y \cdot y}}\right) - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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