Average Error: 31.8 → 16.2
Time: 5.0s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.22352685318922961 \cdot 10^{254}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.62712045946508503 \cdot 10^{212}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -4.96248021588850455 \cdot 10^{128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.583750869341446 \cdot 10^{60}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -6.45314904363278403 \cdot 10^{-7}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 4.22472559063544996 \cdot 10^{-142}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 8.4175975820898431 \cdot 10^{133}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -2.22352685318922961 \cdot 10^{254}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.62712045946508503 \cdot 10^{212}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le -4.96248021588850455 \cdot 10^{128}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -2.583750869341446 \cdot 10^{60}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le -6.45314904363278403 \cdot 10^{-7}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;y \le 4.22472559063544996 \cdot 10^{-142}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 8.4175975820898431 \cdot 10^{133}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
double f(double x, double y) {
        double r778706 = x;
        double r778707 = r778706 * r778706;
        double r778708 = y;
        double r778709 = 4.0;
        double r778710 = r778708 * r778709;
        double r778711 = r778710 * r778708;
        double r778712 = r778707 - r778711;
        double r778713 = r778707 + r778711;
        double r778714 = r778712 / r778713;
        return r778714;
}

double f(double x, double y) {
        double r778715 = y;
        double r778716 = -2.2235268531892296e+254;
        bool r778717 = r778715 <= r778716;
        double r778718 = -1.0;
        double r778719 = -2.627120459465085e+212;
        bool r778720 = r778715 <= r778719;
        double r778721 = 1.0;
        double r778722 = -4.9624802158885046e+128;
        bool r778723 = r778715 <= r778722;
        double r778724 = -2.5837508693414465e+60;
        bool r778725 = r778715 <= r778724;
        double r778726 = -6.453149043632784e-07;
        bool r778727 = r778715 <= r778726;
        double r778728 = x;
        double r778729 = r778728 * r778728;
        double r778730 = 4.0;
        double r778731 = r778715 * r778730;
        double r778732 = r778731 * r778715;
        double r778733 = fma(r778728, r778728, r778732);
        double r778734 = r778729 / r778733;
        double r778735 = r778729 + r778732;
        double r778736 = r778732 / r778735;
        double r778737 = r778734 - r778736;
        double r778738 = 4.22472559063545e-142;
        bool r778739 = r778715 <= r778738;
        double r778740 = 8.417597582089843e+133;
        bool r778741 = r778715 <= r778740;
        double r778742 = r778732 / r778733;
        double r778743 = r778734 - r778742;
        double r778744 = exp(r778743);
        double r778745 = log(r778744);
        double r778746 = r778741 ? r778745 : r778718;
        double r778747 = r778739 ? r778721 : r778746;
        double r778748 = r778727 ? r778737 : r778747;
        double r778749 = r778725 ? r778721 : r778748;
        double r778750 = r778723 ? r778718 : r778749;
        double r778751 = r778720 ? r778721 : r778750;
        double r778752 = r778717 ? r778718 : r778751;
        return r778752;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.5
Herbie16.2
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \lt 0.974323384962678118:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if y < -2.2235268531892296e+254 or -2.627120459465085e+212 < y < -4.9624802158885046e+128 or 8.417597582089843e+133 < y

    1. Initial program 56.7

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around 0 8.8

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

    if -2.2235268531892296e+254 < y < -2.627120459465085e+212 or -4.9624802158885046e+128 < y < -2.5837508693414465e+60 or -6.453149043632784e-07 < y < 4.22472559063545e-142

    1. Initial program 27.3

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 19.7

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

    if -2.5837508693414465e+60 < y < -6.453149043632784e-07

    1. Initial program 16.0

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied div-sub16.0

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Using strategy rm
    6. Applied fma-udef16.0

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

    if 4.22472559063545e-142 < y < 8.417597582089843e+133

    1. Initial program 17.0

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied div-sub17.0

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Using strategy rm
    6. Applied add-log-exp17.0

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)}\]
    7. Applied add-log-exp17.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\]
    8. Applied diff-log17.0

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{e^{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}\right)}\]
    9. Simplified17.0

      \[\leadsto \log \color{blue}{\left(e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification16.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.22352685318922961 \cdot 10^{254}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.62712045946508503 \cdot 10^{212}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -4.96248021588850455 \cdot 10^{128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.583750869341446 \cdot 10^{60}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -6.45314904363278403 \cdot 10^{-7}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 4.22472559063544996 \cdot 10^{-142}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 8.4175975820898431 \cdot 10^{133}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020043 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))