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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r478144 = x;
        double r478145 = r478144 * r478144;
        double r478146 = y;
        double r478147 = 4.0;
        double r478148 = r478146 * r478147;
        double r478149 = r478148 * r478146;
        double r478150 = r478145 - r478149;
        double r478151 = r478145 + r478149;
        double r478152 = r478150 / r478151;
        return r478152;
}

double f(double x, double y) {
        double r478153 = y;
        double r478154 = 4.0;
        double r478155 = r478153 * r478154;
        double r478156 = r478155 * r478153;
        double r478157 = 1.1920917570347169e-148;
        bool r478158 = r478156 <= r478157;
        double r478159 = 1.0;
        double r478160 = 5023037.116648855;
        bool r478161 = r478156 <= r478160;
        double r478162 = x;
        double r478163 = r478162 * r478162;
        double r478164 = r478163 - r478156;
        double r478165 = r478163 + r478156;
        double r478166 = r478164 / r478165;
        double r478167 = 2.2999553787656984e+56;
        bool r478168 = r478156 <= r478167;
        double r478169 = 7.178993365575064e+117;
        bool r478170 = r478156 <= r478169;
        double r478171 = 1.3262748212376038e+134;
        bool r478172 = r478156 <= r478171;
        double r478173 = 5.213367998754109e+168;
        bool r478174 = r478156 <= r478173;
        double r478175 = -1.0;
        double r478176 = r478174 ? r478166 : r478175;
        double r478177 = r478172 ? r478159 : r478176;
        double r478178 = r478170 ? r478166 : r478177;
        double r478179 = r478168 ? r478159 : r478178;
        double r478180 = r478161 ? r478166 : r478179;
        double r478181 = r478158 ? r478159 : r478180;
        return r478181;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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. 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}\]

    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. 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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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