2nthrt (problem 3.4.6)

Percentage Accurate: 52.6% → 85.2%
Time: 24.3s
Alternatives: 15
Speedup: 1.9×

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 15 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: 52.6% 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: 85.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \log \left(1 + x\right)\\ t_2 := \frac{\log x}{n}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{e^{t_2}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\left(0.5 \cdot \frac{{t_1}^{2}}{{n}^{2}} + \frac{t_1}{n}\right) - \left(t_2 + 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n}} - t_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (log (+ 1.0 x))) (t_2 (/ (log x) n)))
   (if (<= (/ 1.0 n) -5e-42)
     (/ (exp t_2) (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (-
        (+ (* 0.5 (/ (pow t_1 2.0) (pow n 2.0))) (/ t_1 n))
        (+ t_2 (* 0.5 (/ (pow (log x) 2.0) (pow n 2.0)))))
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (- (exp (/ x n)) t_0))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = log((1.0 + x));
	double t_2 = log(x) / n;
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = exp(t_2) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = ((0.5 * (pow(t_1, 2.0) / pow(n, 2.0))) + (t_1 / n)) - (t_2 + (0.5 * (pow(log(x), 2.0) / pow(n, 2.0))));
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else {
		tmp = exp((x / n)) - 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) :: t_2
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    t_1 = log((1.0d0 + x))
    t_2 = log(x) / n
    if ((1.0d0 / n) <= (-5d-42)) then
        tmp = exp(t_2) / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = ((0.5d0 * ((t_1 ** 2.0d0) / (n ** 2.0d0))) + (t_1 / n)) - (t_2 + (0.5d0 * ((log(x) ** 2.0d0) / (n ** 2.0d0))))
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else
        tmp = exp((x / n)) - 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.log((1.0 + x));
	double t_2 = Math.log(x) / n;
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = Math.exp(t_2) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = ((0.5 * (Math.pow(t_1, 2.0) / Math.pow(n, 2.0))) + (t_1 / n)) - (t_2 + (0.5 * (Math.pow(Math.log(x), 2.0) / Math.pow(n, 2.0))));
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else {
		tmp = Math.exp((x / n)) - t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	t_1 = math.log((1.0 + x))
	t_2 = math.log(x) / n
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = math.exp(t_2) / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = ((0.5 * (math.pow(t_1, 2.0) / math.pow(n, 2.0))) + (t_1 / n)) - (t_2 + (0.5 * (math.pow(math.log(x), 2.0) / math.pow(n, 2.0))))
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	else:
		tmp = math.exp((x / n)) - t_0
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = log(Float64(1.0 + x))
	t_2 = Float64(log(x) / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = Float64(exp(t_2) / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(Float64(Float64(0.5 * Float64((t_1 ^ 2.0) / (n ^ 2.0))) + Float64(t_1 / n)) - Float64(t_2 + Float64(0.5 * Float64((log(x) ^ 2.0) / (n ^ 2.0)))));
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	else
		tmp = Float64(exp(Float64(x / n)) - t_0);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	t_1 = log((1.0 + x));
	t_2 = log(x) / n;
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = exp(t_2) / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = ((0.5 * ((t_1 ^ 2.0) / (n ^ 2.0))) + (t_1 / n)) - (t_2 + (0.5 * ((log(x) ^ 2.0) / (n ^ 2.0))));
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	else
		tmp = exp((x / n)) - 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[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-42], N[(N[Exp[t$95$2], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[(N[(0.5 * N[(N[Power[t$95$1, 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 / n), $MachinePrecision]), $MachinePrecision] - N[(t$95$2 + N[(0.5 * N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\
\;\;\;\;\left(0.5 \cdot \frac{{t_1}^{2}}{{n}^{2}} + \frac{t_1}{n}\right) - \left(t_2 + 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)\\

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n)

    1. Initial program 56.6%

      \[{\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 56.6%

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

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

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

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

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

Alternative 2: 81.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+151}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{\left(n \cdot x\right)}^{-2}}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -5e-42)
     (/ t_0 (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (if (<= (/ 1.0 n) 1e+151)
           (- (+ 1.0 (/ x n)) t_0)
           (sqrt (pow (* n x) -2.0))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+151) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = sqrt(pow((n * x), -2.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 ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-5d-42)) then
        tmp = t_0 / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else if ((1.0d0 / n) <= 1d+151) then
        tmp = (1.0d0 + (x / n)) - t_0
    else
        tmp = sqrt(((n * x) ** (-2.0d0)))
    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) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+151) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = Math.sqrt(Math.pow((n * x), -2.0));
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = t_0 / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	elif (1.0 / n) <= 1e+151:
		tmp = (1.0 + (x / n)) - t_0
	else:
		tmp = math.sqrt(math.pow((n * x), -2.0))
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = Float64(t_0 / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	elseif (Float64(1.0 / n) <= 1e+151)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = sqrt((Float64(n * x) ^ -2.0));
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = t_0 / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	elseif ((1.0 / n) <= 1e+151)
		tmp = (1.0 + (x / n)) - t_0;
	else
		tmp = sqrt(((n * x) ^ -2.0));
	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], -5e-42], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+151], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[Sqrt[N[Power[N[(n * x), $MachinePrecision], -2.0], $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{{\left(n \cdot x\right)}^{-2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n) < 1.00000000000000002e151

    1. Initial program 85.2%

      \[{\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 87.8%

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

    if 1.00000000000000002e151 < (/.f64 1 n)

    1. Initial program 26.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative43.5%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified43.5%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt43.5%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x \cdot n}} \cdot \sqrt{\frac{1}{x \cdot n}}} \]
      2. sqrt-unprod85.5%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x \cdot n} \cdot \frac{1}{x \cdot n}}} \]
      3. inv-pow85.5%

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

        \[\leadsto \sqrt{{\left(x \cdot n\right)}^{-1} \cdot \color{blue}{{\left(x \cdot n\right)}^{-1}}} \]
      5. pow-prod-up85.5%

        \[\leadsto \sqrt{\color{blue}{{\left(x \cdot n\right)}^{\left(-1 + -1\right)}}} \]
      6. metadata-eval85.5%

        \[\leadsto \sqrt{{\left(x \cdot n\right)}^{\color{blue}{-2}}} \]
    10. Applied egg-rr85.5%

      \[\leadsto \color{blue}{\sqrt{{\left(x \cdot n\right)}^{-2}}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification85.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+151}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{\left(n \cdot x\right)}^{-2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+151}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{\left(n \cdot x\right)}^{-2}}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -5e-42)
     (/ (exp (/ (log x) n)) (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (if (<= (/ 1.0 n) 1e+151)
           (- (+ 1.0 (/ x n)) t_0)
           (sqrt (pow (* n x) -2.0))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = exp((log(x) / n)) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+151) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = sqrt(pow((n * x), -2.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 ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-5d-42)) then
        tmp = exp((log(x) / n)) / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else if ((1.0d0 / n) <= 1d+151) then
        tmp = (1.0d0 + (x / n)) - t_0
    else
        tmp = sqrt(((n * x) ** (-2.0d0)))
    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) <= -5e-42) {
		tmp = Math.exp((Math.log(x) / n)) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+151) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = Math.sqrt(Math.pow((n * x), -2.0));
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = math.exp((math.log(x) / n)) / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	elif (1.0 / n) <= 1e+151:
		tmp = (1.0 + (x / n)) - t_0
	else:
		tmp = math.sqrt(math.pow((n * x), -2.0))
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	elseif (Float64(1.0 / n) <= 1e+151)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = sqrt((Float64(n * x) ^ -2.0));
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = exp((log(x) / n)) / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	elseif ((1.0 / n) <= 1e+151)
		tmp = (1.0 + (x / n)) - t_0;
	else
		tmp = sqrt(((n * x) ^ -2.0));
	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], -5e-42], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+151], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[Sqrt[N[Power[N[(n * x), $MachinePrecision], -2.0], $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{{\left(n \cdot x\right)}^{-2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n) < 1.00000000000000002e151

    1. Initial program 85.2%

      \[{\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 87.8%

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

    if 1.00000000000000002e151 < (/.f64 1 n)

    1. Initial program 26.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative43.5%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified43.5%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt43.5%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x \cdot n}} \cdot \sqrt{\frac{1}{x \cdot n}}} \]
      2. sqrt-unprod85.5%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x \cdot n} \cdot \frac{1}{x \cdot n}}} \]
      3. inv-pow85.5%

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

        \[\leadsto \sqrt{{\left(x \cdot n\right)}^{-1} \cdot \color{blue}{{\left(x \cdot n\right)}^{-1}}} \]
      5. pow-prod-up85.5%

        \[\leadsto \sqrt{\color{blue}{{\left(x \cdot n\right)}^{\left(-1 + -1\right)}}} \]
      6. metadata-eval85.5%

        \[\leadsto \sqrt{{\left(x \cdot n\right)}^{\color{blue}{-2}}} \]
    10. Applied egg-rr85.5%

      \[\leadsto \color{blue}{\sqrt{{\left(x \cdot n\right)}^{-2}}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification85.4%

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

Alternative 4: 85.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n}} - t_0\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -5e-42)
     (/ (exp (/ (log x) n)) (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (- (exp (/ x n)) t_0))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = exp((log(x) / n)) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else {
		tmp = exp((x / n)) - 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 ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-5d-42)) then
        tmp = exp((log(x) / n)) / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else
        tmp = exp((x / n)) - 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 tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = Math.exp((Math.log(x) / n)) / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else {
		tmp = Math.exp((x / n)) - t_0;
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = math.exp((math.log(x) / n)) / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	else:
		tmp = math.exp((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) <= -5e-42)
		tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	else
		tmp = Float64(exp(Float64(x / n)) - t_0);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = exp((log(x) / n)) / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	else
		tmp = exp((x / n)) - t_0;
	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], -5e-42], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(x / 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 -5 \cdot 10^{-42}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n)

    1. Initial program 56.6%

      \[{\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 56.6%

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

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

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

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

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

Alternative 5: 80.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -5e-42)
     (/ t_0 (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (if (<= (/ 1.0 n) 1e+198)
           (- (+ 1.0 (/ x n)) t_0)
           (/ 1.0 (* n x))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+198) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	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) <= (-5d-42)) then
        tmp = t_0 / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else if ((1.0d0 / n) <= 1d+198) then
        tmp = (1.0d0 + (x / n)) - t_0
    else
        tmp = 1.0d0 / (n * x)
    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) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+198) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = t_0 / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	elif (1.0 / n) <= 1e+198:
		tmp = (1.0 + (x / n)) - t_0
	else:
		tmp = 1.0 / (n * x)
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = Float64(t_0 / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	elseif (Float64(1.0 / n) <= 1e+198)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = Float64(1.0 / Float64(n * x));
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = t_0 / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	elseif ((1.0 / n) <= 1e+198)
		tmp = (1.0 + (x / n)) - t_0;
	else
		tmp = 1.0 / (n * x);
	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], -5e-42], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+198], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n) < 1.00000000000000002e198

    1. Initial program 73.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 69.1%

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

    if 1.00000000000000002e198 < (/.f64 1 n)

    1. Initial program 10.6%

      \[{\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 7.3%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative66.2%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified66.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 56.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{-\log x}{n}\\ \mathbf{if}\;x \leq 4.05 \cdot 10^{-290}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-84}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.05:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))) (t_1 (/ (- (log x)) n)))
   (if (<= x 4.05e-290)
     t_0
     (if (<= x 3e-142)
       t_1
       (if (<= x 3.6e-126)
         t_0
         (if (<= x 8e-97)
           t_1
           (if (<= x 2.2e-84)
             t_0
             (if (<= x 0.05) (/ (- x (log x)) n) (/ (/ 1.0 n) x)))))))))
