2nthrt (problem 3.4.6)

Percentage Accurate: 53.5% → 85.7%
Time: 22.1s
Alternatives: 13
Speedup: 2.0×

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 13 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: 53.5% 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.7% accurate, 0.9× 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 -1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n} + -0.5 \cdot \frac{x \cdot x}{n}} - t_0\\ \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) -1e-20)
     t_1
     (if (<= (/ 1.0 n) 5e-82)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 100000.0)
         t_1
         (- (exp (+ (/ x n) (* -0.5 (/ (* x x) n)))) t_0))))))
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) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else {
		tmp = exp(((x / n) + (-0.5 * ((x * 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) :: tmp
    t_0 = x ** (1.0d0 / n)
    t_1 = t_0 / (n * x)
    if ((1.0d0 / n) <= (-1d-20)) then
        tmp = t_1
    else if ((1.0d0 / n) <= 5d-82) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 100000.0d0) then
        tmp = t_1
    else
        tmp = exp(((x / n) + ((-0.5d0) * ((x * 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 = t_0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else {
		tmp = Math.exp(((x / n) + (-0.5 * ((x * x) / n)))) - t_0;
	}
	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) <= -1e-20:
		tmp = t_1
	elif (1.0 / n) <= 5e-82:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 100000.0:
		tmp = t_1
	else:
		tmp = math.exp(((x / n) + (-0.5 * ((x * x) / n)))) - t_0
	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) <= -1e-20)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 5e-82)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 100000.0)
		tmp = t_1;
	else
		tmp = Float64(exp(Float64(Float64(x / n) + Float64(-0.5 * Float64(Float64(x * x) / n)))) - t_0);
	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) <= -1e-20)
		tmp = t_1;
	elseif ((1.0 / n) <= 5e-82)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 100000.0)
		tmp = t_1;
	else
		tmp = exp(((x / n) + (-0.5 * ((x * 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[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-20], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-82], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 100000.0], t$95$1, N[(N[Exp[N[(N[(x / n), $MachinePrecision] + N[(-0.5 * N[(N[(x * x), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - t$95$0), $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 -1 \cdot 10^{-20}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -9.99999999999999945e-21 or 4.9999999999999998e-82 < (/.f64 1 n) < 1e5

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x} \]
      9. unpow-193.4%

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

        \[\leadsto \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x} \]
      11. unpow-193.4%

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

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

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

    if -9.99999999999999945e-21 < (/.f64 1 n) < 4.9999999999999998e-82

    1. Initial program 33.5%

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

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

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

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

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

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

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

    if 1e5 < (/.f64 1 n)

    1. Initial program 46.8%

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

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

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

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

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

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

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

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

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{{n}^{-1}}{\color{blue}{\frac{2}{2}}}\right)} \]
      8. associate-/l*100.0%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left(\frac{{n}^{-1} \cdot 2}{2}\right)}} \]
      9. *-commutative100.0%

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{\color{blue}{2 \cdot {n}^{-1}}}{2}\right)} \]
      10. *-commutative100.0%

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

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

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

        \[\leadsto e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left({n}^{-1}\right)}} \]
      14. unpow-1100.0%

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

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

      \[\leadsto e^{\color{blue}{\frac{x}{n} + -0.5 \cdot \frac{{x}^{2}}{n}}} - {x}^{\left(\frac{1}{n}\right)} \]
    6. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto e^{\frac{x}{n} + -0.5 \cdot \frac{\color{blue}{x \cdot x}}{n}} - {x}^{\left(\frac{1}{n}\right)} \]
    7. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n} + -0.5 \cdot \frac{x \cdot x}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]

Alternative 2: 82.0% 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}\\ t_2 := \frac{1}{n \cdot x}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{t_2 \cdot \frac{t_2}{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))) (t_2 (/ 1.0 (* n x))))
   (if (<= (/ 1.0 n) -1e-20)
     t_1
     (if (<= (/ 1.0 n) 5e-82)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 100000.0)
         t_1
         (if (<= (/ 1.0 n) 4e+195)
           (- (+ 1.0 (/ x n)) t_0)
           (cbrt (* t_2 (/ t_2 (* n x))))))))))
