
(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 9 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 (<= (/ 1.0 n) -4e-77)
(/ (pow x (+ (/ 1.0 n) -1.0)) n)
(if (<= (/ 1.0 n) 0.0005)
(/ (- (log1p x) (log x)) n)
(- (exp (/ x n)) (pow x (/ 1.0 n))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -4e-77) {
tmp = pow(x, ((1.0 / n) + -1.0)) / n;
} else if ((1.0 / n) <= 0.0005) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = exp((x / n)) - pow(x, (1.0 / n));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -4e-77) {
tmp = Math.pow(x, ((1.0 / n) + -1.0)) / n;
} else if ((1.0 / n) <= 0.0005) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = Math.exp((x / n)) - Math.pow(x, (1.0 / n));
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -4e-77: tmp = math.pow(x, ((1.0 / n) + -1.0)) / n elif (1.0 / n) <= 0.0005: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = math.exp((x / n)) - math.pow(x, (1.0 / n)) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -4e-77) tmp = Float64((x ^ Float64(Float64(1.0 / n) + -1.0)) / n); elseif (Float64(1.0 / n) <= 0.0005) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(exp(Float64(x / n)) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -4e-77], N[(N[Power[x, N[(N[(1.0 / n), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.0005], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -4 \cdot 10^{-77}:\\
\;\;\;\;\frac{{x}^{\left(\frac{1}{n} + -1\right)}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.0005:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -3.9999999999999997e-77Initial program 87.6%
Taylor expanded in x around inf 66.3%
log-rec66.3%
mul-1-neg66.3%
neg-mul-166.3%
mul-1-neg66.3%
distribute-frac-neg66.3%
remove-double-neg66.3%
*-rgt-identity66.3%
associate-/l*66.3%
exp-to-pow93.0%
*-commutative93.0%
Simplified93.0%
*-un-lft-identity93.0%
associate-/r*93.5%
pow193.5%
pow-div93.5%
Applied egg-rr93.5%
*-lft-identity93.5%
sub-neg93.5%
metadata-eval93.5%
Simplified93.5%
if -3.9999999999999997e-77 < (/.f64 #s(literal 1 binary64) n) < 5.0000000000000001e-4Initial program 27.5%
Taylor expanded in n around inf 82.8%
log1p-define82.8%
Simplified82.8%
if 5.0000000000000001e-4 < (/.f64 #s(literal 1 binary64) n) Initial program 46.8%
Taylor expanded in n around 0 19.5%
log1p-define47.5%
*-rgt-identity47.5%
associate-*l/47.5%
associate-/l*47.5%
exp-to-pow93.4%
Simplified93.4%
Taylor expanded in x around 0 93.4%
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -4e-77)
(/ (pow x (+ (/ 1.0 n) -1.0)) n)
(if (<= (/ 1.0 n) 0.0005)
(/ (- (log1p x) (log x)) n)
(if (<= (/ 1.0 n) 2e+228)
(- (+ 1.0 (/ x n)) (pow x (/ 1.0 n)))
(expm1 (/ x n))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -4e-77) {
tmp = pow(x, ((1.0 / n) + -1.0)) / n;
} else if ((1.0 / n) <= 0.0005) {
tmp = (log1p(x) - log(x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = (1.0 + (x / n)) - pow(x, (1.0 / n));
} else {
tmp = expm1((x / n));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -4e-77) {
tmp = Math.pow(x, ((1.0 / n) + -1.0)) / n;
} else if ((1.0 / n) <= 0.0005) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = (1.0 + (x / n)) - Math.pow(x, (1.0 / n));
} else {
tmp = Math.expm1((x / n));
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -4e-77: tmp = math.pow(x, ((1.0 / n) + -1.0)) / n elif (1.0 / n) <= 0.0005: tmp = (math.log1p(x) - math.log(x)) / n elif (1.0 / n) <= 2e+228: tmp = (1.0 + (x / n)) - math.pow(x, (1.0 / n)) else: tmp = math.expm1((x / n)) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -4e-77) tmp = Float64((x ^ Float64(Float64(1.0 / n) + -1.0)) / n); elseif (Float64(1.0 / n) <= 0.0005) tmp = Float64(Float64(log1p(x) - log(x)) / n); elseif (Float64(1.0 / n) <= 2e+228) tmp = Float64(Float64(1.0 + Float64(x / n)) - (x ^ Float64(1.0 / n))); else tmp = expm1(Float64(x / n)); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -4e-77], N[(N[Power[x, N[(N[(1.0 / n), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.0005], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+228], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(Exp[N[(x / n), $MachinePrecision]] - 1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -4 \cdot 10^{-77}:\\
\;\;\;\;\frac{{x}^{\left(\frac{1}{n} + -1\right)}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.0005:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+228}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\frac{x}{n}\right)\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -3.9999999999999997e-77Initial program 87.6%
Taylor expanded in x around inf 66.3%
log-rec66.3%
mul-1-neg66.3%
neg-mul-166.3%
mul-1-neg66.3%
distribute-frac-neg66.3%
remove-double-neg66.3%
*-rgt-identity66.3%
associate-/l*66.3%
exp-to-pow93.0%
*-commutative93.0%
Simplified93.0%
*-un-lft-identity93.0%
associate-/r*93.5%
pow193.5%
pow-div93.5%
Applied egg-rr93.5%
*-lft-identity93.5%
sub-neg93.5%
metadata-eval93.5%
Simplified93.5%
if -3.9999999999999997e-77 < (/.f64 #s(literal 1 binary64) n) < 5.0000000000000001e-4Initial program 27.5%
Taylor expanded in n around inf 82.8%
log1p-define82.8%
Simplified82.8%
if 5.0000000000000001e-4 < (/.f64 #s(literal 1 binary64) n) < 1.9999999999999998e228Initial program 64.5%
Taylor expanded in x around 0 61.9%
if 1.9999999999999998e228 < (/.f64 #s(literal 1 binary64) n) Initial program 7.7%
log1p-expm1-u7.7%
Applied egg-rr7.7%
Taylor expanded in n around inf 32.7%
Taylor expanded in n around 0 32.7%
expm1-define32.7%
log1p-define64.2%
Simplified64.2%
Taylor expanded in x around 0 64.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))))
(if (<= x -1e-159)
0.0
(if (<= x 6.2e-280)
t_0
(if (<= x 3e-44) (/ (log x) (- n)) (if (<= x 1.0) t_0 0.0))))))
double code(double x, double n) {
double t_0 = 1.0 - pow(x, (1.0 / n));
double tmp;
if (x <= -1e-159) {
tmp = 0.0;
} else if (x <= 6.2e-280) {
tmp = t_0;
} else if (x <= 3e-44) {
tmp = log(x) / -n;
} else if (x <= 1.0) {
tmp = t_0;
} else {
tmp = 0.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 = 1.0d0 - (x ** (1.0d0 / n))
if (x <= (-1d-159)) then
tmp = 0.0d0
else if (x <= 6.2d-280) then
tmp = t_0
else if (x <= 3d-44) then
tmp = log(x) / -n
else if (x <= 1.0d0) then
tmp = t_0
else
tmp = 0.0d0
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 tmp;
if (x <= -1e-159) {
tmp = 0.0;
} else if (x <= 6.2e-280) {
tmp = t_0;
} else if (x <= 3e-44) {
tmp = Math.log(x) / -n;
} else if (x <= 1.0) {
tmp = t_0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): t_0 = 1.0 - math.pow(x, (1.0 / n)) tmp = 0 if x <= -1e-159: tmp = 0.0 elif x <= 6.2e-280: tmp = t_0 elif x <= 3e-44: tmp = math.log(x) / -n elif x <= 1.0: tmp = t_0 else: tmp = 0.0 return tmp
function code(x, n) t_0 = Float64(1.0 - (x ^ Float64(1.0 / n))) tmp = 0.0 if (x <= -1e-159) tmp = 0.0; elseif (x <= 6.2e-280) tmp = t_0; elseif (x <= 3e-44) tmp = Float64(log(x) / Float64(-n)); elseif (x <= 1.0) tmp = t_0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) t_0 = 1.0 - (x ^ (1.0 / n)); tmp = 0.0; if (x <= -1e-159) tmp = 0.0; elseif (x <= 6.2e-280) tmp = t_0; elseif (x <= 3e-44) tmp = log(x) / -n; elseif (x <= 1.0) tmp = t_0; else tmp = 0.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]}, If[LessEqual[x, -1e-159], 0.0, If[LessEqual[x, 6.2e-280], t$95$0, If[LessEqual[x, 3e-44], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], If[LessEqual[x, 1.0], t$95$0, 0.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq -1 \cdot 10^{-159}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-280}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-44}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -9.99999999999999989e-160 or 1 < x Initial program 67.8%
Taylor expanded in x around inf 42.1%
log-rec42.1%
mul-1-neg42.1%
neg-mul-142.1%
mul-1-neg42.1%
distribute-frac-neg42.1%
remove-double-neg42.1%
*-rgt-identity42.1%
associate-/l*42.1%
exp-to-pow73.5%
Simplified73.5%
Taylor expanded in x around 0 77.0%
if -9.99999999999999989e-160 < x < 6.20000000000000042e-280 or 3.0000000000000002e-44 < x < 1Initial program 70.6%
Taylor expanded in x around 0 40.5%
*-rgt-identity40.5%
associate-*l/40.5%
associate-/l*40.5%
exp-to-pow68.7%
Simplified68.7%
if 6.20000000000000042e-280 < x < 3.0000000000000002e-44Initial program 33.8%
Taylor expanded in x around 0 33.8%
*-rgt-identity33.8%
associate-*l/33.8%
associate-/l*33.8%
exp-to-pow33.8%
Simplified33.8%
Taylor expanded in n around inf 54.8%
associate-*r/54.8%
mul-1-neg54.8%
Simplified54.8%
Final simplification67.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x -1.52e-167)
0.0
(if (<= x 8.6e-280)
(- (+ 1.0 (/ x n)) t_0)
(if (<= x 4.2e-41) (/ (log x) (- n)) (/ (/ t_0 n) x))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= -1.52e-167) {
tmp = 0.0;
} else if (x <= 8.6e-280) {
tmp = (1.0 + (x / n)) - t_0;
} else if (x <= 4.2e-41) {
tmp = log(x) / -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) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= (-1.52d-167)) then
tmp = 0.0d0
else if (x <= 8.6d-280) then
tmp = (1.0d0 + (x / n)) - t_0
else if (x <= 4.2d-41) then
tmp = log(x) / -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 tmp;
if (x <= -1.52e-167) {
tmp = 0.0;
} else if (x <= 8.6e-280) {
tmp = (1.0 + (x / n)) - t_0;
} else if (x <= 4.2e-41) {
tmp = Math.log(x) / -n;
} else {
tmp = (t_0 / n) / x;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= -1.52e-167: tmp = 0.0 elif x <= 8.6e-280: tmp = (1.0 + (x / n)) - t_0 elif x <= 4.2e-41: tmp = math.log(x) / -n else: tmp = (t_0 / n) / x return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= -1.52e-167) tmp = 0.0; elseif (x <= 8.6e-280) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); elseif (x <= 4.2e-41) tmp = Float64(log(x) / Float64(-n)); else tmp = Float64(Float64(t_0 / n) / x); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= -1.52e-167) tmp = 0.0; elseif (x <= 8.6e-280) tmp = (1.0 + (x / n)) - t_0; elseif (x <= 4.2e-41) tmp = log(x) / -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]}, If[LessEqual[x, -1.52e-167], 0.0, If[LessEqual[x, 8.6e-280], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[x, 4.2e-41], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq -1.52 \cdot 10^{-167}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{-280}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t\_0\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-41}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\
\end{array}
\end{array}
if x < -1.52e-167Initial program 65.8%
Taylor expanded in x around inf 0.0%
log-rec0.0%
mul-1-neg0.0%
neg-mul-10.0%
mul-1-neg0.0%
distribute-frac-neg0.0%
remove-double-neg0.0%
*-rgt-identity0.0%
associate-/l*0.0%
exp-to-pow80.5%
Simplified80.5%
Taylor expanded in x around 0 89.5%
if -1.52e-167 < x < 8.5999999999999997e-280Initial program 71.7%
Taylor expanded in x around 0 73.6%
if 8.5999999999999997e-280 < x < 4.20000000000000025e-41Initial program 34.5%
Taylor expanded in x around 0 34.5%
*-rgt-identity34.5%
associate-*l/34.5%
associate-/l*34.5%
exp-to-pow34.5%
Simplified34.5%
Taylor expanded in n around inf 54.3%
associate-*r/54.3%
mul-1-neg54.3%
Simplified54.3%
if 4.20000000000000025e-41 < x Initial program 68.5%
Taylor expanded in x around inf 91.5%
log-rec91.5%
mul-1-neg91.5%
neg-mul-191.5%
mul-1-neg91.5%
distribute-frac-neg91.5%
remove-double-neg91.5%
*-rgt-identity91.5%
associate-/l*91.5%
exp-to-pow91.5%
*-commutative91.5%
Simplified91.5%
sqr-pow91.5%
times-frac92.4%
sqrt-pow192.4%
sqrt-pow192.4%
Applied egg-rr92.4%
associate-*l/92.5%
associate-*r/92.5%
add-sqr-sqrt92.5%
Applied egg-rr92.5%
Final simplification76.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x -8e-171)
0.0
(if (<= x 4.1e-280)
(- 1.0 t_0)
(if (<= x 3.3e-40) (/ (log x) (- n)) (/ (/ t_0 n) x))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= -8e-171) {
tmp = 0.0;
} else if (x <= 4.1e-280) {
tmp = 1.0 - t_0;
} else if (x <= 3.3e-40) {
tmp = log(x) / -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) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= (-8d-171)) then
tmp = 0.0d0
else if (x <= 4.1d-280) then
tmp = 1.0d0 - t_0
else if (x <= 3.3d-40) then
tmp = log(x) / -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 tmp;
if (x <= -8e-171) {
tmp = 0.0;
} else if (x <= 4.1e-280) {
tmp = 1.0 - t_0;
} else if (x <= 3.3e-40) {
tmp = Math.log(x) / -n;
} else {
tmp = (t_0 / n) / x;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= -8e-171: tmp = 0.0 elif x <= 4.1e-280: tmp = 1.0 - t_0 elif x <= 3.3e-40: tmp = math.log(x) / -n else: tmp = (t_0 / n) / x return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= -8e-171) tmp = 0.0; elseif (x <= 4.1e-280) tmp = Float64(1.0 - t_0); elseif (x <= 3.3e-40) tmp = Float64(log(x) / Float64(-n)); else tmp = Float64(Float64(t_0 / n) / x); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= -8e-171) tmp = 0.0; elseif (x <= 4.1e-280) tmp = 1.0 - t_0; elseif (x <= 3.3e-40) tmp = log(x) / -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]}, If[LessEqual[x, -8e-171], 0.0, If[LessEqual[x, 4.1e-280], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[x, 3.3e-40], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq -8 \cdot 10^{-171}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-280}:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-40}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\
\end{array}
\end{array}
if x < -7.9999999999999999e-171Initial program 65.8%
Taylor expanded in x around inf 0.0%
log-rec0.0%
mul-1-neg0.0%
neg-mul-10.0%
mul-1-neg0.0%
distribute-frac-neg0.0%
remove-double-neg0.0%
*-rgt-identity0.0%
associate-/l*0.0%
exp-to-pow80.5%
Simplified80.5%
Taylor expanded in x around 0 89.5%
if -7.9999999999999999e-171 < x < 4.1000000000000002e-280Initial program 71.7%
Taylor expanded in x around 0 31.7%
*-rgt-identity31.7%
associate-*l/31.7%
associate-/l*31.7%
exp-to-pow71.7%
Simplified71.7%
if 4.1000000000000002e-280 < x < 3.29999999999999993e-40Initial program 34.5%
Taylor expanded in x around 0 34.5%
*-rgt-identity34.5%
associate-*l/34.5%
associate-/l*34.5%
exp-to-pow34.5%
Simplified34.5%
Taylor expanded in n around inf 54.3%
associate-*r/54.3%
mul-1-neg54.3%
Simplified54.3%
if 3.29999999999999993e-40 < x Initial program 68.5%
Taylor expanded in x around inf 91.5%
log-rec91.5%
mul-1-neg91.5%
neg-mul-191.5%
mul-1-neg91.5%
distribute-frac-neg91.5%
remove-double-neg91.5%
*-rgt-identity91.5%
associate-/l*91.5%
exp-to-pow91.5%
*-commutative91.5%
Simplified91.5%
sqr-pow91.5%
times-frac92.4%
sqrt-pow192.4%
sqrt-pow192.4%
Applied egg-rr92.4%
associate-*l/92.5%
associate-*r/92.5%
add-sqr-sqrt92.5%
Applied egg-rr92.5%
Final simplification75.9%
(FPCore (x n) :precision binary64 (if (<= x -2e-310) 0.0 (if (<= x 54.0) (/ (- x (log x)) n) 0.0)))
double code(double x, double n) {
double tmp;
if (x <= -2e-310) {
tmp = 0.0;
} else if (x <= 54.0) {
tmp = (x - log(x)) / n;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 0.0d0
else if (x <= 54.0d0) then
tmp = (x - log(x)) / n
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= -2e-310) {
tmp = 0.0;
} else if (x <= 54.0) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= -2e-310: tmp = 0.0 elif x <= 54.0: tmp = (x - math.log(x)) / n else: tmp = 0.0 return tmp
function code(x, n) tmp = 0.0 if (x <= -2e-310) tmp = 0.0; elseif (x <= 54.0) tmp = Float64(Float64(x - log(x)) / n); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= -2e-310) tmp = 0.0; elseif (x <= 54.0) tmp = (x - log(x)) / n; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, -2e-310], 0.0, If[LessEqual[x, 54.0], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 54:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1.999999999999994e-310 or 54 < x Initial program 69.8%
Taylor expanded in x around inf 36.8%
log-rec36.8%
mul-1-neg36.8%
neg-mul-136.8%
mul-1-neg36.8%
distribute-frac-neg36.8%
remove-double-neg36.8%
*-rgt-identity36.8%
associate-/l*36.7%
exp-to-pow66.8%
Simplified66.8%
Taylor expanded in x around 0 69.8%
if -1.999999999999994e-310 < x < 54Initial program 42.2%
Taylor expanded in x around 0 41.8%
Taylor expanded in n around inf 48.8%
(FPCore (x n) :precision binary64 (if (<= x -2e-310) 0.0 (if (<= x 1.0) (/ (log x) (- n)) 0.0)))
double code(double x, double n) {
double tmp;
if (x <= -2e-310) {
tmp = 0.0;
} else if (x <= 1.0) {
tmp = log(x) / -n;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 0.0d0
else if (x <= 1.0d0) then
tmp = log(x) / -n
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= -2e-310) {
tmp = 0.0;
} else if (x <= 1.0) {
tmp = Math.log(x) / -n;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= -2e-310: tmp = 0.0 elif x <= 1.0: tmp = math.log(x) / -n else: tmp = 0.0 return tmp
function code(x, n) tmp = 0.0 if (x <= -2e-310) tmp = 0.0; elseif (x <= 1.0) tmp = Float64(log(x) / Float64(-n)); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= -2e-310) tmp = 0.0; elseif (x <= 1.0) tmp = log(x) / -n; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, -2e-310], 0.0, If[LessEqual[x, 1.0], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1.999999999999994e-310 or 1 < x Initial program 69.4%
Taylor expanded in x around inf 36.5%
log-rec36.5%
mul-1-neg36.5%
neg-mul-136.5%
mul-1-neg36.5%
distribute-frac-neg36.5%
remove-double-neg36.5%
*-rgt-identity36.5%
associate-/l*36.5%
exp-to-pow66.3%
Simplified66.3%
Taylor expanded in x around 0 69.4%
if -1.999999999999994e-310 < x < 1Initial program 42.5%
Taylor expanded in x around 0 41.7%
*-rgt-identity41.7%
associate-*l/41.7%
associate-/l*41.7%
exp-to-pow41.7%
Simplified41.7%
Taylor expanded in n around inf 49.1%
associate-*r/49.1%
mul-1-neg49.1%
Simplified49.1%
Final simplification59.9%
(FPCore (x n) :precision binary64 (if (<= x 1.5e-304) 0.0 (if (<= x 1.8e+128) (/ 1.0 (* n x)) 0.0)))
double code(double x, double n) {
double tmp;
if (x <= 1.5e-304) {
tmp = 0.0;
} else if (x <= 1.8e+128) {
tmp = 1.0 / (n * x);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 1.5d-304) then
tmp = 0.0d0
else if (x <= 1.8d+128) then
tmp = 1.0d0 / (n * x)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1.5e-304) {
tmp = 0.0;
} else if (x <= 1.8e+128) {
tmp = 1.0 / (n * x);
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1.5e-304: tmp = 0.0 elif x <= 1.8e+128: tmp = 1.0 / (n * x) else: tmp = 0.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 1.5e-304) tmp = 0.0; elseif (x <= 1.8e+128) tmp = Float64(1.0 / Float64(n * x)); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1.5e-304) tmp = 0.0; elseif (x <= 1.8e+128) tmp = 1.0 / (n * x); else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1.5e-304], 0.0, If[LessEqual[x, 1.8e+128], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{-304}:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+128}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.5000000000000001e-304 or 1.80000000000000014e128 < x Initial program 72.1%
Taylor expanded in x around inf 33.3%
log-rec33.3%
mul-1-neg33.3%
neg-mul-133.3%
mul-1-neg33.3%
distribute-frac-neg33.3%
remove-double-neg33.3%
*-rgt-identity33.3%
associate-/l*33.2%
exp-to-pow68.5%
Simplified68.5%
Taylor expanded in x around 0 72.1%
if 1.5000000000000001e-304 < x < 1.80000000000000014e128Initial program 44.3%
Taylor expanded in x around inf 43.3%
log-rec43.3%
mul-1-neg43.3%
neg-mul-143.3%
mul-1-neg43.3%
distribute-frac-neg43.3%
remove-double-neg43.3%
*-rgt-identity43.3%
associate-/l*43.3%
exp-to-pow43.3%
*-commutative43.3%
Simplified43.3%
Taylor expanded in n around inf 33.5%
*-commutative33.5%
Simplified33.5%
Final simplification50.8%
(FPCore (x n) :precision binary64 0.0)
double code(double x, double n) {
return 0.0;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = 0.0d0
end function
public static double code(double x, double n) {
return 0.0;
}
def code(x, n): return 0.0
function code(x, n) return 0.0 end
function tmp = code(x, n) tmp = 0.0; end
code[x_, n_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 56.8%
Taylor expanded in x around inf 20.9%
log-rec20.9%
mul-1-neg20.9%
neg-mul-120.9%
mul-1-neg20.9%
distribute-frac-neg20.9%
remove-double-neg20.9%
*-rgt-identity20.9%
associate-/l*20.8%
exp-to-pow36.7%
Simplified36.7%
Taylor expanded in x around 0 38.5%
herbie shell --seed 2024181
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))