
(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 14 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 260000.0)
(/
(log
(/
(exp
(+ (log1p x) (* 0.5 (/ (- (pow (log1p x) 2.0) (pow (log x) 2.0)) n))))
x))
n)
(/ (/ (pow x (/ 1.0 n)) n) x)))
double code(double x, double n) {
double tmp;
if (x <= 260000.0) {
tmp = log((exp((log1p(x) + (0.5 * ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) / n)))) / 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 <= 260000.0) {
tmp = Math.log((Math.exp((Math.log1p(x) + (0.5 * ((Math.pow(Math.log1p(x), 2.0) - Math.pow(Math.log(x), 2.0)) / n)))) / x)) / n;
} else {
tmp = (Math.pow(x, (1.0 / n)) / n) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 260000.0: tmp = math.log((math.exp((math.log1p(x) + (0.5 * ((math.pow(math.log1p(x), 2.0) - math.pow(math.log(x), 2.0)) / n)))) / x)) / n else: tmp = (math.pow(x, (1.0 / n)) / n) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 260000.0) tmp = Float64(log(Float64(exp(Float64(log1p(x) + Float64(0.5 * Float64(Float64((log1p(x) ^ 2.0) - (log(x) ^ 2.0)) / n)))) / x)) / n); else tmp = Float64(Float64((x ^ Float64(1.0 / n)) / n) / x); end return tmp end
code[x_, n_] := If[LessEqual[x, 260000.0], N[(N[Log[N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] + 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]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 260000:\\
\;\;\;\;\frac{\log \left(\frac{e^{\mathsf{log1p}\left(x\right) + 0.5 \cdot \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}{n}}}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\
\end{array}
\end{array}
if x < 2.6e5Initial program 48.0%
Taylor expanded in n around inf 68.0%
associate--l+68.0%
log1p-define68.0%
+-commutative68.0%
associate--r+68.0%
distribute-lft-out--68.0%
div-sub68.0%
log1p-define68.0%
Simplified68.0%
associate-+r-68.0%
add-log-exp80.5%
exp-diff80.5%
add-exp-log80.6%
Applied egg-rr80.6%
if 2.6e5 < x Initial program 69.9%
Taylor expanded in x around inf 98.5%
associate-/r*99.8%
mul-1-neg99.8%
log-rec99.8%
mul-1-neg99.8%
distribute-neg-frac99.8%
mul-1-neg99.8%
remove-double-neg99.8%
*-rgt-identity99.8%
associate-/l*99.8%
exp-to-pow99.8%
Simplified99.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (exp (/ (log1p x) n)))
(t_1 (pow x (/ 1.0 n)))
(t_2 (- (pow (+ x 1.0) (/ 1.0 n)) t_1)))
(if (<= t_2 -0.01)
(fma (pow x (/ 0.5 n)) (- (sqrt t_1)) t_0)
(if (<= t_2 5e-11)
(/
(+
(log1p x)
(- (* 0.5 (/ (- (pow (log1p x) 2.0) (pow (log x) 2.0)) n)) (log x)))
n)
(- t_0 t_1)))))
double code(double x, double n) {
double t_0 = exp((log1p(x) / n));
double t_1 = pow(x, (1.0 / n));
double t_2 = pow((x + 1.0), (1.0 / n)) - t_1;
double tmp;
if (t_2 <= -0.01) {
tmp = fma(pow(x, (0.5 / n)), -sqrt(t_1), t_0);
} else if (t_2 <= 5e-11) {
tmp = (log1p(x) + ((0.5 * ((pow(log1p(x), 2.0) - pow(log(x), 2.0)) / n)) - log(x))) / n;
} else {
tmp = t_0 - t_1;
}
return tmp;
}
function code(x, n) t_0 = exp(Float64(log1p(x) / n)) t_1 = x ^ Float64(1.0 / n) t_2 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_1) tmp = 0.0 if (t_2 <= -0.01) tmp = fma((x ^ Float64(0.5 / n)), Float64(-sqrt(t_1)), t_0); elseif (t_2 <= 5e-11) 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(t_0 - t_1); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -0.01], N[(N[Power[x, N[(0.5 / n), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[t$95$1], $MachinePrecision]) + t$95$0), $MachinePrecision], If[LessEqual[t$95$2, 5e-11], 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[(t$95$0 - t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\\
t_1 := {x}^{\left(\frac{1}{n}\right)}\\
t_2 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_1\\
\mathbf{if}\;t\_2 \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left({x}^{\left(\frac{0.5}{n}\right)}, -\sqrt{t\_1}, t\_0\right)\\
\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\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}:\\
\;\;\;\;t\_0 - t\_1\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
sqr-pow99.7%
distribute-rgt-neg-in99.7%
fma-define99.8%
sqrt-pow199.8%
sqrt-pow199.8%
pow-to-exp99.8%
un-div-inv99.8%
+-commutative99.8%
log1p-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
unpow1/299.8%
exp-to-pow99.8%
associate-*r/99.8%
*-rgt-identity99.8%
exp-prod99.8%
*-rgt-identity99.8%
associate-*r/99.8%
associate-*r*99.8%
exp-to-pow99.8%
associate-*l/99.8%
metadata-eval99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.7%
associate--l+64.5%
log1p-define64.5%
+-commutative64.5%
associate--r+81.7%
distribute-lft-out--81.7%
div-sub81.7%
log1p-define81.7%
Simplified81.7%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
Taylor expanded in n around 0 67.2%
log1p-define99.9%
*-rgt-identity99.9%
associate-*l/99.9%
associate-/l*99.9%
exp-to-pow99.9%
Simplified99.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (exp (/ (log1p x) n)))
(t_1 (pow x (/ 1.0 n)))
(t_2 (- (pow (+ x 1.0) (/ 1.0 n)) t_1)))
(if (<= t_2 -0.01)
(fma (pow x (/ 0.5 n)) (- (sqrt t_1)) t_0)
(if (<= t_2 5e-11) (/ (- (log1p x) (log x)) n) (- t_0 t_1)))))
double code(double x, double n) {
double t_0 = exp((log1p(x) / n));
double t_1 = pow(x, (1.0 / n));
double t_2 = pow((x + 1.0), (1.0 / n)) - t_1;
double tmp;
if (t_2 <= -0.01) {
tmp = fma(pow(x, (0.5 / n)), -sqrt(t_1), t_0);
} else if (t_2 <= 5e-11) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = t_0 - t_1;
}
return tmp;
}
function code(x, n) t_0 = exp(Float64(log1p(x) / n)) t_1 = x ^ Float64(1.0 / n) t_2 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_1) tmp = 0.0 if (t_2 <= -0.01) tmp = fma((x ^ Float64(0.5 / n)), Float64(-sqrt(t_1)), t_0); elseif (t_2 <= 5e-11) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = Float64(t_0 - t_1); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -0.01], N[(N[Power[x, N[(0.5 / n), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[t$95$1], $MachinePrecision]) + t$95$0), $MachinePrecision], If[LessEqual[t$95$2, 5e-11], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(t$95$0 - t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\\
t_1 := {x}^{\left(\frac{1}{n}\right)}\\
t_2 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_1\\
\mathbf{if}\;t\_2 \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left({x}^{\left(\frac{0.5}{n}\right)}, -\sqrt{t\_1}, t\_0\right)\\
\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;t\_0 - t\_1\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
sqr-pow99.7%
distribute-rgt-neg-in99.7%
fma-define99.8%
sqrt-pow199.8%
sqrt-pow199.8%
pow-to-exp99.8%
un-div-inv99.8%
+-commutative99.8%
log1p-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
unpow1/299.8%
exp-to-pow99.8%
associate-*r/99.8%
*-rgt-identity99.8%
exp-prod99.8%
*-rgt-identity99.8%
associate-*r/99.8%
associate-*r*99.8%
exp-to-pow99.8%
associate-*l/99.8%
metadata-eval99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.4%
log1p-define81.4%
Simplified81.4%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
Taylor expanded in n around 0 67.2%
log1p-define99.9%
*-rgt-identity99.9%
associate-*l/99.9%
associate-/l*99.9%
exp-to-pow99.9%
Simplified99.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -0.01)
(log (exp (- 1.0 t_0)))
(if (<= t_1 5e-11)
(/ (- (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 t_1 = pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = log(exp((1.0 - t_0)));
} else if (t_1 <= 5e-11) {
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 t_1 = Math.pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = Math.log(Math.exp((1.0 - t_0)));
} else if (t_1 <= 5e-11) {
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)) t_1 = math.pow((x + 1.0), (1.0 / n)) - t_0 tmp = 0 if t_1 <= -0.01: tmp = math.log(math.exp((1.0 - t_0))) elif t_1 <= 5e-11: 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) t_1 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -0.01) tmp = log(exp(Float64(1.0 - t_0))); elseif (t_1 <= 5e-11) 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]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[Log[N[Exp[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 5e-11], 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)}\\
t_1 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;\log \left(e^{1 - t\_0}\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\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 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
add-log-exp99.8%
pow-to-exp99.8%
un-div-inv99.8%
+-commutative99.8%
log1p-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.8%
exp-diff99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
div-exp99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.4%
log1p-define81.4%
Simplified81.4%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
Taylor expanded in n around 0 67.2%
log1p-define99.9%
*-rgt-identity99.9%
associate-*l/99.9%
associate-/l*99.9%
exp-to-pow99.9%
Simplified99.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -0.01)
(log (exp (- 1.0 t_0)))
(if (<= t_1 5e-11)
(/ (- (log1p x) (log x)) n)
(-
(+
1.0
(*
x
(+
(/ 1.0 n)
(* x (+ (* 0.5 (/ 1.0 (pow n 2.0))) (* 0.5 (/ -1.0 n)))))))
t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = log(exp((1.0 - t_0)));
} else if (t_1 <= 5e-11) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = Math.pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = Math.log(Math.exp((1.0 - t_0)));
} else if (t_1 <= 5e-11) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / Math.pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = math.pow((x + 1.0), (1.0 / n)) - t_0 tmp = 0 if t_1 <= -0.01: tmp = math.log(math.exp((1.0 - t_0))) elif t_1 <= 5e-11: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / math.pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -0.01) tmp = log(exp(Float64(1.0 - t_0))); elseif (t_1 <= 5e-11) 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(0.5 * Float64(1.0 / (n ^ 2.0))) + Float64(0.5 * Float64(-1.0 / n))))))) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[Log[N[Exp[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 5e-11], 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[(0.5 * N[(1.0 / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(-1.0 / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;\log \left(e^{1 - t\_0}\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} + 0.5 \cdot \frac{-1}{n}\right)\right)\right) - t\_0\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
add-log-exp99.8%
pow-to-exp99.8%
un-div-inv99.8%
+-commutative99.8%
log1p-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 99.8%
exp-diff99.8%
*-rgt-identity99.8%
associate-*r/99.8%
exp-to-pow99.8%
div-exp99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.4%
log1p-define81.4%
Simplified81.4%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
Taylor expanded in x around 0 70.1%
Final simplification83.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -0.01)
(- 1.0 t_0)
(if (<= t_1 5e-11)
(/ (- (log1p x) (log x)) n)
(-
(+
1.0
(*
x
(+
(/ 1.0 n)
(* x (+ (* 0.5 (/ 1.0 (pow n 2.0))) (* 0.5 (/ -1.0 n)))))))
t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = 1.0 - t_0;
} else if (t_1 <= 5e-11) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = Math.pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = 1.0 - t_0;
} else if (t_1 <= 5e-11) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / Math.pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = math.pow((x + 1.0), (1.0 / n)) - t_0 tmp = 0 if t_1 <= -0.01: tmp = 1.0 - t_0 elif t_1 <= 5e-11: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = (1.0 + (x * ((1.0 / n) + (x * ((0.5 * (1.0 / math.pow(n, 2.0))) + (0.5 * (-1.0 / n))))))) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -0.01) tmp = Float64(1.0 - t_0); elseif (t_1 <= 5e-11) 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(0.5 * Float64(1.0 / (n ^ 2.0))) + Float64(0.5 * Float64(-1.0 / n))))))) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 5e-11], 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[(0.5 * N[(1.0 / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(-1.0 / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(\frac{1}{n} + x \cdot \left(0.5 \cdot \frac{1}{{n}^{2}} + 0.5 \cdot \frac{-1}{n}\right)\right)\right) - t\_0\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
Taylor expanded in x around 0 99.8%
*-rgt-identity99.8%
associate-*l/99.8%
associate-/l*99.8%
exp-to-pow99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.4%
log1p-define81.4%
Simplified81.4%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
Taylor expanded in x around 0 70.1%
Final simplification83.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 -0.01)
(- 1.0 t_0)
(if (<= t_1 5e-11) (/ (- (log1p x) (log x)) n) t_1))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = 1.0 - t_0;
} else if (t_1 <= 5e-11) {
tmp = (log1p(x) - log(x)) / n;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = Math.pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -0.01) {
tmp = 1.0 - t_0;
} else if (t_1 <= 5e-11) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = math.pow((x + 1.0), (1.0 / n)) - t_0 tmp = 0 if t_1 <= -0.01: tmp = 1.0 - t_0 elif t_1 <= 5e-11: tmp = (math.log1p(x) - math.log(x)) / n else: tmp = t_1 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= -0.01) tmp = Float64(1.0 - t_0); elseif (t_1 <= 5e-11) tmp = Float64(Float64(log1p(x) - log(x)) / n); else tmp = t_1; end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 5e-11], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t\_0\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < -0.0100000000000000002Initial program 99.8%
Taylor expanded in x around 0 99.8%
*-rgt-identity99.8%
associate-*l/99.8%
associate-/l*99.8%
exp-to-pow99.8%
Simplified99.8%
if -0.0100000000000000002 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) < 5.00000000000000018e-11Initial program 42.0%
Taylor expanded in n around inf 81.4%
log1p-define81.4%
Simplified81.4%
if 5.00000000000000018e-11 < (-.f64 (pow.f64 (+.f64 x #s(literal 1 binary64)) (/.f64 #s(literal 1 binary64) n)) (pow.f64 x (/.f64 #s(literal 1 binary64) n))) Initial program 67.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (/ (- (log1p x) (log x)) n)))
(if (<= (/ 1.0 n) -40000.0)
(/ (/ t_0 n) x)
(if (<= (/ 1.0 n) -2e-75)
t_1
(if (<= (/ 1.0 n) -5e-90)
(/ (+ (/ 1.0 n) (/ (/ -0.5 n) x)) x)
(if (<= (/ 1.0 n) 2e-6) t_1 (- (+ (+ 2.0 (/ x n)) -1.0) t_0)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = (log1p(x) - log(x)) / n;
double tmp;
if ((1.0 / n) <= -40000.0) {
tmp = (t_0 / n) / x;
} else if ((1.0 / n) <= -2e-75) {
tmp = t_1;
} else if ((1.0 / n) <= -5e-90) {
tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x;
} else if ((1.0 / n) <= 2e-6) {
tmp = t_1;
} else {
tmp = ((2.0 + (x / n)) + -1.0) - t_0;
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = (Math.log1p(x) - Math.log(x)) / n;
double tmp;
if ((1.0 / n) <= -40000.0) {
tmp = (t_0 / n) / x;
} else if ((1.0 / n) <= -2e-75) {
tmp = t_1;
} else if ((1.0 / n) <= -5e-90) {
tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x;
} else if ((1.0 / n) <= 2e-6) {
tmp = t_1;
} else {
tmp = ((2.0 + (x / n)) + -1.0) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = (math.log1p(x) - math.log(x)) / n tmp = 0 if (1.0 / n) <= -40000.0: tmp = (t_0 / n) / x elif (1.0 / n) <= -2e-75: tmp = t_1 elif (1.0 / n) <= -5e-90: tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x elif (1.0 / n) <= 2e-6: tmp = t_1 else: tmp = ((2.0 + (x / n)) + -1.0) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(Float64(log1p(x) - log(x)) / n) tmp = 0.0 if (Float64(1.0 / n) <= -40000.0) tmp = Float64(Float64(t_0 / n) / x); elseif (Float64(1.0 / n) <= -2e-75) tmp = t_1; elseif (Float64(1.0 / n) <= -5e-90) tmp = Float64(Float64(Float64(1.0 / n) + Float64(Float64(-0.5 / n) / x)) / x); elseif (Float64(1.0 / n) <= 2e-6) tmp = t_1; else tmp = Float64(Float64(Float64(2.0 + Float64(x / n)) + -1.0) - t_0); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -40000.0], N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], -2e-75], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-90], N[(N[(N[(1.0 / n), $MachinePrecision] + N[(N[(-0.5 / n), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e-6], t$95$1, N[(N[(N[(2.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] - t$95$0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{if}\;\frac{1}{n} \leq -40000:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\
\mathbf{elif}\;\frac{1}{n} \leq -2 \cdot 10^{-75}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\frac{1}{n} \leq -5 \cdot 10^{-90}:\\
\;\;\;\;\frac{\frac{1}{n} + \frac{\frac{-0.5}{n}}{x}}{x}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{-6}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(2 + \frac{x}{n}\right) + -1\right) - t\_0\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) n) < -4e4Initial program 100.0%
Taylor expanded in x around inf 100.0%
associate-/r*100.0%
mul-1-neg100.0%
log-rec100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
mul-1-neg100.0%
remove-double-neg100.0%
*-rgt-identity100.0%
associate-/l*100.0%
exp-to-pow100.0%
Simplified100.0%
if -4e4 < (/.f64 #s(literal 1 binary64) n) < -1.9999999999999999e-75 or -5.00000000000000019e-90 < (/.f64 #s(literal 1 binary64) n) < 1.99999999999999991e-6Initial program 31.2%
Taylor expanded in n around inf 81.3%
log1p-define81.3%
Simplified81.3%
if -1.9999999999999999e-75 < (/.f64 #s(literal 1 binary64) n) < -5.00000000000000019e-90Initial program 4.6%
add-log-exp4.6%
pow-to-exp4.6%
un-div-inv4.6%
+-commutative4.6%
log1p-define4.6%
Applied egg-rr4.6%
Taylor expanded in x around inf 86.1%
Simplified86.1%
Taylor expanded in n around inf 86.1%
associate-/r*86.1%
Simplified86.1%
Taylor expanded in n around inf 86.1%
if 1.99999999999999991e-6 < (/.f64 #s(literal 1 binary64) n) Initial program 67.2%
Taylor expanded in x around 0 66.7%
expm1-log1p-u66.7%
expm1-undefine66.7%
Applied egg-rr66.7%
sub-neg66.7%
log1p-undefine66.7%
rem-exp-log66.7%
associate-+r+66.8%
metadata-eval66.8%
metadata-eval66.8%
Simplified66.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))) (t_1 (/ (log x) (- n))))
(if (<= x 1.6e-286)
t_0
(if (<= x 1.95e-224)
t_1
(if (<= x 3.5e-189)
t_0
(if (<= x 4.5e-134)
t_1
(if (<= x 1.0)
t_0
(if (<= x 6.5e+127)
(/ (+ (/ 1.0 n) (/ (/ -0.5 n) x)) x)
0.0))))))))
double code(double x, double n) {
double t_0 = 1.0 - pow(x, (1.0 / n));
double t_1 = log(x) / -n;
double tmp;
if (x <= 1.6e-286) {
tmp = t_0;
} else if (x <= 1.95e-224) {
tmp = t_1;
} else if (x <= 3.5e-189) {
tmp = t_0;
} else if (x <= 4.5e-134) {
tmp = t_1;
} else if (x <= 1.0) {
tmp = t_0;
} else if (x <= 6.5e+127) {
tmp = ((1.0 / n) + ((-0.5 / n) / x)) / 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (x ** (1.0d0 / n))
t_1 = log(x) / -n
if (x <= 1.6d-286) then
tmp = t_0
else if (x <= 1.95d-224) then
tmp = t_1
else if (x <= 3.5d-189) then
tmp = t_0
else if (x <= 4.5d-134) then
tmp = t_1
else if (x <= 1.0d0) then
tmp = t_0
else if (x <= 6.5d+127) then
tmp = ((1.0d0 / n) + (((-0.5d0) / n) / x)) / x
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 t_1 = Math.log(x) / -n;
double tmp;
if (x <= 1.6e-286) {
tmp = t_0;
} else if (x <= 1.95e-224) {
tmp = t_1;
} else if (x <= 3.5e-189) {
tmp = t_0;
} else if (x <= 4.5e-134) {
tmp = t_1;
} else if (x <= 1.0) {
tmp = t_0;
} else if (x <= 6.5e+127) {
tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): t_0 = 1.0 - math.pow(x, (1.0 / n)) t_1 = math.log(x) / -n tmp = 0 if x <= 1.6e-286: tmp = t_0 elif x <= 1.95e-224: tmp = t_1 elif x <= 3.5e-189: tmp = t_0 elif x <= 4.5e-134: tmp = t_1 elif x <= 1.0: tmp = t_0 elif x <= 6.5e+127: tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x else: tmp = 0.0 return tmp
function code(x, n) t_0 = Float64(1.0 - (x ^ Float64(1.0 / n))) t_1 = Float64(log(x) / Float64(-n)) tmp = 0.0 if (x <= 1.6e-286) tmp = t_0; elseif (x <= 1.95e-224) tmp = t_1; elseif (x <= 3.5e-189) tmp = t_0; elseif (x <= 4.5e-134) tmp = t_1; elseif (x <= 1.0) tmp = t_0; elseif (x <= 6.5e+127) tmp = Float64(Float64(Float64(1.0 / n) + Float64(Float64(-0.5 / n) / x)) / x); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) t_0 = 1.0 - (x ^ (1.0 / n)); t_1 = log(x) / -n; tmp = 0.0; if (x <= 1.6e-286) tmp = t_0; elseif (x <= 1.95e-224) tmp = t_1; elseif (x <= 3.5e-189) tmp = t_0; elseif (x <= 4.5e-134) tmp = t_1; elseif (x <= 1.0) tmp = t_0; elseif (x <= 6.5e+127) tmp = ((1.0 / n) + ((-0.5 / n) / x)) / x; 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]}, Block[{t$95$1 = N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision]}, If[LessEqual[x, 1.6e-286], t$95$0, If[LessEqual[x, 1.95e-224], t$95$1, If[LessEqual[x, 3.5e-189], t$95$0, If[LessEqual[x, 4.5e-134], t$95$1, If[LessEqual[x, 1.0], t$95$0, If[LessEqual[x, 6.5e+127], N[(N[(N[(1.0 / n), $MachinePrecision] + N[(N[(-0.5 / n), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], 0.0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{\log x}{-n}\\
\mathbf{if}\;x \leq 1.6 \cdot 10^{-286}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{-224}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-189}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-134}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+127}:\\
\;\;\;\;\frac{\frac{1}{n} + \frac{\frac{-0.5}{n}}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.60000000000000003e-286 or 1.9499999999999999e-224 < x < 3.5000000000000001e-189 or 4.5000000000000005e-134 < x < 1Initial program 59.5%
Taylor expanded in x around 0 58.5%
*-rgt-identity58.5%
associate-*l/58.5%
associate-/l*58.4%
exp-to-pow58.5%
Simplified58.5%
if 1.60000000000000003e-286 < x < 1.9499999999999999e-224 or 3.5000000000000001e-189 < x < 4.5000000000000005e-134Initial program 33.6%
Taylor expanded in x around 0 33.6%
*-rgt-identity33.6%
associate-*l/33.6%
associate-/l*33.6%
exp-to-pow33.6%
Simplified33.6%
Taylor expanded in n around inf 67.4%
mul-1-neg67.4%
distribute-frac-neg67.4%
Simplified67.4%
if 1 < x < 6.5e127Initial program 46.4%
add-log-exp46.4%
pow-to-exp46.4%
un-div-inv46.4%
+-commutative46.4%
log1p-define46.4%
Applied egg-rr46.4%
Taylor expanded in x around inf 82.7%
Simplified82.7%
Taylor expanded in n around inf 66.4%
associate-/r*66.4%
Simplified66.4%
Taylor expanded in n around inf 65.0%
if 6.5e127 < x Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
sqr-pow89.1%
distribute-rgt-neg-in89.1%
fma-define89.1%
sqrt-pow189.1%
sqrt-pow189.1%
pow-to-exp89.1%
un-div-inv89.1%
+-commutative89.1%
log1p-define89.1%
Applied egg-rr89.1%
Taylor expanded in x around inf 89.1%
distribute-rgt1-in89.1%
metadata-eval89.1%
mul0-lft89.1%
Simplified89.1%
Final simplification67.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- 1.0 t_0)) (t_2 (/ (log x) (- n))))
(if (<= x 8.2e-287)
t_1
(if (<= x 1.9e-224)
t_2
(if (<= x 2.7e-189) t_1 (if (<= x 4.9e-36) t_2 (/ (/ t_0 n) x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = 1.0 - t_0;
double t_2 = log(x) / -n;
double tmp;
if (x <= 8.2e-287) {
tmp = t_1;
} else if (x <= 1.9e-224) {
tmp = t_2;
} else if (x <= 2.7e-189) {
tmp = t_1;
} else if (x <= 4.9e-36) {
tmp = t_2;
} else {
tmp = (t_0 / n) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
t_1 = 1.0d0 - t_0
t_2 = log(x) / -n
if (x <= 8.2d-287) then
tmp = t_1
else if (x <= 1.9d-224) then
tmp = t_2
else if (x <= 2.7d-189) then
tmp = t_1
else if (x <= 4.9d-36) then
tmp = t_2
else
tmp = (t_0 / n) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double t_1 = 1.0 - t_0;
double t_2 = Math.log(x) / -n;
double tmp;
if (x <= 8.2e-287) {
tmp = t_1;
} else if (x <= 1.9e-224) {
tmp = t_2;
} else if (x <= 2.7e-189) {
tmp = t_1;
} else if (x <= 4.9e-36) {
tmp = t_2;
} else {
tmp = (t_0 / n) / x;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) t_1 = 1.0 - t_0 t_2 = math.log(x) / -n tmp = 0 if x <= 8.2e-287: tmp = t_1 elif x <= 1.9e-224: tmp = t_2 elif x <= 2.7e-189: tmp = t_1 elif x <= 4.9e-36: tmp = t_2 else: tmp = (t_0 / n) / x return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64(1.0 - t_0) t_2 = Float64(log(x) / Float64(-n)) tmp = 0.0 if (x <= 8.2e-287) tmp = t_1; elseif (x <= 1.9e-224) tmp = t_2; elseif (x <= 2.7e-189) tmp = t_1; elseif (x <= 4.9e-36) tmp = t_2; else tmp = Float64(Float64(t_0 / n) / x); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); t_1 = 1.0 - t_0; t_2 = log(x) / -n; tmp = 0.0; if (x <= 8.2e-287) tmp = t_1; elseif (x <= 1.9e-224) tmp = t_2; elseif (x <= 2.7e-189) tmp = t_1; elseif (x <= 4.9e-36) tmp = t_2; else tmp = (t_0 / n) / x; end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision]}, If[LessEqual[x, 8.2e-287], t$95$1, If[LessEqual[x, 1.9e-224], t$95$2, If[LessEqual[x, 2.7e-189], t$95$1, If[LessEqual[x, 4.9e-36], t$95$2, N[(N[(t$95$0 / n), $MachinePrecision] / x), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := 1 - t\_0\\
t_2 := \frac{\log x}{-n}\\
\mathbf{if}\;x \leq 8.2 \cdot 10^{-287}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-224}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-189}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{-36}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{n}}{x}\\
\end{array}
\end{array}
if x < 8.2000000000000004e-287 or 1.90000000000000001e-224 < x < 2.6999999999999999e-189Initial program 72.4%
Taylor expanded in x around 0 72.4%
*-rgt-identity72.4%
associate-*l/72.4%
associate-/l*72.4%
exp-to-pow72.4%
Simplified72.4%
if 8.2000000000000004e-287 < x < 1.90000000000000001e-224 or 2.6999999999999999e-189 < x < 4.8999999999999997e-36Initial program 41.6%
Taylor expanded in x around 0 41.6%
*-rgt-identity41.6%
associate-*l/41.6%
associate-/l*41.6%
exp-to-pow41.6%
Simplified41.6%
Taylor expanded in n around inf 58.1%
mul-1-neg58.1%
distribute-frac-neg58.1%
Simplified58.1%
if 4.8999999999999997e-36 < x Initial program 68.3%
Taylor expanded in x around inf 94.4%
associate-/r*95.6%
mul-1-neg95.6%
log-rec95.6%
mul-1-neg95.6%
distribute-neg-frac95.6%
mul-1-neg95.6%
remove-double-neg95.6%
*-rgt-identity95.6%
associate-/l*95.6%
exp-to-pow95.6%
Simplified95.6%
Final simplification75.5%
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (log x) (- n))))
(if (<= x 2e-224)
t_0
(if (<= x 1.05e-210)
(/ 1.0 (* x n))
(if (<= x 4.9e-36) t_0 (if (<= x 1.95e+127) (/ (/ 1.0 x) n) 0.0))))))
double code(double x, double n) {
double t_0 = log(x) / -n;
double tmp;
if (x <= 2e-224) {
tmp = t_0;
} else if (x <= 1.05e-210) {
tmp = 1.0 / (x * n);
} else if (x <= 4.9e-36) {
tmp = t_0;
} else if (x <= 1.95e+127) {
tmp = (1.0 / 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) :: t_0
real(8) :: tmp
t_0 = log(x) / -n
if (x <= 2d-224) then
tmp = t_0
else if (x <= 1.05d-210) then
tmp = 1.0d0 / (x * n)
else if (x <= 4.9d-36) then
tmp = t_0
else if (x <= 1.95d+127) then
tmp = (1.0d0 / x) / n
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.log(x) / -n;
double tmp;
if (x <= 2e-224) {
tmp = t_0;
} else if (x <= 1.05e-210) {
tmp = 1.0 / (x * n);
} else if (x <= 4.9e-36) {
tmp = t_0;
} else if (x <= 1.95e+127) {
tmp = (1.0 / x) / n;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): t_0 = math.log(x) / -n tmp = 0 if x <= 2e-224: tmp = t_0 elif x <= 1.05e-210: tmp = 1.0 / (x * n) elif x <= 4.9e-36: tmp = t_0 elif x <= 1.95e+127: tmp = (1.0 / x) / n else: tmp = 0.0 return tmp
function code(x, n) t_0 = Float64(log(x) / Float64(-n)) tmp = 0.0 if (x <= 2e-224) tmp = t_0; elseif (x <= 1.05e-210) tmp = Float64(1.0 / Float64(x * n)); elseif (x <= 4.9e-36) tmp = t_0; elseif (x <= 1.95e+127) tmp = Float64(Float64(1.0 / x) / n); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) t_0 = log(x) / -n; tmp = 0.0; if (x <= 2e-224) tmp = t_0; elseif (x <= 1.05e-210) tmp = 1.0 / (x * n); elseif (x <= 4.9e-36) tmp = t_0; elseif (x <= 1.95e+127) tmp = (1.0 / x) / n; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision]}, If[LessEqual[x, 2e-224], t$95$0, If[LessEqual[x, 1.05e-210], N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.9e-36], t$95$0, If[LessEqual[x, 1.95e+127], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], 0.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\log x}{-n}\\
\mathbf{if}\;x \leq 2 \cdot 10^{-224}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-210}:\\
\;\;\;\;\frac{1}{x \cdot n}\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{+127}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 2e-224 or 1.05000000000000008e-210 < x < 4.8999999999999997e-36Initial program 45.4%
Taylor expanded in x around 0 45.4%
*-rgt-identity45.4%
associate-*l/45.4%
associate-/l*45.3%
exp-to-pow45.4%
Simplified45.4%
Taylor expanded in n around inf 55.5%
mul-1-neg55.5%
distribute-frac-neg55.5%
Simplified55.5%
if 2e-224 < x < 1.05000000000000008e-210Initial program 88.2%
Taylor expanded in x around inf 75.5%
mul-1-neg75.5%
log-rec75.5%
mul-1-neg75.5%
distribute-neg-frac75.5%
mul-1-neg75.5%
remove-double-neg75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in n around inf 75.9%
if 4.8999999999999997e-36 < x < 1.94999999999999991e127Initial program 50.3%
Taylor expanded in x around inf 90.9%
mul-1-neg90.9%
log-rec90.9%
mul-1-neg90.9%
distribute-neg-frac90.9%
mul-1-neg90.9%
remove-double-neg90.9%
*-commutative90.9%
Simplified90.9%
Taylor expanded in n around inf 58.2%
*-commutative58.2%
associate-/r*59.2%
Simplified59.2%
if 1.94999999999999991e127 < x Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
sqr-pow89.1%
distribute-rgt-neg-in89.1%
fma-define89.1%
sqrt-pow189.1%
sqrt-pow189.1%
pow-to-exp89.1%
un-div-inv89.1%
+-commutative89.1%
log1p-define89.1%
Applied egg-rr89.1%
Taylor expanded in x around inf 89.1%
distribute-rgt1-in89.1%
metadata-eval89.1%
mul0-lft89.1%
Simplified89.1%
Final simplification63.5%
(FPCore (x n) :precision binary64 (if (<= x 6e+127) (/ (/ 1.0 x) n) 0.0))
double code(double x, double n) {
double tmp;
if (x <= 6e+127) {
tmp = (1.0 / 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 <= 6d+127) then
tmp = (1.0d0 / x) / n
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 6e+127) {
tmp = (1.0 / x) / n;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 6e+127: tmp = (1.0 / x) / n else: tmp = 0.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 6e+127) tmp = Float64(Float64(1.0 / x) / n); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 6e+127) tmp = (1.0 / x) / n; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 6e+127], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6 \cdot 10^{+127}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 6.0000000000000005e127Initial program 48.4%
Taylor expanded in x around inf 49.4%
mul-1-neg49.4%
log-rec49.4%
mul-1-neg49.4%
distribute-neg-frac49.4%
mul-1-neg49.4%
remove-double-neg49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in n around inf 35.2%
*-commutative35.2%
associate-/r*35.5%
Simplified35.5%
if 6.0000000000000005e127 < x Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
sqr-pow89.1%
distribute-rgt-neg-in89.1%
fma-define89.1%
sqrt-pow189.1%
sqrt-pow189.1%
pow-to-exp89.1%
un-div-inv89.1%
+-commutative89.1%
log1p-define89.1%
Applied egg-rr89.1%
Taylor expanded in x around inf 89.1%
distribute-rgt1-in89.1%
metadata-eval89.1%
mul0-lft89.1%
Simplified89.1%
(FPCore (x n) :precision binary64 (if (<= x 1e+127) (/ 1.0 (* x n)) 0.0))
double code(double x, double n) {
double tmp;
if (x <= 1e+127) {
tmp = 1.0 / (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 <= 1d+127) then
tmp = 1.0d0 / (x * n)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 1e+127) {
tmp = 1.0 / (x * n);
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 1e+127: tmp = 1.0 / (x * n) else: tmp = 0.0 return tmp
function code(x, n) tmp = 0.0 if (x <= 1e+127) tmp = Float64(1.0 / Float64(x * n)); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 1e+127) tmp = 1.0 / (x * n); else tmp = 0.0; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 1e+127], N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+127}:\\
\;\;\;\;\frac{1}{x \cdot n}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 9.99999999999999955e126Initial program 48.4%
Taylor expanded in x around inf 49.4%
mul-1-neg49.4%
log-rec49.4%
mul-1-neg49.4%
distribute-neg-frac49.4%
mul-1-neg49.4%
remove-double-neg49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in n around inf 35.2%
if 9.99999999999999955e126 < x Initial program 89.1%
sub-neg89.1%
+-commutative89.1%
sqr-pow89.1%
distribute-rgt-neg-in89.1%
fma-define89.1%
sqrt-pow189.1%
sqrt-pow189.1%
pow-to-exp89.1%
un-div-inv89.1%
+-commutative89.1%
log1p-define89.1%
Applied egg-rr89.1%
Taylor expanded in x around inf 89.1%
distribute-rgt1-in89.1%
metadata-eval89.1%
mul0-lft89.1%
Simplified89.1%
Final simplification45.7%
(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.4%
sub-neg56.4%
+-commutative56.4%
sqr-pow56.3%
distribute-rgt-neg-in56.3%
fma-define56.3%
sqrt-pow156.4%
sqrt-pow156.3%
pow-to-exp56.3%
un-div-inv56.3%
+-commutative56.3%
log1p-define60.0%
Applied egg-rr60.0%
Taylor expanded in x around inf 28.6%
distribute-rgt1-in28.6%
metadata-eval28.6%
mul0-lft28.9%
Simplified28.9%
herbie shell --seed 2024096
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))