2nthrt (problem 3.4.6)

Percentage Accurate: 51.3% → 95.5%
Time: 1.1min
Alternatives: 21
Speedup: 1.8×

Specification

?
\[\begin{array}{l} \\ {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \end{array} \]
(FPCore (x n)
 :precision binary64
 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
	return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
	return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n):
	return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n)
	return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n)))
end
function tmp = code(x, n)
	tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n));
end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 21 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \end{array} \]
(FPCore (x n)
 :precision binary64
 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
	return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
	return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n):
	return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n)
	return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n)))
end
function tmp = code(x, n)
	tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n));
end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}

Alternative 1: 95.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \sqrt{t\_0}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-6}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{0.5 \cdot \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) + 0.16666666666666666 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}{n}}{n}\right) - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t\_1, -t\_1, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (sqrt t_0)))
   (if (<= (/ 1.0 n) -5e-6)
     (- (pow (+ 1.0 x) (/ 1.0 n)) (expm1 (log1p t_0)))
     (if (<= (/ 1.0 n) 2e-9)
       (/
        (-
         (+
          (log1p x)
          (/
           (+
            (* 0.5 (- (pow (log1p x) 2.0) (pow (log x) 2.0)))
            (*
             0.16666666666666666
             (/ (- (pow (log1p x) 3.0) (pow (log x) 3.0)) n)))
           n))
         (log x))
        n)
       (fma t_1 (- t_1) (exp (/ (log1p x) n)))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = sqrt(t_0);
	double tmp;
	if ((1.0 / n) <= -5e-6) {
		tmp = pow((1.0 + x), (1.0 / n)) - expm1(log1p(t_0));
	} else if ((1.0 / n) <= 2e-9) {
		tmp = ((log1p(x) + (((0.5 * (pow(log1p(x), 2.0) - pow(log(x), 2.0))) + (0.16666666666666666 * ((pow(log1p(x), 3.0) - pow(log(x), 3.0)) / n))) / n)) - log(x)) / n;
	} else {
		tmp = fma(t_1, -t_1, exp((log1p(x) / n)));
	}
	return tmp;
}
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = sqrt(t_0)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-6)
		tmp = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - expm1(log1p(t_0)));
	elseif (Float64(1.0 / n) <= 2e-9)
		tmp = Float64(Float64(Float64(log1p(x) + Float64(Float64(Float64(0.5 * Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0))) + Float64(0.16666666666666666 * Float64(Float64((log1p(x) ^ 3.0) - (log(x) ^ 3.0)) / n))) / n)) - log(x)) / n);
	else
		tmp = fma(t_1, Float64(-t_1), exp(Float64(log1p(x) / n)));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-6], N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + t$95$0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-9], N[(N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(N[(0.5 * N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(t$95$1 * (-t$95$1) + N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \sqrt{t\_0}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-6}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{0.5 \cdot \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) + 0.16666666666666666 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}{n}}{n}\right) - \log x}{n}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, -t\_1, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -5.00000000000000041e-6

    1. Initial program 99.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.8%

        \[\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)} \]
      2. expm1-undefine99.8%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    4. Applied egg-rr99.8%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    5. Step-by-step derivation
      1. expm1-define99.8%

        \[\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)} \]
    6. Simplified99.8%

      \[\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 -5.00000000000000041e-6 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000012e-9

    1. Initial program 7.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around -inf 91.4%

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

      \[\leadsto \color{blue}{\frac{\log x - \left(\mathsf{log1p}\left(x\right) + \frac{0.5 \cdot \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) + 0.16666666666666666 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}{n}}{n}\right)}{-n}} \]

    if 2.00000000000000012e-9 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 45.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg45.8%

        \[\leadsto \color{blue}{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} + \left(-{x}^{\left(\frac{1}{n}\right)}\right)} \]
      2. +-commutative45.8%

        \[\leadsto \color{blue}{\left(-{x}^{\left(\frac{1}{n}\right)}\right) + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}} \]
      3. sqr-pow45.8%

        \[\leadsto \left(-\color{blue}{{x}^{\left(\frac{\frac{1}{n}}{2}\right)} \cdot {x}^{\left(\frac{\frac{1}{n}}{2}\right)}}\right) + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} \]
      4. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{{x}^{\left(\frac{\frac{1}{n}}{2}\right)} \cdot \left(-{x}^{\left(\frac{\frac{1}{n}}{2}\right)}\right)} + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} \]
      5. fma-define45.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{\left(\frac{\frac{1}{n}}{2}\right)}, -{x}^{\left(\frac{\frac{1}{n}}{2}\right)}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right)} \]
      6. sqrt-pow145.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{{x}^{\left(\frac{1}{n}\right)}}}, -{x}^{\left(\frac{\frac{1}{n}}{2}\right)}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right) \]
      7. sqrt-pow145.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\color{blue}{\sqrt{{x}^{\left(\frac{1}{n}\right)}}}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right) \]
      8. pow-to-exp45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, \color{blue}{e^{\log \left(x + 1\right) \cdot \frac{1}{n}}}\right) \]
      9. un-div-inv45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\color{blue}{\frac{\log \left(x + 1\right)}{n}}}\right) \]
      10. +-commutative45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\log \color{blue}{\left(1 + x\right)}}{n}}\right) \]
      11. log1p-define99.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}}\right) \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-6}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\left(\mathsf{log1p}\left(x\right) + \frac{0.5 \cdot \left({\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}\right) + 0.16666666666666666 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}{n}}{n}\right) - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 94.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - t\_0\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-6}:\\ \;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ 1.0 x) (/ 1.0 n)) t_0)))
   (if (<= t_1 -5e-6)
     (- 1.0 (exp (* (/ 1.0 n) (log x))))
     (if (<= t_1 0.0)
       (/ (log (/ (+ 1.0 x) x)) n)
       (- (exp (/ (log1p x) n)) t_0)))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = pow((1.0 + x), (1.0 / n)) - t_0;
	double tmp;
	if (t_1 <= -5e-6) {
		tmp = 1.0 - exp(((1.0 / n) * log(x)));
	} else if (t_1 <= 0.0) {
		tmp = log(((1.0 + x) / x)) / n;
	} else {
		tmp = exp((log1p(x) / n)) - t_0;
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double t_1 = Math.pow((1.0 + x), (1.0 / n)) - t_0;
	double tmp;
	if (t_1 <= -5e-6) {
		tmp = 1.0 - Math.exp(((1.0 / n) * Math.log(x)));
	} else if (t_1 <= 0.0) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else {
		tmp = Math.exp((Math.log1p(x) / n)) - t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	t_1 = math.pow((1.0 + x), (1.0 / n)) - t_0
	tmp = 0
	if t_1 <= -5e-6:
		tmp = 1.0 - math.exp(((1.0 / n) * math.log(x)))
	elif t_1 <= 0.0:
		tmp = math.log(((1.0 + x) / x)) / n
	else:
		tmp = math.exp((math.log1p(x) / n)) - t_0
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - t_0)
	tmp = 0.0
	if (t_1 <= -5e-6)
		tmp = Float64(1.0 - exp(Float64(Float64(1.0 / n) * log(x))));
	elseif (t_1 <= 0.0)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	else
		tmp = Float64(exp(Float64(log1p(x) / n)) - t_0);
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-6], N[(1.0 - N[Exp[N[(N[(1.0 / n), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-6}:\\
\;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\

\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -5.00000000000000041e-6

    1. Initial program 99.1%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.1%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity99.1%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/99.1%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*99.1%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow99.1%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u99.1%

        \[\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)} \]
      2. expm1-undefine99.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr99.0%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define99.1%

        \[\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)} \]
    9. Simplified99.1%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-log1p-u99.1%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
      2. pow-to-exp99.1%

        \[\leadsto 1 - \color{blue}{e^{\log x \cdot \frac{1}{n}}} \]
    11. Applied egg-rr99.1%

      \[\leadsto 1 - \color{blue}{e^{\log x \cdot \frac{1}{n}}} \]

    if -5.00000000000000041e-6 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 0.0

    1. Initial program 29.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 93.1%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define92.5%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified92.5%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine93.1%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log93.2%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr93.2%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative93.2%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified93.2%

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

    if 0.0 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n)))

    1. Initial program 46.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around 0 46.4%

      \[\leadsto \color{blue}{e^{\frac{\log \left(1 + x\right)}{n}} - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. log1p-define98.8%

        \[\leadsto e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - e^{\frac{\log x}{n}} \]
      2. *-rgt-identity98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      3. associate-*l/98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      4. associate-/l*98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      5. exp-to-pow98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified98.8%

      \[\leadsto \color{blue}{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \leq -5 \cdot 10^{-6}:\\ \;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\ \mathbf{elif}\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \leq 0:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \sqrt{t\_0}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t\_1, -t\_1, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (sqrt t_0)))
   (if (<= (/ 1.0 n) -1e-8)
     (- (pow (+ 1.0 x) (/ 1.0 n)) (expm1 (log1p t_0)))
     (if (<= (/ 1.0 n) 2e-9)
       (/
        (+
         (log1p x)
         (- (* 0.5 (/ (- (pow (log1p x) 2.0) (pow (log x) 2.0)) n)) (log x)))
        n)
       (fma t_1 (- t_1) (exp (/ (log1p x) n)))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = sqrt(t_0);
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = pow((1.0 + x), (1.0 / n)) - expm1(log1p(t_0));
	} else if ((1.0 / n) <= 2e-9) {
		tmp = (log1p(x) + ((0.5 * ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) / n)) - log(x))) / n;
	} else {
		tmp = fma(t_1, -t_1, exp((log1p(x) / n)));
	}
	return tmp;
}
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = sqrt(t_0)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-8)
		tmp = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - expm1(log1p(t_0)));
	elseif (Float64(1.0 / n) <= 2e-9)
		tmp = Float64(Float64(log1p(x) + Float64(Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) / n)) - log(x))) / n);
	else
		tmp = fma(t_1, Float64(-t_1), exp(Float64(log1p(x) / n)));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + t$95$0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-9], N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.5 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(t$95$1 * (-t$95$1) + N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \sqrt{t\_0}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, -t\_1, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e-8

    1. Initial program 99.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.5%

        \[\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)} \]
      2. expm1-undefine99.5%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    4. Applied egg-rr99.5%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    5. Step-by-step derivation
      1. expm1-define99.5%

        \[\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)} \]
    6. Simplified99.5%

      \[\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 -1e-8 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000012e-9

    1. Initial program 6.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 91.3%

      \[\leadsto \color{blue}{\frac{\left(\log \left(1 + x\right) + 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n}\right) - \left(\log x + 0.5 \cdot \frac{{\log x}^{2}}{n}\right)}{n}} \]
    4. Step-by-step derivation
      1. associate--l+91.3%

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

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

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n} - \color{blue}{\left(0.5 \cdot \frac{{\log x}^{2}}{n} + \log x\right)}\right)}{n} \]
      4. associate--r+91.3%

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \color{blue}{\left(\left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n} - 0.5 \cdot \frac{{\log x}^{2}}{n}\right) - \log x\right)}}{n} \]
      5. distribute-lft-out--91.3%

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

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

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\color{blue}{\left(\mathsf{log1p}\left(x\right)\right)}}^{2} - {\log x}^{2}}{n} - \log x\right)}{n} \]
    5. Simplified91.3%

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

    if 2.00000000000000012e-9 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 45.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg45.8%

        \[\leadsto \color{blue}{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} + \left(-{x}^{\left(\frac{1}{n}\right)}\right)} \]
      2. +-commutative45.8%

        \[\leadsto \color{blue}{\left(-{x}^{\left(\frac{1}{n}\right)}\right) + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}} \]
      3. sqr-pow45.8%

        \[\leadsto \left(-\color{blue}{{x}^{\left(\frac{\frac{1}{n}}{2}\right)} \cdot {x}^{\left(\frac{\frac{1}{n}}{2}\right)}}\right) + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} \]
      4. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{{x}^{\left(\frac{\frac{1}{n}}{2}\right)} \cdot \left(-{x}^{\left(\frac{\frac{1}{n}}{2}\right)}\right)} + {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} \]
      5. fma-define45.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{\left(\frac{\frac{1}{n}}{2}\right)}, -{x}^{\left(\frac{\frac{1}{n}}{2}\right)}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right)} \]
      6. sqrt-pow145.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{{x}^{\left(\frac{1}{n}\right)}}}, -{x}^{\left(\frac{\frac{1}{n}}{2}\right)}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right) \]
      7. sqrt-pow145.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\color{blue}{\sqrt{{x}^{\left(\frac{1}{n}\right)}}}, {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right) \]
      8. pow-to-exp45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, \color{blue}{e^{\log \left(x + 1\right) \cdot \frac{1}{n}}}\right) \]
      9. un-div-inv45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\color{blue}{\frac{\log \left(x + 1\right)}{n}}}\right) \]
      10. +-commutative45.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\log \color{blue}{\left(1 + x\right)}}{n}}\right) \]
      11. log1p-define99.8%

        \[\leadsto \mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}}\right) \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{{x}^{\left(\frac{1}{n}\right)}}, -\sqrt{{x}^{\left(\frac{1}{n}\right)}}, e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 90.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - t\_0\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-6}:\\ \;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} - \frac{1}{n} \cdot 0.5\right)\right)\right) - t\_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ 1.0 x) (/ 1.0 n)) t_0)))
   (if (<= t_1 -5e-6)
     (- 1.0 (exp (* (/ 1.0 n) (log x))))
     (if (<= t_1 0.0)
       (/ (log (/ (+ 1.0 x) x)) n)
       (-
        (+
         1.0
         (*
          x
          (+
           (/ 1.0 n)
           (* x (- (* 0.5 (/ 1.0 (pow n 2.0))) (* (/ 1.0 n) 0.5))))))
        t_0)))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = pow((1.0 + x), (1.0 / n)) - t_0;
	double tmp;
	if (t_1 <= -5e-6) {
		tmp = 1.0 - exp(((1.0 / n) * log(x)));
	} else if (t_1 <= 0.0) {
		tmp = log(((1.0 + x) / x)) / n;
	} else {
		tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / pow(n, 2.0))) - ((1.0 / n) * 0.5)))))) - t_0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    t_1 = ((1.0d0 + x) ** (1.0d0 / n)) - t_0
    if (t_1 <= (-5d-6)) then
        tmp = 1.0d0 - exp(((1.0d0 / n) * log(x)))
    else if (t_1 <= 0.0d0) then
        tmp = log(((1.0d0 + x) / x)) / n
    else
        tmp = (1.0d0 + (x * ((1.0d0 / n) + (x * ((0.5d0 * (1.0d0 / (n ** 2.0d0))) - ((1.0d0 / n) * 0.5d0)))))) - t_0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double t_1 = Math.pow((1.0 + x), (1.0 / n)) - t_0;
	double tmp;
	if (t_1 <= -5e-6) {
		tmp = 1.0 - Math.exp(((1.0 / n) * Math.log(x)));
	} else if (t_1 <= 0.0) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else {
		tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / Math.pow(n, 2.0))) - ((1.0 / n) * 0.5)))))) - t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	t_1 = math.pow((1.0 + x), (1.0 / n)) - t_0
	tmp = 0
	if t_1 <= -5e-6:
		tmp = 1.0 - math.exp(((1.0 / n) * math.log(x)))
	elif t_1 <= 0.0:
		tmp = math.log(((1.0 + x) / x)) / n
	else:
		tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / math.pow(n, 2.0))) - ((1.0 / n) * 0.5)))))) - t_0
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - t_0)
	tmp = 0.0
	if (t_1 <= -5e-6)
		tmp = Float64(1.0 - exp(Float64(Float64(1.0 / n) * log(x))));
	elseif (t_1 <= 0.0)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	else
		tmp = Float64(Float64(1.0 + Float64(x * Float64(Float64(1.0 / n) + Float64(x * Float64(Float64(0.5 * Float64(1.0 / (n ^ 2.0))) - Float64(Float64(1.0 / n) * 0.5)))))) - t_0);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	t_1 = ((1.0 + x) ^ (1.0 / n)) - t_0;
	tmp = 0.0;
	if (t_1 <= -5e-6)
		tmp = 1.0 - exp(((1.0 / n) * log(x)));
	elseif (t_1 <= 0.0)
		tmp = log(((1.0 + x) / x)) / n;
	else
		tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / (n ^ 2.0))) - ((1.0 / n) * 0.5)))))) - t_0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-6], N[(1.0 - N[Exp[N[(N[(1.0 / n), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 + N[(x * N[(N[(1.0 / n), $MachinePrecision] + N[(x * N[(N[(0.5 * N[(1.0 / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / n), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-6}:\\
\;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\

\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} - \frac{1}{n} \cdot 0.5\right)\right)\right) - t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -5.00000000000000041e-6

    1. Initial program 99.1%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.1%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity99.1%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/99.1%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*99.1%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow99.1%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u99.1%

        \[\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)} \]
      2. expm1-undefine99.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr99.0%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define99.1%

        \[\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)} \]
    9. Simplified99.1%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-log1p-u99.1%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
      2. pow-to-exp99.1%

        \[\leadsto 1 - \color{blue}{e^{\log x \cdot \frac{1}{n}}} \]
    11. Applied egg-rr99.1%

      \[\leadsto 1 - \color{blue}{e^{\log x \cdot \frac{1}{n}}} \]

    if -5.00000000000000041e-6 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 0.0

    1. Initial program 29.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 93.1%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define92.5%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified92.5%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine93.1%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log93.2%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr93.2%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative93.2%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified93.2%

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

    if 0.0 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n)))

    1. Initial program 46.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 71.7%

      \[\leadsto \color{blue}{\left(1 + x \cdot \left(x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} - 0.5 \cdot \frac{1}{n}\right) + \frac{1}{n}\right)\right)} - {x}^{\left(\frac{1}{n}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \leq -5 \cdot 10^{-6}:\\ \;\;\;\;1 - e^{\frac{1}{n} \cdot \log x}\\ \mathbf{elif}\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \leq 0:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} - \frac{1}{n} \cdot 0.5\right)\right)\right) - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 95.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\right)}^{3}}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1e-8)
     (- (pow (+ 1.0 x) (/ 1.0 n)) (expm1 (log1p t_0)))
     (if (<= (/ 1.0 n) 2e-9)
       (/
        (+
         (log1p x)
         (- (* 0.5 (/ (- (pow (log1p x) 2.0) (pow (log x) 2.0)) n)) (log x)))
        n)
       (cbrt (pow (- (exp (/ (log1p x) n)) t_0) 3.0))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = pow((1.0 + x), (1.0 / n)) - expm1(log1p(t_0));
	} else if ((1.0 / n) <= 2e-9) {
		tmp = (log1p(x) + ((0.5 * ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) / n)) - log(x))) / n;
	} else {
		tmp = cbrt(pow((exp((log1p(x) / n)) - t_0), 3.0));
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = Math.pow((1.0 + x), (1.0 / n)) - Math.expm1(Math.log1p(t_0));
	} else if ((1.0 / n) <= 2e-9) {
		tmp = (Math.log1p(x) + ((0.5 * ((Math.pow(Math.log1p(x), 2.0) - Math.pow(Math.log(x), 2.0)) / n)) - Math.log(x))) / n;
	} else {
		tmp = Math.cbrt(Math.pow((Math.exp((Math.log1p(x) / n)) - t_0), 3.0));
	}
	return tmp;
}
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-8)
		tmp = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - expm1(log1p(t_0)));
	elseif (Float64(1.0 / n) <= 2e-9)
		tmp = Float64(Float64(log1p(x) + Float64(Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) / n)) - log(x))) / n);
	else
		tmp = cbrt((Float64(exp(Float64(log1p(x) / n)) - t_0) ^ 3.0));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + t$95$0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-9], N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.5 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[Power[N[Power[N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\right)}^{3}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e-8

    1. Initial program 99.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.5%

        \[\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)} \]
      2. expm1-undefine99.5%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    4. Applied egg-rr99.5%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    5. Step-by-step derivation
      1. expm1-define99.5%

        \[\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)} \]
    6. Simplified99.5%

      \[\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 -1e-8 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000012e-9

    1. Initial program 6.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 91.3%

      \[\leadsto \color{blue}{\frac{\left(\log \left(1 + x\right) + 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n}\right) - \left(\log x + 0.5 \cdot \frac{{\log x}^{2}}{n}\right)}{n}} \]
    4. Step-by-step derivation
      1. associate--l+91.3%

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

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

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n} - \color{blue}{\left(0.5 \cdot \frac{{\log x}^{2}}{n} + \log x\right)}\right)}{n} \]
      4. associate--r+91.3%

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \color{blue}{\left(\left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{n} - 0.5 \cdot \frac{{\log x}^{2}}{n}\right) - \log x\right)}}{n} \]
      5. distribute-lft-out--91.3%

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

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

        \[\leadsto \frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\color{blue}{\left(\mathsf{log1p}\left(x\right)\right)}}^{2} - {\log x}^{2}}{n} - \log x\right)}{n} \]
    5. Simplified91.3%

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

    if 2.00000000000000012e-9 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 45.8%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cbrt-cube45.8%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)\right) \cdot \left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)}} \]
      2. pow345.8%

        \[\leadsto \sqrt[3]{\color{blue}{{\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      3. pow-to-exp45.8%

        \[\leadsto \sqrt[3]{{\left(\color{blue}{e^{\log \left(x + 1\right) \cdot \frac{1}{n}}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
      4. un-div-inv45.8%

        \[\leadsto \sqrt[3]{{\left(e^{\color{blue}{\frac{\log \left(x + 1\right)}{n}}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
      5. +-commutative45.8%

        \[\leadsto \sqrt[3]{{\left(e^{\frac{\log \color{blue}{\left(1 + x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
      6. log1p-define99.8%

        \[\leadsto \sqrt[3]{{\left(e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 94.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\right)}^{3}}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1e-8)
     (- (pow (+ 1.0 x) (/ 1.0 n)) (expm1 (log1p t_0)))
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (cbrt (pow (- (exp (/ (log1p x) n)) t_0) 3.0))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = pow((1.0 + x), (1.0 / n)) - expm1(log1p(t_0));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else {
		tmp = cbrt(pow((exp((log1p(x) / n)) - t_0), 3.0));
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = Math.pow((1.0 + x), (1.0 / n)) - Math.expm1(Math.log1p(t_0));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else {
		tmp = Math.cbrt(Math.pow((Math.exp((Math.log1p(x) / n)) - t_0), 3.0));
	}
	return tmp;
}
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-8)
		tmp = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - expm1(log1p(t_0)));
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	else
		tmp = cbrt((Float64(exp(Float64(log1p(x) / n)) - t_0) ^ 3.0));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + t$95$0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[Power[N[Power[N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\right)}^{3}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e-8

    1. Initial program 99.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.5%

        \[\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)} \]
      2. expm1-undefine99.5%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    4. Applied egg-rr99.5%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    5. Step-by-step derivation
      1. expm1-define99.5%

        \[\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)} \]
    6. Simplified99.5%

      \[\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 -1e-8 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 5.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 90.9%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine90.9%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log91.0%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr91.0%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative91.0%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified91.0%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 46.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cbrt-cube46.4%

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

        \[\leadsto \sqrt[3]{\color{blue}{{\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      3. pow-to-exp46.4%

        \[\leadsto \sqrt[3]{{\left(\color{blue}{e^{\log \left(x + 1\right) \cdot \frac{1}{n}}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
      4. un-div-inv46.4%

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

        \[\leadsto \sqrt[3]{{\left(e^{\frac{\log \color{blue}{\left(1 + x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
      6. log1p-define98.8%

        \[\leadsto \sqrt[3]{{\left(e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}} \]
    4. Applied egg-rr98.8%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 94.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1e-8)
     (- (pow (+ 1.0 x) (/ 1.0 n)) (expm1 (log1p t_0)))
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (- (exp (/ (log1p x) n)) t_0)))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = pow((1.0 + x), (1.0 / n)) - expm1(log1p(t_0));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else {
		tmp = exp((log1p(x) / n)) - t_0;
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = Math.pow((1.0 + x), (1.0 / n)) - Math.expm1(Math.log1p(t_0));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else {
		tmp = Math.exp((Math.log1p(x) / n)) - t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1e-8:
		tmp = math.pow((1.0 + x), (1.0 / n)) - math.expm1(math.log1p(t_0))
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(((1.0 + x) / x)) / n
	else:
		tmp = math.exp((math.log1p(x) / n)) - t_0
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-8)
		tmp = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - expm1(log1p(t_0)));
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	else
		tmp = Float64(exp(Float64(log1p(x) / n)) - t_0);
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + t$95$0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left(t\_0\right)\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e-8

    1. Initial program 99.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.5%

        \[\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)} \]
      2. expm1-undefine99.5%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    4. Applied egg-rr99.5%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    5. Step-by-step derivation
      1. expm1-define99.5%

        \[\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)} \]
    6. Simplified99.5%

      \[\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 -1e-8 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 5.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 90.9%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine90.9%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log91.0%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr91.0%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative91.0%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified91.0%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 46.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around 0 46.4%

      \[\leadsto \color{blue}{e^{\frac{\log \left(1 + x\right)}{n}} - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. log1p-define98.8%

        \[\leadsto e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - e^{\frac{\log x}{n}} \]
      2. *-rgt-identity98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      3. associate-*l/98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      4. associate-/l*98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      5. exp-to-pow98.8%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified98.8%

      \[\leadsto \color{blue}{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 90.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (- (pow (+ 1.0 x) (/ 1.0 n)) (pow x (/ 1.0 n)))))
   (if (<= (/ 1.0 n) -1e-8)
     t_0
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 1e+167) t_0 (log1p (expm1 (/ (/ 1.0 x) n))))))))
double code(double x, double n) {
	double t_0 = pow((1.0 + x), (1.0 / n)) - pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = log1p(expm1(((1.0 / x) / n)));
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow((1.0 + x), (1.0 / n)) - Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = Math.log1p(Math.expm1(((1.0 / x) / n)));
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow((1.0 + x), (1.0 / n)) - math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1e-8:
		tmp = t_0
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 1e+167:
		tmp = t_0
	else:
		tmp = math.log1p(math.expm1(((1.0 / x) / n)))
	return tmp
function code(x, n)
	t_0 = Float64((Float64(1.0 + x) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n)))
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-8)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = t_0;
	else
		tmp = log1p(expm1(Float64(Float64(1.0 / x) / n)));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[(N[Power[N[(1.0 + x), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], t$95$0, N[Log[1 + N[(Exp[N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e-8 or 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 90.6%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing

    if -1e-8 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 5.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 90.9%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine90.9%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log91.0%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr91.0%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative91.0%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified91.0%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 0.5%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. mul-1-neg0.5%

        \[\leadsto \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x} \]
      2. log-rec0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]
      3. mul-1-neg0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]
      4. distribute-neg-frac0.5%

        \[\leadsto \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]
      5. mul-1-neg0.5%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]
      6. remove-double-neg0.5%

        \[\leadsto \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]
      7. *-commutative0.5%

        \[\leadsto \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    5. Simplified0.5%

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Taylor expanded in n around inf 64.5%

      \[\leadsto \frac{\color{blue}{1}}{x \cdot n} \]
    7. Step-by-step derivation
      1. log1p-expm1-u86.6%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{x \cdot n}\right)\right)} \]
      2. associate-/r*86.6%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{x}}{n}}\right)\right) \]
    8. Applied egg-rr86.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification90.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 90.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{t\_0}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t\_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1000.0)
     (/ (/ t_0 n) x)
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 1e+167)
         (- (+ 1.0 (/ x n)) t_0)
         (log1p (expm1 (/ (/ 1.0 x) n))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = log1p(expm1(((1.0 / x) / n)));
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = Math.log1p(Math.expm1(((1.0 / x) / n)));
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1000.0:
		tmp = (t_0 / n) / x
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 1e+167:
		tmp = (1.0 + (x / n)) - t_0
	else:
		tmp = math.log1p(math.expm1(((1.0 / x) / n)))
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1000.0)
		tmp = Float64(Float64(t_0 / n) / x);
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = log1p(expm1(Float64(Float64(1.0 / x) / n)));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1000.0], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[Log[1 + N[(Exp[N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1000:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e3

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. associate-/r*100.0%

        \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n}}{x}} \]
      2. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n}}{x} \]
      3. log-rec100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n}}{x} \]
      4. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n}}{x} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n}}{x} \]
      6. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n}}{x} \]
      7. remove-double-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x}}{n}}}{n}}{x} \]
      8. *-rgt-identity100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x \cdot 1}}{n}}}{n}}{x} \]
      9. associate-/l*100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n}}{x} \]
      10. exp-to-pow100.0%

        \[\leadsto \frac{\frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{n}}{x} \]
    5. Simplified100.0%

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

    if -1e3 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 7.9%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 89.3%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define89.3%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified89.3%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine89.3%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log89.4%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr89.4%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative89.4%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified89.4%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 70.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 66.9%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 0.5%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. mul-1-neg0.5%

        \[\leadsto \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x} \]
      2. log-rec0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]
      3. mul-1-neg0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]
      4. distribute-neg-frac0.5%

        \[\leadsto \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]
      5. mul-1-neg0.5%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]
      6. remove-double-neg0.5%

        \[\leadsto \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]
      7. *-commutative0.5%

        \[\leadsto \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    5. Simplified0.5%

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Taylor expanded in n around inf 64.5%

      \[\leadsto \frac{\color{blue}{1}}{x \cdot n} \]
    7. Step-by-step derivation
      1. log1p-expm1-u86.6%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{x \cdot n}\right)\right)} \]
      2. associate-/r*86.6%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{x}}{n}}\right)\right) \]
    8. Applied egg-rr86.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification89.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 89.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1 + x}{x}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-11}:\\ \;\;\;\;\log \left({t\_0}^{\left(\frac{1}{n}\right)}\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log t\_0}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (/ (+ 1.0 x) x)))
   (if (<= (/ 1.0 n) -1e-11)
     (log (pow t_0 (/ 1.0 n)))
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log t_0) n)
       (if (<= (/ 1.0 n) 1e+167)
         (- (+ 1.0 (/ x n)) (pow x (/ 1.0 n)))
         (log1p (expm1 (/ (/ 1.0 x) n))))))))
