Average Error: 31.1 → 16.3
Time: 1.8s
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 3.121103623042389124428086290470589613646 \cdot 10^{-133}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.037055476264600818538695773598663782551 \cdot 10^{-58}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.052279685526439364674012027710604618857 \cdot 10^{75}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.28348455894001913597103380479105317734 \cdot 10^{148}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.259308201205468781218975789992493624952 \cdot 10^{159}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-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 3.121103623042389124428086290470589613646 \cdot 10^{-133}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.037055476264600818538695773598663782551 \cdot 10^{-58}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\

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

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.28348455894001913597103380479105317734 \cdot 10^{148}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\

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

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

\end{array}
double f(double x, double y) {
        double r687909 = x;
        double r687910 = r687909 * r687909;
        double r687911 = y;
        double r687912 = 4.0;
        double r687913 = r687911 * r687912;
        double r687914 = r687913 * r687911;
        double r687915 = r687910 - r687914;
        double r687916 = r687910 + r687914;
        double r687917 = r687915 / r687916;
        return r687917;
}

double f(double x, double y) {
        double r687918 = y;
        double r687919 = 4.0;
        double r687920 = r687918 * r687919;
        double r687921 = r687920 * r687918;
        double r687922 = 3.121103623042389e-133;
        bool r687923 = r687921 <= r687922;
        double r687924 = 1.0;
        double r687925 = 1.0370554762646008e-58;
        bool r687926 = r687921 <= r687925;
        double r687927 = x;
        double r687928 = r687927 * r687927;
        double r687929 = r687928 + r687921;
        double r687930 = r687921 * r687921;
        double r687931 = -r687930;
        double r687932 = 4.0;
        double r687933 = pow(r687927, r687932);
        double r687934 = r687931 + r687933;
        double r687935 = r687934 / r687929;
        double r687936 = r687929 / r687935;
        double r687937 = r687924 / r687936;
        double r687938 = 4.052279685526439e+75;
        bool r687939 = r687921 <= r687938;
        double r687940 = 3.283484558940019e+148;
        bool r687941 = r687921 <= r687940;
        double r687942 = 4.259308201205469e+159;
        bool r687943 = r687921 <= r687942;
        double r687944 = -1.0;
        double r687945 = r687924 / r687944;
        double r687946 = r687943 ? r687924 : r687945;
        double r687947 = r687941 ? r687937 : r687946;
        double r687948 = r687939 ? r687924 : r687947;
        double r687949 = r687926 ? r687937 : r687948;
        double r687950 = r687923 ? r687924 : r687949;
        return r687950;
}

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.1
Target30.8
Herbie16.3
\[\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) < 3.121103623042389e-133 or 1.0370554762646008e-58 < (* (* y 4.0) y) < 4.052279685526439e+75 or 3.283484558940019e+148 < (* (* y 4.0) y) < 4.259308201205469e+159

    1. Initial program 21.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 17.7

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

    if 3.121103623042389e-133 < (* (* y 4.0) y) < 1.0370554762646008e-58 or 4.052279685526439e+75 < (* (* y 4.0) y) < 3.283484558940019e+148

    1. Initial program 16.2

      \[\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 clear-num16.2

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Using strategy rm
    5. Applied flip--24.4

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

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

    if 4.259308201205469e+159 < (* (* y 4.0) y)

    1. Initial program 48.7

      \[\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 clear-num48.7

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Taylor expanded around 0 11.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 3.121103623042389124428086290470589613646 \cdot 10^{-133}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.037055476264600818538695773598663782551 \cdot 10^{-58}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.052279685526439364674012027710604618857 \cdot 10^{75}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.28348455894001913597103380479105317734 \cdot 10^{148}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\frac{\left(-\left(\left(y \cdot 4\right) \cdot y\right) \cdot \left(\left(y \cdot 4\right) \cdot y\right)\right) + {x}^{4}}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.259308201205468781218975789992493624952 \cdot 10^{159}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-1}\\ \end{array}\]

Reproduce

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