2nthrt (problem 3.4.6)

Percentage Accurate: 53.4% → 85.8%
Time: 33.0s
Alternatives: 19
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 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.4% 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.8% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \log \left(1 + x\right)\\
t_2 := 0.5 \cdot \frac{{t_1}^{2}}{{n}^{2}}\\
t_3 := 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\\
\mathbf{if}\;n \leq -5500000:\\
\;\;\;\;\left(\frac{t_1 - \log x}{n} + \left(\frac{-0.16666666666666666 \cdot {\log x}^{3} - -0.16666666666666666 \cdot {t_1}^{3}}{{n}^{3}} + \left(0.041666666666666664 \cdot \frac{{t_1}^{4}}{{n}^{4}} + t_2\right)\right)\right) - \left(0.041666666666666664 \cdot \frac{{\log x}^{4}}{{n}^{4}} + t_3\right)\\

\mathbf{elif}\;n \leq 0.0126:\\
\;\;\;\;2 \cdot \log \left(\sqrt{e^{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t_0}}\right)\\

\mathbf{elif}\;n \leq 10^{+59}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_0}{n}\\

\mathbf{else}:\\
\;\;\;\;\left(t_2 + \frac{t_1}{n}\right) - \left(t_3 + \frac{\log x}{n}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -5.5e6

    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 77.8%

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

    if -5.5e6 < n < 0.0126

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0126 < n < 9.99999999999999972e58

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999972e58 < n

    1. Initial program 31.8%

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

      \[\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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -5500000:\\ \;\;\;\;\left(\frac{\log \left(1 + x\right) - \log x}{n} + \left(\frac{-0.16666666666666666 \cdot {\log x}^{3} - -0.16666666666666666 \cdot {\log \left(1 + x\right)}^{3}}{{n}^{3}} + \left(0.041666666666666664 \cdot \frac{{\log \left(1 + x\right)}^{4}}{{n}^{4}} + 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}}\right)\right)\right) - \left(0.041666666666666664 \cdot \frac{{\log x}^{4}}{{n}^{4}} + 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{elif}\;n \leq 0.0126:\\ \;\;\;\;2 \cdot \log \left(\sqrt{e^{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}}\right)\\ \mathbf{elif}\;n \leq 10^{+59}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.9% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \log \left(1 + x\right)\\
t_1 := {x}^{\left(\frac{1}{n}\right)}\\
t_2 := \frac{{\log x}^{2}}{{n}^{2}}\\
\mathbf{if}\;n \leq -5500000:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n} + \left(\frac{0.16666666666666666}{\frac{{n}^{3}}{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - t_2\right)\right)\\

\mathbf{elif}\;n \leq 2.7 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \log \left(\sqrt{e^{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t_1}}\right)\\

\mathbf{elif}\;n \leq 2.4 \cdot 10^{+61}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_1}{n}\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{{t_0}^{2}}{{n}^{2}} + \frac{t_0}{n}\right) - \left(0.5 \cdot t_2 + \frac{\log x}{n}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -5.5e6

    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 77.8%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{1} \cdot \left(\log \left(1 + x\right) - \log x\right)}{n} + \left(\left(-1 \cdot \frac{-0.16666666666666666 \cdot {\log \left(1 + x\right)}^{3} - -0.16666666666666666 \cdot {\log x}^{3}}{{n}^{3}} + 0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}}\right) - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right) \]
      6. *-lft-identity77.8%

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

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

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

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

    if -5.5e6 < n < 2.6999999999999999e-5

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.6999999999999999e-5 < n < 2.3999999999999999e61

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.3999999999999999e61 < n

    1. Initial program 31.8%

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

      \[\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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -5500000:\\ \;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n} + \left(\frac{0.16666666666666666}{\frac{{n}^{3}}{{\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}}} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\right)\\ \mathbf{elif}\;n \leq 2.7 \cdot 10^{-5}:\\ \;\;\;\;2 \cdot \log \left(\sqrt{e^{e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}}}\right)\\ \mathbf{elif}\;n \leq 2.4 \cdot 10^{+61}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.6% accurate, 0.3× speedup?

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

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

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