double code(double x, double n) {
	double t_0 = (1.0 + x) / x;
	double tmp;
	if ((1.0 / n) <= -1e-11) {
		tmp = log(pow(t_0, (1.0 / n)));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(t_0) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - pow(x, (1.0 / n));
	} else {
		tmp = log1p(expm1(((1.0 / x) / n)));
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = (1.0 + x) / x;
	double tmp;
	if ((1.0 / n) <= -1e-11) {
		tmp = Math.log(Math.pow(t_0, (1.0 / n)));
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(t_0) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - Math.pow(x, (1.0 / n));
	} else {
		tmp = Math.log1p(Math.expm1(((1.0 / x) / n)));
	}
	return tmp;
}
def code(x, n):
	t_0 = (1.0 + x) / x
	tmp = 0
	if (1.0 / n) <= -1e-11:
		tmp = math.log(math.pow(t_0, (1.0 / n)))
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(t_0) / n
	elif (1.0 / n) <= 1e+167:
		tmp = (1.0 + (x / n)) - math.pow(x, (1.0 / n))
	else:
		tmp = math.log1p(math.expm1(((1.0 / x) / n)))
	return tmp
function code(x, n)
	t_0 = Float64(Float64(1.0 + x) / x)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-11)
		tmp = log((t_0 ^ Float64(1.0 / n)));
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(t_0) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - (x ^ Float64(1.0 / n)));
	else
		tmp = log1p(expm1(Float64(Float64(1.0 / x) / n)));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-11], N[Log[N[Power[t$95$0, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[t$95$0], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(Exp[N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1 + x}{x}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-11}:\\
\;\;\;\;\log \left({t\_0}^{\left(\frac{1}{n}\right)}\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log t\_0}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -9.99999999999999939e-12

    1. Initial program 99.1%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 52.5%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define51.3%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified51.3%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. add-log-exp95.7%

        \[\leadsto \color{blue}{\log \left(e^{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}}\right)} \]
      2. div-inv95.7%

        \[\leadsto \log \left(e^{\color{blue}{\left(\mathsf{log1p}\left(x\right) - \log x\right) \cdot \frac{1}{n}}}\right) \]
      3. exp-prod95.7%

        \[\leadsto \log \color{blue}{\left({\left(e^{\mathsf{log1p}\left(x\right) - \log x}\right)}^{\left(\frac{1}{n}\right)}\right)} \]
      4. exp-diff95.7%

        \[\leadsto \log \left({\color{blue}{\left(\frac{e^{\mathsf{log1p}\left(x\right)}}{e^{\log x}}\right)}}^{\left(\frac{1}{n}\right)}\right) \]
      5. add-exp-log51.4%

        \[\leadsto \log \left({\left(\frac{e^{\mathsf{log1p}\left(x\right)}}{\color{blue}{x}}\right)}^{\left(\frac{1}{n}\right)}\right) \]
      6. log1p-undefine51.4%

        \[\leadsto \log \left({\left(\frac{e^{\color{blue}{\log \left(1 + x\right)}}}{x}\right)}^{\left(\frac{1}{n}\right)}\right) \]
      7. rem-exp-log96.9%

        \[\leadsto \log \left({\left(\frac{\color{blue}{1 + x}}{x}\right)}^{\left(\frac{1}{n}\right)}\right) \]
    7. Applied egg-rr96.9%

      \[\leadsto \color{blue}{\log \left({\left(\frac{1 + x}{x}\right)}^{\left(\frac{1}{n}\right)}\right)} \]
    8. Step-by-step derivation
      1. +-commutative96.9%

        \[\leadsto \log \left({\left(\frac{\color{blue}{x + 1}}{x}\right)}^{\left(\frac{1}{n}\right)}\right) \]
    9. Simplified96.9%

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

    if -9.99999999999999939e-12 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 5.3%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 91.2%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define91.2%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified91.2%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine91.2%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log91.3%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr91.3%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative91.3%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified91.3%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 70.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 66.9%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 0.5%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. mul-1-neg0.5%

        \[\leadsto \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x} \]
      2. log-rec0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]
      3. mul-1-neg0.5%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]
      4. distribute-neg-frac0.5%

        \[\leadsto \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]
      5. mul-1-neg0.5%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]
      6. remove-double-neg0.5%

        \[\leadsto \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]
      7. *-commutative0.5%

        \[\leadsto \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    5. Simplified0.5%

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Taylor expanded in n around inf 64.5%

      \[\leadsto \frac{\color{blue}{1}}{x \cdot n} \]
    7. Step-by-step derivation
      1. log1p-expm1-u86.6%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{x \cdot n}\right)\right)} \]
      2. associate-/r*86.6%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{x}}{n}}\right)\right) \]
    8. Applied egg-rr86.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification89.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-11}:\\ \;\;\;\;\log \left({\left(\frac{1 + x}{x}\right)}^{\left(\frac{1}{n}\right)}\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{x}}{n}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 70.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{+202}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\frac{1}{n} \leq -2 \cdot 10^{+67}:\\ \;\;\;\;0\\ \mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))))
   (if (<= (/ 1.0 n) -5e+202)
     t_0
     (if (<= (/ 1.0 n) -2e+67)
       0.0
       (if (<= (/ 1.0 n) -1e-8)
         t_0
         (if (<= (/ 1.0 n) 2e-21)
           (/ (- x (log x)) n)
           (if (<= (/ 1.0 n) 1e+167)
             t_0
             (/
              (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x)
              n))))))))
