Average Error: 32.2 → 12.6
Time: 8.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}\;x \le -1.517398075841731978978804721327597516736 \cdot 10^{145}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.621300319852041212687540142873364646976 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}\\ \mathbf{elif}\;x \le 1.295898151448028641074794033905884537542 \cdot 10^{-152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.052303689076668472383783695774322400393 \cdot 10^{95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\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.517398075841731978978804721327597516736 \cdot 10^{145}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 1.295898151448028641074794033905884537542 \cdot 10^{-152}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r883498 = x;
        double r883499 = r883498 * r883498;
        double r883500 = y;
        double r883501 = 4.0;
        double r883502 = r883500 * r883501;
        double r883503 = r883502 * r883500;
        double r883504 = r883499 - r883503;
        double r883505 = r883499 + r883503;
        double r883506 = r883504 / r883505;
        return r883506;
}

double f(double x, double y) {
        double r883507 = x;
        double r883508 = -1.517398075841732e+145;
        bool r883509 = r883507 <= r883508;
        double r883510 = 1.0;
        double r883511 = -6.621300319852041e-102;
        bool r883512 = r883507 <= r883511;
        double r883513 = y;
        double r883514 = 4.0;
        double r883515 = r883513 * r883514;
        double r883516 = r883513 * r883515;
        double r883517 = -r883516;
        double r883518 = fma(r883507, r883507, r883517);
        double r883519 = 2.0;
        double r883520 = pow(r883513, r883519);
        double r883521 = r883520 * r883514;
        double r883522 = fma(r883507, r883507, r883521);
        double r883523 = r883518 / r883522;
        double r883524 = 1.2958981514480286e-152;
        bool r883525 = r883507 <= r883524;
        double r883526 = -1.0;
        double r883527 = 6.052303689076668e+95;
        bool r883528 = r883507 <= r883527;
        double r883529 = r883528 ? r883523 : r883510;
        double r883530 = r883525 ? r883526 : r883529;
        double r883531 = r883512 ? r883523 : r883530;
        double r883532 = r883509 ? r883510 : r883531;
        return r883532;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.2
Target31.9
Herbie12.6
\[\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.517398075841732e+145 or 6.052303689076668e+95 < x

    1. Initial program 55.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified55.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. Using strategy rm
    4. Applied *-un-lft-identity55.2

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied *-un-lft-identity55.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}{1 \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\]
    6. Applied times-frac55.2

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

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

      \[\leadsto 1 \cdot \color{blue}{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}}\]
    9. Using strategy rm
    10. Applied add-cbrt-cube63.7

      \[\leadsto 1 \cdot \frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}}}\]
    11. Applied add-cbrt-cube64.0

      \[\leadsto 1 \cdot \frac{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right) \cdot \mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)\right) \cdot \mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}}\]
    12. Applied cbrt-undiv64.0

      \[\leadsto 1 \cdot \color{blue}{\sqrt[3]{\frac{\left(\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right) \cdot \mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)\right) \cdot \mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\left(\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)\right) \cdot \mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}}}\]
    13. Simplified55.2

      \[\leadsto 1 \cdot \sqrt[3]{\color{blue}{{\left(\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}\right)}^{3}}}\]
    14. Taylor expanded around inf 10.1

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

    if -1.517398075841732e+145 < x < -6.621300319852041e-102 or 1.2958981514480286e-152 < x < 6.052303689076668e+95

    1. Initial program 17.1

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

      \[\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. Using strategy rm
    4. Applied *-un-lft-identity17.1

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied *-un-lft-identity17.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}{1 \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\]
    6. Applied times-frac17.1

      \[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    7. Simplified17.1

      \[\leadsto \color{blue}{1} \cdot \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\]
    8. Simplified17.1

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

    if -6.621300319852041e-102 < x < 1.2958981514480286e-152

    1. Initial program 28.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.517398075841731978978804721327597516736 \cdot 10^{145}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.621300319852041212687540142873364646976 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}\\ \mathbf{elif}\;x \le 1.295898151448028641074794033905884537542 \cdot 10^{-152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.052303689076668472383783695774322400393 \cdot 10^{95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, {y}^{2} \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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