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

\mathbf{elif}\;n \le 1358332.53943660879:\\
\;\;\;\;\log \left(e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;\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)\\

\end{array}
double f(double x, double n) {
        double r41130 = x;
        double r41131 = 1.0;
        double r41132 = r41130 + r41131;
        double r41133 = n;
        double r41134 = r41131 / r41133;
        double r41135 = pow(r41132, r41134);
        double r41136 = pow(r41130, r41134);
        double r41137 = r41135 - r41136;
        return r41137;
}

double f(double x, double n) {
        double r41138 = n;
        double r41139 = -13450.546323696572;
        bool r41140 = r41138 <= r41139;
        double r41141 = 1.0;
        double r41142 = 1.0;
        double r41143 = x;
        double r41144 = r41143 * r41138;
        double r41145 = r41142 / r41144;
        double r41146 = 0.5;
        double r41147 = 2.0;
        double r41148 = pow(r41143, r41147);
        double r41149 = r41148 * r41138;
        double r41150 = expm1(r41149);
        double r41151 = log1p(r41150);
        double r41152 = r41142 / r41151;
        double r41153 = r41142 / r41143;
        double r41154 = log(r41153);
        double r41155 = pow(r41138, r41147);
        double r41156 = r41143 * r41155;
        double r41157 = r41154 / r41156;
        double r41158 = r41141 * r41157;
        double r41159 = fma(r41146, r41152, r41158);
        double r41160 = -r41159;
        double r41161 = fma(r41141, r41145, r41160);
        double r41162 = 1358332.5394366088;
        bool r41163 = r41138 <= r41162;
        double r41164 = r41143 + r41141;
        double r41165 = r41141 / r41138;
        double r41166 = pow(r41164, r41165);
        double r41167 = pow(r41143, r41165);
        double r41168 = r41166 - r41167;
        double r41169 = exp(r41168);
        double r41170 = log(r41169);
        double r41171 = r41165 / r41143;
        double r41172 = r41142 / r41149;
        double r41173 = fma(r41146, r41172, r41158);
        double r41174 = -r41173;
        double r41175 = r41171 + r41174;
        double r41176 = r41163 ? r41170 : r41175;
        double r41177 = r41140 ? r41161 : r41176;
        return r41177;
}

Error

Bits error versus x

Bits error versus n

Derivation

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

    1. Initial program 44.8

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

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

      \[\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 log1p-expm1-u32.1

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

    if -13450.546323696572 < n < 1358332.5394366088

    1. Initial program 8.2

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

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\log \left(e^{{x}^{\left(\frac{1}{n}\right)}}\right)}\]
    4. Applied add-log-exp8.4

      \[\leadsto \color{blue}{\log \left(e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}\right)} - \log \left(e^{{x}^{\left(\frac{1}{n}\right)}}\right)\]
    5. Applied diff-log8.4

      \[\leadsto \color{blue}{\log \left(\frac{e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}}{e^{{x}^{\left(\frac{1}{n}\right)}}}\right)}\]
    6. Simplified8.4

      \[\leadsto \log \color{blue}{\left(e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}}\right)}\]

    if 1358332.5394366088 < n

    1. Initial program 44.9

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

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

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

      \[\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)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification22.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -13450.5463236965716:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{x \cdot n}, -\mathsf{fma}\left(0.5, \frac{1}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\right)\right)}, 1 \cdot \frac{\log \left(\frac{1}{x}\right)}{x \cdot {n}^{2}}\right)\right)\\ \mathbf{elif}\;n \le 1358332.53943660879:\\ \;\;\;\;\log \left(e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array}\]

Reproduce

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