double code(double x, double n) {
	double t_0 = pow(x, (1.0 / n));
	double t_1 = t_0 / (n * x);
	double t_2 = 1.0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = cbrt((t_2 * (t_2 / (n * x))));
	}
	return tmp;
}
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 t_2 = 1.0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = Math.cbrt((t_2 * (t_2 / (n * x))));
	}
	return tmp;
}
function code(x, n)
	t_0 = x ^ Float64(1.0 / n)
	t_1 = Float64(t_0 / Float64(n * x))
	t_2 = Float64(1.0 / Float64(n * x))
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-20)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 5e-82)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 100000.0)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 4e+195)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = cbrt(Float64(t_2 * Float64(t_2 / Float64(n * x))));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-20], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-82], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 100000.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[Power[N[(t$95$2 * N[(t$95$2 / N[(n * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]]]]]]]]
\begin{array}{l}

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{t_2 \cdot \frac{t_2}{n \cdot x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -9.99999999999999945e-21 or 4.9999999999999998e-82 < (/.f64 1 n) < 1e5

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x} \]
      9. unpow-193.4%

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

        \[\leadsto \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x} \]
      11. unpow-193.4%

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

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

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

    if -9.99999999999999945e-21 < (/.f64 1 n) < 4.9999999999999998e-82

    1. Initial program 33.5%

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

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

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

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

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

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

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

    if 1e5 < (/.f64 1 n) < 3.99999999999999991e195

    1. Initial program 67.8%

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

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

    if 3.99999999999999991e195 < (/.f64 1 n)

    1. Initial program 20.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    7. Simplified74.6%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    8. Step-by-step derivation
      1. add-cbrt-cube80.6%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{1}{x \cdot n} \cdot \frac{1}{x \cdot n}\right) \cdot \frac{1}{x \cdot n}}} \]
    9. Applied egg-rr80.6%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{1}{x \cdot n} \cdot \frac{1}{x \cdot n}\right) \cdot \frac{1}{x \cdot n}}} \]
    10. Step-by-step derivation
      1. associate-*r/80.6%

        \[\leadsto \sqrt[3]{\color{blue}{\frac{\left(\frac{1}{x \cdot n} \cdot \frac{1}{x \cdot n}\right) \cdot 1}{x \cdot n}}} \]
      2. *-rgt-identity80.6%

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

        \[\leadsto \sqrt[3]{\color{blue}{\frac{1}{x \cdot n} \cdot \frac{\frac{1}{x \cdot n}}{x \cdot n}}} \]
    11. Simplified80.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{1}{n \cdot x} \cdot \frac{\frac{1}{n \cdot x}}{n \cdot x}}\\ \end{array} \]

Alternative 3: 81.1% accurate, 1.7× 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 -1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\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))) (t_1 (/ t_0 (* n x))))
   (if (<= (/ 1.0 n) -1e-20)
     t_1
     (if (<= (/ 1.0 n) 5e-82)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 100000.0)
         t_1
         (if (<= (/ 1.0 n) 4e+195)
           (- (+ 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 t_1 = t_0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		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) :: t_1
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    t_1 = t_0 / (n * x)
    if ((1.0d0 / n) <= (-1d-20)) then
        tmp = t_1
    else if ((1.0d0 / n) <= 5d-82) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 100000.0d0) then
        tmp = t_1
    else if ((1.0d0 / n) <= 4d+195) 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 t_1 = t_0 / (n * x);
	double tmp;
	if ((1.0 / n) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		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))
	t_1 = t_0 / (n * x)
	tmp = 0
	if (1.0 / n) <= -1e-20:
		tmp = t_1
	elif (1.0 / n) <= 5e-82:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 100000.0:
		tmp = t_1
	elif (1.0 / n) <= 4e+195:
		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)
	t_1 = Float64(t_0 / Float64(n * x))
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-20)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 5e-82)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 100000.0)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 4e+195)
		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);
	t_1 = t_0 / (n * x);
	tmp = 0.0;
	if ((1.0 / n) <= -1e-20)
		tmp = t_1;
	elseif ((1.0 / n) <= 5e-82)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 100000.0)
		tmp = t_1;
	elseif ((1.0 / n) <= 4e+195)
		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]}, Block[{t$95$1 = N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-20], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-82], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 100000.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], 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)}\\