double code(double x, double n) {
	double t_0 = 1.0 - pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e+202) {
		tmp = t_0;
	} else if ((1.0 / n) <= -2e+67) {
		tmp = 0.0;
	} else if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = (x - log(x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 - (x ** (1.0d0 / n))
    if ((1.0d0 / n) <= (-5d+202)) then
        tmp = t_0
    else if ((1.0d0 / n) <= (-2d+67)) then
        tmp = 0.0d0
    else if ((1.0d0 / n) <= (-1d-8)) then
        tmp = t_0
    else if ((1.0d0 / n) <= 2d-21) then
        tmp = (x - log(x)) / n
    else if ((1.0d0 / n) <= 1d+167) then
        tmp = t_0
    else
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = 1.0 - Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e+202) {
		tmp = t_0;
	} else if ((1.0 / n) <= -2e+67) {
		tmp = 0.0;
	} else if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = (x - Math.log(x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
def code(x, n):
	t_0 = 1.0 - math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e+202:
		tmp = t_0
	elif (1.0 / n) <= -2e+67:
		tmp = 0.0
	elif (1.0 / n) <= -1e-8:
		tmp = t_0
	elif (1.0 / n) <= 2e-21:
		tmp = (x - math.log(x)) / n
	elif (1.0 / n) <= 1e+167:
		tmp = t_0
	else:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	return tmp
function code(x, n)
	t_0 = Float64(1.0 - (x ^ Float64(1.0 / n)))
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e+202)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= -2e+67)
		tmp = 0.0;
	elseif (Float64(1.0 / n) <= -1e-8)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(Float64(x - log(x)) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = 1.0 - (x ^ (1.0 / n));
	tmp = 0.0;
	if ((1.0 / n) <= -5e+202)
		tmp = t_0;
	elseif ((1.0 / n) <= -2e+67)
		tmp = 0.0;
	elseif ((1.0 / n) <= -1e-8)
		tmp = t_0;
	elseif ((1.0 / n) <= 2e-21)
		tmp = (x - log(x)) / n;
	elseif ((1.0 / n) <= 1e+167)
		tmp = t_0;
	else
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e+202], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], -2e+67], 0.0, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], t$95$0, N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{+202}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\frac{1}{n} \leq -2 \cdot 10^{+67}:\\
\;\;\;\;0\\

\mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{x - \log x}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -4.9999999999999999e202 or -1.99999999999999997e67 < (/.f64 #s(literal 1 binary64) n) < -1e-8 or 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 87.1%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 65.7%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity65.7%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/65.7%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*65.8%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow65.8%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified65.8%

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

    if -4.9999999999999999e202 < (/.f64 #s(literal 1 binary64) n) < -1.99999999999999997e67

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 34.4%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity34.4%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/34.4%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*34.4%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow34.4%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified34.4%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u100.0%

        \[\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)} \]
      2. expm1-undefine100.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr34.4%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define100.0%

        \[\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)} \]
    9. Simplified34.4%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 68.2%

      \[\leadsto 1 - \color{blue}{1} \]

    if -1e-8 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 5.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 90.9%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around 0 89.8%

      \[\leadsto \frac{\color{blue}{x - \log x}}{n} \]

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 6.7%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define6.7%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified6.7%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 80.3%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification78.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{+202}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq -2 \cdot 10^{+67}:\\ \;\;\;\;0\\ \mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 71.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{if}\;\frac{1}{n} \leq -2 \cdot 10^{+207}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\frac{1}{n} \leq -5 \cdot 10^{+38}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))) (t_1 (/ (log (/ (+ 1.0 x) x)) n)))
   (if (<= (/ 1.0 n) -2e+207)
     t_0
     (if (<= (/ 1.0 n) -5e+38)
       t_1
       (if (<= (/ 1.0 n) -1e-8)
         t_0
         (if (<= (/ 1.0 n) 2e-21)
           t_1
           (if (<= (/ 1.0 n) 1e+167)
             t_0
             (/
              (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x)
              n))))))))
