?

Average Accuracy: 49.9% → 97.7%
Time: 23.4s
Precision: binary64
Cost: 13188

?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{n} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{x}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if x < 0.55000000000000004

    1. Initial program 28.4%

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

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

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

      [Start]28.4

      \[ 1 - e^{\frac{\log x}{n}} \]

      *-rgt-identity [<=]28.4

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

      associate-*r/ [<=]28.4

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

      unpow-1 [<=]28.4

      \[ 1 - e^{\log x \cdot \color{blue}{{n}^{-1}}} \]

      exp-to-pow [=>]28.4

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

      unpow-1 [=>]28.4

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

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

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

      [Start]28.4

      \[ 1 - e^{\frac{\log x}{n}} \]

      sub-neg [=>]28.4

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

      +-commutative [=>]28.4

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

      neg-sub0 [=>]28.4

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

      metadata-eval [<=]28.4

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

      associate-+l- [=>]28.4

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

      metadata-eval [=>]28.4

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

      sub0-neg [=>]28.4

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

      expm1-def [=>]97.1

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

    if 0.55000000000000004 < x

    1. Initial program 68.0%

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

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

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

      [Start]97.0

      \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x} \]

      log-rec [=>]97.0

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

      mul-1-neg [<=]97.0

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

      mul-1-neg [=>]97.0

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

      distribute-frac-neg [=>]97.0

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

      neg-mul-1 [<=]97.0

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

      remove-double-neg [=>]97.0

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

      *-rgt-identity [<=]97.0

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

      associate-*r/ [<=]97.0

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

      unpow-1 [<=]97.0

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

      exp-to-pow [=>]97.0

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

      unpow-1 [=>]97.0

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

      *-commutative [=>]97.0

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

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

      [Start]97.0

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

      associate-/r* [=>]98.3

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

      div-inv [=>]98.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.55:\\ \;\;\;\;-\mathsf{expm1}\left(\frac{\log x}{n}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{n} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{x}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy97.9%
Cost7560
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-7}:\\ \;\;\;\;\frac{1}{n} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \end{array} \]
Alternative 2
Accuracy97.2%
Cost7304
\[\begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1000000:\\ \;\;\;\;0\\ \mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
Alternative 3
Accuracy97.4%
Cost7304
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\ \mathbf{if}\;n \leq -85000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq -2 \cdot 10^{-302}:\\ \;\;\;\;\frac{1}{n} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;n \leq 2600000:\\ \;\;\;\;1 - t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy97.4%
Cost7180
\[\begin{array}{l} t_0 := \frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\ t_1 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;n \leq -102000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq -2 \cdot 10^{-302}:\\ \;\;\;\;\frac{t_1}{x \cdot n}\\ \mathbf{elif}\;n \leq 1950000:\\ \;\;\;\;1 - t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy88.0%
Cost6985
\[\begin{array}{l} \mathbf{if}\;n \leq -10.6 \lor \neg \left(n \leq -2 \cdot 10^{-302}\right):\\ \;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Accuracy74.8%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+152}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 7
Accuracy54.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;n \leq -11.5 \lor \neg \left(n \leq 1.26 \cdot 10^{-59}\right):\\ \;\;\;\;\frac{1}{x \cdot n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 8
Accuracy54.9%
Cost585
\[\begin{array}{l} \mathbf{if}\;n \leq -4.8 \lor \neg \left(n \leq 3 \cdot 10^{-59}\right):\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 9
Accuracy54.9%
Cost584
\[\begin{array}{l} \mathbf{if}\;n \leq -10.6:\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \mathbf{elif}\;n \leq 2.2 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \end{array} \]
Alternative 10
Accuracy39.1%
Cost64
\[0 \]

Error

Reproduce?

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