Average Error: 31.7 → 12.4
Time: 13.4s
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.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{1}{\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.883987095627688634773256576903935146579 \cdot 10^{-179}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\
\;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\
\;\;\;\;\frac{1}{\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 r418875 = x;
        double r418876 = r418875 * r418875;
        double r418877 = y;
        double r418878 = 4.0;
        double r418879 = r418877 * r418878;
        double r418880 = r418879 * r418877;
        double r418881 = r418876 - r418880;
        double r418882 = r418876 + r418880;
        double r418883 = r418881 / r418882;
        return r418883;
}

double f(double x, double y) {
        double r418884 = y;
        double r418885 = 4.0;
        double r418886 = r418884 * r418885;
        double r418887 = r418886 * r418884;
        double r418888 = 1.8839870956276886e-179;
        bool r418889 = r418887 <= r418888;
        double r418890 = 1.0;
        double r418891 = 2.5951328951665388e+25;
        bool r418892 = r418887 <= r418891;
        double r418893 = x;
        double r418894 = r418893 * r418893;
        double r418895 = r418894 + r418887;
        double r418896 = r418894 - r418887;
        double r418897 = r418895 / r418896;
        double r418898 = r418890 / r418897;
        double r418899 = 5.630971785438847e+28;
        bool r418900 = r418887 <= r418899;
        double r418901 = 7.251271519567313e+285;
        bool r418902 = r418887 <= r418901;
        double r418903 = -1.0;
        double r418904 = r418902 ? r418898 : r418903;
        double r418905 = r418900 ? r418890 : r418904;
        double r418906 = r418892 ? r418898 : r418905;
        double r418907 = r418889 ? r418890 : r418906;
        return r418907;
}

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
Herbie12.4
\[\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.8839870956276886e-179 or 2.5951328951665388e+25 < (* (* y 4.0) y) < 5.630971785438847e+28

    1. Initial program 26.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 clear-num26.3

      \[\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 inf 11.7

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

    if 1.8839870956276886e-179 < (* (* y 4.0) y) < 2.5951328951665388e+25 or 5.630971785438847e+28 < (* (* y 4.0) y) < 7.251271519567313e+285

    1. Initial program 15.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-num15.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}}}\]

    if 7.251271519567313e+285 < (* (* y 4.0) y)

    1. Initial program 61.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 8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\frac{1}{\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 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{1}{\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 2019323 
(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))))