Average Error: 31.8 → 13.7
Time: 10.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 9.27663531436287128381217661661906819086 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.009231216679780664152274467083127477626 \cdot 10^{-87}:\\ \;\;\;\;\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 5.402861320094046622592646648226721464217 \cdot 10^{-40}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.240352669105307376499490012234923987962 \cdot 10^{217}:\\ \;\;\;\;\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 4.382319121848211154873292476989384127398 \cdot 10^{246}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.584497782919759792357906382925128159173 \cdot 10^{266}:\\ \;\;\;\;\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 9.27663531436287128381217661661906819086 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.009231216679780664152274467083127477626 \cdot 10^{-87}:\\
\;\;\;\;\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 5.402861320094046622592646648226721464217 \cdot 10^{-40}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.240352669105307376499490012234923987962 \cdot 10^{217}:\\
\;\;\;\;\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 4.382319121848211154873292476989384127398 \cdot 10^{246}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.584497782919759792357906382925128159173 \cdot 10^{266}:\\
\;\;\;\;\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 r495964 = x;
        double r495965 = r495964 * r495964;
        double r495966 = y;
        double r495967 = 4.0;
        double r495968 = r495966 * r495967;
        double r495969 = r495968 * r495966;
        double r495970 = r495965 - r495969;
        double r495971 = r495965 + r495969;
        double r495972 = r495970 / r495971;
        return r495972;
}

double f(double x, double y) {
        double r495973 = y;
        double r495974 = 4.0;
        double r495975 = r495973 * r495974;
        double r495976 = r495975 * r495973;
        double r495977 = 9.276635314362871e-162;
        bool r495978 = r495976 <= r495977;
        double r495979 = 1.0;
        double r495980 = 1.0092312166797807e-87;
        bool r495981 = r495976 <= r495980;
        double r495982 = x;
        double r495983 = r495982 * r495982;
        double r495984 = r495983 - r495976;
        double r495985 = r495983 + r495976;
        double r495986 = r495984 / r495985;
        double r495987 = 5.402861320094047e-40;
        bool r495988 = r495976 <= r495987;
        double r495989 = 1.2403526691053074e+217;
        bool r495990 = r495976 <= r495989;
        double r495991 = 4.382319121848211e+246;
        bool r495992 = r495976 <= r495991;
        double r495993 = 3.58449778291976e+266;
        bool r495994 = r495976 <= r495993;
        double r495995 = -1.0;
        double r495996 = r495994 ? r495986 : r495995;
        double r495997 = r495992 ? r495979 : r495996;
        double r495998 = r495990 ? r495986 : r495997;
        double r495999 = r495988 ? r495979 : r495998;
        double r496000 = r495981 ? r495986 : r495999;
        double r496001 = r495978 ? r495979 : r496000;
        return r496001;
}

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.8
Target31.5
Herbie13.7
\[\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) < 9.276635314362871e-162 or 1.0092312166797807e-87 < (* (* y 4.0) y) < 5.402861320094047e-40 or 1.2403526691053074e+217 < (* (* y 4.0) y) < 4.382319121848211e+246

    1. Initial program 24.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 inf 15.5

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

    if 9.276635314362871e-162 < (* (* y 4.0) y) < 1.0092312166797807e-87 or 5.402861320094047e-40 < (* (* y 4.0) y) < 1.2403526691053074e+217 or 4.382319121848211e+246 < (* (* y 4.0) y) < 3.58449778291976e+266

    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}\]

    if 3.58449778291976e+266 < (* (* y 4.0) y)

    1. Initial program 58.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 8.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 9.27663531436287128381217661661906819086 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.009231216679780664152274467083127477626 \cdot 10^{-87}:\\ \;\;\;\;\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 5.402861320094046622592646648226721464217 \cdot 10^{-40}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.240352669105307376499490012234923987962 \cdot 10^{217}:\\ \;\;\;\;\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 4.382319121848211154873292476989384127398 \cdot 10^{246}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.584497782919759792357906382925128159173 \cdot 10^{266}:\\ \;\;\;\;\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 2019235 +o rules:numerics
(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))))