Average Error: 31.2 → 13.9
Time: 17.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}\;y \le -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.63689029313189507811324572738338926855 \cdot 10^{-160}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.575397687437991456648509198388754062127 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 8.134021215145637850375061461407044861883 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;y \le 98355.24381927796639502048492431640625:\\ \;\;\;\;1\\ \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}\;y \le -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.575397687437991456648509198388754062127 \cdot 10^{-55}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 8.134021215145637850375061461407044861883 \cdot 10^{-38}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\

\mathbf{elif}\;y \le 98355.24381927796639502048492431640625:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r499571 = x;
        double r499572 = r499571 * r499571;
        double r499573 = y;
        double r499574 = 4.0;
        double r499575 = r499573 * r499574;
        double r499576 = r499575 * r499573;
        double r499577 = r499572 - r499576;
        double r499578 = r499572 + r499576;
        double r499579 = r499577 / r499578;
        return r499579;
}

double f(double x, double y) {
        double r499580 = y;
        double r499581 = -4.75816735826197e+148;
        bool r499582 = r499580 <= r499581;
        double r499583 = -1.0;
        double r499584 = -1.636890293131895e-160;
        bool r499585 = r499580 <= r499584;
        double r499586 = x;
        double r499587 = 4.0;
        double r499588 = r499580 * r499587;
        double r499589 = r499588 * r499580;
        double r499590 = -r499589;
        double r499591 = fma(r499586, r499586, r499590);
        double r499592 = fma(r499586, r499586, r499589);
        double r499593 = r499591 / r499592;
        double r499594 = 1.5753976874379915e-55;
        bool r499595 = r499580 <= r499594;
        double r499596 = 1.0;
        double r499597 = 8.134021215145638e-38;
        bool r499598 = r499580 <= r499597;
        double r499599 = r499586 * r499586;
        double r499600 = r499599 - r499589;
        double r499601 = r499600 / r499592;
        double r499602 = expm1(r499601);
        double r499603 = log1p(r499602);
        double r499604 = 98355.24381927797;
        bool r499605 = r499580 <= r499604;
        double r499606 = r499605 ? r499596 : r499583;
        double r499607 = r499598 ? r499603 : r499606;
        double r499608 = r499595 ? r499596 : r499607;
        double r499609 = r499585 ? r499593 : r499608;
        double r499610 = r499582 ? r499583 : r499609;
        return r499610;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.2
Target30.9
Herbie13.9
\[\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 4 regimes
  2. if y < -4.75816735826197e+148 or 98355.24381927797 < y

    1. Initial program 47.9

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

      \[\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 log1p-expm1-u47.9

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

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

    if -4.75816735826197e+148 < y < -1.636890293131895e-160

    1. Initial program 16.0

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

      \[\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 fma-neg16.0

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

    if -1.636890293131895e-160 < y < 1.5753976874379915e-55 or 8.134021215145638e-38 < y < 98355.24381927797

    1. Initial program 24.9

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

      \[\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 inf 12.6

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

    if 1.5753976874379915e-55 < y < 8.134021215145638e-38

    1. Initial program 20.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified20.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 log1p-expm1-u20.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.758167358261969805068202523877348166337 \cdot 10^{148}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.63689029313189507811324572738338926855 \cdot 10^{-160}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.575397687437991456648509198388754062127 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 8.134021215145637850375061461407044861883 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;y \le 98355.24381927796639502048492431640625:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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