double code(double x, double n) {
	double t_0 = 1.0 - pow(x, (1.0 / n));
	double t_1 = log(((1.0 + x) / x)) / n;
	double tmp;
	if ((1.0 / n) <= -2e+207) {
		tmp = t_0;
	} else if ((1.0 / n) <= -5e+38) {
		tmp = t_1;
	} else if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = t_1;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 - (x ** (1.0d0 / n))
    t_1 = log(((1.0d0 + x) / x)) / n
    if ((1.0d0 / n) <= (-2d+207)) then
        tmp = t_0
    else if ((1.0d0 / n) <= (-5d+38)) then
        tmp = t_1
    else if ((1.0d0 / n) <= (-1d-8)) then
        tmp = t_0
    else if ((1.0d0 / n) <= 2d-21) then
        tmp = t_1
    else if ((1.0d0 / n) <= 1d+167) then
        tmp = t_0
    else
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = 1.0 - Math.pow(x, (1.0 / n));
	double t_1 = Math.log(((1.0 + x) / x)) / n;
	double tmp;
	if ((1.0 / n) <= -2e+207) {
		tmp = t_0;
	} else if ((1.0 / n) <= -5e+38) {
		tmp = t_1;
	} else if ((1.0 / n) <= -1e-8) {
		tmp = t_0;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = t_1;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
def code(x, n):
	t_0 = 1.0 - math.pow(x, (1.0 / n))
	t_1 = math.log(((1.0 + x) / x)) / n
	tmp = 0
	if (1.0 / n) <= -2e+207:
		tmp = t_0
	elif (1.0 / n) <= -5e+38:
		tmp = t_1
	elif (1.0 / n) <= -1e-8:
		tmp = t_0
	elif (1.0 / n) <= 2e-21:
		tmp = t_1
	elif (1.0 / n) <= 1e+167:
		tmp = t_0
	else:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	return tmp
function code(x, n)
	t_0 = Float64(1.0 - (x ^ Float64(1.0 / n)))
	t_1 = Float64(log(Float64(Float64(1.0 + x) / x)) / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -2e+207)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= -5e+38)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= -1e-8)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = 1.0 - (x ^ (1.0 / n));
	t_1 = log(((1.0 + x) / x)) / n;
	tmp = 0.0;
	if ((1.0 / n) <= -2e+207)
		tmp = t_0;
	elseif ((1.0 / n) <= -5e+38)
		tmp = t_1;
	elseif ((1.0 / n) <= -1e-8)
		tmp = t_0;
	elseif ((1.0 / n) <= 2e-21)
		tmp = t_1;
	elseif ((1.0 / n) <= 1e+167)
		tmp = t_0;
	else
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -2e+207], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e+38], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-8], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], t$95$0, N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{if}\;\frac{1}{n} \leq -2 \cdot 10^{+207}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\frac{1}{n} \leq -5 \cdot 10^{+38}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -2.0000000000000001e207 or -4.9999999999999997e38 < (/.f64 #s(literal 1 binary64) n) < -1e-8 or 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 86.1%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 66.9%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity66.9%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/66.9%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*66.9%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow66.9%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified66.9%

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

    if -2.0000000000000001e207 < (/.f64 #s(literal 1 binary64) n) < -4.9999999999999997e38 or -1e-8 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 29.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 84.9%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define84.2%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified84.2%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine84.9%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log84.9%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr84.9%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative84.9%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified84.9%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 6.7%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define6.7%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified6.7%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 80.3%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -2 \cdot 10^{+207}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq -5 \cdot 10^{+38}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-8}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 89.7% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{t\_0}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1000.0)
     (/ (/ t_0 n) x)
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 1e+167)
         (- (+ 1.0 (/ x n)) t_0)
         (/
          (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x)
          n))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-1000.0d0)) then
        tmp = (t_0 / n) / x
    else if ((1.0d0 / n) <= 2d-21) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 1d+167) then
        tmp = (1.0d0 + (x / n)) - t_0
    else
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1000.0:
		tmp = (t_0 / n) / x
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 1e+167:
		tmp = (1.0 + (x / n)) - t_0
	else:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1000.0)
		tmp = Float64(Float64(t_0 / n) / x);
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -1000.0)
		tmp = (t_0 / n) / x;
	elseif ((1.0 / n) <= 2e-21)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 1e+167)
		tmp = (1.0 + (x / n)) - t_0;
	else
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1000.0], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1000:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e3

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. associate-/r*100.0%

        \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n}}{x}} \]
      2. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n}}{x} \]
      3. log-rec100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n}}{x} \]
      4. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n}}{x} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n}}{x} \]
      6. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n}}{x} \]
      7. remove-double-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x}}{n}}}{n}}{x} \]
      8. *-rgt-identity100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x \cdot 1}}{n}}}{n}}{x} \]
      9. associate-/l*100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n}}{x} \]
      10. exp-to-pow100.0%

        \[\leadsto \frac{\frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{n}}{x} \]
    5. Simplified100.0%

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

    if -1e3 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 7.9%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 89.3%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define89.3%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified89.3%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine89.3%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log89.4%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr89.4%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative89.4%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified89.4%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 70.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 66.9%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 6.7%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define6.7%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified6.7%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 80.3%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 89.6% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{t\_0}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;1 - t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -1000.0)
     (/ (/ t_0 n) x)
     (if (<= (/ 1.0 n) 2e-21)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 1e+167)
         (- 1.0 t_0)
         (/
          (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x)
          n))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = 1.0 - t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-1000.0d0)) then
        tmp = (t_0 / n) / x
    else if ((1.0d0 / n) <= 2d-21) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 1d+167) then
        tmp = 1.0d0 - t_0
    else
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1000.0) {
		tmp = (t_0 / n) / x;
	} else if ((1.0 / n) <= 2e-21) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 1e+167) {
		tmp = 1.0 - t_0;
	} else {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1000.0:
		tmp = (t_0 / n) / x
	elif (1.0 / n) <= 2e-21:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 1e+167:
		tmp = 1.0 - t_0
	else:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1000.0)
		tmp = Float64(Float64(t_0 / n) / x);
	elseif (Float64(1.0 / n) <= 2e-21)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 1e+167)
		tmp = Float64(1.0 - t_0);
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -1000.0)
		tmp = (t_0 / n) / x;
	elseif ((1.0 / n) <= 2e-21)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 1e+167)
		tmp = 1.0 - t_0;
	else
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1000.0], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-21], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+167], N[(1.0 - t$95$0), $MachinePrecision], N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1000:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\
\;\;\;\;1 - t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 #s(literal 1 binary64) n) < -1e3

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. associate-/r*100.0%

        \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n}}{x}} \]
      2. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n}}{x} \]
      3. log-rec100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n}}{x} \]
      4. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n}}{x} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n}}{x} \]
      6. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n}}{x} \]
      7. remove-double-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x}}{n}}}{n}}{x} \]
      8. *-rgt-identity100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{\log x \cdot 1}}{n}}}{n}}{x} \]
      9. associate-/l*100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n}}{x} \]
      10. exp-to-pow100.0%

        \[\leadsto \frac{\frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{n}}{x} \]
    5. Simplified100.0%

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

    if -1e3 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999982e-21

    1. Initial program 7.9%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 89.3%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define89.3%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified89.3%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Step-by-step derivation
      1. log1p-undefine89.3%

        \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
      2. diff-log89.4%

        \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Applied egg-rr89.4%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    8. Step-by-step derivation
      1. +-commutative89.4%

        \[\leadsto \frac{\log \left(\frac{\color{blue}{x + 1}}{x}\right)}{n} \]
    9. Simplified89.4%

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

    if 1.99999999999999982e-21 < (/.f64 #s(literal 1 binary64) n) < 1e167

    1. Initial program 70.5%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 64.2%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity64.2%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/64.2%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*64.2%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow64.2%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified64.2%

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

    if 1e167 < (/.f64 #s(literal 1 binary64) n)

    1. Initial program 17.4%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 6.7%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define6.7%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified6.7%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 80.3%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1000:\\ \;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+167}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 63.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x - \log x}{n}\\ \mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \leq 1.75 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (/ (- x (log x)) n)))
   (if (<= n -5.6e-14)
     t_0
     (if (<= n -3.4e-196)
       0.0
       (if (<= n 1.75e-107)
         (/ (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x) n)
         t_0)))))
