2nthrt (problem 3.4.6)

Percentage Accurate: 53.2% → 85.9%
Time: 28.2s
Alternatives: 10
Speedup: 1.6×

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 10 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.2% 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.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{if}\;n \leq -22000000000:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;n \leq 1.32 \cdot 10^{+66}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -2.2e10 or 1.32000000000000009e66 < n

    1. Initial program 28.6%

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

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

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

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

    if -2.2e10 < n < 0.00220000000000000013

    1. Initial program 86.6%

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

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

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

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

    if 0.00220000000000000013 < n < 1.32000000000000009e66

    1. Initial program 12.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.2%

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

Alternative 2: 86.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq -33000000 \lor \neg \left(n \leq 65000000\right):\\ \;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (or (<= n -33000000.0) (not (<= n 65000000.0)))
   (+
    (/ (log (/ (+ x 1.0) x)) n)
    (*
     0.5
     (-
      (/ (pow (log1p x) 2.0) (pow n 2.0))
      (/ (pow (log x) 2.0) (pow n 2.0)))))
   (- (exp (/ (log1p x) n)) (pow x (/ 1.0 n)))))
double code(double x, double n) {
	double tmp;
	if ((n <= -33000000.0) || !(n <= 65000000.0)) {
		tmp = (log(((x + 1.0) / x)) / n) + (0.5 * ((pow(log1p(x), 2.0) / pow(n, 2.0)) - (pow(log(x), 2.0) / pow(n, 2.0))));
	} else {
		tmp = exp((log1p(x) / n)) - pow(x, (1.0 / n));
	}
	return tmp;
}
public static double code(double x, double n) {
	double tmp;
	if ((n <= -33000000.0) || !(n <= 65000000.0)) {
		tmp = (Math.log(((x + 1.0) / x)) / n) + (0.5 * ((Math.pow(Math.log1p(x), 2.0) / Math.pow(n, 2.0)) - (Math.pow(Math.log(x), 2.0) / Math.pow(n, 2.0))));
	} else {
		tmp = Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n));
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if (n <= -33000000.0) or not (n <= 65000000.0):
		tmp = (math.log(((x + 1.0) / x)) / n) + (0.5 * ((math.pow(math.log1p(x), 2.0) / math.pow(n, 2.0)) - (math.pow(math.log(x), 2.0) / math.pow(n, 2.0))))
	else:
		tmp = math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n))
	return tmp
function code(x, n)
	tmp = 0.0
	if ((n <= -33000000.0) || !(n <= 65000000.0))
		tmp = Float64(Float64(log(Float64(Float64(x + 1.0) / x)) / n) + Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) / (n ^ 2.0)) - Float64((log(x) ^ 2.0) / (n ^ 2.0)))));
	else
		tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n)));
	end
	return tmp
