Average Error: 31.9 → 4.6
Time: 3.2s
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.35942609678321041 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -4.1599445058185013 \cdot 10^{-139}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\right)\right)\\ \mathbf{elif}\;x \le 4.2299291990473933 \cdot 10^{-187}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.18794817367348284 \cdot 10^{141}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\right)\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.35942609678321041 \cdot 10^{154}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 4.2299291990473933 \cdot 10^{-187}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r912456 = x;
        double r912457 = r912456 * r912456;
        double r912458 = y;
        double r912459 = 4.0;
        double r912460 = r912458 * r912459;
        double r912461 = r912460 * r912458;
        double r912462 = r912457 - r912461;
        double r912463 = r912457 + r912461;
        double r912464 = r912462 / r912463;
        return r912464;
}

double f(double x, double y) {
        double r912465 = x;
        double r912466 = -1.3594260967832104e+154;
        bool r912467 = r912465 <= r912466;
        double r912468 = 1.0;
        double r912469 = -4.159944505818501e-139;
        bool r912470 = r912465 <= r912469;
        double r912471 = y;
        double r912472 = 4.0;
        double r912473 = r912471 * r912472;
        double r912474 = r912473 * r912471;
        double r912475 = fma(r912465, r912465, r912474);
        double r912476 = r912475 / r912465;
        double r912477 = r912465 / r912476;
        double r912478 = 2.0;
        double r912479 = pow(r912465, r912478);
        double r912480 = r912479 / r912471;
        double r912481 = fma(r912472, r912471, r912480);
        double r912482 = r912473 / r912481;
        double r912483 = log1p(r912482);
        double r912484 = expm1(r912483);
        double r912485 = r912477 - r912484;
        double r912486 = 4.2299291990473933e-187;
        bool r912487 = r912465 <= r912486;
        double r912488 = -1.0;
        double r912489 = 1.1879481736734828e+141;
        bool r912490 = r912465 <= r912489;
        double r912491 = r912490 ? r912485 : r912468;
        double r912492 = r912487 ? r912488 : r912491;
        double r912493 = r912470 ? r912485 : r912492;
        double r912494 = r912467 ? r912468 : r912493;
        return r912494;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.9
Target31.6
Herbie4.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.974323384962678118:\\ \;\;\;\;\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.3594260967832104e+154 or 1.1879481736734828e+141 < x

    1. Initial program 62.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 inf 9.4

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

    if -1.3594260967832104e+154 < x < -4.159944505818501e-139 or 4.2299291990473933e-187 < x < 1.1879481736734828e+141

    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. Using strategy rm
    3. Applied div-sub17.1

      \[\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. Simplified17.2

      \[\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. Simplified16.7

      \[\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.8

      \[\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.8

      \[\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)}}\]
    8. Using strategy rm
    9. Applied expm1-log1p-u0.8

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

    if -4.159944505818501e-139 < x < 4.2299291990473933e-187

    1. Initial program 29.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 0 7.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.35942609678321041 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -4.1599445058185013 \cdot 10^{-139}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\right)\right)\\ \mathbf{elif}\;x \le 4.2299291990473933 \cdot 10^{-187}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.18794817367348284 \cdot 10^{141}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y \cdot 4}{\mathsf{fma}\left(4, y, \frac{{x}^{2}}{y}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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