\mathbf{elif}\;n \leq 5.2 \cdot 10^{+58}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{t_1}{n}\\

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


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

    1. Initial program 25.8%

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

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

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

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

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

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

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

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

    if -4e10 < n < 62

    1. Initial program 91.6%

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

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
      2. add-exp-log91.6%

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

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

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

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(e^{\color{blue}{\mathsf{log1p}\left(x\right) \cdot \frac{1}{n}}} - {x}^{\left(\frac{1}{n}\right)}\right)\right) \]
      7. un-div-inv99.0%

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

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

    if 62 < n < 5.19999999999999976e58

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.19999999999999976e58 < n

    1. Initial program 31.8%

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

      \[\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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -40000000000:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;n \leq 62:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;n \leq 5.2 \cdot 10^{+58}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{n}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 85.8% accurate, 0.4× speedup?

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

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

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

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

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


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

    1. Initial program 98.7%

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

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\right)\right)} \]
      2. add-exp-log98.7%

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

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

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(e^{\frac{1}{n} \cdot \color{blue}{\mathsf{log1p}\left(x\right)}} - {x}^{\left(\frac{1}{n}\right)}\right)\right) \]
      6. *-commutative98.7%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(e^{\color{blue}{\mathsf{log1p}\left(x\right) \cdot \frac{1}{n}}} - {x}^{\left(\frac{1}{n}\right)}\right)\right) \]
      7. un-div-inv98.7%

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

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

    if -2e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.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.3%

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

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

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

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

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

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

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

    if 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 69.9%

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

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

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

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

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

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

Alternative 5: 81.1% accurate, 0.9× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -9.9999999999999995e-8 or 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

    1. Initial program 82.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 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999995e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.4%

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n) < 1.00000000000000005e242

    1. Initial program 79.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 75.9%

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

    if 1.00000000000000005e242 < (/.f64 1 n)

    1. Initial program 22.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 27.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 85.8% accurate, 0.9× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;t_1\\


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

    1. Initial program 91.6%

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around 0 91.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.0%

        \[\leadsto e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)} \]
    5. Simplified99.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 99.0%

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

    if -2e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.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.3%

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

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

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

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

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

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

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

    if 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 85.8% accurate, 0.9× speedup?

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

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

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

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

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


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

    1. Initial program 98.7%

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

    if -2e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.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.3%

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

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

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

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

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

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

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

    if 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 69.9%

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

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

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

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

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

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

Alternative 8: 64.1% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;\frac{1}{n} \leq -20000000000:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -2e53 or -2e10 < (/.f64 1 n) < 2.00000000000000013e-63

    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 n around inf 74.3%

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

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

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

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

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

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

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

    if -2e53 < (/.f64 1 n) < -2e10 or 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 80.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 69.2%

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

    if 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

    1. Initial program 9.3%

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

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

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

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

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

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

Alternative 9: 78.4% accurate, 1.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -9.9999999999999995e-8 or 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

    1. Initial program 82.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 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999995e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.4%

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 69.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 63.3%

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

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

Alternative 10: 78.7% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{1}{x} \cdot \frac{t_0}{n}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-63}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 0.005:\\ \;\;\;\;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 (* (/ 1.0 x) (/ t_0 n))))
   (if (<= (/ 1.0 n) -1e-7)
     t_1
     (if (<= (/ 1.0 n) 2e-63)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 0.005) 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 = (1.0 / x) * (t_0 / n);
	double tmp;
	if ((1.0 / n) <= -1e-7) {
		tmp = t_1;
	} else if ((1.0 / n) <= 2e-63) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 0.005) {
		tmp = t_1;
	} else {
		tmp = (1.0 + (x / n)) - t_0;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    t_1 = (1.0d0 / x) * (t_0 / n)
    if ((1.0d0 / n) <= (-1d-7)) then
        tmp = t_1
    else if ((1.0d0 / n) <= 2d-63) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 0.005d0) then
        tmp = t_1
    else
        tmp = (1.0d0 + (x / n)) - t_0
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double t_0 = Math.pow(x, (1.0 / n));
	double t_1 = (1.0 / x) * (t_0 / n);
	double tmp;
	if ((1.0 / n) <= -1e-7) {
		tmp = t_1;
	} else if ((1.0 / n) <= 2e-63) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 0.005) {
		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 = (1.0 / x) * (t_0 / n)
	tmp = 0
	if (1.0 / n) <= -1e-7:
		tmp = t_1
	elif (1.0 / n) <= 2e-63:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 0.005:
		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(Float64(1.0 / x) * Float64(t_0 / n))
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-7)
		tmp = t_1;
	elseif (Float64(1.0 / n) <= 2e-63)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 0.005)
		tmp = t_1;
	else
		tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0);
	end
	return tmp
