Average Error: 31.9 → 4.6
Time: 7.1s
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 r2707 = x;
        double r2708 = r2707 * r2707;
        double r2709 = y;
        double r2710 = 4.0;
        double r2711 = r2709 * r2710;
        double r2712 = r2711 * r2709;
        double r2713 = r2708 - r2712;
        double r2714 = r2708 + r2712;
        double r2715 = r2713 / r2714;
        return r2715;
}

double f(double x, double y) {
        double r2716 = x;
        double r2717 = -1.3594260967832104e+154;
        bool r2718 = r2716 <= r2717;
        double r2719 = 1.0;
        double r2720 = -4.159944505818501e-139;
        bool r2721 = r2716 <= r2720;
        double r2722 = y;
        double r2723 = 4.0;
        double r2724 = r2722 * r2723;
        double r2725 = r2724 * r2722;
        double r2726 = fma(r2716, r2716, r2725);
        double r2727 = r2726 / r2716;
        double r2728 = r2716 / r2727;
        double r2729 = 2.0;
        double r2730 = pow(r2716, r2729);
        double r2731 = r2730 / r2722;
        double r2732 = fma(r2723, r2722, r2731);
        double r2733 = r2724 / r2732;
        double r2734 = log1p(r2733);
        double r2735 = expm1(r2734);
        double r2736 = r2728 - r2735;
        double r2737 = 4.2299291990473933e-187;
        bool r2738 = r2716 <= r2737;
        double r2739 = -1.0;
        double r2740 = 1.1879481736734828e+141;
        bool r2741 = r2716 <= r2740;
        double r2742 = r2741 ? r2736 : r2719;
        double r2743 = r2738 ? r2739 : r2742;
        double r2744 = r2721 ? r2736 : r2743;
        double r2745 = r2718 ? r2719 : r2744;
        return r2745;
}

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