double code(double x, double n) {
	double t_0 = 1.0 - pow(x, (1.0 / n));
	double t_1 = -log(x) / n;
	double tmp;
	if (x <= 4.05e-290) {
		tmp = t_0;
	} else if (x <= 3e-142) {
		tmp = t_1;
	} else if (x <= 3.6e-126) {
		tmp = t_0;
	} else if (x <= 8e-97) {
		tmp = t_1;
	} else if (x <= 2.2e-84) {
		tmp = t_0;
	} else if (x <= 0.05) {
		tmp = (x - log(x)) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	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(x) / n
    if (x <= 4.05d-290) then
        tmp = t_0
    else if (x <= 3d-142) then
        tmp = t_1
    else if (x <= 3.6d-126) then
        tmp = t_0
    else if (x <= 8d-97) then
        tmp = t_1
    else if (x <= 2.2d-84) then
        tmp = t_0
    else if (x <= 0.05d0) then
        tmp = (x - log(x)) / n
    else
        tmp = (1.0d0 / n) / x
    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(x) / n;
	double tmp;
	if (x <= 4.05e-290) {
		tmp = t_0;
	} else if (x <= 3e-142) {
		tmp = t_1;
	} else if (x <= 3.6e-126) {
		tmp = t_0;
	} else if (x <= 8e-97) {
		tmp = t_1;
	} else if (x <= 2.2e-84) {
		tmp = t_0;
	} else if (x <= 0.05) {
		tmp = (x - Math.log(x)) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	return tmp;
}
def code(x, n):
	t_0 = 1.0 - math.pow(x, (1.0 / n))
	t_1 = -math.log(x) / n
	tmp = 0
	if x <= 4.05e-290:
		tmp = t_0
	elif x <= 3e-142:
		tmp = t_1
	elif x <= 3.6e-126:
		tmp = t_0
	elif x <= 8e-97:
		tmp = t_1
	elif x <= 2.2e-84:
		tmp = t_0
	elif x <= 0.05:
		tmp = (x - math.log(x)) / n
	else:
		tmp = (1.0 / n) / x
	return tmp
function code(x, n)
	t_0 = Float64(1.0 - (x ^ Float64(1.0 / n)))
	t_1 = Float64(Float64(-log(x)) / n)
	tmp = 0.0
	if (x <= 4.05e-290)
		tmp = t_0;
	elseif (x <= 3e-142)
		tmp = t_1;
	elseif (x <= 3.6e-126)
		tmp = t_0;
	elseif (x <= 8e-97)
		tmp = t_1;
	elseif (x <= 2.2e-84)
		tmp = t_0;
	elseif (x <= 0.05)
		tmp = Float64(Float64(x - log(x)) / n);
	else
		tmp = Float64(Float64(1.0 / n) / x);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = 1.0 - (x ^ (1.0 / n));
	t_1 = -log(x) / n;
	tmp = 0.0;
	if (x <= 4.05e-290)
		tmp = t_0;
	elseif (x <= 3e-142)
		tmp = t_1;
	elseif (x <= 3.6e-126)
		tmp = t_0;
	elseif (x <= 8e-97)
		tmp = t_1;
	elseif (x <= 2.2e-84)
		tmp = t_0;
	elseif (x <= 0.05)
		tmp = (x - log(x)) / n;
	else
		tmp = (1.0 / n) / x;
	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[x], $MachinePrecision]) / n), $MachinePrecision]}, If[LessEqual[x, 4.05e-290], t$95$0, If[LessEqual[x, 3e-142], t$95$1, If[LessEqual[x, 3.6e-126], t$95$0, If[LessEqual[x, 8e-97], t$95$1, If[LessEqual[x, 2.2e-84], t$95$0, If[LessEqual[x, 0.05], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{-\log x}{n}\\
\mathbf{if}\;x \leq 4.05 \cdot 10^{-290}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 3 \cdot 10^{-142}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 3.6 \cdot 10^{-126}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 8 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 2.2 \cdot 10^{-84}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 0.05:\\
\;\;\;\;\frac{x - \log x}{n}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{n}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 4.05000000000000027e-290 or 3.0000000000000001e-142 < x < 3.5999999999999999e-126 or 8.00000000000000029e-97 < x < 2.1999999999999999e-84

    1. Initial program 70.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 70.1%

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

    if 4.05000000000000027e-290 < x < 3.0000000000000001e-142 or 3.5999999999999999e-126 < x < 8.00000000000000029e-97

    1. Initial program 41.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 41.4%

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

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

        \[\leadsto \color{blue}{-\frac{\log x}{n}} \]
      2. distribute-neg-frac55.7%

        \[\leadsto \color{blue}{\frac{-\log x}{n}} \]
    6. Simplified55.7%

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

    if 2.1999999999999999e-84 < x < 0.050000000000000003

    1. Initial program 27.5%

      \[{\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 56.6%

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

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

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

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

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

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

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

    if 0.050000000000000003 < x

    1. Initial program 59.5%

      \[{\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 57.7%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified71.3%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    9. Step-by-step derivation
      1. clear-num71.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot n}{1}}} \]
      2. associate-/r/71.3%

        \[\leadsto \color{blue}{\frac{1}{x \cdot n} \cdot 1} \]
      3. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{n \cdot x}} \cdot 1 \]
      4. associate-/r*72.9%

        \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \cdot 1 \]
    10. Applied egg-rr72.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x} \cdot 1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification64.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 4.05 \cdot 10^{-290}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-142}:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-126}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-97}:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-84}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 0.05:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 66.0% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -400000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))))
   (if (<= (/ 1.0 n) -400000.0)
     t_0
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (/ (/ 1.0 x) n)
         (if (<= (/ 1.0 n) 1e+198) t_0 (/ 1.0 (* n x))))))))
