Average Error: 31.2 → 13.9
Time: 12.0s
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 -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le \frac{-647764373388383}{3.957286423569672544968040336314355040562 \cdot 10^{174}}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le \frac{543649761700873}{3.450873173395281893717377931138512726226 \cdot 10^{69}}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le \frac{3895422262974759}{4.789048565205902682369834459844716198809 \cdot 10^{52}}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le \frac{422432555593905}{4294967296}:\\ \;\;\;\;1\\ \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 -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le \frac{-647764373388383}{3.957286423569672544968040336314355040562 \cdot 10^{174}}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;y \le \frac{543649761700873}{3.450873173395281893717377931138512726226 \cdot 10^{69}}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le \frac{3895422262974759}{4.789048565205902682369834459844716198809 \cdot 10^{52}}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;y \le \frac{422432555593905}{4294967296}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r559888 = x;
        double r559889 = r559888 * r559888;
        double r559890 = y;
        double r559891 = 4.0;
        double r559892 = r559890 * r559891;
        double r559893 = r559892 * r559890;
        double r559894 = r559889 - r559893;
        double r559895 = r559889 + r559893;
        double r559896 = r559894 / r559895;
        return r559896;
}

double f(double x, double y) {
        double r559897 = y;
        double r559898 = -4.75816735826197e+148;
        bool r559899 = r559897 <= r559898;
        double r559900 = -1.0;
        double r559901 = -647764373388383.0;
        double r559902 = 3.9572864235696725e+174;
        double r559903 = r559901 / r559902;
        bool r559904 = r559897 <= r559903;
        double r559905 = 1.0;
        double r559906 = x;
        double r559907 = r559906 * r559906;
        double r559908 = 4.0;
        double r559909 = r559897 * r559908;
        double r559910 = r559909 * r559897;
        double r559911 = r559907 + r559910;
        double r559912 = r559911 / r559907;
        double r559913 = r559905 / r559912;
        double r559914 = r559910 / r559911;
        double r559915 = sqrt(r559914);
        double r559916 = r559915 * r559915;
        double r559917 = r559913 - r559916;
        double r559918 = 543649761700873.0;
        double r559919 = 3.450873173395282e+69;
        double r559920 = r559918 / r559919;
        bool r559921 = r559897 <= r559920;
        double r559922 = 3895422262974759.0;
        double r559923 = 4.789048565205903e+52;
        double r559924 = r559922 / r559923;
        bool r559925 = r559897 <= r559924;
        double r559926 = r559907 / r559911;
        double r559927 = exp(r559926);
        double r559928 = log(r559927);
        double r559929 = r559928 - r559916;
        double r559930 = 422432555593905.0;
        double r559931 = 4294967296.0;
        double r559932 = r559930 / r559931;
        bool r559933 = r559897 <= r559932;
        double r559934 = r559933 ? r559905 : r559900;
        double r559935 = r559925 ? r559929 : r559934;
        double r559936 = r559921 ? r559905 : r559935;
        double r559937 = r559904 ? r559917 : r559936;
        double r559938 = r559899 ? r559900 : r559937;
        return r559938;
}

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.2
Target30.9
Herbie13.9
\[\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 y < -4.75816735826197e+148 or 98355.24381927797 < y

    1. Initial program 47.9

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

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

    if -4.75816735826197e+148 < y < -1.636890293131895e-160

    1. Initial program 16.0

      \[\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.0

      \[\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.0

      \[\leadsto \frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \color{blue}{\sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    6. Using strategy rm
    7. Applied clear-num16.0

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

    if -1.636890293131895e-160 < y < 1.5753976874379915e-55 or 8.134021215145638e-38 < y < 98355.24381927797

    1. Initial program 24.9

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

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

    if 1.5753976874379915e-55 < y < 8.134021215145638e-38

    1. Initial program 20.1

      \[\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-sub20.1

      \[\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-sqrt20.1

      \[\leadsto \frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \color{blue}{\sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    6. Using strategy rm
    7. Applied add-log-exp20.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le \frac{-647764373388383}{3.957286423569672544968040336314355040562 \cdot 10^{174}}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le \frac{543649761700873}{3.450873173395281893717377931138512726226 \cdot 10^{69}}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le \frac{3895422262974759}{4.789048565205902682369834459844716198809 \cdot 10^{52}}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le \frac{422432555593905}{4294967296}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(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.974323384962678118) (- (/ (* 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))))