2nthrt (problem 3.4.6)

Percentage Accurate: 53.1% → 84.2%
Time: 20.5s
Alternatives: 12
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 12 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.1% 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: 84.2% accurate, 0.7× speedup?

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

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

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

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


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

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}} \]
      2. div-inv92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}} \]
    7. Step-by-step derivation
      1. un-div-inv92.1%

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

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

    if -5.00000000000000003e-151 < (/.f64 1 n) < 9.99999999999999908e-22

    1. Initial program 33.8%

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

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

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

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

    if 9.99999999999999908e-22 < (/.f64 1 n)

    1. Initial program 52.9%

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

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

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

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

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

Alternative 2: 79.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\ \;\;\;\;\frac{\frac{t_0}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\ \;\;\;\;\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-151)
     (/ (/ t_0 x) n)
     (if (<= (/ 1.0 n) 5e-9)
       (/ (- (log1p x) (log x)) n)
       (if (<= (/ 1.0 n) 2e+187) (- (+ 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-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (log1p(x) - log(x)) / n;
	} else if ((1.0 / n) <= 2e+187) {
		tmp = (1.0 + (x / n)) - t_0;
	} else {
		tmp = 1.0 / (n * x);
	}
	return tmp;
}
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -5e-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (Math.log1p(x) - Math.log(x)) / n;
	} else if ((1.0 / n) <= 2e+187) {
		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-151:
		tmp = (t_0 / x) / n
	elif (1.0 / n) <= 5e-9:
		tmp = (math.log1p(x) - math.log(x)) / n
	elif (1.0 / n) <= 2e+187:
		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-151)
		tmp = Float64(Float64(t_0 / x) / n);
	elseif (Float64(1.0 / n) <= 5e-9)
		tmp = Float64(Float64(log1p(x) - log(x)) / n);
	elseif (Float64(1.0 / n) <= 2e+187)
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	else
		tmp = Float64(1.0 / Float64(n * x));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], 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^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\

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

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;\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) < -5.00000000000000003e-151

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}} \]
      2. div-inv92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}} \]
    7. Step-by-step derivation
      1. un-div-inv92.1%

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

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

    if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9

    1. Initial program 33.4%

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

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

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

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

    if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187

    1. Initial program 78.9%

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

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

    if 1.99999999999999981e187 < (/.f64 1 n)

    1. Initial program 3.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\ \;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n \cdot x}\\ \end{array} \]

Alternative 3: 79.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\ \;\;\;\;\frac{\frac{t_0}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\ \;\;\;\;\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-151)
     (/ (/ t_0 x) n)
     (if (<= (/ 1.0 n) 5e-9)
       (* (/ 1.0 n) (log (/ (+ 1.0 x) x)))
       (if (<= (/ 1.0 n) 2e+187) (- (+ 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-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (1.0 / n) * log(((1.0 + x) / x));
	} else if ((1.0 / n) <= 2e+187) {
		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-151)) then
        tmp = (t_0 / x) / n
    else if ((1.0d0 / n) <= 5d-9) then
        tmp = (1.0d0 / n) * log(((1.0d0 + x) / x))
    else if ((1.0d0 / n) <= 2d+187) 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-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (1.0 / n) * Math.log(((1.0 + x) / x));
	} else if ((1.0 / n) <= 2e+187) {
		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-151:
		tmp = (t_0 / x) / n
	elif (1.0 / n) <= 5e-9:
		tmp = (1.0 / n) * math.log(((1.0 + x) / x))
	elif (1.0 / n) <= 2e+187:
		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-151)
		tmp = Float64(Float64(t_0 / x) / n);
	elseif (Float64(1.0 / n) <= 5e-9)
		tmp = Float64(Float64(1.0 / n) * log(Float64(Float64(1.0 + x) / x)));
	elseif (Float64(1.0 / n) <= 2e+187)
		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-151)
		tmp = (t_0 / x) / n;
	elseif ((1.0 / n) <= 5e-9)
		tmp = (1.0 / n) * log(((1.0 + x) / x));
	elseif ((1.0 / n) <= 2e+187)
		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-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(1.0 / n), $MachinePrecision] * N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], 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^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\

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

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;\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) < -5.00000000000000003e-151

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}} \]
      2. div-inv92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}} \]
    7. Step-by-step derivation
      1. un-div-inv92.1%

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

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

    if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9

    1. Initial program 33.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{log1p}\left(x\right) - \log x\right) \cdot \frac{1}{n}} \]
      2. *-commutative86.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)} \]
    10. Simplified86.7%

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

    if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187

    1. Initial program 78.9%

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

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

    if 1.99999999999999981e187 < (/.f64 1 n)

    1. Initial program 3.1%

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

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

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

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

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

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

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

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

