Average Error: 31.7 → 13.3
Time: 9.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}\;\left(y \cdot 4\right) \cdot y \le 1.480790185614221498743043118741847658707 \cdot 10^{-275}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.750320082435928664883021307196119648798 \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}\;\left(y \cdot 4\right) \cdot y \le 2.175989416098918886784126226179051353482 \cdot 10^{174}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.807219885468094196175482078912187788212 \cdot 10^{244}:\\ \;\;\;\;\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.480790185614221498743043118741847658707 \cdot 10^{-275}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.750320082435928664883021307196119648798 \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}\;\left(y \cdot 4\right) \cdot y \le 2.175989416098918886784126226179051353482 \cdot 10^{174}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.807219885468094196175482078912187788212 \cdot 10^{244}:\\
\;\;\;\;\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 r415478 = x;
        double r415479 = r415478 * r415478;
        double r415480 = y;
        double r415481 = 4.0;
        double r415482 = r415480 * r415481;
        double r415483 = r415482 * r415480;
        double r415484 = r415479 - r415483;
        double r415485 = r415479 + r415483;
        double r415486 = r415484 / r415485;
        return r415486;
}

double f(double x, double y) {
        double r415487 = y;
        double r415488 = 4.0;
        double r415489 = r415487 * r415488;
        double r415490 = r415489 * r415487;
        double r415491 = 1.4807901856142215e-275;
        bool r415492 = r415490 <= r415491;
        double r415493 = 1.0;
        double r415494 = 1.7503200824359287e+137;
        bool r415495 = r415490 <= r415494;
        double r415496 = x;
        double r415497 = r415496 * r415496;
        double r415498 = r415497 - r415490;
        double r415499 = r415497 + r415490;
        double r415500 = r415498 / r415499;
        double r415501 = 2.175989416098919e+174;
        bool r415502 = r415490 <= r415501;
        double r415503 = 1.8072198854680942e+244;
        bool r415504 = r415490 <= r415503;
        double r415505 = -1.0;
        double r415506 = r415504 ? r415500 : r415505;
        double r415507 = r415502 ? r415493 : r415506;
        double r415508 = r415495 ? r415500 : r415507;
        double r415509 = r415492 ? r415493 : r415508;
        return r415509;
}

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
Herbie13.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.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.4807901856142215e-275 or 1.7503200824359287e+137 < (* (* y 4.0) y) < 2.175989416098919e+174

    1. Initial program 27.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 12.7

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

    if 1.4807901856142215e-275 < (* (* y 4.0) y) < 1.7503200824359287e+137 or 2.175989416098919e+174 < (* (* y 4.0) y) < 1.8072198854680942e+244

    1. Initial program 16.2

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

    if 1.8072198854680942e+244 < (* (* y 4.0) y)

    1. Initial program 55.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.480790185614221498743043118741847658707 \cdot 10^{-275}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.750320082435928664883021307196119648798 \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}\;\left(y \cdot 4\right) \cdot y \le 2.175989416098918886784126226179051353482 \cdot 10^{174}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.807219885468094196175482078912187788212 \cdot 10^{244}:\\ \;\;\;\;\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 2019306 
(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))))