t_1 := \frac{t_0}{n \cdot x}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - 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) < -9.99999999999999945e-21 or 4.9999999999999998e-82 < (/.f64 1 n) < 1e5

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x} \]
      9. unpow-193.4%

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

        \[\leadsto \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x} \]
      11. unpow-193.4%

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

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

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

    if -9.99999999999999945e-21 < (/.f64 1 n) < 4.9999999999999998e-82

    1. Initial program 33.5%

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

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

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

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

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

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

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

    if 1e5 < (/.f64 1 n) < 3.99999999999999991e195

    1. Initial program 67.8%

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

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

    if 3.99999999999999991e195 < (/.f64 1 n)

    1. Initial program 20.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    7. Simplified74.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]

Alternative 4: 81.0% accurate, 1.7× 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 -1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;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) -1e-20)
     t_1
     (if (<= (/ 1.0 n) 5e-82)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 100000.0)
         t_1
         (if (<= (/ 1.0 n) 4e+195) (- 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) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		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) <= (-1d-20)) then
        tmp = t_1
    else if ((1.0d0 / n) <= 5d-82) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 100000.0d0) then
        tmp = t_1
    else if ((1.0d0 / n) <= 4d+195) 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) <= -1e-20) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-82) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 100000.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 4e+195) {
		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) <= -1e-20:
		tmp = t_1
	elif (1.0 / n) <= 5e-82:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 100000.0:
		tmp = t_1
	elif (1.0 / n) <= 4e+195:
		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) <= -1e-20)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 5e-82)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 100000.0)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 4e+195)
		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) <= -1e-20)
		tmp = t_1;
	elseif ((1.0 / n) <= 5e-82)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 100000.0)
		tmp = t_1;
	elseif ((1.0 / n) <= 4e+195)
		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], -1e-20], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-82], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 100000.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], 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 -1 \cdot 10^{-20}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;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) < -9.99999999999999945e-21 or 4.9999999999999998e-82 < (/.f64 1 n) < 1e5

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x} \]
      9. unpow-193.4%

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

        \[\leadsto \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x} \]
      11. unpow-193.4%

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

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

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

    if -9.99999999999999945e-21 < (/.f64 1 n) < 4.9999999999999998e-82

    1. Initial program 33.5%

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

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

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

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

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

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

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

    if 1e5 < (/.f64 1 n) < 3.99999999999999991e195

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

    if 3.99999999999999991e195 < (/.f64 1 n)

    1. Initial program 20.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    7. Simplified74.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-20}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 100000:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]

Alternative 5: 66.6% accurate, 1.8× speedup?

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

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

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

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

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


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

    1. Initial program 53.2%

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

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

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

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

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

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

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

    if 4.9999999999999998e-82 < (/.f64 1 n) < 2e-3

    1. Initial program 4.9%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{n \cdot x}} \]
    6. Step-by-step derivation
      1. *-commutative68.4%

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    7. Simplified68.4%

      \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
    8. Taylor expanded in x around 0 68.4%

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

        \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \]
    10. Simplified68.6%

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

    if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

    if 3.99999999999999991e195 < (/.f64 1 n)

    1. Initial program 20.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
    7. Simplified74.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq 5 \cdot 10^{-82}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 0.002:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]

