Average Error: 31.5 → 14.1
Time: 2.9s
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 6.44495446490974234 \cdot 10^{-285}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1427194724.89060712:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.34707069111200962 \cdot 10^{62}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.3872178848098573 \cdot 10^{156}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.357033785550347 \cdot 10^{219}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.92606420407618166 \cdot 10^{228}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \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 6.44495446490974234 \cdot 10^{-285}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1427194724.89060712:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.34707069111200962 \cdot 10^{62}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.3872178848098573 \cdot 10^{156}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.357033785550347 \cdot 10^{219}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.92606420407618166 \cdot 10^{228}:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{-1}\right)\\

\end{array}
double f(double x, double y) {
        double r691488 = x;
        double r691489 = r691488 * r691488;
        double r691490 = y;
        double r691491 = 4.0;
        double r691492 = r691490 * r691491;
        double r691493 = r691492 * r691490;
        double r691494 = r691489 - r691493;
        double r691495 = r691489 + r691493;
        double r691496 = r691494 / r691495;
        return r691496;
}

double f(double x, double y) {
        double r691497 = y;
        double r691498 = 4.0;
        double r691499 = r691497 * r691498;
        double r691500 = r691499 * r691497;
        double r691501 = 6.444954464909742e-285;
        bool r691502 = r691500 <= r691501;
        double r691503 = 1.0;
        double r691504 = 1427194724.890607;
        bool r691505 = r691500 <= r691504;
        double r691506 = x;
        double r691507 = r691506 * r691506;
        double r691508 = r691507 - r691500;
        double r691509 = r691507 + r691500;
        double r691510 = r691508 / r691509;
        double r691511 = exp(r691510);
        double r691512 = sqrt(r691511);
        double r691513 = log(r691512);
        double r691514 = r691513 + r691513;
        double r691515 = 7.34707069111201e+62;
        bool r691516 = r691500 <= r691515;
        double r691517 = 2.3872178848098573e+156;
        bool r691518 = r691500 <= r691517;
        double r691519 = log(r691511);
        double r691520 = 1.357033785550347e+219;
        bool r691521 = r691500 <= r691520;
        double r691522 = 5.9260642040761817e+228;
        bool r691523 = r691500 <= r691522;
        double r691524 = -1.0;
        double r691525 = exp(r691524);
        double r691526 = log(r691525);
        double r691527 = r691523 ? r691514 : r691526;
        double r691528 = r691521 ? r691503 : r691527;
        double r691529 = r691518 ? r691519 : r691528;
        double r691530 = r691516 ? r691503 : r691529;
        double r691531 = r691505 ? r691514 : r691530;
        double r691532 = r691502 ? r691503 : r691531;
        return r691532;
}

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.5
Target31.2
Herbie14.1
\[\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 4 regimes
  2. if (* (* y 4.0) y) < 6.444954464909742e-285 or 1427194724.890607 < (* (* y 4.0) y) < 7.34707069111201e+62 or 2.3872178848098573e+156 < (* (* y 4.0) y) < 1.357033785550347e+219

    1. Initial program 25.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 inf 16.4

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

    if 6.444954464909742e-285 < (* (* y 4.0) y) < 1427194724.890607 or 1.357033785550347e+219 < (* (* y 4.0) y) < 5.9260642040761817e+228

    1. Initial program 15.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp15.9

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt15.9

      \[\leadsto \log \color{blue}{\left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)}\]
    6. Applied log-prod15.9

      \[\leadsto \color{blue}{\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)}\]

    if 7.34707069111201e+62 < (* (* y 4.0) y) < 2.3872178848098573e+156

    1. Initial program 16.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp16.1

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]

    if 5.9260642040761817e+228 < (* (* y 4.0) y)

    1. Initial program 53.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp53.2

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Taylor expanded around 0 9.7

      \[\leadsto \log \left(e^{\color{blue}{-1}}\right)\]
  3. Recombined 4 regimes into one program.
  4. Final simplification14.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 6.44495446490974234 \cdot 10^{-285}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1427194724.89060712:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.34707069111200962 \cdot 10^{62}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.3872178848098573 \cdot 10^{156}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.357033785550347 \cdot 10^{219}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.92606420407618166 \cdot 10^{228}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right) + \log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \end{array}\]

Reproduce

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