
(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 12 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) -5e-13)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 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) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / 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) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / 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) <= -5e-13: tmp = t_0 / (n * x) elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / 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) <= -5e-13) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / 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], -5e-13], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / 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 -5 \cdot 10^{-13}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t_0\\
\end{array}
\end{array}
if (/.f64 1 n) < -4.9999999999999999e-13Initial program 94.3%
Taylor expanded in x around inf 100.0%
exp-prod100.0%
log-rec100.0%
distribute-frac-neg100.0%
exp-prod100.0%
neg-mul-1100.0%
remove-double-neg100.0%
*-rgt-identity100.0%
associate-*r/100.0%
unpow-1100.0%
exp-to-pow100.0%
unpow-1100.0%
*-commutative100.0%
Simplified100.0%
if -4.9999999999999999e-13 < (/.f64 1 n) < 2e-3Initial program 30.0%
Taylor expanded in n around inf 76.4%
log1p-def76.4%
Simplified76.4%
clear-num76.4%
inv-pow76.4%
Applied egg-rr76.4%
unpow-176.4%
Simplified76.4%
Taylor expanded in n around 0 76.4%
*-rgt-identity76.4%
log-div76.5%
associate-*r/72.8%
*-commutative72.8%
+-commutative72.8%
distribute-rgt-in72.8%
rgt-mult-inverse76.5%
*-lft-identity76.5%
log1p-def98.5%
Simplified98.5%
if 2e-3 < (/.f64 1 n) Initial program 47.0%
Taylor expanded in n around 0 47.0%
log1p-def97.2%
*-rgt-identity97.2%
associate-*r/97.2%
unpow-197.2%
exp-to-pow97.2%
/-rgt-identity97.2%
metadata-eval97.2%
associate-/l*97.2%
*-commutative97.2%
*-commutative97.2%
associate-/l*97.2%
metadata-eval97.2%
/-rgt-identity97.2%
unpow-197.2%
Simplified97.2%
Final simplification98.7%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-13)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 4e+195)
(- (+ 1.0 (/ x n)) t_0)
(/ (log (/ (+ 1.0 x) (+ 1.0 (+ x -1.0)))) n))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = log(((1.0 + x) / (1.0 + (x + -1.0)))) / n;
}
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) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = Math.log(((1.0 + x) / (1.0 + (x + -1.0)))) / n;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-13: tmp = t_0 / (n * x) elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 4e+195: tmp = (1.0 + (x / n)) - t_0 else: tmp = math.log(((1.0 + x) / (1.0 + (x + -1.0)))) / n return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-13) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 4e+195) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); else tmp = Float64(log(Float64(Float64(1.0 + x) / Float64(1.0 + Float64(x + -1.0)))) / n); 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], -5e-13], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / N[(1.0 + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-13}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{1 + \left(x + -1\right)}\right)}{n}\\
\end{array}
\end{array}
if (/.f64 1 n) < -4.9999999999999999e-13Initial program 94.3%
Taylor expanded in x around inf 100.0%
exp-prod100.0%
log-rec100.0%
distribute-frac-neg100.0%
exp-prod100.0%
neg-mul-1100.0%
remove-double-neg100.0%
*-rgt-identity100.0%
associate-*r/100.0%
unpow-1100.0%
exp-to-pow100.0%
unpow-1100.0%
*-commutative100.0%
Simplified100.0%
if -4.9999999999999999e-13 < (/.f64 1 n) < 2e-3Initial program 30.0%
Taylor expanded in n around inf 76.4%
log1p-def76.4%
Simplified76.4%
clear-num76.4%
inv-pow76.4%
Applied egg-rr76.4%
unpow-176.4%
Simplified76.4%
Taylor expanded in n around 0 76.4%
*-rgt-identity76.4%
log-div76.5%
associate-*r/72.8%
*-commutative72.8%
+-commutative72.8%
distribute-rgt-in72.8%
rgt-mult-inverse76.5%
*-lft-identity76.5%
log1p-def98.5%
Simplified98.5%
if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195Initial program 66.1%
Taylor expanded in x around 0 68.3%
*-rgt-identity68.3%
associate-*r/68.3%
unpow-168.3%
exp-to-pow68.3%
unpow-168.3%
Simplified68.3%
if 3.99999999999999991e195 < (/.f64 1 n) Initial program 20.3%
Taylor expanded in n around inf 6.3%
log1p-def6.3%
Simplified6.3%
expm1-log1p-u6.3%
Applied egg-rr6.3%
expm1-log1p-u6.3%
log1p-udef6.3%
log1p-expm1-u80.6%
log1p-udef80.6%
diff-log80.6%
expm1-udef80.6%
add-exp-log80.6%
Applied egg-rr80.6%
Final simplification95.4%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-13)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 4e+195) (- (+ 1.0 (/ x n)) t_0) (/ 1.0 (* n x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.0 / (n * x);
}
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) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-13: tmp = t_0 / (n * x) elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 4e+195: tmp = (1.0 + (x / n)) - t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-13) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 4e+195) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); else tmp = Float64(1.0 / Float64(n * x)); 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], -5e-13], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-13}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -4.9999999999999999e-13Initial program 94.3%
Taylor expanded in x around inf 100.0%
exp-prod100.0%
log-rec100.0%
distribute-frac-neg100.0%
exp-prod100.0%
neg-mul-1100.0%
remove-double-neg100.0%
*-rgt-identity100.0%
associate-*r/100.0%
unpow-1100.0%
exp-to-pow100.0%
unpow-1100.0%
*-commutative100.0%
Simplified100.0%
if -4.9999999999999999e-13 < (/.f64 1 n) < 2e-3Initial program 30.0%
Taylor expanded in n around inf 76.4%
log1p-def76.4%
Simplified76.4%
clear-num76.4%
inv-pow76.4%
Applied egg-rr76.4%
unpow-176.4%
Simplified76.4%
Taylor expanded in n around 0 76.4%
*-rgt-identity76.4%
log-div76.5%
associate-*r/72.8%
*-commutative72.8%
+-commutative72.8%
distribute-rgt-in72.8%
rgt-mult-inverse76.5%
*-lft-identity76.5%
log1p-def98.5%
Simplified98.5%
if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195Initial program 66.1%
Taylor expanded in x around 0 68.3%
*-rgt-identity68.3%
associate-*r/68.3%
unpow-168.3%
exp-to-pow68.3%
unpow-168.3%
Simplified68.3%
if 3.99999999999999991e195 < (/.f64 1 n) Initial program 20.3%
Taylor expanded in n around inf 6.3%
log1p-def6.3%
Simplified6.3%
Taylor expanded in x around inf 74.6%
*-commutative74.6%
Simplified74.6%
Final simplification95.0%
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -2000.0)
(/ 0.0 n)
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 4e+195) (- 1.0 (pow x (/ 1.0 n))) (/ 1.0 (* n x))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -2000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -2000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -2000.0: tmp = 0.0 / n elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 4e+195: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = 1.0 / (n * x) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -2000.0) tmp = Float64(0.0 / n); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 4e+195) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -2000.0], N[(0.0 / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -2000:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -2e3Initial program 100.0%
Taylor expanded in n around inf 60.2%
log1p-def60.2%
Simplified60.2%
log1p-udef60.2%
diff-log60.2%
Applied egg-rr60.2%
Taylor expanded in x around inf 58.7%
if -2e3 < (/.f64 1 n) < 2e-3Initial program 29.3%
Taylor expanded in n around inf 74.6%
log1p-def74.6%
Simplified74.6%
clear-num74.6%
inv-pow74.6%
Applied egg-rr74.6%
unpow-174.6%
Simplified74.6%
Taylor expanded in n around 0 74.6%
*-rgt-identity74.6%
log-div74.7%
associate-*r/71.1%
*-commutative71.1%
+-commutative71.1%
distribute-rgt-in71.1%
rgt-mult-inverse74.7%
*-lft-identity74.7%
log1p-def97.4%
Simplified97.4%
if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195Initial program 66.1%
Taylor expanded in x around 0 66.1%
*-rgt-identity66.1%
associate-*r/66.1%
unpow-166.1%
exp-to-pow66.1%
unpow-166.1%
Simplified66.1%
if 3.99999999999999991e195 < (/.f64 1 n) Initial program 20.3%
Taylor expanded in n around inf 6.3%
log1p-def6.3%
Simplified6.3%
Taylor expanded in x around inf 74.6%
*-commutative74.6%
Simplified74.6%
Final simplification84.1%
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -2000.0)
(/ (log (/ (+ 1.0 x) x)) n)
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 4e+195) (- 1.0 (pow x (/ 1.0 n))) (/ 1.0 (* n x))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -2000.0) {
tmp = log(((1.0 + x) / x)) / n;
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -2000.0) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -2000.0: tmp = math.log(((1.0 + x) / x)) / n elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 4e+195: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = 1.0 / (n * x) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -2000.0) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 4e+195) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -2000.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -2000:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -2e3Initial program 100.0%
Taylor expanded in n around inf 60.2%
log1p-def60.2%
Simplified60.2%
log1p-udef60.2%
diff-log60.2%
Applied egg-rr60.2%
if -2e3 < (/.f64 1 n) < 2e-3Initial program 29.3%
Taylor expanded in n around inf 74.6%
log1p-def74.6%
Simplified74.6%
clear-num74.6%
inv-pow74.6%
Applied egg-rr74.6%
unpow-174.6%
Simplified74.6%
Taylor expanded in n around 0 74.6%
*-rgt-identity74.6%
log-div74.7%
associate-*r/71.1%
*-commutative71.1%
+-commutative71.1%
distribute-rgt-in71.1%
rgt-mult-inverse74.7%
*-lft-identity74.7%
log1p-def97.4%
Simplified97.4%
if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195Initial program 66.1%
Taylor expanded in x around 0 66.1%
*-rgt-identity66.1%
associate-*r/66.1%
unpow-166.1%
exp-to-pow66.1%
unpow-166.1%
Simplified66.1%
if 3.99999999999999991e195 < (/.f64 1 n) Initial program 20.3%
Taylor expanded in n around inf 6.3%
log1p-def6.3%
Simplified6.3%
Taylor expanded in x around inf 74.6%
*-commutative74.6%
Simplified74.6%
Final simplification84.5%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-13)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 0.002)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 4e+195) (- 1.0 t_0) (/ 1.0 (* n x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - t_0;
} else {
tmp = 1.0 / (n * x);
}
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) <= -5e-13) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 0.002) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 4e+195) {
tmp = 1.0 - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-13: tmp = t_0 / (n * x) elif (1.0 / n) <= 0.002: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 4e+195: tmp = 1.0 - t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-13) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 0.002) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 4e+195) tmp = Float64(1.0 - t_0); else tmp = Float64(1.0 / Float64(n * x)); 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], -5e-13], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.002], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 4e+195], N[(1.0 - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-13}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.002:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 4 \cdot 10^{+195}:\\
\;\;\;\;1 - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -4.9999999999999999e-13Initial program 94.3%
Taylor expanded in x around inf 100.0%
exp-prod100.0%
log-rec100.0%
distribute-frac-neg100.0%
exp-prod100.0%
neg-mul-1100.0%
remove-double-neg100.0%
*-rgt-identity100.0%
associate-*r/100.0%
unpow-1100.0%
exp-to-pow100.0%
unpow-1100.0%
*-commutative100.0%
Simplified100.0%
if -4.9999999999999999e-13 < (/.f64 1 n) < 2e-3Initial program 30.0%
Taylor expanded in n around inf 76.4%
log1p-def76.4%
Simplified76.4%
clear-num76.4%
inv-pow76.4%
Applied egg-rr76.4%
unpow-176.4%
Simplified76.4%
Taylor expanded in n around 0 76.4%
*-rgt-identity76.4%
log-div76.5%
associate-*r/72.8%
*-commutative72.8%
+-commutative72.8%
distribute-rgt-in72.8%
rgt-mult-inverse76.5%
*-lft-identity76.5%
log1p-def98.5%
Simplified98.5%
if 2e-3 < (/.f64 1 n) < 3.99999999999999991e195Initial program 66.1%
Taylor expanded in x around 0 66.1%
*-rgt-identity66.1%
associate-*r/66.1%
unpow-166.1%
exp-to-pow66.1%
unpow-166.1%
Simplified66.1%
if 3.99999999999999991e195 < (/.f64 1 n) Initial program 20.3%
Taylor expanded in n around inf 6.3%
log1p-def6.3%
Simplified6.3%
Taylor expanded in x around inf 74.6%
*-commutative74.6%
Simplified74.6%
Final simplification94.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (log1p (/ 1.0 x)) n)))
(if (<= n -12.5)
t_0
(if (<= n -7.6e-283) (/ 0.0 n) (if (<= n 4e-196) (/ 1.0 (* n x)) t_0)))))
double code(double x, double n) {
double t_0 = log1p((1.0 / x)) / n;
double tmp;
if (n <= -12.5) {
tmp = t_0;
} else if (n <= -7.6e-283) {
tmp = 0.0 / n;
} else if (n <= 4e-196) {
tmp = 1.0 / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.log1p((1.0 / x)) / n;
double tmp;
if (n <= -12.5) {
tmp = t_0;
} else if (n <= -7.6e-283) {
tmp = 0.0 / n;
} else if (n <= 4e-196) {
tmp = 1.0 / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, n): t_0 = math.log1p((1.0 / x)) / n tmp = 0 if n <= -12.5: tmp = t_0 elif n <= -7.6e-283: tmp = 0.0 / n elif n <= 4e-196: tmp = 1.0 / (n * x) else: tmp = t_0 return tmp
function code(x, n) t_0 = Float64(log1p(Float64(1.0 / x)) / n) tmp = 0.0 if (n <= -12.5) tmp = t_0; elseif (n <= -7.6e-283) tmp = Float64(0.0 / n); elseif (n <= 4e-196) tmp = Float64(1.0 / Float64(n * x)); else tmp = t_0; end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[n, -12.5], t$95$0, If[LessEqual[n, -7.6e-283], N[(0.0 / n), $MachinePrecision], If[LessEqual[n, 4e-196], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{if}\;n \leq -12.5:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq -7.6 \cdot 10^{-283}:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;n \leq 4 \cdot 10^{-196}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if n < -12.5 or 4.0000000000000002e-196 < n Initial program 33.7%
Taylor expanded in n around inf 66.6%
log1p-def66.6%
Simplified66.6%
clear-num66.6%
inv-pow66.6%
Applied egg-rr66.6%
unpow-166.6%
Simplified66.6%
Taylor expanded in n around 0 66.6%
*-rgt-identity66.6%
log-div66.6%
associate-*r/63.5%
*-commutative63.5%
+-commutative63.5%
distribute-rgt-in63.5%
rgt-mult-inverse66.6%
*-lft-identity66.6%
log1p-def86.7%
Simplified86.7%
if -12.5 < n < -7.6000000000000002e-283Initial program 100.0%
Taylor expanded in n around inf 60.6%
log1p-def60.6%
Simplified60.6%
log1p-udef60.6%
diff-log60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 61.0%
if -7.6000000000000002e-283 < n < 4.0000000000000002e-196Initial program 37.1%
Taylor expanded in n around inf 16.5%
log1p-def16.5%
Simplified16.5%
Taylor expanded in x around inf 74.8%
*-commutative74.8%
Simplified74.8%
Final simplification80.0%
(FPCore (x n) :precision binary64 (if (<= x 0.7) (/ (- (log x)) n) (if (<= x 9.5e+123) (/ (- (/ 1.0 x) (/ 0.5 (* x x))) n) (/ 0.0 n))))
double code(double x, double n) {
double tmp;
if (x <= 0.7) {
tmp = -log(x) / n;
} else if (x <= 9.5e+123) {
tmp = ((1.0 / x) - (0.5 / (x * x))) / n;
} else {
tmp = 0.0 / 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.7d0) then
tmp = -log(x) / n
else if (x <= 9.5d+123) then
tmp = ((1.0d0 / x) - (0.5d0 / (x * x))) / n
else
tmp = 0.0d0 / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.7) {
tmp = -Math.log(x) / n;
} else if (x <= 9.5e+123) {
tmp = ((1.0 / x) - (0.5 / (x * x))) / n;
} else {
tmp = 0.0 / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.7: tmp = -math.log(x) / n elif x <= 9.5e+123: tmp = ((1.0 / x) - (0.5 / (x * x))) / n else: tmp = 0.0 / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.7) tmp = Float64(Float64(-log(x)) / n); elseif (x <= 9.5e+123) tmp = Float64(Float64(Float64(1.0 / x) - Float64(0.5 / Float64(x * x))) / n); else tmp = Float64(0.0 / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.7) tmp = -log(x) / n; elseif (x <= 9.5e+123) tmp = ((1.0 / x) - (0.5 / (x * x))) / n; else tmp = 0.0 / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.7], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], If[LessEqual[x, 9.5e+123], N[(N[(N[(1.0 / x), $MachinePrecision] - N[(0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(0.0 / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.7:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+123}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{n}\\
\end{array}
\end{array}
if x < 0.69999999999999996Initial program 34.5%
Taylor expanded in n around inf 58.5%
log1p-def58.5%
Simplified58.5%
Taylor expanded in x around 0 58.2%
neg-mul-158.2%
Simplified58.2%
if 0.69999999999999996 < x < 9.4999999999999996e123Initial program 42.3%
Taylor expanded in n around inf 40.9%
log1p-def40.9%
Simplified40.9%
Taylor expanded in x around inf 70.1%
associate-*r/70.1%
metadata-eval70.1%
unpow270.1%
Simplified70.1%
if 9.4999999999999996e123 < x Initial program 80.7%
Taylor expanded in n around inf 80.7%
log1p-def80.7%
Simplified80.7%
log1p-udef80.7%
diff-log80.7%
Applied egg-rr80.7%
Taylor expanded in x around inf 80.7%
Final simplification66.7%
(FPCore (x n) :precision binary64 (if (<= n -4.6) (/ 1.0 (* n (+ x 0.5))) (if (<= n -3.4e-280) (/ 0.0 n) (/ (/ 1.0 x) n))))
double code(double x, double n) {
double tmp;
if (n <= -4.6) {
tmp = 1.0 / (n * (x + 0.5));
} else if (n <= -3.4e-280) {
tmp = 0.0 / 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 (n <= (-4.6d0)) then
tmp = 1.0d0 / (n * (x + 0.5d0))
else if (n <= (-3.4d-280)) then
tmp = 0.0d0 / n
else
tmp = (1.0d0 / x) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (n <= -4.6) {
tmp = 1.0 / (n * (x + 0.5));
} else if (n <= -3.4e-280) {
tmp = 0.0 / n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if n <= -4.6: tmp = 1.0 / (n * (x + 0.5)) elif n <= -3.4e-280: tmp = 0.0 / n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (n <= -4.6) tmp = Float64(1.0 / Float64(n * Float64(x + 0.5))); elseif (n <= -3.4e-280) tmp = Float64(0.0 / n); else tmp = Float64(Float64(1.0 / x) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (n <= -4.6) tmp = 1.0 / (n * (x + 0.5)); elseif (n <= -3.4e-280) tmp = 0.0 / n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[n, -4.6], N[(1.0 / N[(n * N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, -3.4e-280], N[(0.0 / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -4.6:\\
\;\;\;\;\frac{1}{n \cdot \left(x + 0.5\right)}\\
\mathbf{elif}\;n \leq -3.4 \cdot 10^{-280}:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
if n < -4.5999999999999996Initial program 27.7%
Taylor expanded in n around inf 78.0%
log1p-def78.0%
Simplified78.0%
clear-num78.0%
inv-pow78.0%
Applied egg-rr78.0%
unpow-178.0%
Simplified78.0%
Taylor expanded in x around inf 51.4%
+-commutative51.4%
*-commutative51.4%
distribute-lft-out51.4%
Simplified51.4%
if -4.5999999999999996 < n < -3.3999999999999998e-280Initial program 100.0%
Taylor expanded in n around inf 60.6%
log1p-def60.6%
Simplified60.6%
log1p-udef60.6%
diff-log60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 61.0%
if -3.3999999999999998e-280 < n Initial program 38.1%
Taylor expanded in n around inf 51.2%
log1p-def51.2%
Simplified51.2%
Taylor expanded in x around inf 50.7%
Final simplification53.2%
(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 48.9%
Taylor expanded in n around inf 61.5%
log1p-def61.5%
Simplified61.5%
Taylor expanded in x around inf 42.7%
*-commutative42.7%
Simplified42.7%
Final simplification42.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(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 48.9%
Taylor expanded in n around inf 61.5%
log1p-def61.5%
Simplified61.5%
Taylor expanded in x around inf 43.0%
Final simplification43.0%
(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 48.9%
Taylor expanded in x around 0 27.7%
*-rgt-identity27.7%
associate-*r/27.7%
unpow-127.7%
exp-to-pow27.7%
unpow-127.7%
Simplified27.7%
Taylor expanded in x around inf 4.6%
Final simplification4.6%
herbie shell --seed 2023279
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))