end
code[x_, n_] := If[Or[LessEqual[n, -33000000.0], N[Not[LessEqual[n, 65000000.0]], $MachinePrecision]], N[(N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] + N[(0.5 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq -33000000 \lor \neg \left(n \leq 65000000\right):\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -3.3e7 or 6.5e7 < n

    1. Initial program 26.5%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \left(\color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right) \]
      5. remove-double-neg76.7%

        \[\leadsto 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \left(\frac{\color{blue}{-\left(-\left(\log \left(1 + x\right) - \log x\right)\right)}}{n} - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right) \]
      6. mul-1-neg76.7%

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

        \[\leadsto 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \left(\frac{-\color{blue}{\left(-1 \cdot \log \left(1 + x\right) - -1 \cdot \log x\right)}}{n} - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right) \]
      8. distribute-neg-frac76.7%

        \[\leadsto 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \left(\color{blue}{\left(-\frac{-1 \cdot \log \left(1 + x\right) - -1 \cdot \log x}{n}\right)} - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right) \]
      9. mul-1-neg76.7%

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

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

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

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

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

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

    if -3.3e7 < n < 6.5e7

    1. Initial program 85.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -33000000 \lor \neg \left(n \leq 65000000\right):\\ \;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.0% 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 -50:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-69}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|1 - t_0\right|\\ \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) -50.0)
     t_1
     (if (<= (/ 1.0 n) 5e-69)
       (/ (- (log1p x) (log x)) n)
       (if (<= (/ 1.0 n) 2e-26) t_1 (fabs (- 1.0 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) <= -50.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-69) {
		tmp = (log1p(x) - log(x)) / n;
	} else if ((1.0 / n) <= 2e-26) {
		tmp = t_1;
	} else {
		tmp = fabs((1.0 - t_0));
	}
	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 tmp;
	if ((1.0 / n) <= -50.0) {
		tmp = t_1;
	} else if ((1.0 / n) <= 5e-69) {
		tmp = (Math.log1p(x) - Math.log(x)) / n;
	} else if ((1.0 / n) <= 2e-26) {
		tmp = t_1;
	} else {
		tmp = Math.abs((1.0 - 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) <= -50.0:
		tmp = t_1
	elif (1.0 / n) <= 5e-69:
		tmp = (math.log1p(x) - math.log(x)) / n
	elif (1.0 / n) <= 2e-26:
		tmp = t_1
	else:
		tmp = math.fabs((1.0 - 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) <= -50.0)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 5e-69)
		tmp = Float64(Float64(log1p(x) - log(x)) / n);
	elseif (Float64(1.0 / n) <= 2e-26)
		tmp = t_1;
	else
		tmp = abs(Float64(1.0 - t_0));
	end
	return tmp
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -50.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-69], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-26], t$95$1, N[Abs[N[(1.0 - t$95$0), $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 -50:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-26}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\left|1 - t_0\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -50 or 5.00000000000000033e-69 < (/.f64 1 n) < 2.0000000000000001e-26

    1. Initial program 84.1%

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

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

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

      \[\leadsto \color{blue}{e^{\frac{\mathsf{log1p}\left(x\right)}{n}}} - {x}^{\left(\frac{1}{n}\right)} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube84.1%

        \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      2. pow1/345.2%

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

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

        \[\leadsto \color{blue}{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{0.3333333333333333} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333}} \]
      5. pow1/384.1%

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

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\color{blue}{\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}}^{0.3333333333333333} \]
    7. Applied egg-rr84.1%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}^{0.3333333333333333}} \]
    8. Step-by-step derivation
      1. unpow1/384.1%

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

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    10. Taylor expanded in x around inf 94.7%

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

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

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

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

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

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

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

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

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

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

    if -50 < (/.f64 1 n) < 5.00000000000000033e-69

    1. Initial program 29.6%

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

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

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

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

    if 2.0000000000000001e-26 < (/.f64 1 n)

    1. Initial program 61.3%

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

      \[\leadsto \color{blue}{1} - {x}^{\left(\frac{1}{n}\right)} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt57.2%

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(1 - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    5. Applied egg-rr59.4%

      \[\leadsto \color{blue}{\sqrt{{\left(1 - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    6. Step-by-step derivation
      1. unpow259.4%

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

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

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

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

Alternative 4: 85.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{if}\;n \leq -3600000:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;n \leq 1.95 \cdot 10^{+66}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -3.6e6 or 1.9500000000000002e66 < n

    1. Initial program 29.0%

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

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

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

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

    if -3.6e6 < n < 0.00339999999999999981

    1. Initial program 87.3%

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

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

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

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

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

    if 0.00339999999999999981 < n < 1.9500000000000002e66

    1. Initial program 12.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -50 or 5.00000000000000033e-69 < (/.f64 1 n) < 50

    1. Initial program 81.7%

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

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

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

      \[\leadsto \color{blue}{e^{\frac{\mathsf{log1p}\left(x\right)}{n}}} - {x}^{\left(\frac{1}{n}\right)} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube81.7%

        \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      2. pow1/344.8%

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

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

        \[\leadsto \color{blue}{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{0.3333333333333333} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333}} \]
      5. pow1/381.7%

        \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333} \]
      6. pow281.7%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\color{blue}{\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}}^{0.3333333333333333} \]
    7. Applied egg-rr81.7%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}^{0.3333333333333333}} \]
    8. Step-by-step derivation
      1. unpow1/381.7%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    9. Simplified81.7%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    10. Taylor expanded in x around inf 91.9%

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

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

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

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

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

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

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

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

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

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

    if -50 < (/.f64 1 n) < 5.00000000000000033e-69

    1. Initial program 29.6%

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

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

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

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

    if 50 < (/.f64 1 n)

    1. Initial program 64.2%

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

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

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

Alternative 6: 69.3% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;x \leq 10^{-169}:\\
\;\;\;\;-\frac{\log x}{n}\\