double code(double x, double n) {
	double t_0 = (x - log(x)) / n;
	double tmp;
	if (n <= -5.6e-14) {
		tmp = t_0;
	} else if (n <= -3.4e-196) {
		tmp = 0.0;
	} else if (n <= 1.75e-107) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x - log(x)) / n
    if (n <= (-5.6d-14)) then
        tmp = t_0
    else if (n <= (-3.4d-196)) then
        tmp = 0.0d0
    else if (n <= 1.75d-107) then
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = (x - Math.log(x)) / n;
	double tmp;
	if (n <= -5.6e-14) {
		tmp = t_0;
	} else if (n <= -3.4e-196) {
		tmp = 0.0;
	} else if (n <= 1.75e-107) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = (x - math.log(x)) / n
	tmp = 0
	if n <= -5.6e-14:
		tmp = t_0
	elif n <= -3.4e-196:
		tmp = 0.0
	elif n <= 1.75e-107:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	else:
		tmp = t_0
	return tmp
function code(x, n)
	t_0 = Float64(Float64(x - log(x)) / n)
	tmp = 0.0
	if (n <= -5.6e-14)
		tmp = t_0;
	elseif (n <= -3.4e-196)
		tmp = 0.0;
	elseif (n <= 1.75e-107)
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = (x - log(x)) / n;
	tmp = 0.0;
	if (n <= -5.6e-14)
		tmp = t_0;
	elseif (n <= -3.4e-196)
		tmp = 0.0;
	elseif (n <= 1.75e-107)
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[n, -5.6e-14], t$95$0, If[LessEqual[n, -3.4e-196], 0.0, If[LessEqual[n, 1.75e-107], N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x - \log x}{n}\\
\mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\
\;\;\;\;0\\

\mathbf{elif}\;n \leq 1.75 \cdot 10^{-107}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -5.6000000000000001e-14 or 1.74999999999999993e-107 < n

    1. Initial program 19.9%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 77.1%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define77.1%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified77.1%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around 0 76.2%

      \[\leadsto \frac{\color{blue}{x - \log x}}{n} \]

    if -5.6000000000000001e-14 < n < -3.4e-196

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 39.5%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity39.5%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/39.5%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*39.5%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow39.5%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified39.5%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u100.0%

        \[\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)} \]
      2. expm1-undefine100.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr39.5%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define100.0%

        \[\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)} \]
    9. Simplified39.5%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 63.1%

      \[\leadsto 1 - \color{blue}{1} \]

    if -3.4e-196 < n < 1.74999999999999993e-107

    1. Initial program 60.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 22.4%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define22.4%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified22.4%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 64.1%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \leq 1.75 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - \log x}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 63.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-\log x}{n}\\ \mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \leq 1.8 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (/ (- (log x)) n)))
   (if (<= n -5.6e-14)
     t_0
     (if (<= n -3.4e-196)
       0.0
       (if (<= n 1.8e-107)
         (/ (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x) n)
         t_0)))))