double code(double x, double n) {
	double t_0 = 1.0 - pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -400000.0) {
		tmp = t_0;
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) / n;
	} else if ((1.0 / n) <= 1e+198) {
		tmp = t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	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) <= (-400000.0d0)) then
        tmp = t_0
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) / n
    else if ((1.0d0 / n) <= 1d+198) then
        tmp = t_0
    else
        tmp = 1.0d0 / (n * x)
    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) <= -400000.0) {
		tmp = t_0;
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) / n;
	} else if ((1.0 / n) <= 1e+198) {
		tmp = t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	return tmp;
}
def code(x, n):
	t_0 = 1.0 - math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -400000.0:
		tmp = t_0
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) / n
	elif (1.0 / n) <= 1e+198:
		tmp = t_0
	else:
		tmp = 1.0 / (n * x)
	return tmp
function code(x, n)
	t_0 = Float64(1.0 - (x ^ Float64(1.0 / n)))
	tmp = 0.0
	if (Float64(1.0 / n) <= -400000.0)
		tmp = t_0;
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) / n);
	elseif (Float64(1.0 / n) <= 1e+198)
		tmp = t_0;
	else
		tmp = Float64(1.0 / Float64(n * x));
	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) <= -400000.0)
		tmp = t_0;
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) / n;
	elseif ((1.0 / n) <= 1e+198)
		tmp = t_0;
	else
		tmp = 1.0 / (n * x);
	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], -400000.0], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+198], t$95$0, N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -4e5 or 2e3 < (/.f64 1 n) < 1.00000000000000002e198

    1. Initial program 91.6%

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

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

    if -4e5 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 75.7%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.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 43.0%

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

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

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

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

    if 1.00000000000000002e198 < (/.f64 1 n)

    1. Initial program 10.6%

      \[{\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 7.3%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative66.2%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified66.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -400000:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 80.8% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{t_0}{n \cdot x}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-100}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;1 - t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))) (t_1 (/ t_0 (* n x))))
   (if (<= (/ 1.0 n) -5e-42)
     t_1
     (if (<= (/ 1.0 n) 2e-100)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         t_1
         (if (<= (/ 1.0 n) 1e+198) (- 1.0 t_0) (/ 1.0 (* n x))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = t_0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = t_1;
	} else if ((1.0 / n) <= 2e-100) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 1e+198) {
		tmp = 1.0 - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	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 = t_0 / (n * x)
    if ((1.0d0 / n) <= (-5d-42)) then
        tmp = t_1
    else if ((1.0d0 / n) <= 2d-100) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = t_1
    else if ((1.0d0 / n) <= 1d+198) then
        tmp = 1.0d0 - t_0
    else
        tmp = 1.0d0 / (n * x)
    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 = t_0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = t_1;
	} else if ((1.0 / n) <= 2e-100) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 1e+198) {
		tmp = 1.0 - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	t_1 = t_0 / (n * x)
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = t_1
	elif (1.0 / n) <= 2e-100:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = t_1
	elif (1.0 / n) <= 1e+198:
		tmp = 1.0 - t_0
	else:
		tmp = 1.0 / (n * x)
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = Float64(t_0 / Float64(n * x))
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 2e-100)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 1e+198)
		tmp = Float64(1.0 - t_0);
	else
		tmp = Float64(1.0 / Float64(n * x));
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	t_1 = t_0 / (n * x);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = t_1;
	elseif ((1.0 / n) <= 2e-100)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = t_1;
	elseif ((1.0 / n) <= 1e+198)
		tmp = 1.0 - t_0;
	else
		tmp = 1.0 / (n * x);
	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[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-42], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-100], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+198], N[(1.0 - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\
\;\;\;\;1 - t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42 or 2e-100 < (/.f64 1 n) < 2e3

    1. Initial program 73.6%

      \[{\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 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{{x}^{\left(\frac{1}{n}\right)}}{\color{blue}{x \cdot n}} \]
    8. Simplified91.4%

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 2e-100

    1. Initial program 30.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 79.5%

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

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

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

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

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

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

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

    if 2e3 < (/.f64 1 n) < 1.00000000000000002e198

    1. Initial program 73.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 67.0%

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

    if 1.00000000000000002e198 < (/.f64 1 n)

    1. Initial program 10.6%

      \[{\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 7.3%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative66.2%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified66.2%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification81.9%

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

Alternative 9: 80.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 -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;1 - t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (pow x (/ 1.0 n))))
   (if (<= (/ 1.0 n) -5e-42)
     (/ t_0 (* n x))
     (if (<= (/ 1.0 n) 4e-105)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 2000.0)
         (* (/ 1.0 x) (/ t_0 n))
         (if (<= (/ 1.0 n) 1e+198) (- 1.0 t_0) (/ 1.0 (* n x))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+198) {
		tmp = 1.0 - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	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) <= (-5d-42)) then
        tmp = t_0 / (n * x)
    else if ((1.0d0 / n) <= 4d-105) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 2000.0d0) then
        tmp = (1.0d0 / x) * (t_0 / n)
    else if ((1.0d0 / n) <= 1d+198) then
        tmp = 1.0d0 - t_0
    else
        tmp = 1.0d0 / (n * x)
    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) <= -5e-42) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 4e-105) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 2000.0) {
		tmp = (1.0 / x) * (t_0 / n);
	} else if ((1.0 / n) <= 1e+198) {
		tmp = 1.0 - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	return tmp;
}
def code(x, n):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -5e-42:
		tmp = t_0 / (n * x)
	elif (1.0 / n) <= 4e-105:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 2000.0:
		tmp = (1.0 / x) * (t_0 / n)
	elif (1.0 / n) <= 1e+198:
		tmp = 1.0 - t_0
	else:
		tmp = 1.0 / (n * x)
	return tmp
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -5e-42)
		tmp = Float64(t_0 / Float64(n * x));
	elseif (Float64(1.0 / n) <= 4e-105)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 2000.0)
		tmp = Float64(Float64(1.0 / x) * Float64(t_0 / n));
	elseif (Float64(1.0 / n) <= 1e+198)
		tmp = Float64(1.0 - t_0);
	else
		tmp = Float64(1.0 / Float64(n * x));
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -5e-42)
		tmp = t_0 / (n * x);
	elseif ((1.0 / n) <= 4e-105)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 2000.0)
		tmp = (1.0 / x) * (t_0 / n);
	elseif ((1.0 / n) <= 1e+198)
		tmp = 1.0 - t_0;
	else
		tmp = 1.0 / (n * x);
	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], -5e-42], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e-105], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2000.0], N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e+198], N[(1.0 - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\frac{1}{n} \leq 2000:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\
\;\;\;\;1 - t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 1 n) < -5.00000000000000003e-42

    1. Initial program 90.2%

      \[{\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 97.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-neg97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000003e-42 < (/.f64 1 n) < 3.99999999999999986e-105

    1. Initial program 30.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 79.9%

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

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

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

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

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

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

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

    if 3.99999999999999986e-105 < (/.f64 1 n) < 2e3

    1. Initial program 13.8%

      \[{\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 67.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
    6. Step-by-step derivation
      1. div-inv67.6%

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n} \]
      2. pow-to-exp67.6%

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n} \]
      3. *-un-lft-identity67.6%

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}} \]
    7. Applied egg-rr71.1%

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

    if 2e3 < (/.f64 1 n) < 1.00000000000000002e198

    1. Initial program 73.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 67.0%

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

    if 1.00000000000000002e198 < (/.f64 1 n)

    1. Initial program 10.6%

      \[{\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 7.3%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative66.2%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified66.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-42}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{-105}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2000:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{+198}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 57.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.05:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 0.05) (/ (- x (log x)) n) (/ (/ 1.0 n) x)))
