Average Error: 31.7 → 14.8
Time: 48.1s
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 -1.302473734361689583818414967767065647429 \cdot 10^{64}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 4.427972959141087508327226963770083374106 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.117086201251834897728735635968684829902 \cdot 10^{60}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\ \mathbf{elif}\;y \le 5.419438360639095008822556977586250635758 \cdot 10^{72}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.027562094282635282760369761847330220115 \cdot 10^{103}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \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}\;y \le -1.302473734361689583818414967767065647429 \cdot 10^{64}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 4.427972959141087508327226963770083374106 \cdot 10^{-125}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 4.117086201251834897728735635968684829902 \cdot 10^{60}:\\
\;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\

\mathbf{elif}\;y \le 5.419438360639095008822556977586250635758 \cdot 10^{72}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.027562094282635282760369761847330220115 \cdot 10^{103}:\\
\;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\

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

\end{array}
double f(double x, double y) {
        double r36272174 = x;
        double r36272175 = r36272174 * r36272174;
        double r36272176 = y;
        double r36272177 = 4.0;
        double r36272178 = r36272176 * r36272177;
        double r36272179 = r36272178 * r36272176;
        double r36272180 = r36272175 - r36272179;
        double r36272181 = r36272175 + r36272179;
        double r36272182 = r36272180 / r36272181;
        return r36272182;
}

double f(double x, double y) {
        double r36272183 = y;
        double r36272184 = -1.3024737343616896e+64;
        bool r36272185 = r36272183 <= r36272184;
        double r36272186 = -1.0;
        double r36272187 = 4.4279729591410875e-125;
        bool r36272188 = r36272183 <= r36272187;
        double r36272189 = 1.0;
        double r36272190 = 4.117086201251835e+60;
        bool r36272191 = r36272183 <= r36272190;
        double r36272192 = x;
        double r36272193 = r36272192 * r36272192;
        double r36272194 = 4.0;
        double r36272195 = r36272194 * r36272183;
        double r36272196 = r36272183 * r36272195;
        double r36272197 = r36272193 + r36272196;
        double r36272198 = r36272193 / r36272197;
        double r36272199 = sqrt(r36272198);
        double r36272200 = r36272199 * r36272199;
        double r36272201 = r36272196 / r36272197;
        double r36272202 = r36272200 - r36272201;
        double r36272203 = 5.419438360639095e+72;
        bool r36272204 = r36272183 <= r36272203;
        double r36272205 = 1.0275620942826353e+103;
        bool r36272206 = r36272183 <= r36272205;
        double r36272207 = r36272206 ? r36272202 : r36272186;
        double r36272208 = r36272204 ? r36272189 : r36272207;
        double r36272209 = r36272191 ? r36272202 : r36272208;
        double r36272210 = r36272188 ? r36272189 : r36272209;
        double r36272211 = r36272185 ? r36272186 : r36272210;
        return r36272211;
}

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.7
Target31.4
Herbie14.8
\[\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 < -1.3024737343616896e+64 or 1.0275620942826353e+103 < y

    1. Initial program 48.8

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

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

    if -1.3024737343616896e+64 < y < 4.4279729591410875e-125 or 4.117086201251835e+60 < y < 5.419438360639095e+72

    1. Initial program 24.5

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

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

    if 4.4279729591410875e-125 < y < 4.117086201251835e+60 or 5.419438360639095e+72 < y < 1.0275620942826353e+103

    1. Initial program 16.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 div-sub16.3

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt16.3

      \[\leadsto \color{blue}{\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.302473734361689583818414967767065647429 \cdot 10^{64}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 4.427972959141087508327226963770083374106 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.117086201251834897728735635968684829902 \cdot 10^{60}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\ \mathbf{elif}\;y \le 5.419438360639095008822556977586250635758 \cdot 10^{72}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.027562094282635282760369761847330220115 \cdot 10^{103}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + y \cdot \left(4 \cdot y\right)}} - \frac{y \cdot \left(4 \cdot y\right)}{x \cdot x + y \cdot \left(4 \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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