
(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 10 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))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 (- INFINITY))
(- 1.0 t_0)
(if (<= t_1 0.0)
(+
(/ (log (/ (+ x 1.0) x)) n)
(* (/ 0.5 n) (- (/ (pow (log1p x) 2.0) n) (/ (pow (log x) 2.0) 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 <= -((double) INFINITY)) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
tmp = (log(((x + 1.0) / x)) / n) + ((0.5 / n) * ((pow(log1p(x), 2.0) / n) - (pow(log(x), 2.0) / 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 <= -Double.POSITIVE_INFINITY) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
tmp = (Math.log(((x + 1.0) / x)) / n) + ((0.5 / n) * ((Math.pow(Math.log1p(x), 2.0) / n) - (Math.pow(Math.log(x), 2.0) / 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 <= -math.inf: tmp = 1.0 - t_0 elif t_1 <= 0.0: tmp = (math.log(((x + 1.0) / x)) / n) + ((0.5 / n) * ((math.pow(math.log1p(x), 2.0) / n) - (math.pow(math.log(x), 2.0) / 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 <= Float64(-Inf)) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) tmp = Float64(Float64(log(Float64(Float64(x + 1.0) / x)) / n) + Float64(Float64(0.5 / n) * Float64(Float64((log1p(x) ^ 2.0) / n) - Float64((log(x) ^ 2.0) / 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, (-Infinity)], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] + N[(N[(0.5 / n), $MachinePrecision] * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision] - N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -\infty:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n} + \frac{0.5}{n} \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n} - \frac{{\log x}^{2}}{n}\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t\_0\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < -inf.0Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-rgt-identity100.0%
associate-*l/100.0%
associate-/l*100.0%
exp-to-pow100.0%
Simplified100.0%
if -inf.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < 0.0Initial program 40.3%
Taylor expanded in n around inf 71.8%
Simplified79.8%
log1p-undefine79.8%
diff-log79.9%
Applied egg-rr79.9%
+-commutative79.9%
Simplified79.9%
if 0.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) Initial program 51.3%
Taylor expanded in n around 0 51.3%
log1p-define97.4%
*-rgt-identity97.4%
associate-*l/97.4%
associate-/l*97.4%
exp-to-pow97.4%
Simplified97.4%
Final simplification84.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 (- INFINITY))
(- 1.0 t_0)
(if (<= t_1 0.0)
(/ (- (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 <= -((double) INFINITY)) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
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 <= -Double.POSITIVE_INFINITY) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
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 <= -math.inf: tmp = 1.0 - t_0 elif t_1 <= 0.0: 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 <= Float64(-Inf)) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) 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, (-Infinity)], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], 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 -\infty:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\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 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < -inf.0Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-rgt-identity100.0%
associate-*l/100.0%
associate-/l*100.0%
exp-to-pow100.0%
Simplified100.0%
if -inf.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < 0.0Initial program 40.3%
Taylor expanded in n around inf 79.4%
log1p-define79.4%
Simplified79.4%
if 0.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) Initial program 51.3%
Taylor expanded in n around 0 51.3%
log1p-define97.4%
*-rgt-identity97.4%
associate-*l/97.4%
associate-/l*97.4%
exp-to-pow97.4%
Simplified97.4%
Final simplification84.4%
(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 (- INFINITY))
(- 1.0 t_0)
(if (<= t_1 0.0) (/ (- (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 <= -((double) INFINITY)) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
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 <= -Double.POSITIVE_INFINITY) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
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 <= -math.inf: tmp = 1.0 - t_0 elif t_1 <= 0.0: 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 <= Float64(-Inf)) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) 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, (-Infinity)], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], 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 -\infty:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < -inf.0Initial program 100.0%
Taylor expanded in x around 0 100.0%
*-rgt-identity100.0%
associate-*l/100.0%
associate-/l*100.0%
exp-to-pow100.0%
Simplified100.0%
if -inf.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < 0.0Initial program 40.3%
Taylor expanded in n around inf 79.4%
log1p-define79.4%
Simplified79.4%
if 0.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) Initial program 51.3%
Final simplification77.6%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (/ (- (log1p x) (log x)) n)))
(if (<= (/ 1.0 n) -1e-10)
(/ t_0 (* x n))
(if (<= (/ 1.0 n) -5e-59)
t_1
(if (<= (/ 1.0 n) -1e-119)
(+
(/ 1.0 (* x n))
(/ (+ (/ 0.3333333333333333 x) -0.5) (* n (pow x 2.0))))
(if (<= (/ 1.0 n) 0.001)
t_1
(if (<= (/ 1.0 n) 1.03e+214)
(+ (- 1.0 t_0) (/ x n))
(/ (+ (/ 1.0 x) (/ 0.3333333333333333 (pow x 3.0))) n))))))))
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) <= -1e-10) {
tmp = t_0 / (x * n);
} else if ((1.0 / n) <= -5e-59) {
tmp = t_1;
} else if ((1.0 / n) <= -1e-119) {
tmp = (1.0 / (x * n)) + (((0.3333333333333333 / x) + -0.5) / (n * pow(x, 2.0)));
} else if ((1.0 / n) <= 0.001) {
tmp = t_1;
} else if ((1.0 / n) <= 1.03e+214) {
tmp = (1.0 - t_0) + (x / n);
} else {
tmp = ((1.0 / x) + (0.3333333333333333 / pow(x, 3.0))) / n;
}
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) <= -1e-10) {
tmp = t_0 / (x * n);
} else if ((1.0 / n) <= -5e-59) {
tmp = t_1;
} else if ((1.0 / n) <= -1e-119) {
tmp = (1.0 / (x * n)) + (((0.3333333333333333 / x) + -0.5) / (n * Math.pow(x, 2.0)));
} else if ((1.0 / n) <= 0.001) {
tmp = t_1;
} else if ((1.0 / n) <= 1.03e+214) {
tmp = (1.0 - t_0) + (x / n);
} else {
tmp = ((1.0 / x) + (0.3333333333333333 / Math.pow(x, 3.0))) / n;
}
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) <= -1e-10: tmp = t_0 / (x * n) elif (1.0 / n) <= -5e-59: tmp = t_1 elif (1.0 / n) <= -1e-119: tmp = (1.0 / (x * n)) + (((0.3333333333333333 / x) + -0.5) / (n * math.pow(x, 2.0))) elif (1.0 / n) <= 0.001: tmp = t_1 elif (1.0 / n) <= 1.03e+214: tmp = (1.0 - t_0) + (x / n) else: tmp = ((1.0 / x) + (0.3333333333333333 / math.pow(x, 3.0))) / n 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) <= -1e-10) tmp = Float64(t_0 / Float64(x * n)); elseif (Float64(1.0 / n) <= -5e-59) tmp = t_1; elseif (Float64(1.0 / n) <= -1e-119) tmp = Float64(Float64(1.0 / Float64(x * n)) + Float64(Float64(Float64(0.3333333333333333 / x) + -0.5) / Float64(n * (x ^ 2.0)))); elseif (Float64(1.0 / n) <= 0.001) tmp = t_1; elseif (Float64(1.0 / n) <= 1.03e+214) tmp = Float64(Float64(1.0 - t_0) + Float64(x / n)); else tmp = Float64(Float64(Float64(1.0 / x) + Float64(0.3333333333333333 / (x ^ 3.0))) / n); 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], -1e-10], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-59], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-119], N[(N[(1.0 / N[(x * n), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(0.3333333333333333 / x), $MachinePrecision] + -0.5), $MachinePrecision] / N[(n * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.001], t$95$1, If[LessEqual[N[(1.0 / n), $MachinePrecision], 1.03e+214], N[(N[(1.0 - t$95$0), $MachinePrecision] + N[(x / n), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] + N[(0.3333333333333333 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $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 -1 \cdot 10^{-10}:\\
\;\;\;\;\frac{t\_0}{x \cdot n}\\
\mathbf{elif}\;\frac{1}{n} \leq -5 \cdot 10^{-59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\frac{1}{n} \leq -1 \cdot 10^{-119}:\\
\;\;\;\;\frac{1}{x \cdot n} + \frac{\frac{0.3333333333333333}{x} + -0.5}{n \cdot {x}^{2}}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.001:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\frac{1}{n} \leq 1.03 \cdot 10^{+214}:\\
\;\;\;\;\left(1 - t\_0\right) + \frac{x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x} + \frac{0.3333333333333333}{{x}^{3}}}{n}\\
\end{array}
\end{array}
if (/.f64 1 n) < -1.00000000000000004e-10Initial program 96.8%
Taylor expanded in x around inf 100.0%
log-rec100.0%
mul-1-neg100.0%
associate-*r/100.0%
associate-*r*100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/l*100.0%
exp-to-pow100.0%
*-commutative100.0%
Simplified100.0%
if -1.00000000000000004e-10 < (/.f64 1 n) < -5.0000000000000001e-59 or -1.00000000000000001e-119 < (/.f64 1 n) < 1e-3Initial program 31.4%
Taylor expanded in n around inf 79.9%
log1p-define79.9%
Simplified79.9%
if -5.0000000000000001e-59 < (/.f64 1 n) < -1.00000000000000001e-119Initial program 12.8%
Taylor expanded in x around inf 71.2%
Simplified71.7%
Taylor expanded in n around inf 71.7%
sub-neg71.7%
associate-*r/71.7%
metadata-eval71.7%
metadata-eval71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in n around inf 71.7%
*-commutative71.7%
Simplified71.7%
if 1e-3 < (/.f64 1 n) < 1.03e214Initial program 63.8%
Taylor expanded in x around 0 61.9%
+-commutative61.9%
*-rgt-identity61.9%
associate-*l/61.9%
associate-/l*61.9%
exp-to-pow61.9%
associate-+r-61.9%
Simplified61.9%
if 1.03e214 < (/.f64 1 n) Initial program 20.7%
Taylor expanded in x around inf 0.0%
Simplified0.0%
Taylor expanded in n around inf 19.1%
sub-neg19.1%
associate-*r/19.1%
metadata-eval19.1%
metadata-eval19.1%
*-commutative19.1%
Simplified19.1%
Taylor expanded in x around 0 19.1%
associate-/r*19.1%
Simplified19.1%
Taylor expanded in n around inf 74.2%
associate-*r/74.2%
metadata-eval74.2%
Simplified74.2%
Final simplification82.0%
(FPCore (x n)
:precision binary64
(let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))) (t_1 (/ (- x (log x)) n)))
(if (<= n -2.2e+195)
t_0
(if (<= n -60000.0)
t_1
(if (<= n 1400.0)
t_0
(if (<= n 1e+280) t_1 (if (<= n 8e+295) t_0 (/ (log x) (- n)))))))))
double code(double x, double n) {
double t_0 = 1.0 - pow(x, (1.0 / n));
double t_1 = (x - log(x)) / n;
double tmp;
if (n <= -2.2e+195) {
tmp = t_0;
} else if (n <= -60000.0) {
tmp = t_1;
} else if (n <= 1400.0) {
tmp = t_0;
} else if (n <= 1e+280) {
tmp = t_1;
} else if (n <= 8e+295) {
tmp = t_0;
} else {
tmp = log(x) / -n;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (x ** (1.0d0 / n))
t_1 = (x - log(x)) / n
if (n <= (-2.2d+195)) then
tmp = t_0
else if (n <= (-60000.0d0)) then
tmp = t_1
else if (n <= 1400.0d0) then
tmp = t_0
else if (n <= 1d+280) then
tmp = t_1
else if (n <= 8d+295) then
tmp = t_0
else
tmp = log(x) / -n
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 = (x - Math.log(x)) / n;
double tmp;
if (n <= -2.2e+195) {
tmp = t_0;
} else if (n <= -60000.0) {
tmp = t_1;
} else if (n <= 1400.0) {
tmp = t_0;
} else if (n <= 1e+280) {
tmp = t_1;
} else if (n <= 8e+295) {
tmp = t_0;
} else {
tmp = Math.log(x) / -n;
}
return tmp;
}
def code(x, n): t_0 = 1.0 - math.pow(x, (1.0 / n)) t_1 = (x - math.log(x)) / n tmp = 0 if n <= -2.2e+195: tmp = t_0 elif n <= -60000.0: tmp = t_1 elif n <= 1400.0: tmp = t_0 elif n <= 1e+280: tmp = t_1 elif n <= 8e+295: tmp = t_0 else: tmp = math.log(x) / -n return tmp
function code(x, n) t_0 = Float64(1.0 - (x ^ Float64(1.0 / n))) t_1 = Float64(Float64(x - log(x)) / n) tmp = 0.0 if (n <= -2.2e+195) tmp = t_0; elseif (n <= -60000.0) tmp = t_1; elseif (n <= 1400.0) tmp = t_0; elseif (n <= 1e+280) tmp = t_1; elseif (n <= 8e+295) tmp = t_0; else tmp = Float64(log(x) / Float64(-n)); end return tmp end
function tmp_2 = code(x, n) t_0 = 1.0 - (x ^ (1.0 / n)); t_1 = (x - log(x)) / n; tmp = 0.0; if (n <= -2.2e+195) tmp = t_0; elseif (n <= -60000.0) tmp = t_1; elseif (n <= 1400.0) tmp = t_0; elseif (n <= 1e+280) tmp = t_1; elseif (n <= 8e+295) tmp = t_0; else tmp = log(x) / -n; 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[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[n, -2.2e+195], t$95$0, If[LessEqual[n, -60000.0], t$95$1, If[LessEqual[n, 1400.0], t$95$0, If[LessEqual[n, 1e+280], t$95$1, If[LessEqual[n, 8e+295], t$95$0, N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{x - \log x}{n}\\
\mathbf{if}\;n \leq -2.2 \cdot 10^{+195}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq -60000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;n \leq 1400:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 10^{+280}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;n \leq 8 \cdot 10^{+295}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\log x}{-n}\\
\end{array}
\end{array}
if n < -2.2e195 or -6e4 < n < 1400 or 1e280 < n < 7.9999999999999999e295Initial program 75.9%
Taylor expanded in x around 0 53.6%
*-rgt-identity53.6%
associate-*l/53.6%
associate-/l*53.6%
exp-to-pow53.6%
Simplified53.6%
if -2.2e195 < n < -6e4 or 1400 < n < 1e280Initial program 20.1%
Taylor expanded in x around 0 7.0%
+-commutative7.0%
*-rgt-identity7.0%
associate-*l/7.0%
associate-/l*7.0%
exp-to-pow7.0%
associate-+r-6.1%
Simplified6.1%
Taylor expanded in n around inf 52.5%
if 7.9999999999999999e295 < n Initial program 33.4%
Taylor expanded in x around 0 33.4%
*-rgt-identity33.4%
associate-*l/33.4%
associate-/l*33.4%
exp-to-pow33.4%
Simplified33.4%
Taylor expanded in n around inf 77.5%
associate-*r/77.5%
neg-mul-177.5%
Simplified77.5%
Final simplification53.4%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x 8.8e-243)
(/ (log x) (- n))
(if (<= x 1.8e-202)
(- 1.0 t_0)
(if (<= x 1.55e-5) (/ (- x (log x)) n) (/ t_0 (* x n)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 8.8e-243) {
tmp = log(x) / -n;
} else if (x <= 1.8e-202) {
tmp = 1.0 - t_0;
} else if (x <= 1.55e-5) {
tmp = (x - log(x)) / n;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= 8.8d-243) then
tmp = log(x) / -n
else if (x <= 1.8d-202) then
tmp = 1.0d0 - t_0
else if (x <= 1.55d-5) then
tmp = (x - log(x)) / n
else
tmp = t_0 / (x * n)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 8.8e-243) {
tmp = Math.log(x) / -n;
} else if (x <= 1.8e-202) {
tmp = 1.0 - t_0;
} else if (x <= 1.55e-5) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 8.8e-243: tmp = math.log(x) / -n elif x <= 1.8e-202: tmp = 1.0 - t_0 elif x <= 1.55e-5: tmp = (x - math.log(x)) / n else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 8.8e-243) tmp = Float64(log(x) / Float64(-n)); elseif (x <= 1.8e-202) tmp = Float64(1.0 - t_0); elseif (x <= 1.55e-5) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 8.8e-243) tmp = log(x) / -n; elseif (x <= 1.8e-202) tmp = 1.0 - t_0; elseif (x <= 1.55e-5) tmp = (x - log(x)) / n; else tmp = t_0 / (x * n); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 8.8e-243], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], If[LessEqual[x, 1.8e-202], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[x, 1.55e-5], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 8.8 \cdot 10^{-243}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-202}:\\
\;\;\;\;1 - t\_0\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-5}:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 8.7999999999999996e-243Initial program 35.9%
Taylor expanded in x around 0 35.9%
*-rgt-identity35.9%
associate-*l/35.9%
associate-/l*35.9%
exp-to-pow35.9%
Simplified35.9%
Taylor expanded in n around inf 69.0%
associate-*r/69.0%
neg-mul-169.0%
Simplified69.0%
if 8.7999999999999996e-243 < x < 1.8000000000000001e-202Initial program 61.3%
Taylor expanded in x around 0 61.3%
*-rgt-identity61.3%
associate-*l/61.3%
associate-/l*61.3%
exp-to-pow61.3%
Simplified61.3%
if 1.8000000000000001e-202 < x < 1.55000000000000007e-5Initial program 32.1%
Taylor expanded in x around 0 31.7%
+-commutative31.7%
*-rgt-identity31.7%
associate-*l/31.7%
associate-/l*31.7%
exp-to-pow31.7%
associate-+r-32.6%
Simplified32.6%
Taylor expanded in n around inf 57.3%
if 1.55000000000000007e-5 < x Initial program 62.5%
Taylor expanded in x around inf 95.9%
log-rec95.9%
mul-1-neg95.9%
associate-*r/95.9%
associate-*r*95.9%
metadata-eval95.9%
*-commutative95.9%
associate-/l*95.9%
exp-to-pow95.9%
*-commutative95.9%
Simplified95.9%
Final simplification76.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x 8e-242)
(/ (log x) (- n))
(if (<= x 1.5e-202)
(+ (- 1.0 t_0) (/ x n))
(if (<= x 1.36e-5) (/ (- x (log x)) n) (/ t_0 (* x n)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if (x <= 8e-242) {
tmp = log(x) / -n;
} else if (x <= 1.5e-202) {
tmp = (1.0 - t_0) + (x / n);
} else if (x <= 1.36e-5) {
tmp = (x - log(x)) / n;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = x ** (1.0d0 / n)
if (x <= 8d-242) then
tmp = log(x) / -n
else if (x <= 1.5d-202) then
tmp = (1.0d0 - t_0) + (x / n)
else if (x <= 1.36d-5) then
tmp = (x - log(x)) / n
else
tmp = t_0 / (x * n)
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if (x <= 8e-242) {
tmp = Math.log(x) / -n;
} else if (x <= 1.5e-202) {
tmp = (1.0 - t_0) + (x / n);
} else if (x <= 1.36e-5) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if x <= 8e-242: tmp = math.log(x) / -n elif x <= 1.5e-202: tmp = (1.0 - t_0) + (x / n) elif x <= 1.36e-5: tmp = (x - math.log(x)) / n else: tmp = t_0 / (x * n) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (x <= 8e-242) tmp = Float64(log(x) / Float64(-n)); elseif (x <= 1.5e-202) tmp = Float64(Float64(1.0 - t_0) + Float64(x / n)); elseif (x <= 1.36e-5) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 8e-242) tmp = log(x) / -n; elseif (x <= 1.5e-202) tmp = (1.0 - t_0) + (x / n); elseif (x <= 1.36e-5) tmp = (x - log(x)) / n; else tmp = t_0 / (x * n); end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 8e-242], N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision], If[LessEqual[x, 1.5e-202], N[(N[(1.0 - t$95$0), $MachinePrecision] + N[(x / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.36e-5], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 8 \cdot 10^{-242}:\\
\;\;\;\;\frac{\log x}{-n}\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{-202}:\\
\;\;\;\;\left(1 - t\_0\right) + \frac{x}{n}\\
\mathbf{elif}\;x \leq 1.36 \cdot 10^{-5}:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{x \cdot n}\\
\end{array}
\end{array}
if x < 8e-242Initial program 35.9%
Taylor expanded in x around 0 35.9%
*-rgt-identity35.9%
associate-*l/35.9%
associate-/l*35.9%
exp-to-pow35.9%
Simplified35.9%
Taylor expanded in n around inf 69.0%
associate-*r/69.0%
neg-mul-169.0%
Simplified69.0%
if 8e-242 < x < 1.50000000000000005e-202Initial program 61.3%
Taylor expanded in x around 0 61.4%
+-commutative61.4%
*-rgt-identity61.4%
associate-*l/61.4%
associate-/l*61.4%
exp-to-pow61.4%
associate-+r-61.5%
Simplified61.5%
if 1.50000000000000005e-202 < x < 1.36000000000000002e-5Initial program 32.1%
Taylor expanded in x around 0 31.7%
+-commutative31.7%
*-rgt-identity31.7%
associate-*l/31.7%
associate-/l*31.7%
exp-to-pow31.7%
associate-+r-32.6%
Simplified32.6%
Taylor expanded in n around inf 57.3%
if 1.36000000000000002e-5 < x Initial program 62.5%
Taylor expanded in x around inf 95.9%
log-rec95.9%
mul-1-neg95.9%
associate-*r/95.9%
associate-*r*95.9%
metadata-eval95.9%
*-commutative95.9%
associate-/l*95.9%
exp-to-pow95.9%
*-commutative95.9%
Simplified95.9%
Final simplification76.2%
(FPCore (x n) :precision binary64 (/ (- x (log x)) n))
double code(double x, double n) {
return (x - log(x)) / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = (x - log(x)) / n
end function
public static double code(double x, double n) {
return (x - Math.log(x)) / n;
}
def code(x, n): return (x - math.log(x)) / n
function code(x, n) return Float64(Float64(x - log(x)) / n) end
function tmp = code(x, n) tmp = (x - log(x)) / n; end
code[x_, n_] := N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \log x}{n}
\end{array}
Initial program 48.7%
Taylor expanded in x around 0 29.3%
+-commutative29.3%
*-rgt-identity29.3%
associate-*l/29.3%
associate-/l*29.3%
exp-to-pow29.3%
associate-+r-22.9%
Simplified22.9%
Taylor expanded in n around inf 33.2%
Final simplification33.2%
(FPCore (x n) :precision binary64 (/ (log x) (- n)))
double code(double x, double n) {
return log(x) / -n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = log(x) / -n
end function
public static double code(double x, double n) {
return Math.log(x) / -n;
}
def code(x, n): return math.log(x) / -n
function code(x, n) return Float64(log(x) / Float64(-n)) end
function tmp = code(x, n) tmp = log(x) / -n; end
code[x_, n_] := N[(N[Log[x], $MachinePrecision] / (-n)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log x}{-n}
\end{array}
Initial program 48.7%
Taylor expanded in x around 0 37.3%
*-rgt-identity37.3%
associate-*l/37.3%
associate-/l*37.3%
exp-to-pow37.3%
Simplified37.3%
Taylor expanded in n around inf 32.8%
associate-*r/32.8%
neg-mul-132.8%
Simplified32.8%
Final simplification32.8%
(FPCore (x n) :precision binary64 (/ x n))
double code(double x, double n) {
return x / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = x / n
end function
public static double code(double x, double n) {
return x / n;
}
def code(x, n): return x / n
function code(x, n) return Float64(x / n) end
function tmp = code(x, n) tmp = x / n; end
code[x_, n_] := N[(x / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{n}
\end{array}
Initial program 48.7%
Taylor expanded in x around 0 29.3%
+-commutative29.3%
*-rgt-identity29.3%
associate-*l/29.3%
associate-/l*29.3%
exp-to-pow29.3%
associate-+r-22.9%
Simplified22.9%
Taylor expanded in x around inf 4.8%
Final simplification4.8%
herbie shell --seed 2024046
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))