double code(double x, double n) {
	double tmp;
	if (x <= 0.05) {
		tmp = (x - log(x)) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 0.05d0) then
        tmp = (x - log(x)) / n
    else
        tmp = (1.0d0 / n) / x
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 0.05) {
		tmp = (x - Math.log(x)) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 0.05:
		tmp = (x - math.log(x)) / n
	else:
		tmp = (1.0 / n) / x
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 0.05)
		tmp = Float64(Float64(x - log(x)) / n);
	else
		tmp = Float64(Float64(1.0 / n) / x);
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 0.05)
		tmp = (x - log(x)) / n;
	else
		tmp = (1.0 / n) / x;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 0.05], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.05:\\
\;\;\;\;\frac{x - \log x}{n}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{n}}{x}\\


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

    1. Initial program 44.6%

      \[{\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 49.8%

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

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

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

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

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

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

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

    if 0.050000000000000003 < x

    1. Initial program 59.5%

      \[{\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 57.7%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified71.3%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    9. Step-by-step derivation
      1. clear-num71.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot n}{1}}} \]
      2. associate-/r/71.3%

        \[\leadsto \color{blue}{\frac{1}{x \cdot n} \cdot 1} \]
      3. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{n \cdot x}} \cdot 1 \]
      4. associate-/r*72.9%

        \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \cdot 1 \]
    10. Applied egg-rr72.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x} \cdot 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification59.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.05:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 57.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.04:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 0.04) (/ (- (log x)) n) (/ (/ 1.0 n) x)))
