Average Error: 31.2 → 12.3
Time: 2.3s
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 -7.09243729226095 \cdot 10^{99}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.53150117367809198 \cdot 10^{-22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le -5.7886743587257764 \cdot 10^{-49}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -1.60165638621187645 \cdot 10^{-137}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 2.186097498494804 \cdot 10^{-112}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 9.42275717176671717 \cdot 10^{77}:\\ \;\;\;\;\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}\;y \le -7.09243729226095 \cdot 10^{99}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le -5.7886743587257764 \cdot 10^{-49}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \le 2.186097498494804 \cdot 10^{-112}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 9.42275717176671717 \cdot 10^{77}:\\
\;\;\;\;\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 r729364 = x;
        double r729365 = r729364 * r729364;
        double r729366 = y;
        double r729367 = 4.0;
        double r729368 = r729366 * r729367;
        double r729369 = r729368 * r729366;
        double r729370 = r729365 - r729369;
        double r729371 = r729365 + r729369;
        double r729372 = r729370 / r729371;
        return r729372;
}

double f(double x, double y) {
        double r729373 = y;
        double r729374 = -7.09243729226095e+99;
        bool r729375 = r729373 <= r729374;
        double r729376 = -1.0;
        double r729377 = -1.531501173678092e-22;
        bool r729378 = r729373 <= r729377;
        double r729379 = x;
        double r729380 = r729379 * r729379;
        double r729381 = 4.0;
        double r729382 = r729373 * r729381;
        double r729383 = r729382 * r729373;
        double r729384 = r729380 - r729383;
        double r729385 = r729380 + r729383;
        double r729386 = r729384 / r729385;
        double r729387 = -5.7886743587257764e-49;
        bool r729388 = r729373 <= r729387;
        double r729389 = 1.0;
        double r729390 = -1.6016563862118764e-137;
        bool r729391 = r729373 <= r729390;
        double r729392 = 2.1860974984948043e-112;
        bool r729393 = r729373 <= r729392;
        double r729394 = 9.422757171766717e+77;
        bool r729395 = r729373 <= r729394;
        double r729396 = r729395 ? r729386 : r729376;
        double r729397 = r729393 ? r729389 : r729396;
        double r729398 = r729391 ? r729386 : r729397;
        double r729399 = r729388 ? r729389 : r729398;
        double r729400 = r729378 ? r729386 : r729399;
        double r729401 = r729375 ? r729376 : r729400;
        return r729401;
}

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
Herbie12.3
\[\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 y < -7.09243729226095e+99 or 9.422757171766717e+77 < y

    1. Initial program 49.6

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

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

    if -7.09243729226095e+99 < y < -1.531501173678092e-22 or -5.7886743587257764e-49 < y < -1.6016563862118764e-137 or 2.1860974984948043e-112 < y < 9.422757171766717e+77

    1. Initial program 14.6

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

    if -1.531501173678092e-22 < y < -5.7886743587257764e-49 or -1.6016563862118764e-137 < y < 2.1860974984948043e-112

    1. Initial program 28.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.09243729226095 \cdot 10^{99}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.53150117367809198 \cdot 10^{-22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le -5.7886743587257764 \cdot 10^{-49}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -1.60165638621187645 \cdot 10^{-137}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 2.186097498494804 \cdot 10^{-112}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 9.42275717176671717 \cdot 10^{77}:\\ \;\;\;\;\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 2020035 
(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))))