double code(double x, double n) {
	double t_0 = -log(x) / n;
	double tmp;
	if (n <= -5.6e-14) {
		tmp = t_0;
	} else if (n <= -3.4e-196) {
		tmp = 0.0;
	} else if (n <= 1.8e-107) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -log(x) / n
    if (n <= (-5.6d-14)) then
        tmp = t_0
    else if (n <= (-3.4d-196)) then
        tmp = 0.0d0
    else if (n <= 1.8d-107) then
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = -Math.log(x) / n;
	double tmp;
	if (n <= -5.6e-14) {
		tmp = t_0;
	} else if (n <= -3.4e-196) {
		tmp = 0.0;
	} else if (n <= 1.8e-107) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = -math.log(x) / n
	tmp = 0
	if n <= -5.6e-14:
		tmp = t_0
	elif n <= -3.4e-196:
		tmp = 0.0
	elif n <= 1.8e-107:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	else:
		tmp = t_0
	return tmp
function code(x, n)
	t_0 = Float64(Float64(-log(x)) / n)
	tmp = 0.0
	if (n <= -5.6e-14)
		tmp = t_0;
	elseif (n <= -3.4e-196)
		tmp = 0.0;
	elseif (n <= 1.8e-107)
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = -log(x) / n;
	tmp = 0.0;
	if (n <= -5.6e-14)
		tmp = t_0;
	elseif (n <= -3.4e-196)
		tmp = 0.0;
	elseif (n <= 1.8e-107)
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision]}, If[LessEqual[n, -5.6e-14], t$95$0, If[LessEqual[n, -3.4e-196], 0.0, If[LessEqual[n, 1.8e-107], N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-\log x}{n}\\
\mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\
\;\;\;\;0\\

\mathbf{elif}\;n \leq 1.8 \cdot 10^{-107}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -5.6000000000000001e-14 or 1.79999999999999988e-107 < n

    1. Initial program 19.9%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 19.0%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity19.0%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/19.0%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*19.1%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow19.1%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified19.1%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Taylor expanded in n around inf 75.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{\log x}{n}} \]
    7. Step-by-step derivation
      1. associate-*r/75.3%

        \[\leadsto \color{blue}{\frac{-1 \cdot \log x}{n}} \]
      2. neg-mul-175.3%

        \[\leadsto \frac{\color{blue}{-\log x}}{n} \]
    8. Simplified75.3%

      \[\leadsto \color{blue}{\frac{-\log x}{n}} \]

    if -5.6000000000000001e-14 < n < -3.4e-196

    1. Initial program 100.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 39.5%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity39.5%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/39.5%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*39.5%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow39.5%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified39.5%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u100.0%

        \[\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)} \]
      2. expm1-undefine100.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr39.5%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define100.0%

        \[\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)} \]
    9. Simplified39.5%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 63.1%

      \[\leadsto 1 - \color{blue}{1} \]

    if -3.4e-196 < n < 1.79999999999999988e-107

    1. Initial program 60.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 22.4%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define22.4%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified22.4%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 64.1%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -5.6 \cdot 10^{-14}:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;n \leq -3.4 \cdot 10^{-196}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \leq 1.8 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\log x}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 43.3% accurate, 8.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.9 \cdot 10^{+18}:\\ \;\;\;\;\frac{\frac{1}{n} + \frac{0.3333333333333333 \cdot \frac{1}{n \cdot x} + 0.5 \cdot \frac{-1}{n}}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 1.9e+18)
   (/
    (+
     (/ 1.0 n)
     (/ (+ (* 0.3333333333333333 (/ 1.0 (* n x))) (* 0.5 (/ -1.0 n))) x))
    x)
   0.0))
