Average Error: 31.2 → 16.0
Time: 2.7s
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 -2590647937.20362567901611328125:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1190.57638633722717713681049644947052002:\\ \;\;\;\;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 -2590647937.20362567901611328125:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 1190.57638633722717713681049644947052002:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r487981 = x;
        double r487982 = r487981 * r487981;
        double r487983 = y;
        double r487984 = 4.0;
        double r487985 = r487983 * r487984;
        double r487986 = r487985 * r487983;
        double r487987 = r487982 - r487986;
        double r487988 = r487982 + r487986;
        double r487989 = r487987 / r487988;
        return r487989;
}

double f(double __attribute__((unused)) x, double y) {
        double r487990 = y;
        double r487991 = -2590647937.2036257;
        bool r487992 = r487990 <= r487991;
        double r487993 = -1.0;
        double r487994 = 1190.5763863372272;
        bool r487995 = r487990 <= r487994;
        double r487996 = 1.0;
        double r487997 = r487995 ? r487996 : r487993;
        double r487998 = r487992 ? r487993 : r487997;
        return r487998;
}

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
Herbie16.0
\[\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 2 regimes
  2. if y < -2590647937.2036257 or 1190.5763863372272 < y

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

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

    if -2590647937.2036257 < y < 1190.5763863372272

    1. Initial program 22.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2590647937.20362567901611328125:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1190.57638633722717713681049644947052002:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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