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 r683585 = x;
        double r683586 = r683585 * r683585;
        double r683587 = y;
        double r683588 = 4.0;
        double r683589 = r683587 * r683588;
        double r683590 = r683589 * r683587;
        double r683591 = r683586 - r683590;
        double r683592 = r683586 + r683590;
        double r683593 = r683591 / r683592;
        return r683593;
}

double f(double x, double y) {
        double r683594 = x;
        double r683595 = -1.3318871728471391e+154;
        bool r683596 = r683594 <= r683595;
        double r683597 = 1.0;
        double r683598 = -1.5707844452269527e-162;
        bool r683599 = r683594 <= r683598;
        double r683600 = y;
        double r683601 = 4.0;
        double r683602 = r683600 * r683601;
        double r683603 = r683602 * r683600;
        double r683604 = fma(r683594, r683594, r683603);
        double r683605 = r683604 / r683594;
        double r683606 = r683594 / r683605;
        double r683607 = 2.0;
        double r683608 = pow(r683594, r683607);
        double r683609 = r683608 / r683600;
        double r683610 = fma(r683601, r683600, r683609);
        double r683611 = r683602 / r683610;
        double r683612 = r683606 - r683611;
        double r683613 = 6.596793469983034e-163;
        bool r683614 = r683594 <= r683613;
        double r683615 = -1.0;
        double r683616 = 6.373484080558642e+144;
        bool r683617 = r683594 <= r683616;
        double r683618 = r683617 ? r683612 : r683597;
        double r683619 = r683614 ? r683615 : r683618;
        double r683620 = r683599 ? r683612 : r683619;
        double r683621 = r683596 ? r683597 : r683620;
        return r683621;
}

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))))