double code(double x, double n) {
	double tmp;
	if (x <= 1.9e+18) {
		tmp = ((1.0 / n) + (((0.3333333333333333 * (1.0 / (n * x))) + (0.5 * (-1.0 / n))) / x)) / x;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 1.9d+18) then
        tmp = ((1.0d0 / n) + (((0.3333333333333333d0 * (1.0d0 / (n * x))) + (0.5d0 * ((-1.0d0) / n))) / x)) / x
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 1.9e+18) {
		tmp = ((1.0 / n) + (((0.3333333333333333 * (1.0 / (n * x))) + (0.5 * (-1.0 / n))) / x)) / x;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 1.9e+18:
		tmp = ((1.0 / n) + (((0.3333333333333333 * (1.0 / (n * x))) + (0.5 * (-1.0 / n))) / x)) / x
	else:
		tmp = 0.0
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 1.9e+18)
		tmp = Float64(Float64(Float64(1.0 / n) + Float64(Float64(Float64(0.3333333333333333 * Float64(1.0 / Float64(n * x))) + Float64(0.5 * Float64(-1.0 / n))) / x)) / x);
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 1.9e+18)
		tmp = ((1.0 / n) + (((0.3333333333333333 * (1.0 / (n * x))) + (0.5 * (-1.0 / n))) / x)) / x;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 1.9e+18], N[(N[(N[(1.0 / n), $MachinePrecision] + N[(N[(N[(0.3333333333333333 * N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(-1.0 / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9 \cdot 10^{+18}:\\
\;\;\;\;\frac{\frac{1}{n} + \frac{0.3333333333333333 \cdot \frac{1}{n \cdot x} + 0.5 \cdot \frac{-1}{n}}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.9e18

    1. Initial program 36.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 53.2%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define53.2%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified53.2%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 33.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{n \cdot x} - 0.5 \cdot \frac{1}{n}}{x} - \frac{1}{n}}{x}} \]

    if 1.9e18 < x

    1. Initial program 83.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 3.3%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*3.3%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow3.3%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified3.3%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u83.0%

        \[\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)} \]
      2. expm1-undefine83.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr3.3%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define83.0%

        \[\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)} \]
    9. Simplified3.3%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 83.0%

      \[\leadsto 1 - \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.9 \cdot 10^{+18}:\\ \;\;\;\;\frac{\frac{1}{n} + \frac{0.3333333333333333 \cdot \frac{1}{n \cdot x} + 0.5 \cdot \frac{-1}{n}}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 43.3% accurate, 10.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.15 \cdot 10^{+18}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 2.15e+18)
   (/ (/ (+ 1.0 (/ (- (* (/ 1.0 x) 0.3333333333333333) 0.5) x)) x) n)
   0.0))
double code(double x, double n) {
	double tmp;
	if (x <= 2.15e+18) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 2.15d+18) then
        tmp = ((1.0d0 + ((((1.0d0 / x) * 0.3333333333333333d0) - 0.5d0) / x)) / x) / n
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 2.15e+18) {
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 2.15e+18:
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n
	else:
		tmp = 0.0
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 2.15e+18)
		tmp = Float64(Float64(Float64(1.0 + Float64(Float64(Float64(Float64(1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n);
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 2.15e+18)
		tmp = ((1.0 + ((((1.0 / x) * 0.3333333333333333) - 0.5) / x)) / x) / n;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 2.15e+18], N[(N[(N[(1.0 + N[(N[(N[(N[(1.0 / x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / n), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.15 \cdot 10^{+18}:\\
\;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.15e18

    1. Initial program 36.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 53.2%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define53.2%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified53.2%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around -inf 33.6%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{-1 \cdot \frac{0.3333333333333333 \cdot \frac{1}{x} - 0.5}{x} - 1}{x}}}{n} \]

    if 2.15e18 < x

    1. Initial program 83.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 3.3%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*3.3%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow3.3%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified3.3%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u83.0%

        \[\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)} \]
      2. expm1-undefine83.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr3.3%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define83.0%

        \[\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)} \]
    9. Simplified3.3%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 83.0%

      \[\leadsto 1 - \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.15 \cdot 10^{+18}:\\ \;\;\;\;\frac{\frac{1 + \frac{\frac{1}{x} \cdot 0.3333333333333333 - 0.5}{x}}{x}}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 36.3% accurate, 21.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.7 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x n) :precision binary64 (if (<= x 2.7e+18) (/ 1.0 (* n x)) 0.0))
double code(double x, double n) {
	double tmp;
	if (x <= 2.7e+18) {
		tmp = 1.0 / (n * x);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 2.7d+18) then
        tmp = 1.0d0 / (n * x)
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 2.7e+18) {
		tmp = 1.0 / (n * x);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 2.7e+18:
		tmp = 1.0 / (n * x)
	else:
		tmp = 0.0
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 2.7e+18)
		tmp = Float64(1.0 / Float64(n * x));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 2.7e+18)
		tmp = 1.0 / (n * x);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 2.7e+18], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.7 \cdot 10^{+18}:\\
\;\;\;\;\frac{1}{n \cdot x}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.7e18

    1. Initial program 36.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 22.7%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    4. Step-by-step derivation
      1. mul-1-neg22.7%

        \[\leadsto \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x} \]
      2. log-rec22.7%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]
      3. mul-1-neg22.7%

        \[\leadsto \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]
      4. distribute-neg-frac22.7%

        \[\leadsto \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]
      5. mul-1-neg22.7%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]
      6. remove-double-neg22.7%

        \[\leadsto \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]
      7. *-commutative22.7%

        \[\leadsto \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    5. Simplified22.7%

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Taylor expanded in n around inf 23.1%

      \[\leadsto \frac{\color{blue}{1}}{x \cdot n} \]

    if 2.7e18 < x

    1. Initial program 83.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 3.3%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*3.3%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow3.3%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified3.3%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u83.0%

        \[\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)} \]
      2. expm1-undefine83.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr3.3%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define83.0%

        \[\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)} \]
    9. Simplified3.3%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 83.0%

      \[\leadsto 1 - \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification33.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.7 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 22.6% accurate, 26.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.8 \cdot 10^{+18}:\\ \;\;\;\;\frac{x}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x n) :precision binary64 (if (<= x 1.8e+18) (/ x n) 0.0))
double code(double x, double n) {
	double tmp;
	if (x <= 1.8e+18) {
		tmp = x / n;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 1.8d+18) then
        tmp = x / n
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 1.8e+18) {
		tmp = x / n;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 1.8e+18:
		tmp = x / n
	else:
		tmp = 0.0
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 1.8e+18)
		tmp = Float64(x / n);
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 1.8e+18)
		tmp = x / n;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 1.8e+18], N[(x / n), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.8 \cdot 10^{+18}:\\
\;\;\;\;\frac{x}{n}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.8e18

    1. Initial program 36.7%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around inf 53.2%

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    4. Step-by-step derivation
      1. log1p-define53.2%

        \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n} \]
    5. Simplified53.2%

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    6. Taylor expanded in x around 0 52.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{\log x}{n} + \frac{x}{n}} \]
    7. Step-by-step derivation
      1. neg-mul-152.5%

        \[\leadsto \color{blue}{\left(-\frac{\log x}{n}\right)} + \frac{x}{n} \]
      2. +-commutative52.5%

        \[\leadsto \color{blue}{\frac{x}{n} + \left(-\frac{\log x}{n}\right)} \]
      3. unsub-neg52.5%

        \[\leadsto \color{blue}{\frac{x}{n} - \frac{\log x}{n}} \]
    8. Simplified52.5%

      \[\leadsto \color{blue}{\frac{x}{n} - \frac{\log x}{n}} \]
    9. Taylor expanded in x around inf 5.7%

      \[\leadsto \color{blue}{\frac{x}{n}} \]

    if 1.8e18 < x

    1. Initial program 83.0%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 3.3%

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    4. Step-by-step derivation
      1. *-rgt-identity3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
      2. associate-*l/3.3%

        \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
      3. associate-/l*3.3%

        \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
      4. exp-to-pow3.3%

        \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
    5. Simplified3.3%

      \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u83.0%

        \[\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)} \]
      2. expm1-undefine83.0%

        \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    7. Applied egg-rr3.3%

      \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-define83.0%

        \[\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)} \]
    9. Simplified3.3%

      \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
    10. Taylor expanded in n around inf 83.0%

      \[\leadsto 1 - \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.8 \cdot 10^{+18}:\\ \;\;\;\;\frac{x}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 22.1% accurate, 211.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x n) :precision binary64 0.0)
double code(double x, double n) {
	return 0.0;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = 0.0d0
end function
public static double code(double x, double n) {
	return 0.0;
}
def code(x, n):
	return 0.0
function code(x, n)
	return 0.0
end
function tmp = code(x, n)
	tmp = 0.0;
end
code[x_, n_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 44.9%

    \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 29.6%

    \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
  4. Step-by-step derivation
    1. *-rgt-identity29.6%

      \[\leadsto 1 - e^{\color{blue}{\frac{\log x}{n} \cdot 1}} \]
    2. associate-*l/29.6%

      \[\leadsto 1 - e^{\color{blue}{\frac{\log x \cdot 1}{n}}} \]
    3. associate-/l*29.6%

      \[\leadsto 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}} \]
    4. exp-to-pow29.6%

      \[\leadsto 1 - \color{blue}{{x}^{\left(\frac{1}{n}\right)}} \]
  5. Simplified29.6%

    \[\leadsto \color{blue}{1 - {x}^{\left(\frac{1}{n}\right)}} \]
  6. Step-by-step derivation
    1. expm1-log1p-u44.8%

      \[\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)} \]
    2. expm1-undefine44.7%

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
  7. Applied egg-rr29.5%

    \[\leadsto 1 - \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)} - 1\right)} \]
  8. Step-by-step derivation
    1. expm1-define44.8%

      \[\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)} \]
  9. Simplified29.6%

    \[\leadsto 1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
  10. Taylor expanded in n around inf 17.5%

    \[\leadsto 1 - \color{blue}{1} \]
  11. Final simplification17.5%

    \[\leadsto 0 \]
  12. Add Preprocessing

Reproduce

?
herbie shell --seed 2024083 
(FPCore (x n)
  :name "2nthrt (problem 3.4.6)"
  :precision binary64
  (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))