
(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
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -2e-55)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 2e-35)
(/
(+
(log1p x)
(- (* 0.5 (/ (- (pow (log1p x) 2.0) (pow (log x) 2.0)) n)) (log x)))
n)
(- (exp (/ (log1p 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-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 2e-35) {
tmp = (log1p(x) + ((0.5 * ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) / n)) - log(x))) / n;
} else {
tmp = exp((log1p(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-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 2e-35) {
tmp = (Math.log1p(x) + ((0.5 * ((Math.pow(Math.log1p(x), 2.0) - Math.pow(Math.log(x), 2.0)) / n)) - Math.log(x))) / n;
} else {
tmp = Math.exp((Math.log1p(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-55: tmp = t_0 / (n * x) elif (1.0 / n) <= 2e-35: tmp = (math.log1p(x) + ((0.5 * ((math.pow(math.log1p(x), 2.0) - math.pow(math.log(x), 2.0)) / n)) - math.log(x))) / n else: tmp = math.exp((math.log1p(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-55) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 2e-35) tmp = Float64(Float64(log1p(x) + Float64(Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) / n)) - log(x))) / n); else tmp = Float64(exp(Float64(log1p(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-55], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-35], N[(N[(N[Log[1 + x], $MachinePrecision] + N[(N[(0.5 * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / 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^{-55}:\\
\;\;\;\;\frac{t\_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-35}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) + \left(0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n} - \log x\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -1.99999999999999999e-55Initial program 87.8%
Taylor expanded in x around inf 93.8%
mul-1-neg93.8%
log-rec93.8%
mul-1-neg93.8%
distribute-neg-frac93.8%
mul-1-neg93.8%
remove-double-neg93.8%
*-rgt-identity93.8%
associate-/l*93.8%
exp-to-pow93.8%
*-commutative93.8%
Simplified93.8%
if -1.99999999999999999e-55 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000002e-35Initial program 30.1%
Taylor expanded in n around inf 76.7%
Simplified76.7%
if 2.00000000000000002e-35 < (/.f64 #s(literal 1 binary64) n) Initial program 52.2%
Taylor expanded in n around 0 52.2%
log1p-define97.6%
*-rgt-identity97.6%
associate-/l*97.6%
exp-to-pow97.7%
Simplified97.7%
Final simplification86.0%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -2e-55)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 2e-35)
(/ (- (log1p x) (log x)) n)
(- (exp (/ (log1p 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-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 2e-35) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = exp((log1p(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-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 2e-35) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = Math.exp((Math.log1p(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-55: tmp = t_0 / (n * x) elif (1.0 / n) <= 2e-35: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = math.exp((math.log1p(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-55) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 2e-35) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(exp(Float64(log1p(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-55], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-35], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / 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^{-55}:\\
\;\;\;\;\frac{t\_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-35}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -1.99999999999999999e-55Initial program 87.8%
Taylor expanded in x around inf 93.8%
mul-1-neg93.8%
log-rec93.8%
mul-1-neg93.8%
distribute-neg-frac93.8%
mul-1-neg93.8%
remove-double-neg93.8%
*-rgt-identity93.8%
associate-/l*93.8%
exp-to-pow93.8%
*-commutative93.8%
Simplified93.8%
if -1.99999999999999999e-55 < (/.f64 #s(literal 1 binary64) n) < 2.00000000000000002e-35Initial program 30.1%
Taylor expanded in n around inf 76.7%
log1p-define76.7%
Simplified76.7%
if 2.00000000000000002e-35 < (/.f64 #s(literal 1 binary64) n) Initial program 52.2%
Taylor expanded in n around 0 52.2%
log1p-define97.6%
*-rgt-identity97.6%
associate-/l*97.6%
exp-to-pow97.7%
Simplified97.7%
Final simplification86.0%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -2e-55)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 1e-7)
(/ (- (log1p x) (log x)) n)
(- (+ 1.0 (* x (+ (/ 1.0 n) (* x (/ (+ (/ 0.5 n) -0.5) n))))) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -2e-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 1e-7) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * (((0.5 / n) + -0.5) / 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-55) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 1e-7) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * (((0.5 / n) + -0.5) / n))))) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -2e-55: tmp = t_0 / (n * x) elif (1.0 / n) <= 1e-7: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = (1.0 + (x * ((1.0 / n) + (x * (((0.5 / n) + -0.5) / 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-55) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 1e-7) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(Float64(1.0 + Float64(x * Float64(Float64(1.0 / n) + Float64(x * Float64(Float64(Float64(0.5 / n) + -0.5) / 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-55], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e-7], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 + N[(x * N[(N[(1.0 / n), $MachinePrecision] + N[(x * N[(N[(N[(0.5 / n), $MachinePrecision] + -0.5), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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^{-55}:\\
\;\;\;\;\frac{t\_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \frac{\frac{0.5}{n} + -0.5}{n}\right)\right) - t\_0\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -1.99999999999999999e-55Initial program 87.8%
Taylor expanded in x around inf 93.8%
mul-1-neg93.8%
log-rec93.8%
mul-1-neg93.8%
distribute-neg-frac93.8%
mul-1-neg93.8%
remove-double-neg93.8%
*-rgt-identity93.8%
associate-/l*93.8%
exp-to-pow93.8%
*-commutative93.8%
Simplified93.8%
if -1.99999999999999999e-55 < (/.f64 #s(literal 1 binary64) n) < 9.9999999999999995e-8Initial program 29.9%
Taylor expanded in n around inf 76.1%
log1p-define76.1%
Simplified76.1%
if 9.9999999999999995e-8 < (/.f64 #s(literal 1 binary64) n) Initial program 53.3%
Taylor expanded in x around 0 83.5%
Taylor expanded in n around inf 83.5%
sub-neg83.5%
associate-*r/83.5%
metadata-eval83.5%
metadata-eval83.5%
Simplified83.5%
Final simplification83.3%
(FPCore (x n) :precision binary64 (if (<= x 5.2e-53) (/ (log x) (- n)) (if (<= x 1.0) (log1p (expm1 (/ x n))) (/ (pow x (/ 1.0 n)) (* n x)))))
double code(double x, double n) {
double tmp;
if (x <= 5.2e-53) {
tmp = log(x) / -n;
} else if (x <= 1.0) {
tmp = log1p(expm1((x / n)));
} else {
tmp = pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if (x <= 5.2e-53) {
tmp = Math.log(x) / -n;
} else if (x <= 1.0) {
tmp = Math.log1p(Math.expm1((x / n)));
} else {
tmp = Math.pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 5.2e-53: tmp = math.log(x) / -n elif x <= 1.0: tmp = math.log1p(math.expm1((x / n))) else: tmp = math.pow(x, (1.0 / n)) / (n * x) return tmp
function code(x, n) tmp = 0.0 if (x <= 5.2e-53) tmp = Float64(log(x) / Float64(-n)); elseif (x <= 1.0) tmp = log1p(expm1(Float64(x / n))); else tmp = Float64((x ^ Float64(1.0 / n)) / Float64(n * x)); end return tmp end
code[x_, n_] := If[LessEqual[x, 5.2e-53], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], If[LessEqual[x, 1.0], N[Log[1 + N[(Exp[N[(x / n), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.2 \cdot 10^{-53}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x}{n}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\
\end{array}
\end{array}
if x < 5.19999999999999993e-53Initial program 38.9%
Taylor expanded in x around 0 38.9%
*-rgt-identity38.9%
associate-/l*38.9%
exp-to-pow38.9%
Simplified38.9%
Taylor expanded in n around inf 56.6%
associate-*r/56.6%
neg-mul-156.6%
Simplified56.6%
if 5.19999999999999993e-53 < x < 1Initial program 36.0%
Taylor expanded in x around 0 28.8%
Taylor expanded in x around inf 6.5%
log1p-expm1-u70.0%
Applied egg-rr70.0%
if 1 < x Initial program 69.5%
Taylor expanded in x around inf 98.2%
mul-1-neg98.2%
log-rec98.2%
mul-1-neg98.2%
distribute-neg-frac98.2%
mul-1-neg98.2%
remove-double-neg98.2%
*-rgt-identity98.2%
associate-/l*98.2%
exp-to-pow98.2%
*-commutative98.2%
Simplified98.2%
Final simplification77.9%
(FPCore (x n) :precision binary64 (if (<= x 0.78) (/ (- (* x (+ 1.0 (* x -0.5))) (log x)) n) (/ (pow x (/ 1.0 n)) (* n x))))
double code(double x, double n) {
double tmp;
if (x <= 0.78) {
tmp = ((x * (1.0 + (x * -0.5))) - log(x)) / n;
} else {
tmp = pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 0.78d0) then
tmp = ((x * (1.0d0 + (x * (-0.5d0)))) - log(x)) / n
else
tmp = (x ** (1.0d0 / n)) / (n * x)
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.78) {
tmp = ((x * (1.0 + (x * -0.5))) - Math.log(x)) / n;
} else {
tmp = Math.pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.78: tmp = ((x * (1.0 + (x * -0.5))) - math.log(x)) / n else: tmp = math.pow(x, (1.0 / n)) / (n * x) return tmp
function code(x, n) tmp = 0.0 if (x <= 0.78) tmp = Float64(Float64(Float64(x * Float64(1.0 + Float64(x * -0.5))) - log(x)) / n); else tmp = Float64((x ^ Float64(1.0 / n)) / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.78) tmp = ((x * (1.0 + (x * -0.5))) - log(x)) / n; else tmp = (x ^ (1.0 / n)) / (n * x); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.78], N[(N[(N[(x * N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.78:\\
\;\;\;\;\frac{x \cdot \left(1 + x \cdot -0.5\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\
\end{array}
\end{array}
if x < 0.78000000000000003Initial program 38.4%
Taylor expanded in x around 0 36.4%
Taylor expanded in n around inf 52.5%
*-commutative52.5%
Simplified52.5%
if 0.78000000000000003 < x Initial program 69.5%
Taylor expanded in x around inf 98.2%
mul-1-neg98.2%
log-rec98.2%
mul-1-neg98.2%
distribute-neg-frac98.2%
mul-1-neg98.2%
remove-double-neg98.2%
*-rgt-identity98.2%
associate-/l*98.2%
exp-to-pow98.2%
*-commutative98.2%
Simplified98.2%
Final simplification74.5%
(FPCore (x n) :precision binary64 (if (<= x 0.78) (/ (- x (log x)) n) (/ (pow x (/ 1.0 n)) (* n x))))
double code(double x, double n) {
double tmp;
if (x <= 0.78) {
tmp = (x - log(x)) / n;
} else {
tmp = pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 0.78d0) then
tmp = (x - log(x)) / n
else
tmp = (x ** (1.0d0 / n)) / (n * x)
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.78) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = Math.pow(x, (1.0 / n)) / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.78: tmp = (x - math.log(x)) / n else: tmp = math.pow(x, (1.0 / n)) / (n * x) return tmp
function code(x, n) tmp = 0.0 if (x <= 0.78) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64((x ^ Float64(1.0 / n)) / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.78) tmp = (x - log(x)) / n; else tmp = (x ^ (1.0 / n)) / (n * x); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.78], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.78:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\
\end{array}
\end{array}
if x < 0.78000000000000003Initial program 38.4%
Taylor expanded in x around 0 37.2%
Taylor expanded in n around inf 52.5%
if 0.78000000000000003 < x Initial program 69.5%
Taylor expanded in x around inf 98.2%
mul-1-neg98.2%
log-rec98.2%
mul-1-neg98.2%
distribute-neg-frac98.2%
mul-1-neg98.2%
remove-double-neg98.2%
*-rgt-identity98.2%
associate-/l*98.2%
exp-to-pow98.2%
*-commutative98.2%
Simplified98.2%
Final simplification74.5%
(FPCore (x n) :precision binary64 (if (<= x 0.76) (/ (- x (log x)) n) (/ (/ 1.0 x) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.76) {
tmp = (x - log(x)) / 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 <= 0.76d0) then
tmp = (x - log(x)) / 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 <= 0.76) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.76: tmp = (x - math.log(x)) / n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.76) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.76) tmp = (x - log(x)) / n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.76], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 37.9%
Taylor expanded in x around 0 37.5%
Taylor expanded in n around inf 52.9%
if 0.76000000000000001 < x Initial program 69.8%
Taylor expanded in n around inf 69.6%
Simplified70.4%
Taylor expanded in x around inf 59.1%
mul-1-neg59.1%
log-rec59.1%
neg-mul-159.1%
associate-*r/59.1%
mul-1-neg59.1%
remove-double-neg59.1%
Simplified59.1%
Taylor expanded in n around inf 59.3%
(FPCore (x n) :precision binary64 (if (<= x 0.55) (/ (log x) (- n)) (/ (/ 1.0 x) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.55) {
tmp = log(x) / -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 <= 0.55d0) then
tmp = log(x) / -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 <= 0.55) {
tmp = Math.log(x) / -n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.55: tmp = math.log(x) / -n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.55) tmp = Float64(log(x) / Float64(-n)); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.55) tmp = log(x) / -n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.55], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.55:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if x < 0.55000000000000004Initial program 37.9%
Taylor expanded in x around 0 37.2%
*-rgt-identity37.2%
associate-/l*37.2%
exp-to-pow37.2%
Simplified37.2%
Taylor expanded in n around inf 52.7%
associate-*r/52.7%
neg-mul-152.7%
Simplified52.7%
if 0.55000000000000004 < x Initial program 69.8%
Taylor expanded in n around inf 69.6%
Simplified70.4%
Taylor expanded in x around inf 59.1%
mul-1-neg59.1%
log-rec59.1%
neg-mul-159.1%
associate-*r/59.1%
mul-1-neg59.1%
remove-double-neg59.1%
Simplified59.1%
Taylor expanded in n around inf 59.3%
Final simplification55.9%
(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}
Initial program 53.3%
Taylor expanded in n around inf 66.2%
Simplified66.6%
Taylor expanded in x around inf 38.8%
mul-1-neg38.8%
log-rec38.8%
neg-mul-138.8%
associate-*r/38.8%
mul-1-neg38.8%
remove-double-neg38.8%
Simplified38.8%
Taylor expanded in n around inf 39.3%
(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}
Initial program 53.3%
Taylor expanded in n around inf 66.2%
Simplified66.6%
Taylor expanded in x around inf 38.8%
mul-1-neg38.8%
log-rec38.8%
neg-mul-138.8%
associate-*r/38.8%
mul-1-neg38.8%
remove-double-neg38.8%
Simplified38.8%
Taylor expanded in n around inf 38.8%
(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}
Initial program 53.3%
Taylor expanded in x around 0 25.5%
Taylor expanded in x around inf 4.3%
herbie shell --seed 2024131
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))