Average Error: 29.3 → 22.4
Time: 1.3m
Precision: 64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \le -380251775535541.9375:\\ \;\;\;\;\sqrt{\frac{1}{x}} \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\right) - \frac{0.5}{{x}^{2} \cdot n}\\ \mathbf{elif}\;n \le 247.0873999593015071241097757592797279358:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, \sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, -{x}^{\left(\frac{1}{n}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}\right) \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} - \frac{0.5}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}\\ \end{array}\]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;n \le -380251775535541.9375:\\
\;\;\;\;\sqrt{\frac{1}{x}} \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\right) - \frac{0.5}{{x}^{2} \cdot n}\\

\mathbf{elif}\;n \le 247.0873999593015071241097757592797279358:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, \sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, -{x}^{\left(\frac{1}{n}\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}\right) \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} - \frac{0.5}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}\\

\end{array}
double f(double x, double n) {
        double r140359 = x;
        double r140360 = 1.0;
        double r140361 = r140359 + r140360;
        double r140362 = n;
        double r140363 = r140360 / r140362;
        double r140364 = pow(r140361, r140363);
        double r140365 = pow(r140359, r140363);
        double r140366 = r140364 - r140365;
        return r140366;
}

double f(double x, double n) {
        double r140367 = n;
        double r140368 = -380251775535541.94;
        bool r140369 = r140367 <= r140368;
        double r140370 = 1.0;
        double r140371 = x;
        double r140372 = r140370 / r140371;
        double r140373 = sqrt(r140372);
        double r140374 = 1.0;
        double r140375 = r140374 / r140367;
        double r140376 = log(r140371);
        double r140377 = -r140376;
        double r140378 = 2.0;
        double r140379 = pow(r140367, r140378);
        double r140380 = r140377 / r140379;
        double r140381 = r140375 - r140380;
        double r140382 = r140373 * r140381;
        double r140383 = r140373 * r140382;
        double r140384 = 0.5;
        double r140385 = pow(r140371, r140378);
        double r140386 = r140385 * r140367;
        double r140387 = r140384 / r140386;
        double r140388 = r140383 - r140387;
        double r140389 = 247.0873999593015;
        bool r140390 = r140367 <= r140389;
        double r140391 = r140371 + r140370;
        double r140392 = r140370 / r140367;
        double r140393 = pow(r140391, r140392);
        double r140394 = sqrt(r140393);
        double r140395 = pow(r140371, r140392);
        double r140396 = -r140395;
        double r140397 = fma(r140394, r140394, r140396);
        double r140398 = r140372 * r140381;
        double r140399 = cbrt(r140398);
        double r140400 = r140399 * r140399;
        double r140401 = r140400 * r140399;
        double r140402 = expm1(r140386);
        double r140403 = log1p(r140402);
        double r140404 = r140384 / r140403;
        double r140405 = r140401 - r140404;
        double r140406 = r140390 ? r140397 : r140405;
        double r140407 = r140369 ? r140388 : r140406;
        return r140407;
}

Error

Bits error versus x

Bits error versus n

Derivation

  1. Split input into 3 regimes
  2. if n < -380251775535541.94

    1. Initial program 44.1

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    2. Taylor expanded around inf 32.3

      \[\leadsto \color{blue}{1 \cdot \frac{1}{x \cdot n} - \left(0.5 \cdot \frac{1}{{x}^{2} \cdot n} + 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)}\]
    3. Simplified31.6

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right) - \frac{0.5}{{x}^{2} \cdot n}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt31.7

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}\right)} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right) - \frac{0.5}{{x}^{2} \cdot n}\]
    6. Applied associate-*l*31.7

      \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\right)} - \frac{0.5}{{x}^{2} \cdot n}\]

    if -380251775535541.94 < n < 247.0873999593015

    1. Initial program 9.2

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt9.2

      \[\leadsto \color{blue}{\sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}} \cdot \sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}} - {x}^{\left(\frac{1}{n}\right)}\]
    4. Applied fma-neg9.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, \sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, -{x}^{\left(\frac{1}{n}\right)}\right)}\]

    if 247.0873999593015 < n

    1. Initial program 45.8

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    2. Taylor expanded around inf 33.6

      \[\leadsto \color{blue}{1 \cdot \frac{1}{x \cdot n} - \left(0.5 \cdot \frac{1}{{x}^{2} \cdot n} + 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)}\]
    3. Simplified33.2

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right) - \frac{0.5}{{x}^{2} \cdot n}}\]
    4. Using strategy rm
    5. Applied log1p-expm1-u33.1

      \[\leadsto \frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right) - \frac{0.5}{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt33.3

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}\right) \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}} - \frac{0.5}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification22.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -380251775535541.9375:\\ \;\;\;\;\sqrt{\frac{1}{x}} \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\right) - \frac{0.5}{{x}^{2} \cdot n}\\ \mathbf{elif}\;n \le 247.0873999593015071241097757592797279358:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, \sqrt{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}, -{x}^{\left(\frac{1}{n}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}\right) \cdot \sqrt[3]{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)} - \frac{0.5}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019304 +o rules:numerics
(FPCore (x n)
  :name "2nthrt (problem 3.4.6)"
  :precision binary64
  (- (pow (+ x 1) (/ 1 n)) (pow x (/ 1 n))))