Average Error: 31.5 → 13.7
Time: 5.2s
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}\;\left(y \cdot 4\right) \cdot y \le 1.192091757034716875562004260761946839377 \cdot 10^{-148}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5023037.11664885468780994415283203125:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.299955378765698430754228883252507192043 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.178993365575064349423842969964358817229 \cdot 10^{117}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.326274821237603836714109292552910696965 \cdot 10^{134}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.213367998754109189462840924333391286818 \cdot 10^{168}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\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}\;\left(y \cdot 4\right) \cdot y \le 1.192091757034716875562004260761946839377 \cdot 10^{-148}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5023037.11664885468780994415283203125:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.299955378765698430754228883252507192043 \cdot 10^{56}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.326274821237603836714109292552910696965 \cdot 10^{134}:\\
\;\;\;\;1\\

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

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

\end{array}
double f(double x, double y) {
        double r469874 = x;
        double r469875 = r469874 * r469874;
        double r469876 = y;
        double r469877 = 4.0;
        double r469878 = r469876 * r469877;
        double r469879 = r469878 * r469876;
        double r469880 = r469875 - r469879;
        double r469881 = r469875 + r469879;
        double r469882 = r469880 / r469881;
        return r469882;
}

double f(double x, double y) {
        double r469883 = y;
        double r469884 = 4.0;
        double r469885 = r469883 * r469884;
        double r469886 = r469885 * r469883;
        double r469887 = 1.1920917570347169e-148;
        bool r469888 = r469886 <= r469887;
        double r469889 = 1.0;
        double r469890 = 5023037.116648855;
        bool r469891 = r469886 <= r469890;
        double r469892 = x;
        double r469893 = r469892 * r469892;
        double r469894 = r469893 - r469886;
        double r469895 = fma(r469892, r469892, r469886);
        double r469896 = r469894 / r469895;
        double r469897 = 2.2999553787656984e+56;
        bool r469898 = r469886 <= r469897;
        double r469899 = 7.178993365575064e+117;
        bool r469900 = r469886 <= r469899;
        double r469901 = 1.3262748212376038e+134;
        bool r469902 = r469886 <= r469901;
        double r469903 = 5.213367998754109e+168;
        bool r469904 = r469886 <= r469903;
        double r469905 = -1.0;
        double r469906 = r469904 ? r469896 : r469905;
        double r469907 = r469902 ? r469889 : r469906;
        double r469908 = r469900 ? r469896 : r469907;
        double r469909 = r469898 ? r469889 : r469908;
        double r469910 = r469891 ? r469896 : r469909;
        double r469911 = r469888 ? r469889 : r469910;
        return r469911;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie13.7
\[\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 3 regimes
  2. if (* (* y 4.0) y) < 1.1920917570347169e-148 or 5023037.116648855 < (* (* y 4.0) y) < 2.2999553787656984e+56 or 7.178993365575064e+117 < (* (* y 4.0) y) < 1.3262748212376038e+134

    1. Initial program 24.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified24.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. Taylor expanded around inf 14.8

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

    if 1.1920917570347169e-148 < (* (* y 4.0) y) < 5023037.116648855 or 2.2999553787656984e+56 < (* (* y 4.0) y) < 7.178993365575064e+117 or 1.3262748212376038e+134 < (* (* y 4.0) y) < 5.213367998754109e+168

    1. Initial program 15.2

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

      \[\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)}}\]

    if 5.213367998754109e+168 < (* (* y 4.0) y)

    1. Initial program 49.2

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

      \[\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 11.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.192091757034716875562004260761946839377 \cdot 10^{-148}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5023037.11664885468780994415283203125:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.299955378765698430754228883252507192043 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.178993365575064349423842969964358817229 \cdot 10^{117}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.326274821237603836714109292552910696965 \cdot 10^{134}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.213367998754109189462840924333391286818 \cdot 10^{168}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019325 +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))))