Average Error: 31.4 → 13.8
Time: 9.4s
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 -4.75486451228188590222826906220099481589 \cdot 10^{122}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -4.332313917220748901311195815363194649965 \cdot 10^{80}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -9211266202426181632:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\ \mathbf{elif}\;x \le 2.139551810604105186057739335770012586275 \cdot 10^{-153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.373518315070099961643182713875384049377 \cdot 10^{127}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\ \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 -4.75486451228188590222826906220099481589 \cdot 10^{122}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -4.332313917220748901311195815363194649965 \cdot 10^{80}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -9211266202426181632:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\

\mathbf{elif}\;x \le 2.139551810604105186057739335770012586275 \cdot 10^{-153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 7.373518315070099961643182713875384049377 \cdot 10^{127}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\

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

\end{array}
double f(double x, double y) {
        double r398446 = x;
        double r398447 = r398446 * r398446;
        double r398448 = y;
        double r398449 = 4.0;
        double r398450 = r398448 * r398449;
        double r398451 = r398450 * r398448;
        double r398452 = r398447 - r398451;
        double r398453 = r398447 + r398451;
        double r398454 = r398452 / r398453;
        return r398454;
}

double f(double x, double y) {
        double r398455 = x;
        double r398456 = -4.754864512281886e+122;
        bool r398457 = r398455 <= r398456;
        double r398458 = 1.0;
        double r398459 = -4.332313917220749e+80;
        bool r398460 = r398455 <= r398459;
        double r398461 = -1.0;
        double r398462 = -9.211266202426182e+18;
        bool r398463 = r398455 <= r398462;
        double r398464 = 4.0;
        double r398465 = y;
        double r398466 = -r398465;
        double r398467 = r398465 * r398466;
        double r398468 = r398455 * r398455;
        double r398469 = fma(r398464, r398467, r398468);
        double r398470 = r398464 * r398465;
        double r398471 = r398465 * r398470;
        double r398472 = fma(r398455, r398455, r398471);
        double r398473 = r398469 / r398472;
        double r398474 = 3.0;
        double r398475 = pow(r398473, r398474);
        double r398476 = cbrt(r398475);
        double r398477 = 2.1395518106041052e-153;
        bool r398478 = r398455 <= r398477;
        double r398479 = 7.3735183150701e+127;
        bool r398480 = r398455 <= r398479;
        double r398481 = r398480 ? r398476 : r398458;
        double r398482 = r398478 ? r398461 : r398481;
        double r398483 = r398463 ? r398476 : r398482;
        double r398484 = r398460 ? r398461 : r398483;
        double r398485 = r398457 ? r398458 : r398484;
        return r398485;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.4
Target31.1
Herbie13.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 < -4.754864512281886e+122 or 7.3735183150701e+127 < x

    1. Initial program 56.1

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\]
    3. Using strategy rm
    4. Applied clear-num56.1

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

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

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

    if -4.754864512281886e+122 < x < -4.332313917220749e+80 or -9.211266202426182e+18 < x < 2.1395518106041052e-153

    1. Initial program 24.5

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

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

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

    if -4.332313917220749e+80 < x < -9.211266202426182e+18 or 2.1395518106041052e-153 < x < 7.3735183150701e+127

    1. Initial program 15.3

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\]
    3. Using strategy rm
    4. Applied add-cbrt-cube44.8

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

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right) \cdot \mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)\right) \cdot \mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}}}{\sqrt[3]{\left(\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right) \cdot \mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)\right) \cdot \mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}}\]
    6. Applied cbrt-undiv45.2

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

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.75486451228188590222826906220099481589 \cdot 10^{122}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -4.332313917220748901311195815363194649965 \cdot 10^{80}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -9211266202426181632:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\ \mathbf{elif}\;x \le 2.139551810604105186057739335770012586275 \cdot 10^{-153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.373518315070099961643182713875384049377 \cdot 10^{127}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))