Alternative 4: 79.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\ \;\;\;\;\frac{\frac{t_0}{x}}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\ \;\;\;\;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-151)
     (/ (/ t_0 x) n)
     (if (<= (/ 1.0 n) 5e-9)
       (* (/ 1.0 n) (log (/ (+ 1.0 x) x)))
       (if (<= (/ 1.0 n) 2e+187) (- 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-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (1.0 / n) * log(((1.0 + x) / x));
	} else if ((1.0 / n) <= 2e+187) {
		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-151)) then
        tmp = (t_0 / x) / n
    else if ((1.0d0 / n) <= 5d-9) then
        tmp = (1.0d0 / n) * log(((1.0d0 + x) / x))
    else if ((1.0d0 / n) <= 2d+187) 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-151) {
		tmp = (t_0 / x) / n;
	} else if ((1.0 / n) <= 5e-9) {
		tmp = (1.0 / n) * Math.log(((1.0 + x) / x));
	} else if ((1.0 / n) <= 2e+187) {
		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-151:
		tmp = (t_0 / x) / n
	elif (1.0 / n) <= 5e-9:
		tmp = (1.0 / n) * math.log(((1.0 + x) / x))
	elif (1.0 / n) <= 2e+187:
		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-151)
		tmp = Float64(Float64(t_0 / x) / n);
	elseif (Float64(1.0 / n) <= 5e-9)
		tmp = Float64(Float64(1.0 / n) * log(Float64(Float64(1.0 + x) / x)));
	elseif (Float64(1.0 / n) <= 2e+187)
		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-151)
		tmp = (t_0 / x) / n;
	elseif ((1.0 / n) <= 5e-9)
		tmp = (1.0 / n) * log(((1.0 + x) / x));
	elseif ((1.0 / n) <= 2e+187)
		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-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(1.0 / n), $MachinePrecision] * N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], 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^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\

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

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;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-151

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}} \]
      2. div-inv92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}} \]
    7. Step-by-step derivation
      1. un-div-inv92.1%

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

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

    if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9

    1. Initial program 33.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{log1p}\left(x\right) - \log x\right) \cdot \frac{1}{n}} \]
      2. *-commutative86.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)} \]
    10. Simplified86.7%

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

    if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187

    1. Initial program 78.9%

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

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

    if 1.99999999999999981e187 < (/.f64 1 n)

    1. Initial program 3.1%

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

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

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

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

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

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

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

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

Alternative 5: 61.0% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.45 \cdot 10^{+197}:\\
\;\;\;\;\log x \cdot \frac{-1}{n}\\

\mathbf{elif}\;n \leq -10.5:\\
\;\;\;\;\frac{1}{n} \cdot \frac{1}{x}\\

