Average Error: 31.2 → 16.0
Time: 4.0s
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 r475036 = x;
        double r475037 = r475036 * r475036;
        double r475038 = y;
        double r475039 = 4.0;
        double r475040 = r475038 * r475039;
        double r475041 = r475040 * r475038;
        double r475042 = r475037 - r475041;
        double r475043 = r475037 + r475041;
        double r475044 = r475042 / r475043;
        return r475044;
}

double f(double __attribute__((unused)) x, double y) {
        double r475045 = y;
        double r475046 = -2590647937.2036257;
        bool r475047 = r475045 <= r475046;
        double r475048 = -1.0;
        double r475049 = 1190.5763863372272;
        bool r475050 = r475045 <= r475049;
        double r475051 = 1.0;
        double r475052 = r475050 ? r475051 : r475048;
        double r475053 = r475047 ? r475048 : r475052;
        return r475053;
}

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. Simplified40.2

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. 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. Simplified22.4

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. 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 +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))))