double code(double x, double n) {
	double tmp;
	if (x <= 0.04) {
		tmp = -log(x) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 0.04d0) then
        tmp = -log(x) / n
    else
        tmp = (1.0d0 / n) / x
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 0.04) {
		tmp = -Math.log(x) / n;
	} else {
		tmp = (1.0 / n) / x;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 0.04:
		tmp = -math.log(x) / n
	else:
		tmp = (1.0 / n) / x
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 0.04)
		tmp = Float64(Float64(-log(x)) / n);
	else
		tmp = Float64(Float64(1.0 / n) / x);
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 0.04)
		tmp = -log(x) / n;
	else
		tmp = (1.0 / n) / x;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 0.04], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.04:\\
\;\;\;\;\frac{-\log x}{n}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{n}}{x}\\


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

    1. Initial program 44.6%

      \[{\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 44.0%

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

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

        \[\leadsto \color{blue}{-\frac{\log x}{n}} \]
      2. distribute-neg-frac48.8%

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

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

    if 0.0400000000000000008 < x

    1. Initial program 59.5%

      \[{\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 57.7%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    8. Simplified71.3%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    9. Step-by-step derivation
      1. clear-num71.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot n}{1}}} \]
      2. associate-/r/71.3%

        \[\leadsto \color{blue}{\frac{1}{x \cdot n} \cdot 1} \]
      3. *-commutative71.3%

        \[\leadsto \frac{1}{\color{blue}{n \cdot x}} \cdot 1 \]
      4. associate-/r*72.9%

        \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \cdot 1 \]
    10. Applied egg-rr72.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x} \cdot 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.04:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 40.3% accurate, 42.2× speedup?

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