\mathbf{elif}\;n \leq 2.5 \cdot 10^{-188}:\\
\;\;\;\;\frac{0.3333333333333333}{n \cdot {x}^{3}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if n < -1.45000000000000001e197

    1. Initial program 31.3%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{n} \cdot \left(\mathsf{log1p}\left(x\right) - \log x\right)} \]
    6. Applied egg-rr98.9%

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

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

        \[\leadsto \frac{\color{blue}{-\log x}}{n} \]
    9. Simplified68.0%

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

    if -1.45000000000000001e197 < n < -10.5

    1. Initial program 16.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{n}} \]
      2. div-inv65.4%

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

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

    if -10.5 < n < 2.5e-188

    1. Initial program 88.3%

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

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

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

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

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{n \cdot {x}^{3}} + \frac{1}{n \cdot x}\right) - 0.5 \cdot \frac{1}{n \cdot {x}^{2}}} \]
    6. Taylor expanded in x around 0 80.8%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{n \cdot {x}^{3}}} \]

    if 2.5e-188 < n < 2.3e8

    1. Initial program 78.9%

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

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

    if 2.3e8 < n

    1. Initial program 33.1%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1}{n}} \]
      2. add-sqr-sqrt51.3%

        \[\leadsto \frac{1}{x} \cdot \color{blue}{\left(\sqrt{\frac{1}{n}} \cdot \sqrt{\frac{1}{n}}\right)} \]
      3. associate-*r*51.3%

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

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

        \[\leadsto \left(\frac{1}{x} \cdot \sqrt{{n}^{\color{blue}{\left(-1\right)}}}\right) \cdot \sqrt{\frac{1}{n}} \]
      6. sqrt-pow151.3%

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

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

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{\color{blue}{-0.5}}\right) \cdot \sqrt{\frac{1}{n}} \]
      9. inv-pow51.3%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{\color{blue}{{n}^{-1}}} \]
      10. metadata-eval51.3%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{{n}^{\color{blue}{\left(-1\right)}}} \]
      11. sqrt-pow151.3%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \color{blue}{{n}^{\left(\frac{-1}{2}\right)}} \]
      12. metadata-eval51.3%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      13. metadata-eval51.3%

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

      \[\leadsto \color{blue}{\left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{-0.5}} \]
    8. Step-by-step derivation
      1. associate-*l/51.3%

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

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

        \[\leadsto \frac{\color{blue}{{n}^{-0.5}} \cdot {n}^{-0.5}}{x} \]
      4. pow-sqr51.4%

        \[\leadsto \frac{\color{blue}{{n}^{\left(2 \cdot -0.5\right)}}}{x} \]
      5. metadata-eval51.4%

        \[\leadsto \frac{{n}^{\color{blue}{-1}}}{x} \]
    9. Simplified51.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.45 \cdot 10^{+197}:\\ \;\;\;\;\log x \cdot \frac{-1}{n}\\ \mathbf{elif}\;n \leq -10.5:\\ \;\;\;\;\frac{1}{n} \cdot \frac{1}{x}\\ \mathbf{elif}\;n \leq 2.5 \cdot 10^{-188}:\\ \;\;\;\;\frac{0.3333333333333333}{n \cdot {x}^{3}}\\ \mathbf{elif}\;n \leq 230000000:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{{n}^{-1}}{x}\\ \end{array} \]

Alternative 6: 71.0% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 55.1%

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

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

    if 6.2000000000000001e-164 < x < 0.095000000000000001

    1. Initial program 27.5%

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

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

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

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

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

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

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

    if 0.095000000000000001 < x

    1. Initial program 69.6%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Taylor expanded in x around inf 96.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. mul-1-neg96.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{e^{\frac{\log x}{n}}}{x}}{n}} \]
      2. div-inv97.9%

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

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

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

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}} \]
    7. Step-by-step derivation
      1. un-div-inv97.9%

        \[\leadsto \color{blue}{\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}} \]
    8. Applied egg-rr97.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6.2 \cdot 10^{-164}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 0.095:\\ \;\;\;\;\frac{x}{n} - \frac{\log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}\\ \end{array} \]

Alternative 7: 56.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-164}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\

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

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


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

    1. Initial program 55.1%

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

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

    if 3.99999999999999985e-164 < x < 0.54000000000000004

    1. Initial program 27.5%

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

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

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

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

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

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

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

    if 0.54000000000000004 < x

    1. Initial program 69.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x}}}{n} \]
    6. Step-by-step derivation
      1. div-inv58.0%

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1}{n}} \]
      2. add-sqr-sqrt30.5%

        \[\leadsto \frac{1}{x} \cdot \color{blue}{\left(\sqrt{\frac{1}{n}} \cdot \sqrt{\frac{1}{n}}\right)} \]
      3. associate-*r*30.5%

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

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

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

        \[\leadsto \left(\frac{1}{x} \cdot \color{blue}{{n}^{\left(\frac{-1}{2}\right)}}\right) \cdot \sqrt{\frac{1}{n}} \]
      7. metadata-eval30.5%

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

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

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{\color{blue}{{n}^{-1}}} \]
      10. metadata-eval30.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{{n}^{\color{blue}{\left(-1\right)}}} \]
      11. sqrt-pow130.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \color{blue}{{n}^{\left(\frac{-1}{2}\right)}} \]
      12. metadata-eval30.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      13. metadata-eval30.5%

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

      \[\leadsto \color{blue}{\left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{-0.5}} \]
    8. Step-by-step derivation
      1. associate-*l/30.5%

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

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

        \[\leadsto \frac{\color{blue}{{n}^{-0.5}} \cdot {n}^{-0.5}}{x} \]
      4. pow-sqr58.0%

        \[\leadsto \frac{\color{blue}{{n}^{\left(2 \cdot -0.5\right)}}}{x} \]
      5. metadata-eval58.0%

        \[\leadsto \frac{{n}^{\color{blue}{-1}}}{x} \]
    9. Simplified58.0%

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

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

