Average Error: 31.1 → 12.2
Time: 2.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}\;x \cdot x \le 8.48677548777607887 \cdot 10^{-264}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.1340718332425224 \cdot 10^{-245}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 2.7325230911480087 \cdot 10^{-173}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\ \;\;\;\;\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}\;x \cdot x \le 8.48677548777607887 \cdot 10^{-264}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \le 2.7325230911480087 \cdot 10^{-173}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\
\;\;\;\;\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 r662887 = x;
        double r662888 = r662887 * r662887;
        double r662889 = y;
        double r662890 = 4.0;
        double r662891 = r662889 * r662890;
        double r662892 = r662891 * r662889;
        double r662893 = r662888 - r662892;
        double r662894 = r662888 + r662892;
        double r662895 = r662893 / r662894;
        return r662895;
}

double f(double x, double y) {
        double r662896 = x;
        double r662897 = r662896 * r662896;
        double r662898 = 8.486775487776079e-264;
        bool r662899 = r662897 <= r662898;
        double r662900 = -1.0;
        double r662901 = 2.1340718332425224e-245;
        bool r662902 = r662897 <= r662901;
        double r662903 = y;
        double r662904 = 4.0;
        double r662905 = r662903 * r662904;
        double r662906 = r662905 * r662903;
        double r662907 = r662897 - r662906;
        double r662908 = r662897 + r662906;
        double r662909 = r662907 / r662908;
        double r662910 = 2.7325230911480087e-173;
        bool r662911 = r662897 <= r662910;
        double r662912 = 4.686018001101959e+264;
        bool r662913 = r662897 <= r662912;
        double r662914 = 1.0;
        double r662915 = r662913 ? r662909 : r662914;
        double r662916 = r662911 ? r662900 : r662915;
        double r662917 = r662902 ? r662909 : r662916;
        double r662918 = r662899 ? r662900 : r662917;
        return r662918;
}

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
Herbie12.2
\[\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.974323384962678118:\\ \;\;\;\;\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 (* x x) < 8.486775487776079e-264 or 2.1340718332425224e-245 < (* x x) < 2.7325230911480087e-173

    1. Initial program 26.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 0 11.1

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

    if 8.486775487776079e-264 < (* x x) < 2.1340718332425224e-245 or 2.7325230911480087e-173 < (* x x) < 4.686018001101959e+264

    1. Initial program 15.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]

    if 4.686018001101959e+264 < (* x x)

    1. Initial program 57.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 9.1

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 8.48677548777607887 \cdot 10^{-264}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.1340718332425224 \cdot 10^{-245}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 2.7325230911480087 \cdot 10^{-173}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\ \;\;\;\;\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 2020045 
(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))))