\\
\frac{1}{n \cdot x}
\end{array}
Derivation
  1. Initial program 50.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 53.1%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
  7. Step-by-step derivation
    1. *-commutative43.3%

      \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
  8. Simplified43.3%

    \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
  9. Final simplification43.3%

    \[\leadsto \frac{1}{n \cdot x} \]
  10. Add Preprocessing

Alternative 13: 40.8% accurate, 42.2× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{x}}{n} \end{array} \]
(FPCore (x n) :precision binary64 (/ (/ 1.0 x) n))
double code(double x, double n) {
	return (1.0 / x) / n;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = (1.0d0 / x) / n
end function
public static double code(double x, double n) {
	return (1.0 / x) / n;
}
def code(x, n):
	return (1.0 / x) / n
function code(x, n)
	return Float64(Float64(1.0 / x) / n)
end
function tmp = code(x, n)
	tmp = (1.0 / x) / n;
end
code[x_, n_] := N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{x}}{n}
\end{array}
Derivation
  1. Initial program 50.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 53.1%

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{1}{x}}}{n} \]
  7. Final simplification43.9%

    \[\leadsto \frac{\frac{1}{x}}{n} \]
  8. Add Preprocessing

Alternative 14: 40.8% accurate, 42.2× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{n}}{x} \end{array} \]
(FPCore (x n) :precision binary64 (/ (/ 1.0 n) x))
double code(double x, double n) {
	return (1.0 / n) / x;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = (1.0d0 / n) / x
end function
public static double code(double x, double n) {
	return (1.0 / n) / x;
}
def code(x, n):
	return (1.0 / n) / x
function code(x, n)
	return Float64(Float64(1.0 / n) / x)
end
function tmp = code(x, n)
	tmp = (1.0 / n) / x;
end
code[x_, n_] := N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{1}{n}}{x}
\end{array}
Derivation
  1. Initial program 50.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 53.1%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
  7. Step-by-step derivation
    1. *-commutative43.3%

      \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
  8. Simplified43.3%

    \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
  9. Step-by-step derivation
    1. clear-num43.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot n}{1}}} \]
    2. associate-/r/43.3%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n} \cdot 1} \]
    3. *-commutative43.3%

      \[\leadsto \frac{1}{\color{blue}{n \cdot x}} \cdot 1 \]
    4. associate-/r*44.0%

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \cdot 1 \]
  10. Applied egg-rr44.0%

    \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x} \cdot 1} \]
  11. Final simplification44.0%

    \[\leadsto \frac{\frac{1}{n}}{x} \]
  12. Add Preprocessing

Alternative 15: 4.5% accurate, 70.3× speedup?

\[\begin{array}{l} \\ \frac{x}{n} \end{array} \]
(FPCore (x n) :precision binary64 (/ x n))
double code(double x, double n) {
	return x / n;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = x / n
end function
public static double code(double x, double n) {
	return x / n;
}
def code(x, n):
	return x / n
function code(x, n)
	return Float64(x / n)
end
function tmp = code(x, n)
	tmp = x / n;
end
code[x_, n_] := N[(x / n), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{n}
\end{array}
Derivation
  1. Initial program 50.8%

    \[{\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 32.7%

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

    \[\leadsto \color{blue}{\frac{x}{n}} \]
  5. Final simplification4.4%

    \[\leadsto \frac{x}{n} \]
  6. Add Preprocessing

Reproduce

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