Average Error: 31.6 → 11.8
Time: 12.3s
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.452213238363225603526830662891862420183 \cdot 10^{134}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\ \mathbf{elif}\;x \le -1.751961519124681504554348985455740434235 \cdot 10^{-113}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;x \le 1.524472339546404145946734820851418870368 \cdot 10^{-122}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(-1\right)\right)\\ \mathbf{elif}\;x \le 7.812277400687207974693837013539398746936 \cdot 10^{107}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\ \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.452213238363225603526830662891862420183 \cdot 10^{134}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\

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

\mathbf{elif}\;x \le 1.524472339546404145946734820851418870368 \cdot 10^{-122}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(-1\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\

\end{array}
double f(double x, double y) {
        double r423147 = x;
        double r423148 = r423147 * r423147;
        double r423149 = y;
        double r423150 = 4.0;
        double r423151 = r423149 * r423150;
        double r423152 = r423151 * r423149;
        double r423153 = r423148 - r423152;
        double r423154 = r423148 + r423152;
        double r423155 = r423153 / r423154;
        return r423155;
}

double f(double x, double y) {
        double r423156 = x;
        double r423157 = -4.452213238363226e+134;
        bool r423158 = r423156 <= r423157;
        double r423159 = 1.0;
        double r423160 = log1p(r423159);
        double r423161 = expm1(r423160);
        double r423162 = -1.7519615191246815e-113;
        bool r423163 = r423156 <= r423162;
        double r423164 = 2.0;
        double r423165 = pow(r423156, r423164);
        double r423166 = y;
        double r423167 = 4.0;
        double r423168 = r423166 * r423167;
        double r423169 = r423168 * r423166;
        double r423170 = fma(r423156, r423156, r423169);
        double r423171 = r423165 / r423170;
        double r423172 = pow(r423166, r423164);
        double r423173 = r423167 * r423172;
        double r423174 = r423173 / r423170;
        double r423175 = r423171 - r423174;
        double r423176 = log1p(r423175);
        double r423177 = expm1(r423176);
        double r423178 = 1.5244723395464041e-122;
        bool r423179 = r423156 <= r423178;
        double r423180 = 1.0;
        double r423181 = -r423180;
        double r423182 = log1p(r423181);
        double r423183 = expm1(r423182);
        double r423184 = 7.812277400687208e+107;
        bool r423185 = r423156 <= r423184;
        double r423186 = r423185 ? r423177 : r423161;
        double r423187 = r423179 ? r423183 : r423186;
        double r423188 = r423163 ? r423177 : r423187;
        double r423189 = r423158 ? r423161 : r423188;
        return r423189;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.6
Target31.3
Herbie11.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.452213238363226e+134 or 7.812277400687208e+107 < x

    1. Initial program 54.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 expm1-log1p-u54.9

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]
    4. Simplified54.9

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\frac{{x}^{2} - 4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}\right)\]
    5. Using strategy rm
    6. Applied div-sub54.9

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{{x}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\right)\]
    7. Taylor expanded around inf 9.7

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1}\right)\right)\]

    if -4.452213238363226e+134 < x < -1.7519615191246815e-113 or 1.5244723395464041e-122 < x < 7.812277400687208e+107

    1. Initial program 15.5

      \[\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 expm1-log1p-u15.5

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]
    4. Simplified15.5

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\frac{{x}^{2} - 4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}\right)\]
    5. Using strategy rm
    6. Applied div-sub15.5

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

    if -1.7519615191246815e-113 < x < 1.5244723395464041e-122

    1. Initial program 28.2

      \[\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 expm1-log1p-u28.2

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]
    4. Simplified28.5

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\frac{{x}^{2} - 4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}\right)\]
    5. Using strategy rm
    6. Applied div-sub28.5

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{-1}\right)\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification11.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.452213238363225603526830662891862420183 \cdot 10^{134}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\ \mathbf{elif}\;x \le -1.751961519124681504554348985455740434235 \cdot 10^{-113}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;x \le 1.524472339546404145946734820851418870368 \cdot 10^{-122}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(-1\right)\right)\\ \mathbf{elif}\;x \le 7.812277400687207974693837013539398746936 \cdot 10^{107}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{4 \cdot {y}^{2}}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(1\right)\right)\\ \end{array}\]

Reproduce

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