\mathbf{elif}\;x \leq 1.2 \cdot 10^{-141}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 1.4200000000000001e-204 or 1.00000000000000002e-169 < x < 1.2e-141

    1. Initial program 56.8%

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

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

    if 1.4200000000000001e-204 < x < 1.00000000000000002e-169

    1. Initial program 22.0%

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

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

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

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

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

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

    if 1.2e-141 < x < 1.70000000000000008e-13

    1. Initial program 31.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-\left(-\log x\right)\right) \cdot \frac{1}{-n}} \]
      3. remove-double-neg61.6%

        \[\leadsto \color{blue}{\log x} \cdot \frac{1}{-n} \]
    8. Applied egg-rr61.6%

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

    if 1.70000000000000008e-13 < x

    1. Initial program 68.5%

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

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

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

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

        \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      2. pow1/365.7%

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

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

        \[\leadsto \color{blue}{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{0.3333333333333333} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333}} \]
      5. pow1/368.5%

        \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333} \]
      6. pow268.5%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\color{blue}{\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}}^{0.3333333333333333} \]
    7. Applied egg-rr68.5%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}^{0.3333333333333333}} \]
    8. Step-by-step derivation
      1. unpow1/368.5%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    9. Simplified68.5%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    10. Taylor expanded in x around inf 96.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.42 \cdot 10^{-204}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 10^{-169}:\\ \;\;\;\;-\frac{\log x}{n}\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-141}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-13}:\\ \;\;\;\;\log x \cdot \frac{1}{-n}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 69.4% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\
\;\;\;\;-\frac{\log x}{n}\\

\mathbf{elif}\;x \leq 2.05 \cdot 10^{-141}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 7.59999999999999983e-205 or 1.65000000000000002e-170 < x < 2.05000000000000001e-141

    1. Initial program 56.8%

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

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

    if 7.59999999999999983e-205 < x < 1.65000000000000002e-170

    1. Initial program 22.0%

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

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

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

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

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

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

    if 2.05000000000000001e-141 < x < 1.57999999999999993e-12

    1. Initial program 31.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-\left(-\log x\right)\right) \cdot \frac{1}{-n}} \]
      3. remove-double-neg61.6%

        \[\leadsto \color{blue}{\log x} \cdot \frac{1}{-n} \]
    8. Applied egg-rr61.6%

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

    if 1.57999999999999993e-12 < x

    1. Initial program 68.5%

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

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

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

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

        \[\leadsto \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{3}}} \]
      2. pow1/365.7%

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

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

        \[\leadsto \color{blue}{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{0.3333333333333333} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333}} \]
      5. pow1/368.5%

        \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}} \cdot {\left(\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right) \cdot \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)}^{0.3333333333333333} \]
      6. pow268.5%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\color{blue}{\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}}^{0.3333333333333333} \]
    7. Applied egg-rr68.5%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot {\left({\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}\right)}^{0.3333333333333333}} \]
    8. Step-by-step derivation
      1. unpow1/368.5%

        \[\leadsto \sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \color{blue}{\sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    9. Simplified68.5%

      \[\leadsto \color{blue}{\sqrt[3]{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}} \cdot \sqrt[3]{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)}^{2}}} \]
    10. Taylor expanded in x around inf 96.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.6 \cdot 10^{-205}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\ \;\;\;\;-\frac{\log x}{n}\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-141}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 1.58 \cdot 10^{-12}:\\ \;\;\;\;\log x \cdot \frac{1}{-n}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 51.0% accurate, 1.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -5.4e10

    1. Initial program 21.5%

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

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

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

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

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

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

    if -5.4e10 < n < 4.7e10

    1. Initial program 85.3%

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

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

    if 4.7e10 < n

    1. Initial program 30.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-\left(-\log x\right)\right) \cdot \frac{1}{-n}} \]
      3. remove-double-neg50.1%

        \[\leadsto \color{blue}{\log x} \cdot \frac{1}{-n} \]
    8. Applied egg-rr50.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -54000000000:\\ \;\;\;\;-\frac{\log x}{n}\\ \mathbf{elif}\;n \leq 47000000000:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\log x \cdot \frac{1}{-n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 31.1% accurate, 2.0× speedup?

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

\\
-\frac{\log x}{n}
\end{array}
Derivation
  1. Initial program 54.6%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-\log x}{n}} \]
  7. Final simplification31.1%

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

Alternative 10: 3.3% accurate, 2.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-\log x}{n}} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt29.4%

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

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-\log x\right) \cdot \left(-\log x\right)}}}{n} \]
    3. sqr-neg31.5%

      \[\leadsto \frac{\sqrt{\color{blue}{\log x \cdot \log x}}}{n} \]
    4. sqrt-unprod1.9%

      \[\leadsto \frac{\color{blue}{\sqrt{\log x} \cdot \sqrt{\log x}}}{n} \]
    5. add-sqr-sqrt3.1%

      \[\leadsto \frac{\color{blue}{\log x}}{n} \]
    6. clear-num3.1%

      \[\leadsto \color{blue}{\frac{1}{\frac{n}{\log x}}} \]
    7. associate-/r/3.1%

      \[\leadsto \color{blue}{\frac{1}{n} \cdot \log x} \]
  8. Applied egg-rr3.1%

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

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

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

Reproduce

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