end
function tmp_2 = code(x, n)
	t_0 = x ^ (1.0 / n);
	t_1 = (1.0 / x) * (t_0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -1e-7)
		tmp = t_1;
	elseif ((1.0 / n) <= 2e-63)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 0.005)
		tmp = t_1;
	else
		tmp = (1.0 + (x / n)) - t_0;
	end
	tmp_2 = tmp;
end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / x), $MachinePrecision] * N[(t$95$0 / n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-7], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-63], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.005], 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{1}{x} \cdot \frac{t_0}{n}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-7}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\frac{1}{n} \leq 0.005:\\
\;\;\;\;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) < -9.9999999999999995e-8 or 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

    1. Initial program 82.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 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999995e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.4%

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 69.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 63.9%

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

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

Alternative 11: 78.4% accurate, 1.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 1 n) < -9.9999999999999995e-8 or 2.00000000000000013e-63 < (/.f64 1 n) < 0.0050000000000000001

    1. Initial program 82.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 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999995e-8 < (/.f64 1 n) < 2.00000000000000013e-63

    1. Initial program 28.4%

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

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

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

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

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

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

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

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

    if 0.0050000000000000001 < (/.f64 1 n)

    1. Initial program 69.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 63.3%

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

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

Alternative 12: 57.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.05 \cdot 10^{-245}:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-141}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+58} \lor \neg \left(x \leq 6.5 \cdot 10^{+184}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 1.05e-245)
   (/ (- (log x)) n)
   (if (<= x 2.1e-141)
     (- 1.0 (pow x (/ 1.0 n)))
     (if (<= x 1.0)
       (/ (- x (log x)) n)
       (if (or (<= x 5.5e+58) (not (<= x 6.5e+184)))
         (/ 0.0 n)
         (/ (/ 1.0 x) n))))))
