Average Error: 29.3 → 22.4
Time: 9.3s
Precision: 64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \le -36780699.510345064103603363037109375:\\ \;\;\;\;\frac{\frac{1}{n}}{x} + \left(-\mathsf{fma}\left(0.5, \frac{1}{{x}^{2} \cdot n}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)\\ \mathbf{elif}\;n \le 32842187320271.03515625:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x} + \left(-\mathsf{fma}\left(0.5, \frac{1}{\log \left(e^{{x}^{2} \cdot n}\right)}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\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 -36780699.510345064103603363037109375:\\
\;\;\;\;\frac{\frac{1}{n}}{x} + \left(-\mathsf{fma}\left(0.5, \frac{1}{{x}^{2} \cdot n}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)\\

\mathbf{elif}\;n \le 32842187320271.03515625:\\
\;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{n}}{x} + \left(-\mathsf{fma}\left(0.5, \frac{1}{\log \left(e^{{x}^{2} \cdot n}\right)}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)\\

\end{array}
double f(double x, double n) {
        double r53138 = x;
        double r53139 = 1.0;
        double r53140 = r53138 + r53139;
        double r53141 = n;
        double r53142 = r53139 / r53141;
        double r53143 = pow(r53140, r53142);
        double r53144 = pow(r53138, r53142);
        double r53145 = r53143 - r53144;
        return r53145;
}

double f(double x, double n) {
        double r53146 = n;
        double r53147 = -36780699.510345064;
        bool r53148 = r53146 <= r53147;
        double r53149 = 1.0;
        double r53150 = r53149 / r53146;
        double r53151 = x;
        double r53152 = r53150 / r53151;
        double r53153 = 0.5;
        double r53154 = 1.0;
        double r53155 = 2.0;
        double r53156 = pow(r53151, r53155);
        double r53157 = r53156 * r53146;
        double r53158 = r53154 / r53157;
        double r53159 = r53154 / r53151;
        double r53160 = log(r53159);
        double r53161 = pow(r53146, r53155);
        double r53162 = r53151 * r53161;
        double r53163 = r53160 / r53162;
        double r53164 = r53149 * r53163;
        double r53165 = fma(r53153, r53158, r53164);
        double r53166 = -r53165;
        double r53167 = r53152 + r53166;
        double r53168 = 32842187320271.035;
        bool r53169 = r53146 <= r53168;
        double r53170 = r53151 + r53149;
        double r53171 = pow(r53170, r53150);
        double r53172 = pow(r53151, r53150);
        double r53173 = log1p(r53172);
        double r53174 = expm1(r53173);
        double r53175 = r53171 - r53174;
        double r53176 = exp(r53157);
        double r53177 = log(r53176);
        double r53178 = r53154 / r53177;
        double r53179 = fma(r53153, r53178, r53164);
        double r53180 = -r53179;
        double r53181 = r53152 + r53180;
        double r53182 = r53169 ? r53175 : r53181;
        double r53183 = r53148 ? r53167 : r53182;
        return r53183;
}

Error

Bits error versus x

Bits error versus n

Derivation

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

    1. Initial program 44.3

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

      \[\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. Simplified32.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x \cdot n}, -\mathsf{fma}\left(0.5, \frac{1}{{x}^{2} \cdot n}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)}\]
    4. Using strategy rm
    5. Applied fma-udef32.9

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

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

    if -36780699.510345064 < n < 32842187320271.035

    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 expm1-log1p-u9.2

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

    if 32842187320271.035 < n

    1. Initial program 45.6

      \[{\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.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x \cdot n}, -\mathsf{fma}\left(0.5, \frac{1}{{x}^{2} \cdot n}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)}\]
    4. Using strategy rm
    5. Applied fma-udef33.6

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

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} + \left(-\mathsf{fma}\left(0.5, \frac{1}{{x}^{2} \cdot n}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)\]
    7. Using strategy rm
    8. Applied add-log-exp33.0

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

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

Reproduce

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