Average Error: 29.3 → 21.2
Time: 1.2m
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{1 \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}{x} - \frac{0.5}{{x}^{2} \cdot n}\\ \mathbf{elif}\;n \le 1.942013714684433697935665803170596182069 \cdot 10^{-310}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - e^{\log \left({x}^{\left(\frac{1}{n}\right)}\right)}\\ \mathbf{elif}\;n \le 1.012667898645555936369897838515456630976 \cdot 10^{-162}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - 1\\ \mathbf{elif}\;n \le 117373745.427556931972503662109375:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - e^{\log \left({x}^{\left(\frac{1}{n}\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\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 -36780699.510345064103603363037109375:\\
\;\;\;\;\frac{1 \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}{x} - \frac{0.5}{{x}^{2} \cdot n}\\

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

\mathbf{elif}\;n \le 1.012667898645555936369897838515456630976 \cdot 10^{-162}:\\
\;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - 1\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\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 r142633 = x;
        double r142634 = 1.0;
        double r142635 = r142633 + r142634;
        double r142636 = n;
        double r142637 = r142634 / r142636;
        double r142638 = pow(r142635, r142637);
        double r142639 = pow(r142633, r142637);
        double r142640 = r142638 - r142639;
        return r142640;
}

double f(double x, double n) {
        double r142641 = n;
        double r142642 = -36780699.510345064;
        bool r142643 = r142641 <= r142642;
        double r142644 = 1.0;
        double r142645 = 1.0;
        double r142646 = r142645 / r142641;
        double r142647 = x;
        double r142648 = log(r142647);
        double r142649 = -r142648;
        double r142650 = 2.0;
        double r142651 = pow(r142641, r142650);
        double r142652 = r142649 / r142651;
        double r142653 = r142646 - r142652;
        double r142654 = r142644 * r142653;
        double r142655 = r142654 / r142647;
        double r142656 = 0.5;
        double r142657 = pow(r142647, r142650);
        double r142658 = r142657 * r142641;
        double r142659 = r142656 / r142658;
        double r142660 = r142655 - r142659;
        double r142661 = 1.94201371468443e-310;
        bool r142662 = r142641 <= r142661;
        double r142663 = r142647 + r142644;
        double r142664 = r142644 / r142641;
        double r142665 = pow(r142663, r142664);
        double r142666 = pow(r142647, r142664);
        double r142667 = log(r142666);
        double r142668 = exp(r142667);
        double r142669 = r142665 - r142668;
        double r142670 = 1.0126678986455559e-162;
        bool r142671 = r142641 <= r142670;
        double r142672 = r142665 - r142645;
        double r142673 = 117373745.42755693;
        bool r142674 = r142641 <= r142673;
        double r142675 = sqrt(r142644);
        double r142676 = sqrt(r142647);
        double r142677 = r142675 / r142676;
        double r142678 = r142677 * r142653;
        double r142679 = r142677 * r142678;
        double r142680 = expm1(r142658);
        double r142681 = log1p(r142680);
        double r142682 = r142656 / r142681;
        double r142683 = r142679 - r142682;
        double r142684 = r142674 ? r142669 : r142683;
        double r142685 = r142671 ? r142672 : r142684;
        double r142686 = r142662 ? r142669 : r142685;
        double r142687 = r142643 ? r142660 : r142686;
        return r142687;
}

Error

Bits error versus x

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 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.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 associate-*l/32.2

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

    if -36780699.510345064 < n < 1.94201371468443e-310 or 1.0126678986455559e-162 < n < 117373745.42755693

    1. Initial program 3.8

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

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

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

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

    if 1.94201371468443e-310 < n < 1.0126678986455559e-162

    1. Initial program 42.4

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

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

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

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - e^{\color{blue}{\log \left({x}^{\left(\frac{1}{n}\right)}\right)}}\]
    6. Taylor expanded around 0 21.6

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

    if 117373745.42755693 < n

    1. Initial program 45.4

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

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

      \[\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-sqr-sqrt33.1

      \[\leadsto \frac{1}{\color{blue}{\sqrt{x} \cdot \sqrt{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)}\]
    8. Applied add-sqr-sqrt33.1

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\sqrt{x} \cdot \sqrt{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)}\]
    9. Applied times-frac33.1

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{\sqrt{x}} \cdot \frac{\sqrt{1}}{\sqrt{x}}\right)} \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)}\]
    10. Applied associate-*l*33.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -36780699.510345064103603363037109375:\\ \;\;\;\;\frac{1 \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)}{x} - \frac{0.5}{{x}^{2} \cdot n}\\ \mathbf{elif}\;n \le 1.942013714684433697935665803170596182069 \cdot 10^{-310}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - e^{\log \left({x}^{\left(\frac{1}{n}\right)}\right)}\\ \mathbf{elif}\;n \le 1.012667898645555936369897838515456630976 \cdot 10^{-162}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - 1\\ \mathbf{elif}\;n \le 117373745.427556931972503662109375:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - e^{\log \left({x}^{\left(\frac{1}{n}\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{\sqrt{1}}{\sqrt{x}} \cdot \left(\frac{1}{n} - \frac{-\log x}{{n}^{2}}\right)\right) - \frac{0.5}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2} \cdot n\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))))