
(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))))
(if (<= (/ 1.0 n) -1.85e-30)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 500000.0)
(/ (log (/ (+ 1.0 x) x)) n)
(- (exp (/ x n)) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = log(((1.0 + x) / x)) / n;
} else {
tmp = exp((x / n)) - 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 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-1.85d-30)) then
tmp = t_0 / (n * x)
else if ((1.0d0 / n) <= 500000.0d0) then
tmp = log(((1.0d0 + x) / x)) / n
else
tmp = exp((x / n)) - t_0
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 ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else {
tmp = Math.exp((x / n)) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -1.85e-30: tmp = t_0 / (n * x) elif (1.0 / n) <= 500000.0: tmp = math.log(((1.0 + x) / x)) / n else: tmp = math.exp((x / n)) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -1.85e-30) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 500000.0) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); else tmp = Float64(exp(Float64(x / n)) - t_0); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -1.85e-30) tmp = t_0 / (n * x); elseif ((1.0 / n) <= 500000.0) tmp = log(((1.0 + x) / x)) / n; else tmp = exp((x / n)) - t_0; end tmp_2 = 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], -1.85e-30], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 500000.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1.85 \cdot 10^{-30}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 500000:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\
\end{array}
\end{array}
if (/.f64 1 n) < -1.8500000000000002e-30Initial program 96.8%
Taylor expanded in x around inf 98.8%
log-rec98.8%
mul-1-neg98.8%
associate-*r/98.8%
neg-mul-198.8%
mul-1-neg98.8%
remove-double-neg98.8%
*-commutative98.8%
Simplified98.8%
expm1-log1p-u49.8%
expm1-udef46.9%
div-inv46.9%
pow-to-exp46.9%
Applied egg-rr46.9%
expm1-def49.8%
expm1-log1p98.8%
Simplified98.8%
if -1.8500000000000002e-30 < (/.f64 1 n) < 5e5Initial program 23.3%
Taylor expanded in n around inf 77.1%
+-rgt-identity77.1%
+-rgt-identity77.1%
log1p-def77.1%
Simplified77.1%
log1p-udef77.1%
diff-log77.3%
Applied egg-rr77.3%
if 5e5 < (/.f64 1 n) Initial program 70.1%
Taylor expanded in n around 0 70.1%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification88.3%
(FPCore (x n)
:precision binary64
(if (or (<= (/ 1.0 n) -1e+136)
(and (not (<= (/ 1.0 n) -2e+60)) (<= (/ 1.0 n) 500000.0)))
(/ (log (/ (+ 1.0 x) x)) n)
(- 1.0 (pow x (/ 1.0 n)))))
double code(double x, double n) {
double tmp;
if (((1.0 / n) <= -1e+136) || (!((1.0 / n) <= -2e+60) && ((1.0 / n) <= 500000.0))) {
tmp = log(((1.0 + x) / x)) / n;
} else {
tmp = 1.0 - pow(x, (1.0 / n));
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (((1.0d0 / n) <= (-1d+136)) .or. (.not. ((1.0d0 / n) <= (-2d+60))) .and. ((1.0d0 / n) <= 500000.0d0)) then
tmp = log(((1.0d0 + x) / x)) / n
else
tmp = 1.0d0 - (x ** (1.0d0 / n))
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (((1.0 / n) <= -1e+136) || (!((1.0 / n) <= -2e+60) && ((1.0 / n) <= 500000.0))) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else {
tmp = 1.0 - Math.pow(x, (1.0 / n));
}
return tmp;
}
def code(x, n): tmp = 0 if ((1.0 / n) <= -1e+136) or (not ((1.0 / n) <= -2e+60) and ((1.0 / n) <= 500000.0)): tmp = math.log(((1.0 + x) / x)) / n else: tmp = 1.0 - math.pow(x, (1.0 / n)) return tmp
function code(x, n) tmp = 0.0 if ((Float64(1.0 / n) <= -1e+136) || (!(Float64(1.0 / n) <= -2e+60) && (Float64(1.0 / n) <= 500000.0))) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); else tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (((1.0 / n) <= -1e+136) || (~(((1.0 / n) <= -2e+60)) && ((1.0 / n) <= 500000.0))) tmp = log(((1.0 + x) / x)) / n; else tmp = 1.0 - (x ^ (1.0 / n)); end tmp_2 = tmp; end
code[x_, n_] := If[Or[LessEqual[N[(1.0 / n), $MachinePrecision], -1e+136], And[N[Not[LessEqual[N[(1.0 / n), $MachinePrecision], -2e+60]], $MachinePrecision], LessEqual[N[(1.0 / n), $MachinePrecision], 500000.0]]], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{+136} \lor \neg \left(\frac{1}{n} \leq -2 \cdot 10^{+60}\right) \land \frac{1}{n} \leq 500000:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\end{array}
\end{array}
if (/.f64 1 n) < -1.00000000000000006e136 or -1.9999999999999999e60 < (/.f64 1 n) < 5e5Initial program 47.8%
Taylor expanded in n around inf 70.7%
+-rgt-identity70.7%
+-rgt-identity70.7%
log1p-def70.7%
Simplified70.7%
log1p-udef70.7%
diff-log70.3%
Applied egg-rr70.3%
if -1.00000000000000006e136 < (/.f64 1 n) < -1.9999999999999999e60 or 5e5 < (/.f64 1 n) Initial program 83.7%
Taylor expanded in x around 0 68.5%
Final simplification69.9%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -1.85e-30)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 500000.0)
(/ (log (/ (+ 1.0 x) x)) n)
(- (+ 1.0 (/ x n)) t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = log(((1.0 + x) / x)) / n;
} else {
tmp = (1.0 + (x / n)) - 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 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-1.85d-30)) then
tmp = t_0 / (n * x)
else if ((1.0d0 / n) <= 500000.0d0) then
tmp = log(((1.0d0 + x) / x)) / n
else
tmp = (1.0d0 + (x / n)) - t_0
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 ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else {
tmp = (1.0 + (x / n)) - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -1.85e-30: tmp = t_0 / (n * x) elif (1.0 / n) <= 500000.0: tmp = math.log(((1.0 + x) / x)) / n else: tmp = (1.0 + (x / n)) - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -1.85e-30) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 500000.0) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); else tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -1.85e-30) tmp = t_0 / (n * x); elseif ((1.0 / n) <= 500000.0) tmp = log(((1.0 + x) / x)) / n; else tmp = (1.0 + (x / n)) - t_0; end tmp_2 = 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], -1.85e-30], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 500000.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1.85 \cdot 10^{-30}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 500000:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\end{array}
\end{array}
if (/.f64 1 n) < -1.8500000000000002e-30Initial program 96.8%
Taylor expanded in x around inf 98.8%
log-rec98.8%
mul-1-neg98.8%
associate-*r/98.8%
neg-mul-198.8%
mul-1-neg98.8%
remove-double-neg98.8%
*-commutative98.8%
Simplified98.8%
expm1-log1p-u49.8%
expm1-udef46.9%
div-inv46.9%
pow-to-exp46.9%
Applied egg-rr46.9%
expm1-def49.8%
expm1-log1p98.8%
Simplified98.8%
if -1.8500000000000002e-30 < (/.f64 1 n) < 5e5Initial program 23.3%
Taylor expanded in n around inf 77.1%
+-rgt-identity77.1%
+-rgt-identity77.1%
log1p-def77.1%
Simplified77.1%
log1p-udef77.1%
diff-log77.3%
Applied egg-rr77.3%
if 5e5 < (/.f64 1 n) Initial program 70.1%
Taylor expanded in x around 0 67.4%
Final simplification83.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -1.85e-30)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 500000.0) (/ (log (/ (+ 1.0 x) x)) n) (- 1.0 t_0)))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = log(((1.0 + x) / x)) / n;
} else {
tmp = 1.0 - 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 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-1.85d-30)) then
tmp = t_0 / (n * x)
else if ((1.0d0 / n) <= 500000.0d0) then
tmp = log(((1.0d0 + x) / x)) / n
else
tmp = 1.0d0 - t_0
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 ((1.0 / n) <= -1.85e-30) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 500000.0) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else {
tmp = 1.0 - t_0;
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -1.85e-30: tmp = t_0 / (n * x) elif (1.0 / n) <= 500000.0: tmp = math.log(((1.0 + x) / x)) / n else: tmp = 1.0 - t_0 return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -1.85e-30) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 500000.0) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); else tmp = Float64(1.0 - t_0); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -1.85e-30) tmp = t_0 / (n * x); elseif ((1.0 / n) <= 500000.0) tmp = log(((1.0 + x) / x)) / n; else tmp = 1.0 - t_0; end tmp_2 = 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], -1.85e-30], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 500000.0], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(1.0 - t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1.85 \cdot 10^{-30}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 500000:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;1 - t_0\\
\end{array}
\end{array}
if (/.f64 1 n) < -1.8500000000000002e-30Initial program 96.8%
Taylor expanded in x around inf 98.8%
log-rec98.8%
mul-1-neg98.8%
associate-*r/98.8%
neg-mul-198.8%
mul-1-neg98.8%
remove-double-neg98.8%
*-commutative98.8%
Simplified98.8%
expm1-log1p-u49.8%
expm1-udef46.9%
div-inv46.9%
pow-to-exp46.9%
Applied egg-rr46.9%
expm1-def49.8%
expm1-log1p98.8%
Simplified98.8%
if -1.8500000000000002e-30 < (/.f64 1 n) < 5e5Initial program 23.3%
Taylor expanded in n around inf 77.1%
+-rgt-identity77.1%
+-rgt-identity77.1%
log1p-def77.1%
Simplified77.1%
log1p-udef77.1%
diff-log77.3%
Applied egg-rr77.3%
if 5e5 < (/.f64 1 n) Initial program 70.1%
Taylor expanded in x around 0 64.6%
Final simplification83.4%
(FPCore (x n) :precision binary64 (if (<= n -3500000000.0) (/ (/ 1.0 x) n) (if (<= n 2.4e-6) (- 1.0 (pow x (/ 1.0 n))) (/ (- x (log x)) n))))
double code(double x, double n) {
double tmp;
if (n <= -3500000000.0) {
tmp = (1.0 / x) / n;
} else if (n <= 2.4e-6) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = (x - log(x)) / n;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (n <= (-3500000000.0d0)) then
tmp = (1.0d0 / x) / n
else if (n <= 2.4d-6) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else
tmp = (x - log(x)) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (n <= -3500000000.0) {
tmp = (1.0 / x) / n;
} else if (n <= 2.4e-6) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = (x - Math.log(x)) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if n <= -3500000000.0: tmp = (1.0 / x) / n elif n <= 2.4e-6: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = (x - math.log(x)) / n return tmp
function code(x, n) tmp = 0.0 if (n <= -3500000000.0) tmp = Float64(Float64(1.0 / x) / n); elseif (n <= 2.4e-6) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64(Float64(x - log(x)) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (n <= -3500000000.0) tmp = (1.0 / x) / n; elseif (n <= 2.4e-6) tmp = 1.0 - (x ^ (1.0 / n)); else tmp = (x - log(x)) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[n, -3500000000.0], N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[n, 2.4e-6], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -3500000000:\\
\;\;\;\;\frac{\frac{1}{x}}{n}\\
\mathbf{elif}\;n \leq 2.4 \cdot 10^{-6}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \log x}{n}\\
\end{array}
\end{array}
if n < -3.5e9Initial program 26.0%
Taylor expanded in x around inf 52.7%
log-rec52.7%
mul-1-neg52.7%
associate-*r/52.7%
neg-mul-152.7%
mul-1-neg52.7%
remove-double-neg52.7%
*-commutative52.7%
Simplified52.7%
Taylor expanded in n around inf 52.7%
*-commutative52.7%
associate-/r*53.0%
Simplified53.0%
if -3.5e9 < n < 2.3999999999999999e-6Initial program 91.6%
Taylor expanded in x around 0 56.7%
if 2.3999999999999999e-6 < n Initial program 20.9%
Taylor expanded in n around 0 20.9%
log1p-def20.9%
Simplified20.9%
Taylor expanded in x around 0 14.7%
Taylor expanded in n around inf 59.6%
Final simplification56.5%
(FPCore (x n) :precision binary64 (if (<= x 0.98) (/ (- x (log x)) n) (/ (- (/ 1.0 x) (/ 0.5 (* x x))) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.98) {
tmp = (x - log(x)) / n;
} else {
tmp = ((1.0 / x) - (0.5 / (x * 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.98d0) then
tmp = (x - log(x)) / n
else
tmp = ((1.0d0 / x) - (0.5d0 / (x * x))) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.98) {
tmp = (x - Math.log(x)) / n;
} else {
tmp = ((1.0 / x) - (0.5 / (x * x))) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.98: tmp = (x - math.log(x)) / n else: tmp = ((1.0 / x) - (0.5 / (x * x))) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.98) tmp = Float64(Float64(x - log(x)) / n); else tmp = Float64(Float64(Float64(1.0 / x) - Float64(0.5 / Float64(x * x))) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.98) tmp = (x - log(x)) / n; else tmp = ((1.0 / x) - (0.5 / (x * x))) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.98], N[(N[(x - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] - N[(0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.98:\\
\;\;\;\;\frac{x - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\
\end{array}
\end{array}
if x < 0.97999999999999998Initial program 49.2%
Taylor expanded in n around 0 49.2%
log1p-def56.0%
Simplified56.0%
Taylor expanded in x around 0 56.0%
Taylor expanded in n around inf 48.3%
if 0.97999999999999998 < x Initial program 67.9%
Taylor expanded in n around inf 68.3%
+-rgt-identity68.3%
+-rgt-identity68.3%
log1p-def68.3%
Simplified68.3%
Taylor expanded in x around inf 56.4%
unpow256.4%
associate-*r/56.4%
metadata-eval56.4%
Simplified56.4%
Final simplification51.6%
(FPCore (x n) :precision binary64 (if (<= x 0.68) (/ (- (log x)) n) (/ (- (/ 1.0 x) (/ 0.5 (* x x))) n)))
double code(double x, double n) {
double tmp;
if (x <= 0.68) {
tmp = -log(x) / n;
} else {
tmp = ((1.0 / x) - (0.5 / (x * 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.68d0) then
tmp = -log(x) / n
else
tmp = ((1.0d0 / x) - (0.5d0 / (x * x))) / n
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.68) {
tmp = -Math.log(x) / n;
} else {
tmp = ((1.0 / x) - (0.5 / (x * x))) / n;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.68: tmp = -math.log(x) / n else: tmp = ((1.0 / x) - (0.5 / (x * x))) / n return tmp
function code(x, n) tmp = 0.0 if (x <= 0.68) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64(Float64(Float64(1.0 / x) - Float64(0.5 / Float64(x * x))) / n); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.68) tmp = -log(x) / n; else tmp = ((1.0 / x) - (0.5 / (x * x))) / n; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.68], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] - N[(0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{x \cdot x}}{n}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 49.2%
Taylor expanded in x around 0 47.9%
Taylor expanded in n around inf 47.7%
associate-*r/47.7%
mul-1-neg47.7%
Simplified47.7%
if 0.680000000000000049 < x Initial program 67.9%
Taylor expanded in n around inf 68.3%
+-rgt-identity68.3%
+-rgt-identity68.3%
log1p-def68.3%
Simplified68.3%
Taylor expanded in x around inf 56.4%
unpow256.4%
associate-*r/56.4%
metadata-eval56.4%
Simplified56.4%
Final simplification51.2%
(FPCore (x n) :precision binary64 (/ 1.0 (* n x)))
double code(double x, double n) {
return 1.0 / (n * x);
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = 1.0d0 / (n * x)
end function
public static double code(double x, double n) {
return 1.0 / (n * x);
}
def code(x, n): return 1.0 / (n * x)
function code(x, n) return Float64(1.0 / Float64(n * x)) end
function tmp = code(x, n) tmp = 1.0 / (n * x); end
code[x_, n_] := N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{n \cdot x}
\end{array}
Initial program 56.7%
Taylor expanded in x around inf 59.0%
log-rec59.0%
mul-1-neg59.0%
associate-*r/59.0%
neg-mul-159.0%
mul-1-neg59.0%
remove-double-neg59.0%
*-commutative59.0%
Simplified59.0%
Taylor expanded in n around inf 35.5%
*-commutative35.5%
Simplified35.5%
Final simplification35.5%
(FPCore (x n) :precision binary64 (/ (/ 1.0 x) n))
double code(double x, double n) {
return (1.0 / x) / n;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = (1.0d0 / x) / n
end function
public static double code(double x, double n) {
return (1.0 / x) / n;
}
def code(x, n): return (1.0 / x) / n
function code(x, n) return Float64(Float64(1.0 / x) / n) end
function tmp = code(x, n) tmp = (1.0 / x) / n; end
code[x_, n_] := N[(N[(1.0 / x), $MachinePrecision] / n), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{n}
\end{array}
Initial program 56.7%
Taylor expanded in x around inf 59.0%
log-rec59.0%
mul-1-neg59.0%
associate-*r/59.0%
neg-mul-159.0%
mul-1-neg59.0%
remove-double-neg59.0%
*-commutative59.0%
Simplified59.0%
Taylor expanded in n around inf 35.5%
*-commutative35.5%
associate-/r*35.5%
Simplified35.5%
Final simplification35.5%
(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 56.7%
Taylor expanded in x around 0 22.7%
associate-+r+22.7%
+-commutative22.7%
associate-*r/22.7%
metadata-eval22.7%
unpow222.7%
associate-*r/22.7%
metadata-eval22.7%
unpow222.7%
Simplified22.7%
Taylor expanded in n around 0 5.1%
fma-def5.1%
unpow25.1%
unpow25.1%
times-frac4.4%
unpow24.4%
Simplified4.4%
Taylor expanded in x around 0 4.6%
Final simplification4.6%
herbie shell --seed 2023240
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))