
(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 11 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 (if (<= x 0.056) (- (cbrt (pow (exp 3.0) (/ (log1p x) n))) (pow x (/ 1.0 n))) (/ (exp (* 2.0 (log (pow x (/ (/ 1.0 n) 2.0))))) (* x n))))
double code(double x, double n) {
double tmp;
if (x <= 0.056) {
tmp = cbrt(pow(exp(3.0), (log1p(x) / n))) - pow(x, (1.0 / n));
} else {
tmp = exp((2.0 * log(pow(x, ((1.0 / n) / 2.0))))) / (x * n);
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if (x <= 0.056) {
tmp = Math.cbrt(Math.pow(Math.exp(3.0), (Math.log1p(x) / n))) - Math.pow(x, (1.0 / n));
} else {
tmp = Math.exp((2.0 * Math.log(Math.pow(x, ((1.0 / n) / 2.0))))) / (x * n);
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.056) tmp = Float64(cbrt((exp(3.0) ^ Float64(log1p(x) / n))) - (x ^ Float64(1.0 / n))); else tmp = Float64(exp(Float64(2.0 * log((x ^ Float64(Float64(1.0 / n) / 2.0))))) / Float64(x * n)); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.056], N[(N[Power[N[Power[N[Exp[3.0], $MachinePrecision], N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(2.0 * N[Log[N[Power[x, N[(N[(1.0 / n), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;\sqrt[3]{{\left(e^{3}\right)}^{\left(\frac{\mathsf{log1p}\left(x\right)}{n}\right)}} - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{2 \cdot \log \left({x}^{\left(\frac{\frac{1}{n}}{2}\right)}\right)}}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
add-cbrt-cube78.6%
pow378.6%
pow-to-exp78.6%
pow-exp78.6%
un-div-inv78.6%
+-commutative78.6%
log1p-udef98.9%
Applied egg-rr98.9%
Taylor expanded in n around 0 98.9%
exp-prod98.9%
Simplified98.9%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in x around inf 99.8%
log-rec99.8%
mul-1-neg99.8%
associate-*r/99.8%
neg-mul-199.8%
mul-1-neg99.8%
remove-double-neg99.8%
*-commutative99.8%
Simplified99.8%
add-log-exp99.8%
div-inv99.8%
pow-to-exp99.8%
add-sqr-sqrt99.8%
log-prod99.8%
Applied egg-rr99.8%
count-299.8%
Simplified99.8%
sqrt-pow199.9%
Applied egg-rr99.9%
Final simplification99.2%
(FPCore (x n) :precision binary64 (if (<= x 0.056) (- (cbrt (exp (* 3.0 (/ x n)))) (pow x (/ 1.0 n))) (/ (exp (* 2.0 (log (pow x (/ (/ 1.0 n) 2.0))))) (* x n))))
double code(double x, double n) {
double tmp;
if (x <= 0.056) {
tmp = cbrt(exp((3.0 * (x / n)))) - pow(x, (1.0 / n));
} else {
tmp = exp((2.0 * log(pow(x, ((1.0 / n) / 2.0))))) / (x * n);
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if (x <= 0.056) {
tmp = Math.cbrt(Math.exp((3.0 * (x / n)))) - Math.pow(x, (1.0 / n));
} else {
tmp = Math.exp((2.0 * Math.log(Math.pow(x, ((1.0 / n) / 2.0))))) / (x * n);
}
return tmp;
}
function code(x, n) tmp = 0.0 if (x <= 0.056) tmp = Float64(cbrt(exp(Float64(3.0 * Float64(x / n)))) - (x ^ Float64(1.0 / n))); else tmp = Float64(exp(Float64(2.0 * log((x ^ Float64(Float64(1.0 / n) / 2.0))))) / Float64(x * n)); end return tmp end
code[x_, n_] := If[LessEqual[x, 0.056], N[(N[Power[N[Exp[N[(3.0 * N[(x / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(2.0 * N[Log[N[Power[x, N[(N[(1.0 / n), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;\sqrt[3]{e^{3 \cdot \frac{x}{n}}} - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{2 \cdot \log \left({x}^{\left(\frac{\frac{1}{n}}{2}\right)}\right)}}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
add-cbrt-cube78.6%
pow378.6%
pow-to-exp78.6%
pow-exp78.6%
un-div-inv78.6%
+-commutative78.6%
log1p-udef98.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 98.9%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in x around inf 99.8%
log-rec99.8%
mul-1-neg99.8%
associate-*r/99.8%
neg-mul-199.8%
mul-1-neg99.8%
remove-double-neg99.8%
*-commutative99.8%
Simplified99.8%
add-log-exp99.8%
div-inv99.8%
pow-to-exp99.8%
add-sqr-sqrt99.8%
log-prod99.8%
Applied egg-rr99.8%
count-299.8%
Simplified99.8%
sqrt-pow199.9%
Applied egg-rr99.9%
Final simplification99.2%
(FPCore (x n) :precision binary64 (let* ((t_0 (pow x (/ 1.0 n)))) (if (<= x 0.056) (- (cbrt (exp (* 3.0 (/ x n)))) t_0) (/ t_0 (* x n)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = cbrt(exp((3.0 * (x / n)))) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = Math.cbrt(Math.exp((3.0 * (x / n)))) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 0.056) tmp = Float64(cbrt(exp(Float64(3.0 * Float64(x / n)))) - t_0); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 0.056], N[(N[Power[N[Exp[N[(3.0 * N[(x / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision] - t$95$0), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;\sqrt[3]{e^{3 \cdot \frac{x}{n}}} - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
add-cbrt-cube78.6%
pow378.6%
pow-to-exp78.6%
pow-exp78.6%
un-div-inv78.6%
+-commutative78.6%
log1p-udef98.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 98.9%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in n around 0 6.7%
log1p-def6.7%
Simplified6.7%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
log-rec99.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x n) :precision binary64 (let* ((t_0 (pow x (/ 1.0 n)))) (if (<= x 0.056) (- (exp (/ x n)) t_0) (/ t_0 (* x n)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = exp((x / n)) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= 0.056d0) then
tmp = exp((x / n)) - t_0
else
tmp = t_0 / (x * n)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = Math.exp((x / n)) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 0.056: tmp = math.exp((x / n)) - t_0 else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 0.056) tmp = Float64(exp(Float64(x / n)) - t_0); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 0.056) tmp = exp((x / n)) - t_0; else tmp = t_0 / (x * n); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 0.056], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
Taylor expanded in n around 0 78.6%
log1p-def98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in n around 0 6.7%
log1p-def6.7%
Simplified6.7%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
log-rec99.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x 1.5e-141)
(- (+ 1.0 (/ x n)) t_0)
(if (<= x 0.056) (log1p (expm1 (/ 1.0 (* x n)))) (/ t_0 (* x n))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 1.5e-141) {
tmp = (1.0 + (x / n)) - t_0;
} else if (x <= 0.056) {
tmp = log1p(expm1((1.0 / (x * n))));
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 1.5e-141) {
tmp = (1.0 + (x / n)) - t_0;
} else if (x <= 0.056) {
tmp = Math.log1p(Math.expm1((1.0 / (x * n))));
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 1.5e-141: tmp = (1.0 + (x / n)) - t_0 elif x <= 0.056: tmp = math.log1p(math.expm1((1.0 / (x * n)))) else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 1.5e-141) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); elseif (x <= 0.056) tmp = log1p(expm1(Float64(1.0 / Float64(x * n)))); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 1.5e-141], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[x, 0.056], N[Log[1 + N[(Exp[N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 1.5 \cdot 10^{-141}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{elif}\;x \leq 0.056:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{x \cdot n}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 1.49999999999999992e-141Initial program 91.6%
Taylor expanded in x around 0 91.9%
if 1.49999999999999992e-141 < x < 0.0560000000000000012Initial program 60.5%
Taylor expanded in n around 0 60.5%
log1p-def99.9%
Simplified99.9%
Taylor expanded in x around inf 47.8%
mul-1-neg47.8%
log-rec47.8%
distribute-frac-neg47.8%
remove-double-neg47.8%
*-rgt-identity47.8%
associate-*r/47.8%
exp-to-pow47.8%
*-commutative47.8%
Simplified47.8%
Taylor expanded in n around inf 35.2%
*-commutative35.2%
Simplified35.2%
log1p-expm1-u91.5%
Applied egg-rr91.5%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in n around 0 6.7%
log1p-def6.7%
Simplified6.7%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
log-rec99.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
*-commutative99.8%
Simplified99.8%
Final simplification94.7%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (/ 1.0 n) x)) (t_1 (pow x (/ 1.0 n))))
(if (<= x 7e-142)
(- (+ 1.0 (/ x n)) t_1)
(if (<= x 1.2e-5) (cbrt (* t_0 (/ t_0 (* x n)))) (/ t_1 (* x n))))))
double code(double x, double n) {
double t_0 = (1.0 / n) / x;
double t_1 = pow(x, (1.0 / n));
double tmp;
if (x <= 7e-142) {
tmp = (1.0 + (x / n)) - t_1;
} else if (x <= 1.2e-5) {
tmp = cbrt((t_0 * (t_0 / (x * n))));
} else {
tmp = t_1 / (x * n);
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = (1.0 / n) / x;
double t_1 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 7e-142) {
tmp = (1.0 + (x / n)) - t_1;
} else if (x <= 1.2e-5) {
tmp = Math.cbrt((t_0 * (t_0 / (x * n))));
} else {
tmp = t_1 / (x * n);
}
return tmp;
}
function code(x, n) t_0 = Float64(Float64(1.0 / n) / x) t_1 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 7e-142) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_1); elseif (x <= 1.2e-5) tmp = cbrt(Float64(t_0 * Float64(t_0 / Float64(x * n)))); else tmp = Float64(t_1 / Float64(x * n)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]}, Block[{t$95$1 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 7e-142], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[x, 1.2e-5], N[Power[N[(t$95$0 * N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(t$95$1 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{n}}{x}\\
t_1 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 7 \cdot 10^{-142}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_1\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-5}:\\
\;\;\;\;\sqrt[3]{t_0 \cdot \frac{t_0}{x \cdot n}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{x \cdot n}\\
\end{array}
\end{array}
if x < 7.00000000000000029e-142Initial program 91.6%
Taylor expanded in x around 0 91.9%
if 7.00000000000000029e-142 < x < 1.2e-5Initial program 58.1%
Taylor expanded in n around 0 58.1%
log1p-def99.9%
Simplified99.9%
Taylor expanded in x around inf 46.1%
mul-1-neg46.1%
log-rec46.1%
distribute-frac-neg46.1%
remove-double-neg46.1%
*-rgt-identity46.1%
associate-*r/46.1%
exp-to-pow46.1%
*-commutative46.1%
Simplified46.1%
Taylor expanded in n around inf 37.0%
*-commutative37.0%
Simplified37.0%
add-cbrt-cube85.0%
Applied egg-rr85.0%
associate-*l*85.0%
*-commutative85.0%
associate-/r*85.0%
associate-*l/85.0%
*-lft-identity85.0%
*-commutative85.0%
associate-/r*85.0%
Simplified85.0%
if 1.2e-5 < x Initial program 10.5%
Taylor expanded in n around 0 10.5%
log1p-def10.5%
Simplified10.5%
Taylor expanded in x around inf 98.8%
mul-1-neg98.8%
log-rec98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
*-rgt-identity98.8%
associate-*r/98.8%
exp-to-pow98.8%
*-commutative98.8%
Simplified98.8%
Final simplification92.9%
(FPCore (x n) :precision binary64 (let* ((t_0 (pow x (/ 1.0 n)))) (if (<= x 0.056) (- (+ 1.0 (/ x n)) t_0) (/ t_0 (* x n)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= 0.056d0) then
tmp = (1.0d0 + (x / n)) - t_0
else
tmp = t_0 / (x * n)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 0.056: tmp = (1.0 + (x / n)) - t_0 else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 0.056) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 0.056) tmp = (1.0 + (x / n)) - t_0; else tmp = t_0 / (x * n); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 0.056], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
Taylor expanded in x around 0 76.7%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in n around 0 6.7%
log1p-def6.7%
Simplified6.7%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
log-rec99.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
*-commutative99.8%
Simplified99.8%
Final simplification85.2%
(FPCore (x n) :precision binary64 (let* ((t_0 (pow x (/ 1.0 n)))) (if (<= x 0.056) (- 1.0 t_0) (/ t_0 (* x n)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = 1.0 - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= 0.056d0) then
tmp = 1.0d0 - t_0
else
tmp = t_0 / (x * n)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 0.056) {
tmp = 1.0 - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 0.056: tmp = 1.0 - t_0 else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 0.056) tmp = Float64(1.0 - t_0); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 0.056) tmp = 1.0 - t_0; else tmp = t_0 / (x * n); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 0.056], N[(1.0 - t$95$0), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 0.056:\\
\;\;\;\;1 - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 0.0560000000000000012Initial program 78.6%
Taylor expanded in x around 0 76.2%
if 0.0560000000000000012 < x Initial program 6.7%
Taylor expanded in n around 0 6.7%
log1p-def6.7%
Simplified6.7%
Taylor expanded in x around inf 99.8%
mul-1-neg99.8%
log-rec99.8%
distribute-frac-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
*-commutative99.8%
Simplified99.8%
Final simplification84.9%
(FPCore (x n) :precision binary64 (if (<= x 1.0) (- 1.0 (pow x (/ 1.0 n))) (/ (- x (log x)) n)))
double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = (x - log(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 = 1.0d0 - (x ** (1.0d0 / n))
else
tmp = (x - log(x)) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = (x - Math.log(x)) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.0: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = (x - math.log(x)) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(Float64(x - log(x)) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.0) tmp = 1.0 - (x ^ (1.0 / n)); else tmp = (x - log(x)) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.0], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \log x}{n}\\
\end{array}
\end{array}
if x < 1Initial program 79.0%
Taylor expanded in x around 0 76.6%
if 1 < x Initial program 3.6%
Taylor expanded in n around 0 3.6%
log1p-def3.6%
Simplified3.6%
Taylor expanded in x around 0 3.5%
Taylor expanded in n around inf 52.3%
Final simplification68.0%
(FPCore (x n) :precision binary64 (if (<= x 4.2e+23) (/ 1.0 (* x n)) (/ (- x (log x)) n)))
double code(double x, double n) {
double tmp;
if (x <= 4.2e+23) {
tmp = 1.0 / (x * n);
} else {
tmp = (x - log(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 <= 4.2d+23) then
tmp = 1.0d0 / (x * n)
else
tmp = (x - log(x)) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 4.2e+23) {
tmp = 1.0 / (x * n);
} else {
tmp = (x - Math.log(x)) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 4.2e+23: tmp = 1.0 / (x * n) else: tmp = (x - math.log(x)) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 4.2e+23) tmp = Float64(1.0 / Float64(x * n)); else tmp = Float64(Float64(x - log(x)) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 4.2e+23) tmp = 1.0 / (x * n); else tmp = (x - log(x)) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 4.2e+23], N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{1}{x \cdot n}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \log x}{n}\\
\end{array}
\end{array}
if x < 4.2000000000000003e23Initial program 74.5%
Taylor expanded in n around 0 74.5%
log1p-def92.9%
Simplified92.9%
Taylor expanded in x around inf 54.9%
mul-1-neg54.9%
log-rec54.9%
distribute-frac-neg54.9%
remove-double-neg54.9%
*-rgt-identity54.9%
associate-*r/54.9%
exp-to-pow54.9%
*-commutative54.9%
Simplified54.9%
Taylor expanded in n around inf 36.3%
*-commutative36.3%
Simplified36.3%
if 4.2000000000000003e23 < x Initial program 0.3%
Taylor expanded in n around 0 0.3%
log1p-def0.3%
Simplified0.3%
Taylor expanded in x around 0 0.1%
Taylor expanded in n around inf 60.9%
Final simplification43.7%
(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(1.0 / Float64(x * n)) end
function tmp = code(x, n) tmp = 1.0 / (x * n); end
code[x_, n_] := N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot n}
\end{array}
Initial program 52.2%
Taylor expanded in n around 0 52.2%
log1p-def65.0%
Simplified65.0%
Taylor expanded in x around inf 68.4%
mul-1-neg68.4%
log-rec68.4%
distribute-frac-neg68.4%
remove-double-neg68.4%
*-rgt-identity68.4%
associate-*r/68.4%
exp-to-pow68.4%
*-commutative68.4%
Simplified68.4%
Taylor expanded in n around inf 26.8%
*-commutative26.8%
Simplified26.8%
Final simplification26.8%
herbie shell --seed 2023278
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))