Alternative 6: 60.2% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;x \leq 4.2 \cdot 10^{+123}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\

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


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

    1. Initial program 34.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{x - \log x}}{n} \]
    8. Step-by-step derivation
      1. div-sub58.4%

        \[\leadsto \color{blue}{\frac{x}{n} - \frac{\log x}{n}} \]
    9. Applied egg-rr58.4%

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

    if 0.95999999999999996 < x < 4.19999999999999988e123

    1. Initial program 42.3%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - 0.5 \cdot \frac{1}{{x}^{2}}}}{n} \]
    6. Step-by-step derivation
      1. associate-*r/70.1%

        \[\leadsto \frac{\frac{1}{x} - \color{blue}{\frac{0.5 \cdot 1}{{x}^{2}}}}{n} \]
      2. metadata-eval70.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{\color{blue}{0.5}}{{x}^{2}}}{n} \]
      3. unpow270.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{0.5}{\color{blue}{x \cdot x}}}{n} \]
    7. Simplified70.1%

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

    if 4.19999999999999988e123 < x

    1. Initial program 80.7%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Taylor expanded in x around inf 80.7%

      \[\leadsto \frac{\log \color{blue}{1}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.96:\\ \;\;\;\;\frac{x}{n} - \frac{\log x}{n}\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{+123}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{n}\\ \end{array} \]

Alternative 7: 60.2% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;x \leq 1.7 \cdot 10^{+124}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\

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


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

    1. Initial program 34.5%

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

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

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

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

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

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

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

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

    if 1 < x < 1.7e124

    1. Initial program 42.3%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - 0.5 \cdot \frac{1}{{x}^{2}}}}{n} \]
    6. Step-by-step derivation
      1. associate-*r/70.1%

        \[\leadsto \frac{\frac{1}{x} - \color{blue}{\frac{0.5 \cdot 1}{{x}^{2}}}}{n} \]
      2. metadata-eval70.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{\color{blue}{0.5}}{{x}^{2}}}{n} \]
      3. unpow270.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{0.5}{\color{blue}{x \cdot x}}}{n} \]
    7. Simplified70.1%

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

    if 1.7e124 < x

    1. Initial program 80.7%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Taylor expanded in x around inf 80.7%

      \[\leadsto \frac{\log \color{blue}{1}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+124}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{n}\\ \end{array} \]

Alternative 8: 60.0% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;x \leq 4.8 \cdot 10^{+123}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\

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


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

    1. Initial program 34.5%

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

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

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

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

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

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

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

    if 0.69999999999999996 < x < 4.79999999999999978e123

    1. Initial program 42.3%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - 0.5 \cdot \frac{1}{{x}^{2}}}}{n} \]
    6. Step-by-step derivation
      1. associate-*r/70.1%

        \[\leadsto \frac{\frac{1}{x} - \color{blue}{\frac{0.5 \cdot 1}{{x}^{2}}}}{n} \]
      2. metadata-eval70.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{\color{blue}{0.5}}{{x}^{2}}}{n} \]
      3. unpow270.1%

        \[\leadsto \frac{\frac{1}{x} - \frac{0.5}{\color{blue}{x \cdot x}}}{n} \]
    7. Simplified70.1%

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

    if 4.79999999999999978e123 < x

    1. Initial program 80.7%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Taylor expanded in x around inf 80.7%

      \[\leadsto \frac{\log \color{blue}{1}}{n} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.7:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+123}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{n}\\ \end{array} \]

Alternative 9: 46.8% accurate, 23.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -2000:\\
\;\;\;\;\frac{0}{n}\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    7. Taylor expanded in x around inf 58.7%

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

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

    1. Initial program 32.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -2000:\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \]

Alternative 10: 39.2% 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 48.9%

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
  7. Simplified42.7%

    \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
  8. Final simplification42.7%

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

Alternative 11: 39.6% 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 48.9%

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{x \cdot n}} \]
  7. Simplified42.7%

    \[\leadsto \color{blue}{\frac{1}{x \cdot n}} \]
  8. Taylor expanded in x around 0 42.7%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{n}}{x}} \]
  10. Simplified42.9%

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

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

Alternative 12: 39.6% 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 48.9%

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

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

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

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

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

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

Alternative 13: 4.6% 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 48.9%

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

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

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

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

Reproduce

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