Average Error: 31.1 → 3.8
Time: 2.8s
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}\;x \le -1.331887172847139076544407291057659922741 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.570784445226952748816445846527769860735 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.373484080558642358416244903315687209789 \cdot 10^{144}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \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}\;x \le -1.331887172847139076544407291057659922741 \cdot 10^{154}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.570784445226952748816445846527769860735 \cdot 10^{-162}:\\
\;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\

\mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 6.373484080558642358416244903315687209789 \cdot 10^{144}:\\
\;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\

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

\end{array}
double f(double x, double y) {
        double r604447 = x;
        double r604448 = r604447 * r604447;
        double r604449 = y;
        double r604450 = 4.0;
        double r604451 = r604449 * r604450;
        double r604452 = r604451 * r604449;
        double r604453 = r604448 - r604452;
        double r604454 = r604448 + r604452;
        double r604455 = r604453 / r604454;
        return r604455;
}

double f(double x, double y) {
        double r604456 = x;
        double r604457 = -1.3318871728471391e+154;
        bool r604458 = r604456 <= r604457;
        double r604459 = 1.0;
        double r604460 = -1.5707844452269527e-162;
        bool r604461 = r604456 <= r604460;
        double r604462 = y;
        double r604463 = 4.0;
        double r604464 = r604462 * r604463;
        double r604465 = r604464 * r604462;
        double r604466 = fma(r604456, r604456, r604465);
        double r604467 = r604466 / r604456;
        double r604468 = r604456 / r604467;
        double r604469 = 2.0;
        double r604470 = pow(r604456, r604469);
        double r604471 = r604470 / r604462;
        double r604472 = fma(r604463, r604462, r604471);
        double r604473 = r604464 / r604472;
        double r604474 = r604468 - r604473;
        double r604475 = 6.596793469983034e-163;
        bool r604476 = r604456 <= r604475;
        double r604477 = -1.0;
        double r604478 = 6.373484080558642e+144;
        bool r604479 = r604456 <= r604478;
        double r604480 = r604479 ? r604474 : r604459;
        double r604481 = r604476 ? r604477 : r604480;
        double r604482 = r604461 ? r604474 : r604481;
        double r604483 = r604458 ? r604459 : r604482;
        return r604483;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.1
Target30.8
Herbie3.8
\[\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 x < -1.3318871728471391e+154 or 6.373484080558642e+144 < x

    1. Initial program 62.7

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

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

    if -1.3318871728471391e+154 < x < -1.5707844452269527e-162 or 6.596793469983034e-163 < x < 6.373484080558642e+144

    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 div-sub15.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Simplified16.1

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified15.6

      \[\leadsto \frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \color{blue}{\frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}}\]
    6. Taylor expanded around 0 0.3

      \[\leadsto \frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\color{blue}{4 \cdot y + \frac{{x}^{2}}{y}}}\]
    7. Simplified0.3

      \[\leadsto \frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\color{blue}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}}\]

    if -1.5707844452269527e-162 < x < 6.596793469983034e-163

    1. Initial program 30.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.331887172847139076544407291057659922741 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.570784445226952748816445846527769860735 \cdot 10^{-162}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{elif}\;x \le 6.596793469983033519295935857748423121887 \cdot 10^{-163}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.373484080558642358416244903315687209789 \cdot 10^{144}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020001 +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.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))))