
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow (cbrt x) (/ 1.0 n)))
(t_1 (pow (pow (cbrt x) 2.0) (/ 1.0 n)))
(t_2 (* t_0 t_1)))
(if (<= (/ 1.0 n) -0.5)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (/ 1.0 n) 5e-7)
(/ (log1p (/ 1.0 x)) n)
(+ (fma (- t_0) t_1 t_2) (- (exp (/ (log1p x) n)) t_2))))))
double code(double x, double n) {
double t_0 = pow(cbrt(x), (1.0 / n));
double t_1 = pow(pow(cbrt(x), 2.0), (1.0 / n));
double t_2 = t_0 * t_1;
double tmp;
if ((1.0 / n) <= -0.5) {
tmp = exp((log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 5e-7) {
tmp = log1p((1.0 / x)) / n;
} else {
tmp = fma(-t_0, t_1, t_2) + (exp((log1p(x) / n)) - t_2);
}
return tmp;
}
function code(x, n) t_0 = cbrt(x) ^ Float64(1.0 / n) t_1 = (cbrt(x) ^ 2.0) ^ Float64(1.0 / n) t_2 = Float64(t_0 * t_1) tmp = 0.0 if (Float64(1.0 / n) <= -0.5) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif (Float64(1.0 / n) <= 5e-7) tmp = Float64(log1p(Float64(1.0 / x)) / n); else tmp = Float64(fma(Float64(-t_0), t_1, t_2) + Float64(exp(Float64(log1p(x) / n)) - t_2)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[N[Power[x, 1/3], $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -0.5], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-7], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[((-t$95$0) * t$95$1 + t$95$2), $MachinePrecision] + N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\sqrt[3]{x}\right)}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left({\left(\sqrt[3]{x}\right)}^{2}\right)}^{\left(\frac{1}{n}\right)}\\
t_2 := t_0 \cdot t_1\\
\mathbf{if}\;\frac{1}{n} \leq -0.5:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-t_0, t_1, t_2\right) + \left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t_2\right)\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -0.5)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (/ 1.0 n) 5e-7)
(/ (log1p (/ 1.0 x)) n)
(- (exp (/ x n)) (pow x (/ 1.0 n))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -0.5) {
tmp = exp((log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 5e-7) {
tmp = log1p((1.0 / x)) / n;
} else {
tmp = exp((x / n)) - pow(x, (1.0 / n));
}
return tmp;
}
public static double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -0.5) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 5e-7) {
tmp = Math.log1p((1.0 / x)) / n;
} else {
tmp = Math.exp((x / n)) - Math.pow(x, (1.0 / n));
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -0.5: tmp = math.exp((math.log(x) / n)) / (n * x) elif (1.0 / n) <= 5e-7: tmp = math.log1p((1.0 / x)) / n else: tmp = math.exp((x / n)) - math.pow(x, (1.0 / n)) return tmp
function code(x, n) tmp = 0.0 if (Float64(1.0 / n) <= -0.5) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif (Float64(1.0 / n) <= 5e-7) tmp = Float64(log1p(Float64(1.0 / x)) / n); else tmp = Float64(exp(Float64(x / n)) - (x ^ Float64(1.0 / n))); end return tmp end
code[x_, n_] := If[LessEqual[N[(1.0 / n), $MachinePrecision], -0.5], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-7], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -0.5:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(if (<= (/ 1.0 n) -0.5)
(/ (exp (/ (log x) n)) (* n x))
(if (<= (/ 1.0 n) 5e-7)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 2e+228)
(- (+ 1.0 (/ x n)) (pow x (/ 1.0 n)))
(/ 1.0 (* n x))))))
double code(double x, double n) {
double tmp;
if ((1.0 / n) <= -0.5) {
tmp = exp((log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 5e-7) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = (1.0 + (x / n)) - 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) <= -0.5) {
tmp = Math.exp((Math.log(x) / n)) / (n * x);
} else if ((1.0 / n) <= 5e-7) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = (1.0 + (x / n)) - Math.pow(x, (1.0 / n));
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): tmp = 0 if (1.0 / n) <= -0.5: tmp = math.exp((math.log(x) / n)) / (n * x) elif (1.0 / n) <= 5e-7: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 2e+228: tmp = (1.0 + (x / n)) - 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) <= -0.5) tmp = Float64(exp(Float64(log(x) / n)) / Float64(n * x)); elseif (Float64(1.0 / n) <= 5e-7) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 2e+228) tmp = Float64(Float64(1.0 + Float64(x / n)) - (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], -0.5], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-7], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+228], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -0.5:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+228}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -1e+188)
(- 1.0 t_0)
(if (<= (/ 1.0 n) -50000000.0)
(/ 0.0 n)
(if (<= (/ 1.0 n) 5e-7)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 2e+228)
(- (+ 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) <= -1e+188) {
tmp = 1.0 - t_0;
} else if ((1.0 / n) <= -50000000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 5e-7) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
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) <= -1e+188) {
tmp = 1.0 - t_0;
} else if ((1.0 / n) <= -50000000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 5e-7) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
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) <= -1e+188: tmp = 1.0 - t_0 elif (1.0 / n) <= -50000000.0: tmp = 0.0 / n elif (1.0 / n) <= 5e-7: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 2e+228: 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) <= -1e+188) tmp = Float64(1.0 - t_0); elseif (Float64(1.0 / n) <= -50000000.0) tmp = Float64(0.0 / n); elseif (Float64(1.0 / n) <= 5e-7) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 2e+228) 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], -1e+188], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], -50000000.0], N[(0.0 / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-7], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+228], 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 -1 \cdot 10^{+188}:\\
\;\;\;\;1 - t_0\\
\mathbf{elif}\;\frac{1}{n} \leq -50000000:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+228}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (- 1.0 (pow x (/ 1.0 n)))))
(if (<= (/ 1.0 n) -1e+188)
t_0
(if (<= (/ 1.0 n) -50000000.0)
(/ 0.0 n)
(if (<= (/ 1.0 n) 5e-7)
(/ (log1p (/ 1.0 x)) n)
(if (<= (/ 1.0 n) 2e+228) t_0 (/ 1.0 (* n x))))))))
double code(double x, double n) {
double t_0 = 1.0 - pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1e+188) {
tmp = t_0;
} else if ((1.0 / n) <= -50000000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 5e-7) {
tmp = log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = 1.0 - Math.pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1e+188) {
tmp = t_0;
} else if ((1.0 / n) <= -50000000.0) {
tmp = 0.0 / n;
} else if ((1.0 / n) <= 5e-7) {
tmp = Math.log1p((1.0 / x)) / n;
} else if ((1.0 / n) <= 2e+228) {
tmp = t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = 1.0 - math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -1e+188: tmp = t_0 elif (1.0 / n) <= -50000000.0: tmp = 0.0 / n elif (1.0 / n) <= 5e-7: tmp = math.log1p((1.0 / x)) / n elif (1.0 / n) <= 2e+228: tmp = t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = Float64(1.0 - (x ^ Float64(1.0 / n))) tmp = 0.0 if (Float64(1.0 / n) <= -1e+188) tmp = t_0; elseif (Float64(1.0 / n) <= -50000000.0) tmp = Float64(0.0 / n); elseif (Float64(1.0 / n) <= 5e-7) tmp = Float64(log1p(Float64(1.0 / x)) / n); elseif (Float64(1.0 / n) <= 2e+228) tmp = t_0; else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e+188], t$95$0, If[LessEqual[N[(1.0 / n), $MachinePrecision], -50000000.0], N[(0.0 / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-7], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+228], t$95$0, N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{+188}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\frac{1}{n} \leq -50000000:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+228}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ (log1p (/ 1.0 x)) n)))
(if (<= n -0.00038)
t_0
(if (<= n -2.1e-188)
(/ 0.0 n)
(if (<= n 7.2e-157) (/ 1.0 (* n x)) t_0)))))
double code(double x, double n) {
double t_0 = log1p((1.0 / x)) / n;
double tmp;
if (n <= -0.00038) {
tmp = t_0;
} else if (n <= -2.1e-188) {
tmp = 0.0 / n;
} else if (n <= 7.2e-157) {
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 <= -0.00038) {
tmp = t_0;
} else if (n <= -2.1e-188) {
tmp = 0.0 / n;
} else if (n <= 7.2e-157) {
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 <= -0.00038: tmp = t_0 elif n <= -2.1e-188: tmp = 0.0 / n elif n <= 7.2e-157: 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 <= -0.00038) tmp = t_0; elseif (n <= -2.1e-188) tmp = Float64(0.0 / n); elseif (n <= 7.2e-157) 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, -0.00038], t$95$0, If[LessEqual[n, -2.1e-188], N[(0.0 / n), $MachinePrecision], If[LessEqual[n, 7.2e-157], 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 -0.00038:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq -2.1 \cdot 10^{-188}:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;n \leq 7.2 \cdot 10^{-157}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(if (<= x 0.33)
(/ (- (log x)) n)
(if (<= x 4.4e+56)
(/ 1.0 (- (* n (+ x 0.5)) (/ (* n 0.08333333333333333) x)))
(if (or (<= x 3e+158) (not (<= x 9.5e+264))) (/ 0.0 n) (/ (/ 1.0 x) n)))))
double code(double x, double n) {
double tmp;
if (x <= 0.33) {
tmp = -log(x) / n;
} else if (x <= 4.4e+56) {
tmp = 1.0 / ((n * (x + 0.5)) - ((n * 0.08333333333333333) / x));
} else if ((x <= 3e+158) || !(x <= 9.5e+264)) {
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 (x <= 0.33d0) then
tmp = -log(x) / n
else if (x <= 4.4d+56) then
tmp = 1.0d0 / ((n * (x + 0.5d0)) - ((n * 0.08333333333333333d0) / x))
else if ((x <= 3d+158) .or. (.not. (x <= 9.5d+264))) 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 (x <= 0.33) {
tmp = -Math.log(x) / n;
} else if (x <= 4.4e+56) {
tmp = 1.0 / ((n * (x + 0.5)) - ((n * 0.08333333333333333) / x));
} else if ((x <= 3e+158) || !(x <= 9.5e+264)) {
tmp = 0.0 / n;
} else {
tmp = (1.0 / x) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.33: tmp = -math.log(x) / n elif x <= 4.4e+56: tmp = 1.0 / ((n * (x + 0.5)) - ((n * 0.08333333333333333) / x)) elif (x <= 3e+158) or not (x <= 9.5e+264): tmp = 0.0 / n else: tmp = (1.0 / x) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.33) tmp = Float64(Float64(-log(x)) / n); elseif (x <= 4.4e+56) tmp = Float64(1.0 / Float64(Float64(n * Float64(x + 0.5)) - Float64(Float64(n * 0.08333333333333333) / x))); elseif ((x <= 3e+158) || !(x <= 9.5e+264)) 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 (x <= 0.33) tmp = -log(x) / n; elseif (x <= 4.4e+56) tmp = 1.0 / ((n * (x + 0.5)) - ((n * 0.08333333333333333) / x)); elseif ((x <= 3e+158) || ~((x <= 9.5e+264))) tmp = 0.0 / n; else tmp = (1.0 / x) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.33], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], If[LessEqual[x, 4.4e+56], N[(1.0 / N[(N[(n * N[(x + 0.5), $MachinePrecision]), $MachinePrecision] - N[(N[(n * 0.08333333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 3e+158], N[Not[LessEqual[x, 9.5e+264]], $MachinePrecision]], N[(0.0 / n), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.33:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{+56}:\\
\;\;\;\;\frac{1}{n \cdot \left(x + 0.5\right) - \frac{n \cdot 0.08333333333333333}{x}}\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+158} \lor \neg \left(x \leq 9.5 \cdot 10^{+264}\right):\\
\;\;\;\;\frac{0}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\end{array}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (/ 1.0 (* n (+ x 0.5)))))
(if (<= n -0.00038)
t_0
(if (<= n -1.8e-188)
(/ 0.0 n)
(if (<= n 7.5e-157) (/ 1.0 (* n x)) t_0)))))
double code(double x, double n) {
double t_0 = 1.0 / (n * (x + 0.5));
double tmp;
if (n <= -0.00038) {
tmp = t_0;
} else if (n <= -1.8e-188) {
tmp = 0.0 / n;
} else if (n <= 7.5e-157) {
tmp = 1.0 / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 / (n * (x + 0.5d0))
if (n <= (-0.00038d0)) then
tmp = t_0
else if (n <= (-1.8d-188)) then
tmp = 0.0d0 / n
else if (n <= 7.5d-157) then
tmp = 1.0d0 / (n * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double n) {
double t_0 = 1.0 / (n * (x + 0.5));
double tmp;
if (n <= -0.00038) {
tmp = t_0;
} else if (n <= -1.8e-188) {
tmp = 0.0 / n;
} else if (n <= 7.5e-157) {
tmp = 1.0 / (n * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, n): t_0 = 1.0 / (n * (x + 0.5)) tmp = 0 if n <= -0.00038: tmp = t_0 elif n <= -1.8e-188: tmp = 0.0 / n elif n <= 7.5e-157: tmp = 1.0 / (n * x) else: tmp = t_0 return tmp
function code(x, n) t_0 = Float64(1.0 / Float64(n * Float64(x + 0.5))) tmp = 0.0 if (n <= -0.00038) tmp = t_0; elseif (n <= -1.8e-188) tmp = Float64(0.0 / n); elseif (n <= 7.5e-157) tmp = Float64(1.0 / Float64(n * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, n) t_0 = 1.0 / (n * (x + 0.5)); tmp = 0.0; if (n <= -0.00038) tmp = t_0; elseif (n <= -1.8e-188) tmp = 0.0 / n; elseif (n <= 7.5e-157) tmp = 1.0 / (n * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, n_] := Block[{t$95$0 = N[(1.0 / N[(n * N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -0.00038], t$95$0, If[LessEqual[n, -1.8e-188], N[(0.0 / n), $MachinePrecision], If[LessEqual[n, 7.5e-157], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{n \cdot \left(x + 0.5\right)}\\
\mathbf{if}\;n \leq -0.00038:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq -1.8 \cdot 10^{-188}:\\
\;\;\;\;\frac{0}{n}\\
\mathbf{elif}\;n \leq 7.5 \cdot 10^{-157}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x n) :precision binary64 (if (<= n 6.5e-160) (/ (/ 1.0 x) n) (/ 1.0 (* n (+ x 0.5)))))
double code(double x, double n) {
double tmp;
if (n <= 6.5e-160) {
tmp = (1.0 / x) / n;
} else {
tmp = 1.0 / (n * (x + 0.5));
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 6.5d-160) then
tmp = (1.0d0 / x) / n
else
tmp = 1.0d0 / (n * (x + 0.5d0))
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (n <= 6.5e-160) {
tmp = (1.0 / x) / n;
} else {
tmp = 1.0 / (n * (x + 0.5));
}
return tmp;
}
def code(x, n): tmp = 0 if n <= 6.5e-160: tmp = (1.0 / x) / n else: tmp = 1.0 / (n * (x + 0.5)) return tmp
function code(x, n) tmp = 0.0 if (n <= 6.5e-160) tmp = Float64(Float64(1.0 / x) / n); else tmp = Float64(1.0 / Float64(n * Float64(x + 0.5))); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (n <= 6.5e-160) tmp = (1.0 / x) / n; else tmp = 1.0 / (n * (x + 0.5)); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[n, 6.5e-160], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], N[(1.0 / N[(n * N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq 6.5 \cdot 10^{-160}:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot \left(x + 0.5\right)}\\
\end{array}
\end{array}
(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}
(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}
herbie shell --seed 2023350
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))