
(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:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (- (log1p x) (log x)) n)))
(if (<= n -22000000000.0)
t_0
(if (<= n 0.0022)
(- (exp (/ (log1p x) n)) (pow x (/ 1.0 n)))
(if (<= n 1.32e+66) (/ (exp (/ (log x) n)) (* n x)) t_0)))))
double code(double x, double n) {
double t_0 = (log1p(x) - log(x)) / n;
double tmp;
if (n <= -22000000000.0) {
tmp = t_0;
} else if (n <= 0.0022) {
tmp = exp((log1p(x) / n)) - pow(x, (1.0 / n));
} else if (n <= 1.32e+66) {
tmp = exp((log(x) / n)) / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = (Math.log1p(x) - Math.log(x)) / n;
double tmp;
if (n <= -22000000000.0) {
tmp = t_0;
} else if (n <= 0.0022) {
tmp = Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n));
} else if (n <= 1.32e+66) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, n): t_0 = (math.log1p(x) - math.log(x)) / n tmp = 0 if n <= -22000000000.0: tmp = t_0 elif n <= 0.0022: tmp = math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n)) elif n <= 1.32e+66: tmp = math.exp((math.log(x) / n)) / (n * x) else: tmp = t_0 return tmp
function code(x, n) t_0 = Float64(Float64(log1p(x) - log(x)) / n) tmp = 0.0 if (n <= -22000000000.0) tmp = t_0; elseif (n <= 0.0022) tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n))); elseif (n <= 1.32e+66) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); else tmp = t_0; end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[n, -22000000000.0], t$95$0, If[LessEqual[n, 0.0022], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 1.32e+66], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{if}\;n \leq -22000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq 0.0022:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{elif}\;n \leq 1.32 \cdot 10^{+66}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if n < -2.2e10 or 1.32000000000000009e66 < n Initial program 28.6%
Taylor expanded in n around inf 81.4%
log1p-def81.4%
Simplified81.4%
if -2.2e10 < n < 0.00220000000000000013Initial program 86.6%
Taylor expanded in n around 0 86.6%
log1p-def99.1%
Simplified99.1%
if 0.00220000000000000013 < n < 1.32000000000000009e66Initial program 12.9%
Taylor expanded in x around inf 61.7%
mul-1-neg61.7%
log-rec61.7%
mul-1-neg61.7%
distribute-neg-frac61.7%
mul-1-neg61.7%
remove-double-neg61.7%
*-commutative61.7%
Simplified61.7%
Final simplification88.2%
(FPCore (x n)
:precision binary64
(if (or (<= n -33000000.0) (not (<= n 65000000.0)))
(+
(/ (log (/ (+ x 1.0) x)) n)
(*
0.5
(-
(/ (pow (log1p x) 2.0) (pow n 2.0))
(/ (pow (log x) 2.0) (pow n 2.0)))))
(- (exp (/ (log1p x) n)) (pow x (/ 1.0 n)))))
double code(double x, double n) {
double tmp;
if ((n <= -33000000.0) || !(n <= 65000000.0)) {
tmp = (log(((x + 1.0) / x)) / n) + (0.5 * ((pow(log1p(x), 2.0) / pow(n, 2.0)) - (pow(log(x), 2.0) / pow(n, 2.0))));
} else {
tmp = exp((log1p(x) / n)) - pow(x, (1.0 / n));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((n <= -33000000.0) || !(n <= 65000000.0)) {
tmp = (Math.log(((x + 1.0) / x)) / n) + (0.5 * ((Math.pow(Math.log1p(x), 2.0) / Math.pow(n, 2.0)) - (Math.pow(Math.log(x), 2.0) / Math.pow(n, 2.0))));
} else {
tmp = Math.exp((Math.log1p(x) / n)) - Math.pow(x, (1.0 / n));
}
return tmp;
}
def code(x, n): tmp = 0 if (n <= -33000000.0) or not (n <= 65000000.0): tmp = (math.log(((x + 1.0) / x)) / n) + (0.5 * ((math.pow(math.log1p(x), 2.0) / math.pow(n, 2.0)) - (math.pow(math.log(x), 2.0) / math.pow(n, 2.0)))) else: tmp = math.exp((math.log1p(x) / n)) - math.pow(x, (1.0 / n)) return tmp
function code(x, n) tmp = 0.0 if ((n <= -33000000.0) || !(n <= 65000000.0)) tmp = Float64(Float64(log(Float64(Float64(x + 1.0) / x)) / n) + Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) / (n ^ 2.0)) - Float64((log(x) ^ 2.0) / (n ^ 2.0))))); else tmp = Float64(exp(Float64(log1p(x) / n)) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[Or[LessEqual[n, -33000000.0], N[Not[LessEqual[n, 65000000.0]], $MachinePrecision]], N[(N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] + N[(0.5 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -33000000 \lor \neg \left(n \leq 65000000\right):\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n} + 0.5 \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if n < -3.3e7 or 6.5e7 < n Initial program 26.5%
Taylor expanded in n around inf 76.7%
associate--l+70.9%
+-commutative70.9%
associate--r+76.7%
div-sub76.7%
remove-double-neg76.7%
mul-1-neg76.7%
distribute-lft-out--76.7%
distribute-neg-frac76.7%
mul-1-neg76.7%
Simplified76.7%
log1p-udef76.7%
diff-log76.8%
+-commutative76.8%
Applied egg-rr76.8%
if -3.3e7 < n < 6.5e7Initial program 85.4%
Taylor expanded in n around 0 85.4%
log1p-def97.7%
Simplified97.7%
Final simplification86.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (/ t_0 (* n x))))
(if (<= (/ 1.0 n) -50.0)
t_1
(if (<= (/ 1.0 n) 5e-69)
(/ (- (log1p x) (log x)) n)
(if (<= (/ 1.0 n) 2e-26) t_1 (fabs (- 1.0 t_0)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = t_0 / (n * x);
double tmp;
if ((1.0 / n) <= -50.0) {
tmp = t_1;
} else if ((1.0 / n) <= 5e-69) {
tmp = (log1p(x) - log(x)) / n;
} else if ((1.0 / n) <= 2e-26) {
tmp = t_1;
} else {
tmp = fabs((1.0 - t_0));
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = t_0 / (n * x);
double tmp;
if ((1.0 / n) <= -50.0) {
tmp = t_1;
} else if ((1.0 / n) <= 5e-69) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else if ((1.0 / n) <= 2e-26) {
tmp = t_1;
} else {
tmp = Math.abs((1.0 - t_0));
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = t_0 / (n * x) tmp = 0 if (1.0 / n) <= -50.0: tmp = t_1 elif (1.0 / n) <= 5e-69: tmp = (math.log1p(x) - math.log(x)) / n elif (1.0 / n) <= 2e-26: tmp = t_1 else: tmp = math.fabs((1.0 - t_0)) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(t_0 / Float64(n * x)) tmp = 0.0 if (Float64(1.0 / n) <= -50.0) tmp = t_1; elseif (Float64(1.0 / n) <= 5e-69) tmp = Float64(Float64(log1p(x) - log(x)) / n); elseif (Float64(1.0 / n) <= 2e-26) tmp = t_1; else tmp = abs(Float64(1.0 - t_0)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -50.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-69], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-26], t$95$1, N[Abs[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{t_0}{n \cdot x}\\
\mathbf{if}\;\frac{1}{n} \leq -50:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-69}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-26}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\left|1 - t_0\right|\\
\end{array}
\end{array}
if (/.f64 1 n) < -50 or 5.00000000000000033e-69 < (/.f64 1 n) < 2.0000000000000001e-26Initial program 84.1%
Taylor expanded in n around 0 84.1%
log1p-def84.1%
Simplified84.1%
rem-cbrt-cube84.1%
pow1/345.2%
cube-mult45.2%
unpow-prod-down45.2%
pow1/384.1%
pow284.1%
Applied egg-rr84.1%
unpow1/384.1%
Simplified84.1%
Taylor expanded in x around inf 94.7%
mul-1-neg94.7%
log-rec94.7%
distribute-neg-frac94.7%
remove-double-neg94.7%
*-rgt-identity94.7%
associate-*r/94.7%
exp-to-pow94.7%
*-commutative94.7%
Simplified94.7%
if -50 < (/.f64 1 n) < 5.00000000000000033e-69Initial program 29.6%
Taylor expanded in n around inf 80.9%
log1p-def80.9%
Simplified80.9%
if 2.0000000000000001e-26 < (/.f64 1 n) Initial program 61.3%
Taylor expanded in x around 0 57.2%
add-sqr-sqrt57.2%
sqrt-unprod59.4%
pow259.4%
Applied egg-rr59.4%
unpow259.4%
rem-sqrt-square59.5%
Simplified59.5%
Final simplification81.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (- (log1p x) (log x)) n)))
(if (<= n -3600000.0)
t_0
(if (<= n 0.0034)
(- (exp (/ x n)) (pow x (/ 1.0 n)))
(if (<= n 1.95e+66) (/ (exp (/ (log x) n)) (* n x)) t_0)))))
double code(double x, double n) {
double t_0 = (log1p(x) - log(x)) / n;
double tmp;
if (n <= -3600000.0) {
tmp = t_0;
} else if (n <= 0.0034) {
tmp = exp((x / n)) - pow(x, (1.0 / n));
} else if (n <= 1.95e+66) {
tmp = exp((log(x) / n)) / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = (Math.log1p(x) - Math.log(x)) / n;
double tmp;
if (n <= -3600000.0) {
tmp = t_0;
} else if (n <= 0.0034) {
tmp = Math.exp((x / n)) - Math.pow(x, (1.0 / n));
} else if (n <= 1.95e+66) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, n): t_0 = (math.log1p(x) - math.log(x)) / n tmp = 0 if n <= -3600000.0: tmp = t_0 elif n <= 0.0034: tmp = math.exp((x / n)) - math.pow(x, (1.0 / n)) elif n <= 1.95e+66: tmp = math.exp((math.log(x) / n)) / (n * x) else: tmp = t_0 return tmp
function code(x, n) t_0 = Float64(Float64(log1p(x) - log(x)) / n) tmp = 0.0 if (n <= -3600000.0) tmp = t_0; elseif (n <= 0.0034) tmp = Float64(exp(Float64(x / n)) - (x ^ Float64(1.0 / n))); elseif (n <= 1.95e+66) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); else tmp = t_0; end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[n, -3600000.0], t$95$0, If[LessEqual[n, 0.0034], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 1.95e+66], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{if}\;n \leq -3600000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq 0.0034:\\
\;\;\;\;e^{\frac{x}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{elif}\;n \leq 1.95 \cdot 10^{+66}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if n < -3.6e6 or 1.9500000000000002e66 < n Initial program 29.0%
Taylor expanded in n around inf 80.7%
log1p-def80.7%
Simplified80.7%
if -3.6e6 < n < 0.00339999999999999981Initial program 87.3%
Taylor expanded in n around 0 87.3%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if 0.00339999999999999981 < n < 1.9500000000000002e66Initial program 12.9%
Taylor expanded in x around inf 61.7%
mul-1-neg61.7%
log-rec61.7%
mul-1-neg61.7%
distribute-neg-frac61.7%
mul-1-neg61.7%
remove-double-neg61.7%
*-commutative61.7%
Simplified61.7%
Final simplification88.1%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (/ t_0 (* n x))))
(if (<= (/ 1.0 n) -50.0)
t_1
(if (<= (/ 1.0 n) 5e-69)
(/ (- (log1p x) (log x)) n)
(if (<= (/ 1.0 n) 50.0) t_1 (- (+ 1.0 (/ x n)) t_0))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = t_0 / (n * x);
double tmp;
if ((1.0 / n) <= -50.0) {
tmp = t_1;
} else if ((1.0 / n) <= 5e-69) {
tmp = (log1p(x) - log(x)) / n;
} else if ((1.0 / n) <= 50.0) {
tmp = t_1;
} else {
tmp = (1.0 + (x / n)) - t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = t_0 / (n * x);
double tmp;
if ((1.0 / n) <= -50.0) {
tmp = t_1;
} else if ((1.0 / n) <= 5e-69) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else if ((1.0 / n) <= 50.0) {
tmp = t_1;
} else {
tmp = (1.0 + (x / n)) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = t_0 / (n * x) tmp = 0 if (1.0 / n) <= -50.0: tmp = t_1 elif (1.0 / n) <= 5e-69: tmp = (math.log1p(x) - math.log(x)) / n elif (1.0 / n) <= 50.0: tmp = t_1 else: tmp = (1.0 + (x / n)) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(t_0 / Float64(n * x)) tmp = 0.0 if (Float64(1.0 / n) <= -50.0) tmp = t_1; elseif (Float64(1.0 / n) <= 5e-69) tmp = Float64(Float64(log1p(x) - log(x)) / n); elseif (Float64(1.0 / n) <= 50.0) tmp = t_1; else tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -50.0], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-69], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 50.0], t$95$1, N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{t_0}{n \cdot x}\\
\mathbf{if}\;\frac{1}{n} \leq -50:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-69}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 50:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\end{array}
\end{array}
if (/.f64 1 n) < -50 or 5.00000000000000033e-69 < (/.f64 1 n) < 50Initial program 81.7%
Taylor expanded in n around 0 81.7%
log1p-def81.7%
Simplified81.7%
rem-cbrt-cube81.7%
pow1/344.8%
cube-mult44.8%
unpow-prod-down44.8%
pow1/381.7%
pow281.7%
Applied egg-rr81.7%
unpow1/381.7%
Simplified81.7%
Taylor expanded in x around inf 91.9%
mul-1-neg91.9%
log-rec91.9%
distribute-neg-frac91.9%
remove-double-neg91.9%
*-rgt-identity91.9%
associate-*r/91.9%
exp-to-pow91.9%
*-commutative91.9%
Simplified91.9%
if -50 < (/.f64 1 n) < 5.00000000000000033e-69Initial program 29.6%
Taylor expanded in n around inf 80.9%
log1p-def80.9%
Simplified80.9%
if 50 < (/.f64 1 n) Initial program 64.2%
Taylor expanded in x around 0 60.3%
Final simplification81.6%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- 1.0 t_0)))
(if (<= x 1.42e-204)
t_1
(if (<= x 1e-169)
(- (/ (log x) n))
(if (<= x 1.2e-141)
t_1
(if (<= x 1.7e-13) (* (log x) (/ 1.0 (- n))) (/ t_0 (* n x))))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = 1.0 - t_0;
double tmp;
if (x <= 1.42e-204) {
tmp = t_1;
} else if (x <= 1e-169) {
tmp = -(log(x) / n);
} else if (x <= 1.2e-141) {
tmp = t_1;
} else if (x <= 1.7e-13) {
tmp = log(x) * (1.0 / -n);
} else {
tmp = t_0 / (n * x);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
t_1 = 1.0d0 - t_0
if (x <= 1.42d-204) then
tmp = t_1
else if (x <= 1d-169) then
tmp = -(log(x) / n)
else if (x <= 1.2d-141) then
tmp = t_1
else if (x <= 1.7d-13) then
tmp = log(x) * (1.0d0 / -n)
else
tmp = t_0 / (n * x)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = 1.0 - t_0;
double tmp;
if (x <= 1.42e-204) {
tmp = t_1;
} else if (x <= 1e-169) {
tmp = -(Math.log(x) / n);
} else if (x <= 1.2e-141) {
tmp = t_1;
} else if (x <= 1.7e-13) {
tmp = Math.log(x) * (1.0 / -n);
} else {
tmp = t_0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = 1.0 - t_0 tmp = 0 if x <= 1.42e-204: tmp = t_1 elif x <= 1e-169: tmp = -(math.log(x) / n) elif x <= 1.2e-141: tmp = t_1 elif x <= 1.7e-13: tmp = math.log(x) * (1.0 / -n) else: tmp = t_0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(1.0 - t_0) tmp = 0.0 if (x <= 1.42e-204) tmp = t_1; elseif (x <= 1e-169) tmp = Float64(-Float64(log(x) / n)); elseif (x <= 1.2e-141) tmp = t_1; elseif (x <= 1.7e-13) tmp = Float64(log(x) * Float64(1.0 / Float64(-n))); else tmp = Float64(t_0 / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); t_1 = 1.0 - t_0; tmp = 0.0; if (x <= 1.42e-204) tmp = t_1; elseif (x <= 1e-169) tmp = -(log(x) / n); elseif (x <= 1.2e-141) tmp = t_1; elseif (x <= 1.7e-13) tmp = log(x) * (1.0 / -n); else tmp = t_0 / (n * x); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, If[LessEqual[x, 1.42e-204], t$95$1, If[LessEqual[x, 1e-169], (-N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]), If[LessEqual[x, 1.2e-141], t$95$1, If[LessEqual[x, 1.7e-13], N[(N[Log[x], $MachinePrecision] * N[(1.0 / (-n)), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := 1 - t_0\\
\mathbf{if}\;x \leq 1.42 \cdot 10^{-204}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 10^{-169}:\\
\;\;\;\;-\frac{\log x}{n}\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-141}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-13}:\\
\;\;\;\;\log x \cdot \frac{1}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\end{array}
\end{array}
if x < 1.4200000000000001e-204 or 1.00000000000000002e-169 < x < 1.2e-141Initial program 56.8%
Taylor expanded in x around 0 56.8%
if 1.4200000000000001e-204 < x < 1.00000000000000002e-169Initial program 22.0%
Taylor expanded in x around 0 22.0%
Taylor expanded in n around inf 77.9%
neg-mul-177.9%
distribute-neg-frac77.9%
Simplified77.9%
if 1.2e-141 < x < 1.70000000000000008e-13Initial program 31.9%
Taylor expanded in x around 0 30.1%
Taylor expanded in n around inf 61.6%
neg-mul-161.6%
distribute-neg-frac61.6%
Simplified61.6%
frac-2neg61.6%
div-inv61.6%
remove-double-neg61.6%
Applied egg-rr61.6%
if 1.70000000000000008e-13 < x Initial program 68.5%
Taylor expanded in n around 0 68.5%
log1p-def68.5%
Simplified68.5%
rem-cbrt-cube68.5%
pow1/365.7%
cube-mult65.7%
unpow-prod-down65.7%
pow1/368.5%
pow268.5%
Applied egg-rr68.5%
unpow1/368.5%
Simplified68.5%
Taylor expanded in x around inf 96.3%
mul-1-neg96.3%
log-rec96.3%
distribute-neg-frac96.3%
remove-double-neg96.3%
*-rgt-identity96.3%
associate-*r/96.2%
exp-to-pow96.2%
*-commutative96.2%
Simplified96.2%
Final simplification75.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (+ 1.0 (/ x n)) t_0)))
(if (<= x 7.6e-205)
t_1
(if (<= x 1.65e-170)
(- (/ (log x) n))
(if (<= x 2.05e-141)
t_1
(if (<= x 1.58e-12) (* (log x) (/ 1.0 (- n))) (/ t_0 (* n x))))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = (1.0 + (x / n)) - t_0;
double tmp;
if (x <= 7.6e-205) {
tmp = t_1;
} else if (x <= 1.65e-170) {
tmp = -(log(x) / n);
} else if (x <= 2.05e-141) {
tmp = t_1;
} else if (x <= 1.58e-12) {
tmp = log(x) * (1.0 / -n);
} else {
tmp = t_0 / (n * x);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
t_1 = (1.0d0 + (x / n)) - t_0
if (x <= 7.6d-205) then
tmp = t_1
else if (x <= 1.65d-170) then
tmp = -(log(x) / n)
else if (x <= 2.05d-141) then
tmp = t_1
else if (x <= 1.58d-12) then
tmp = log(x) * (1.0d0 / -n)
else
tmp = t_0 / (n * x)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = (1.0 + (x / n)) - t_0;
double tmp;
if (x <= 7.6e-205) {
tmp = t_1;
} else if (x <= 1.65e-170) {
tmp = -(Math.log(x) / n);
} else if (x <= 2.05e-141) {
tmp = t_1;
} else if (x <= 1.58e-12) {
tmp = Math.log(x) * (1.0 / -n);
} else {
tmp = t_0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = (1.0 + (x / n)) - t_0 tmp = 0 if x <= 7.6e-205: tmp = t_1 elif x <= 1.65e-170: tmp = -(math.log(x) / n) elif x <= 2.05e-141: tmp = t_1 elif x <= 1.58e-12: tmp = math.log(x) * (1.0 / -n) else: tmp = t_0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(Float64(1.0 + Float64(x / n)) - t_0) tmp = 0.0 if (x <= 7.6e-205) tmp = t_1; elseif (x <= 1.65e-170) tmp = Float64(-Float64(log(x) / n)); elseif (x <= 2.05e-141) tmp = t_1; elseif (x <= 1.58e-12) tmp = Float64(log(x) * Float64(1.0 / Float64(-n))); else tmp = Float64(t_0 / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); t_1 = (1.0 + (x / n)) - t_0; tmp = 0.0; if (x <= 7.6e-205) tmp = t_1; elseif (x <= 1.65e-170) tmp = -(log(x) / n); elseif (x <= 2.05e-141) tmp = t_1; elseif (x <= 1.58e-12) tmp = log(x) * (1.0 / -n); else tmp = t_0 / (n * x); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[x, 7.6e-205], t$95$1, If[LessEqual[x, 1.65e-170], (-N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]), If[LessEqual[x, 2.05e-141], t$95$1, If[LessEqual[x, 1.58e-12], N[(N[Log[x], $MachinePrecision] * N[(1.0 / (-n)), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{if}\;x \leq 7.6 \cdot 10^{-205}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-170}:\\
\;\;\;\;-\frac{\log x}{n}\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-141}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.58 \cdot 10^{-12}:\\
\;\;\;\;\log x \cdot \frac{1}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\end{array}
\end{array}
if x < 7.59999999999999983e-205 or 1.65000000000000002e-170 < x < 2.05000000000000001e-141Initial program 56.8%
Taylor expanded in x around 0 57.0%
if 7.59999999999999983e-205 < x < 1.65000000000000002e-170Initial program 22.0%
Taylor expanded in x around 0 22.0%
Taylor expanded in n around inf 77.9%
neg-mul-177.9%
distribute-neg-frac77.9%
Simplified77.9%
if 2.05000000000000001e-141 < x < 1.57999999999999993e-12Initial program 31.9%
Taylor expanded in x around 0 30.1%
Taylor expanded in n around inf 61.6%
neg-mul-161.6%
distribute-neg-frac61.6%
Simplified61.6%
frac-2neg61.6%
div-inv61.6%
remove-double-neg61.6%
Applied egg-rr61.6%
if 1.57999999999999993e-12 < x Initial program 68.5%
Taylor expanded in n around 0 68.5%
log1p-def68.5%
Simplified68.5%
rem-cbrt-cube68.5%
pow1/365.7%
cube-mult65.7%
unpow-prod-down65.7%
pow1/368.5%
pow268.5%
Applied egg-rr68.5%
unpow1/368.5%
Simplified68.5%
Taylor expanded in x around inf 96.3%
mul-1-neg96.3%
log-rec96.3%
distribute-neg-frac96.3%
remove-double-neg96.3%
*-rgt-identity96.3%
associate-*r/96.2%
exp-to-pow96.2%
*-commutative96.2%
Simplified96.2%
Final simplification75.9%
(FPCore (x n)
:precision binary64
(if (<= n -54000000000.0)
(- (/ (log x) n))
(if (<= n 47000000000.0)
(- 1.0 (pow x (/ 1.0 n)))
(* (log x) (/ 1.0 (- n))))))
double code(double x, double n) {
double tmp;
if (n <= -54000000000.0) {
tmp = -(log(x) / n);
} else if (n <= 47000000000.0) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = log(x) * (1.0 / -n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (n <= (-54000000000.0d0)) then
tmp = -(log(x) / n)
else if (n <= 47000000000.0d0) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else
tmp = log(x) * (1.0d0 / -n)
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (n <= -54000000000.0) {
tmp = -(Math.log(x) / n);
} else if (n <= 47000000000.0) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = Math.log(x) * (1.0 / -n);
}
return tmp;
}
def code(x, n): tmp = 0 if n <= -54000000000.0: tmp = -(math.log(x) / n) elif n <= 47000000000.0: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = math.log(x) * (1.0 / -n) return tmp
function code(x, n) tmp = 0.0 if (n <= -54000000000.0) tmp = Float64(-Float64(log(x) / n)); elseif (n <= 47000000000.0) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(log(x) * Float64(1.0 / Float64(-n))); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (n <= -54000000000.0) tmp = -(log(x) / n); elseif (n <= 47000000000.0) tmp = 1.0 - (x ^ (1.0 / n)); else tmp = log(x) * (1.0 / -n); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[n, -54000000000.0], (-N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]), If[LessEqual[n, 47000000000.0], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Log[x], $MachinePrecision] * N[(1.0 / (-n)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -54000000000:\\
\;\;\;\;-\frac{\log x}{n}\\
\mathbf{elif}\;n \leq 47000000000:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\log x \cdot \frac{1}{-n}\\
\end{array}
\end{array}
if n < -5.4e10Initial program 21.5%
Taylor expanded in x around 0 21.5%
Taylor expanded in n around inf 60.4%
neg-mul-160.4%
distribute-neg-frac60.4%
Simplified60.4%
if -5.4e10 < n < 4.7e10Initial program 85.3%
Taylor expanded in x around 0 51.2%
if 4.7e10 < n Initial program 30.4%
Taylor expanded in x around 0 30.4%
Taylor expanded in n around inf 50.1%
neg-mul-150.1%
distribute-neg-frac50.1%
Simplified50.1%
frac-2neg50.1%
div-inv50.1%
remove-double-neg50.1%
Applied egg-rr50.1%
Final simplification53.1%
(FPCore (x n) :precision binary64 (- (/ (log x) n)))
double code(double x, double n) {
return -(log(x) / n);
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = -(log(x) / n)
end function
public static double code(double x, double n) {
return -(Math.log(x) / n);
}
def code(x, n): return -(math.log(x) / n)
function code(x, n) return Float64(-Float64(log(x) / n)) end
function tmp = code(x, n) tmp = -(log(x) / n); end
code[x_, n_] := (-N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision])
\begin{array}{l}
\\
-\frac{\log x}{n}
\end{array}
Initial program 54.6%
Taylor expanded in x around 0 38.2%
Taylor expanded in n around inf 31.1%
neg-mul-131.1%
distribute-neg-frac31.1%
Simplified31.1%
Final simplification31.1%
(FPCore (x n) :precision binary64 (/ (log x) n))
double code(double x, double n) {
return log(x) / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = log(x) / n
end function
public static double code(double x, double n) {
return Math.log(x) / n;
}
def code(x, n): return math.log(x) / n
function code(x, n) return Float64(log(x) / n) end
function tmp = code(x, n) tmp = log(x) / n; end
code[x_, n_] := N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log x}{n}
\end{array}
Initial program 54.6%
Taylor expanded in x around 0 38.2%
Taylor expanded in n around inf 31.1%
neg-mul-131.1%
distribute-neg-frac31.1%
Simplified31.1%
add-sqr-sqrt29.4%
sqrt-unprod31.5%
sqr-neg31.5%
sqrt-unprod1.9%
add-sqr-sqrt3.1%
clear-num3.1%
associate-/r/3.1%
Applied egg-rr3.1%
Taylor expanded in n around 0 3.1%
Final simplification3.1%
herbie shell --seed 2024023
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))