Average Error: 31.5 → 13.2
Time: 11.6s
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}\;x \le -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\ \;\;\;\;\sqrt[3]{\frac{1}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}}} \cdot \left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right)\\ \mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\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}\;x \le -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\
\;\;\;\;\sqrt[3]{\frac{1}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}}} \cdot \left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right)\\

\mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\
\;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\

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

\end{array}
double f(double x, double y) {
        double r622739 = x;
        double r622740 = r622739 * r622739;
        double r622741 = y;
        double r622742 = 4.0;
        double r622743 = r622741 * r622742;
        double r622744 = r622743 * r622741;
        double r622745 = r622740 - r622744;
        double r622746 = r622740 + r622744;
        double r622747 = r622745 / r622746;
        return r622747;
}

double f(double x, double y) {
        double r622748 = x;
        double r622749 = -4.542162861981963e+56;
        bool r622750 = r622748 <= r622749;
        double r622751 = 1.0;
        double r622752 = -5.780522729495913e-162;
        bool r622753 = r622748 <= r622752;
        double r622754 = y;
        double r622755 = 4.0;
        double r622756 = r622755 * r622754;
        double r622757 = r622754 * r622756;
        double r622758 = fma(r622748, r622748, r622757);
        double r622759 = -r622754;
        double r622760 = r622759 * r622754;
        double r622761 = r622748 * r622748;
        double r622762 = fma(r622755, r622760, r622761);
        double r622763 = r622758 / r622762;
        double r622764 = r622751 / r622763;
        double r622765 = cbrt(r622764);
        double r622766 = fma(r622756, r622759, r622761);
        double r622767 = fma(r622754, r622756, r622761);
        double r622768 = r622766 / r622767;
        double r622769 = cbrt(r622768);
        double r622770 = r622769 * r622769;
        double r622771 = r622765 * r622770;
        double r622772 = 5.430501749338193e-128;
        bool r622773 = r622748 <= r622772;
        double r622774 = -1.0;
        double r622775 = 6.680131771318429e+54;
        bool r622776 = r622748 <= r622775;
        double r622777 = r622770 * r622769;
        double r622778 = r622776 ? r622777 : r622751;
        double r622779 = r622773 ? r622774 : r622778;
        double r622780 = r622753 ? r622771 : r622779;
        double r622781 = r622750 ? r622751 : r622780;
        return r622781;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie13.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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 x < -4.542162861981963e+56 or 6.680131771318429e+54 < x

    1. Initial program 45.6

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

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

    if -4.542162861981963e+56 < x < -5.780522729495913e-162

    1. Initial program 15.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt15.8

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

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\right)} \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    5. Simplified15.8

      \[\leadsto \left(\sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\right) \cdot \color{blue}{\sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}}\]
    6. Using strategy rm
    7. Applied clear-num15.8

      \[\leadsto \left(\sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\right) \cdot \sqrt[3]{\color{blue}{\frac{1}{\frac{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}}}}\]
    8. Simplified15.8

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

    if -5.780522729495913e-162 < x < 5.430501749338193e-128

    1. Initial program 29.3

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

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

    if 5.430501749338193e-128 < x < 6.680131771318429e+54

    1. Initial program 15.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\ \;\;\;\;\sqrt[3]{\frac{1}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}}} \cdot \left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right)\\ \mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

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

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