Alternative 8: 57.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.54:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n} \cdot \frac{1}{x}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 0.54) (/ (- (log x)) n) (* (/ 1.0 n) (/ 1.0 x))))
double code(double x, double n) {
	double tmp;
	if (x <= 0.54) {
		tmp = -log(x) / n;
	} else {
		tmp = (1.0 / n) * (1.0 / 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.54d0) then
        tmp = -log(x) / n
    else
        tmp = (1.0d0 / n) * (1.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 0.54) {
		tmp = -Math.log(x) / n;
	} else {
		tmp = (1.0 / n) * (1.0 / x);
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 0.54:
		tmp = -math.log(x) / n
	else:
		tmp = (1.0 / n) * (1.0 / x)
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 0.54)
		tmp = Float64(Float64(-log(x)) / n);
	else
		tmp = Float64(Float64(1.0 / n) * Float64(1.0 / x));
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 0.54)
		tmp = -log(x) / n;
	else
		tmp = (1.0 / n) * (1.0 / x);
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 0.54], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[(1.0 / n), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 40.3%

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

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

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

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

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

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

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

    if 0.54000000000000004 < x

    1. Initial program 69.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{n}} \]
      2. div-inv58.0%

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

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

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

Alternative 9: 57.2% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 40.3%

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

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

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

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

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

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

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

    if 0.55000000000000004 < x

    1. Initial program 69.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x}}}{n} \]
    6. Step-by-step derivation
      1. div-inv58.0%

        \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1}{n}} \]
      2. add-sqr-sqrt30.5%

        \[\leadsto \frac{1}{x} \cdot \color{blue}{\left(\sqrt{\frac{1}{n}} \cdot \sqrt{\frac{1}{n}}\right)} \]
      3. associate-*r*30.5%

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

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

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

        \[\leadsto \left(\frac{1}{x} \cdot \color{blue}{{n}^{\left(\frac{-1}{2}\right)}}\right) \cdot \sqrt{\frac{1}{n}} \]
      7. metadata-eval30.5%

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

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

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{\color{blue}{{n}^{-1}}} \]
      10. metadata-eval30.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \sqrt{{n}^{\color{blue}{\left(-1\right)}}} \]
      11. sqrt-pow130.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot \color{blue}{{n}^{\left(\frac{-1}{2}\right)}} \]
      12. metadata-eval30.5%

        \[\leadsto \left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      13. metadata-eval30.5%

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

      \[\leadsto \color{blue}{\left(\frac{1}{x} \cdot {n}^{-0.5}\right) \cdot {n}^{-0.5}} \]
    8. Step-by-step derivation
      1. associate-*l/30.5%

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

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

        \[\leadsto \frac{\color{blue}{{n}^{-0.5}} \cdot {n}^{-0.5}}{x} \]
      4. pow-sqr58.0%

        \[\leadsto \frac{\color{blue}{{n}^{\left(2 \cdot -0.5\right)}}}{x} \]
      5. metadata-eval58.0%

        \[\leadsto \frac{{n}^{\color{blue}{-1}}}{x} \]
    9. Simplified58.0%

      \[\leadsto \color{blue}{\frac{{n}^{-1}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification54.9%

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

Alternative 10: 41.1% accurate, 30.1× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{n}} \]
    2. div-inv40.1%

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

    \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1}{n}} \]
  10. Final simplification40.1%

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

Alternative 11: 40.5% 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 54.0%

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

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

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

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

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

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

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

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

Alternative 12: 41.1% 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 54.0%

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

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

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

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

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

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

Reproduce

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