Average Error: 31.5 → 13.7
Time: 5.3s
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 r424965 = x;
        double r424966 = r424965 * r424965;
        double r424967 = y;
        double r424968 = 4.0;
        double r424969 = r424967 * r424968;
        double r424970 = r424969 * r424967;
        double r424971 = r424966 - r424970;
        double r424972 = r424966 + r424970;
        double r424973 = r424971 / r424972;
        return r424973;
}

double f(double x, double y) {
        double r424974 = y;
        double r424975 = 4.0;
        double r424976 = r424974 * r424975;
        double r424977 = r424976 * r424974;
        double r424978 = 1.1920917570347169e-148;
        bool r424979 = r424977 <= r424978;
        double r424980 = 1.0;
        double r424981 = 5023037.116648855;
        bool r424982 = r424977 <= r424981;
        double r424983 = x;
        double r424984 = r424983 * r424983;
        double r424985 = r424984 - r424977;
        double r424986 = fma(r424983, r424983, r424977);
        double r424987 = r424985 / r424986;
        double r424988 = 2.2999553787656984e+56;
        bool r424989 = r424977 <= r424988;
        double r424990 = 7.178993365575064e+117;
        bool r424991 = r424977 <= r424990;
        double r424992 = 1.3262748212376038e+134;
        bool r424993 = r424977 <= r424992;
        double r424994 = 5.213367998754109e+168;
        bool r424995 = r424977 <= r424994;
        double r424996 = -1.0;
        double r424997 = r424995 ? r424987 : r424996;
        double r424998 = r424993 ? r424980 : r424997;
        double r424999 = r424991 ? r424987 : r424998;
        double r425000 = r424989 ? r424980 : r424999;
        double r425001 = r424982 ? r424987 : r425000;
        double r425002 = r424979 ? r424980 : r425001;
        return r425002;
}

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))))