double code(double x, double n) {
	double tmp;
	if (x <= 1.05e-245) {
		tmp = -log(x) / n;
	} else if (x <= 2.1e-141) {
		tmp = 1.0 - pow(x, (1.0 / n));
	} else if (x <= 1.0) {
		tmp = (x - log(x)) / n;
	} else if ((x <= 5.5e+58) || !(x <= 6.5e+184)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 1.05d-245) then
        tmp = -log(x) / n
    else if (x <= 2.1d-141) then
        tmp = 1.0d0 - (x ** (1.0d0 / n))
    else if (x <= 1.0d0) then
        tmp = (x - log(x)) / n
    else if ((x <= 5.5d+58) .or. (.not. (x <= 6.5d+184))) then
        tmp = 0.0d0 / n
    else
        tmp = (1.0d0 / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 1.05e-245) {
		tmp = -Math.log(x) / n;
	} else if (x <= 2.1e-141) {
		tmp = 1.0 - Math.pow(x, (1.0 / n));
	} else if (x <= 1.0) {
		tmp = (x - Math.log(x)) / n;
	} else if ((x <= 5.5e+58) || !(x <= 6.5e+184)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 1.05e-245:
		tmp = -math.log(x) / n
	elif x <= 2.1e-141:
		tmp = 1.0 - math.pow(x, (1.0 / n))
	elif x <= 1.0:
		tmp = (x - math.log(x)) / n
	elif (x <= 5.5e+58) or not (x <= 6.5e+184):
		tmp = 0.0 / n
	else:
		tmp = (1.0 / x) / n
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 1.05e-245)
		tmp = Float64(Float64(-log(x)) / n);
	elseif (x <= 2.1e-141)
		tmp = Float64(1.0 - (x ^ Float64(1.0 / n)));
	elseif (x <= 1.0)
		tmp = Float64(Float64(x - log(x)) / n);
	elseif ((x <= 5.5e+58) || !(x <= 6.5e+184))
		tmp = Float64(0.0 / n);
	else
		tmp = Float64(Float64(1.0 / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 1.05e-245)
		tmp = -log(x) / n;
	elseif (x <= 2.1e-141)
		tmp = 1.0 - (x ^ (1.0 / n));
	elseif (x <= 1.0)
		tmp = (x - log(x)) / n;
	elseif ((x <= 5.5e+58) || ~((x <= 6.5e+184)))
		tmp = 0.0 / n;
	else
		tmp = (1.0 / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 1.05e-245], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], If[LessEqual[x, 2.1e-141], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[Or[LessEqual[x, 5.5e+58], N[Not[LessEqual[x, 6.5e+184]], $MachinePrecision]], N[(0.0 / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.05 \cdot 10^{-245}:\\
\;\;\;\;\frac{-\log x}{n}\\

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

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

\mathbf{elif}\;x \leq 5.5 \cdot 10^{+58} \lor \neg \left(x \leq 6.5 \cdot 10^{+184}\right):\\
\;\;\;\;\frac{0}{n}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if x < 1.05000000000000005e-245

    1. Initial program 42.8%

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

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

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

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

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

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

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

    if 1.05000000000000005e-245 < x < 2.0999999999999999e-141

    1. Initial program 64.5%

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

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

    if 2.0999999999999999e-141 < x < 1

    1. Initial program 38.8%

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

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

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

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

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

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

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

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

    if 1 < x < 5.4999999999999999e58 or 6.50000000000000002e184 < x

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

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

    if 5.4999999999999999e58 < x < 6.50000000000000002e184

    1. Initial program 50.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.05 \cdot 10^{-245}:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-141}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+58} \lor \neg \left(x \leq 6.5 \cdot 10^{+184}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 58.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+58} \lor \neg \left(x \leq 5.3 \cdot 10^{+184}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 1.0)
   (/ (- x (log x)) n)
   (if (or (<= x 3.1e+58) (not (<= x 5.3e+184))) (/ 0.0 n) (/ (/ 1.0 x) n))))
double code(double x, double n) {
	double tmp;
	if (x <= 1.0) {
		tmp = (x - log(x)) / n;
	} else if ((x <= 3.1e+58) || !(x <= 5.3e+184)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = (x - log(x)) / n
    else if ((x <= 3.1d+58) .or. (.not. (x <= 5.3d+184))) then
        tmp = 0.0d0 / n
    else
        tmp = (1.0d0 / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 1.0) {
		tmp = (x - Math.log(x)) / n;
	} else if ((x <= 3.1e+58) || !(x <= 5.3e+184)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 1.0:
		tmp = (x - math.log(x)) / n
	elif (x <= 3.1e+58) or not (x <= 5.3e+184):
		tmp = 0.0 / n
	else:
		tmp = (1.0 / x) / n
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 1.0)
		tmp = Float64(Float64(x - log(x)) / n);
	elseif ((x <= 3.1e+58) || !(x <= 5.3e+184))
		tmp = Float64(0.0 / n);
	else
		tmp = Float64(Float64(1.0 / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = (x - log(x)) / n;
	elseif ((x <= 3.1e+58) || ~((x <= 5.3e+184)))
		tmp = 0.0 / n;
	else
		tmp = (1.0 / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 1.0], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[Or[LessEqual[x, 3.1e+58], N[Not[LessEqual[x, 5.3e+184]], $MachinePrecision]], N[(0.0 / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 3.1 \cdot 10^{+58} \lor \neg \left(x \leq 5.3 \cdot 10^{+184}\right):\\
\;\;\;\;\frac{0}{n}\\

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


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

    1. Initial program 46.2%

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

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

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

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

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

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

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

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

    if 1 < x < 3.0999999999999999e58 or 5.30000000000000022e184 < x

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

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

    if 3.0999999999999999e58 < x < 5.30000000000000022e184

    1. Initial program 50.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+58} \lor \neg \left(x \leq 5.3 \cdot 10^{+184}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 58.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+58} \lor \neg \left(x \leq 2.45 \cdot 10^{+185}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \end{array} \]
(FPCore (x n)
 :precision binary64
 (if (<= x 1.0)
   (/ (- (log x)) n)
   (if (or (<= x 2.4e+58) (not (<= x 2.45e+185))) (/ 0.0 n) (/ (/ 1.0 x) n))))
double code(double x, double n) {
	double tmp;
	if (x <= 1.0) {
		tmp = -log(x) / n;
	} else if ((x <= 2.4e+58) || !(x <= 2.45e+185)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = -log(x) / n
    else if ((x <= 2.4d+58) .or. (.not. (x <= 2.45d+185))) then
        tmp = 0.0d0 / n
    else
        tmp = (1.0d0 / x) / n
    end if
    code = tmp
end function
public static double code(double x, double n) {
	double tmp;
	if (x <= 1.0) {
		tmp = -Math.log(x) / n;
	} else if ((x <= 2.4e+58) || !(x <= 2.45e+185)) {
		tmp = 0.0 / n;
	} else {
		tmp = (1.0 / x) / n;
	}
	return tmp;
}
def code(x, n):
	tmp = 0
	if x <= 1.0:
		tmp = -math.log(x) / n
	elif (x <= 2.4e+58) or not (x <= 2.45e+185):
		tmp = 0.0 / n
	else:
		tmp = (1.0 / x) / n
	return tmp
function code(x, n)
	tmp = 0.0
	if (x <= 1.0)
		tmp = Float64(Float64(-log(x)) / n);
	elseif ((x <= 2.4e+58) || !(x <= 2.45e+185))
		tmp = Float64(0.0 / n);
	else
		tmp = Float64(Float64(1.0 / x) / n);
	end
	return tmp
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = -log(x) / n;
	elseif ((x <= 2.4e+58) || ~((x <= 2.45e+185)))
		tmp = 0.0 / n;
	else
		tmp = (1.0 / x) / n;
	end
	tmp_2 = tmp;
end
code[x_, n_] := If[LessEqual[x, 1.0], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], If[Or[LessEqual[x, 2.4e+58], N[Not[LessEqual[x, 2.45e+185]], $MachinePrecision]], N[(0.0 / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 2.4 \cdot 10^{+58} \lor \neg \left(x \leq 2.45 \cdot 10^{+185}\right):\\
\;\;\;\;\frac{0}{n}\\

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


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

    1. Initial program 46.2%

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

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

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

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

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

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

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

    if 1 < x < 2.4e58 or 2.44999999999999992e185 < x

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

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

    if 2.4e58 < x < 2.44999999999999992e185

    1. Initial program 50.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+58} \lor \neg \left(x \leq 2.45 \cdot 10^{+185}\right):\\ \;\;\;\;\frac{0}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 48.6% accurate, 14.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.5:\\
\;\;\;\;\frac{1}{n \cdot \left(x + 0.5\right)}\\

\mathbf{elif}\;n \leq -2.05 \cdot 10^{-306}:\\
\;\;\;\;\frac{0}{n}\\

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


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

    1. Initial program 27.1%

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{n}{\mathsf{log1p}\left(x\right) - \log x}}} \]
      2. inv-pow75.3%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{0.5 \cdot n + n \cdot x}} \]
    11. Step-by-step derivation
      1. *-commutative51.9%

        \[\leadsto \frac{1}{\color{blue}{n \cdot 0.5} + n \cdot x} \]
      2. distribute-lft-out51.9%

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

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

    if -1.5 < n < -2.04999999999999992e-306

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if -2.04999999999999992e-306 < n

    1. Initial program 41.1%

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

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

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

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

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

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

Alternative 16: 42.9% accurate, 17.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -2:\\
\;\;\;\;\frac{1}{n \cdot \left(x + 0.5\right)}\\

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


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

    1. Initial program 27.1%

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{n}{\mathsf{log1p}\left(x\right) - \log x}}} \]
      2. inv-pow75.3%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{0.5 \cdot n + n \cdot x}} \]
    11. Step-by-step derivation
      1. *-commutative51.9%

        \[\leadsto \frac{1}{\color{blue}{n \cdot 0.5} + n \cdot x} \]
      2. distribute-lft-out51.9%

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

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

    if -2 < n

    1. Initial program 68.4%

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

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

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

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

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

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

Alternative 17: 41.2% accurate, 42.2× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 18: 41.9% 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 55.7%

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

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

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

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

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

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

Alternative 19: 4.6% accurate, 70.3× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{x}{n}} \]
  10. Final simplification4.3%

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

Reproduce

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