
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
public static double code(double x, double n) {
return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
def code(x, n): return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function tmp = code(x, n) tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n)); end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\end{array}
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-151)
(/ (/ t_0 x) n)
(if (<= (/ 1.0 n) 1e-21)
(/ (- (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 tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 1e-21) {
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 tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 1e-21) {
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)) tmp = 0 if (1.0 / n) <= -5e-151: tmp = (t_0 / x) / n elif (1.0 / n) <= 1e-21: 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) tmp = 0.0 if (Float64(1.0 / n) <= -5e-151) tmp = Float64(Float64(t_0 / x) / n); elseif (Float64(1.0 / n) <= 1e-21) 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]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e-21], 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)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 10^{-21}:\\
\;\;\;\;\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 1 n) < -5.00000000000000003e-151Initial program 75.0%
Taylor expanded in x around inf 92.0%
mul-1-neg92.0%
log-rec92.0%
mul-1-neg92.0%
distribute-neg-frac92.0%
mul-1-neg92.0%
remove-double-neg92.0%
*-commutative92.0%
Simplified92.0%
associate-/r*92.1%
div-inv92.1%
div-inv92.1%
pow-to-exp92.1%
Applied egg-rr92.1%
un-div-inv92.1%
Applied egg-rr92.1%
if -5.00000000000000003e-151 < (/.f64 1 n) < 9.99999999999999908e-22Initial program 33.8%
Taylor expanded in n around inf 88.6%
log1p-def88.6%
Simplified88.6%
if 9.99999999999999908e-22 < (/.f64 1 n) Initial program 52.9%
Taylor expanded in n around 0 52.9%
log1p-def93.3%
Simplified93.3%
Final simplification90.7%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-151)
(/ (/ t_0 x) n)
(if (<= (/ 1.0 n) 5e-9)
(/ (- (log1p x) (log x)) n)
(if (<= (/ 1.0 n) 2e+187) (- (+ 1.0 (/ x n)) t_0) (/ 1.0 (* n x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (log1p(x) - log(x)) / n;
} else if ((1.0 / n) <= 2e+187) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
public static double code(double x, double n) {
double t_0 = Math.pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (Math.log1p(x) - Math.log(x)) / n;
} else if ((1.0 / n) <= 2e+187) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-151: tmp = (t_0 / x) / n elif (1.0 / n) <= 5e-9: tmp = (math.log1p(x) - math.log(x)) / n elif (1.0 / n) <= 2e+187: tmp = (1.0 + (x / n)) - t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-151) tmp = Float64(Float64(t_0 / x) / n); elseif (Float64(1.0 / n) <= 5e-9) tmp = Float64(Float64(log1p(x) - log(x)) / n); elseif (Float64(1.0 / n) <= 2e+187) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -5e-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(x\right) - \log x}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -5.00000000000000003e-151Initial program 75.0%
Taylor expanded in x around inf 92.0%
mul-1-neg92.0%
log-rec92.0%
mul-1-neg92.0%
distribute-neg-frac92.0%
mul-1-neg92.0%
remove-double-neg92.0%
*-commutative92.0%
Simplified92.0%
associate-/r*92.1%
div-inv92.1%
div-inv92.1%
pow-to-exp92.1%
Applied egg-rr92.1%
un-div-inv92.1%
Applied egg-rr92.1%
if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9Initial program 33.4%
Taylor expanded in n around inf 86.7%
log1p-def86.7%
Simplified86.7%
if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187Initial program 78.9%
Taylor expanded in x around 0 79.0%
if 1.99999999999999981e187 < (/.f64 1 n) Initial program 3.1%
Taylor expanded in n around inf 7.4%
log1p-def7.4%
Simplified7.4%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification88.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-151)
(/ (/ t_0 x) n)
(if (<= (/ 1.0 n) 5e-9)
(* (/ 1.0 n) (log (/ (+ 1.0 x) x)))
(if (<= (/ 1.0 n) 2e+187) (- (+ 1.0 (/ x n)) t_0) (/ 1.0 (* n x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (1.0 / n) * log(((1.0 + x) / x));
} else if ((1.0 / n) <= 2e+187) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.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) :: tmp
t_0 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-5d-151)) then
tmp = (t_0 / x) / n
else if ((1.0d0 / n) <= 5d-9) then
tmp = (1.0d0 / n) * log(((1.0d0 + x) / x))
else if ((1.0d0 / n) <= 2d+187) then
tmp = (1.0d0 + (x / n)) - t_0
else
tmp = 1.0d0 / (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 tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (1.0 / n) * Math.log(((1.0 + x) / x));
} else if ((1.0 / n) <= 2e+187) {
tmp = (1.0 + (x / n)) - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-151: tmp = (t_0 / x) / n elif (1.0 / n) <= 5e-9: tmp = (1.0 / n) * math.log(((1.0 + x) / x)) elif (1.0 / n) <= 2e+187: tmp = (1.0 + (x / n)) - t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-151) tmp = Float64(Float64(t_0 / x) / n); elseif (Float64(1.0 / n) <= 5e-9) tmp = Float64(Float64(1.0 / n) * log(Float64(Float64(1.0 + x) / x))); elseif (Float64(1.0 / n) <= 2e+187) tmp = Float64(Float64(1.0 + Float64(x / n)) - t_0); else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -5e-151) tmp = (t_0 / x) / n; elseif ((1.0 / n) <= 5e-9) tmp = (1.0 / n) * log(((1.0 + x) / x)); elseif ((1.0 / n) <= 2e+187) tmp = (1.0 + (x / n)) - t_0; else tmp = 1.0 / (n * x); 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], -5e-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(1.0 / n), $MachinePrecision] * N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], N[(N[(1.0 + N[(x / n), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -5.00000000000000003e-151Initial program 75.0%
Taylor expanded in x around inf 92.0%
mul-1-neg92.0%
log-rec92.0%
mul-1-neg92.0%
distribute-neg-frac92.0%
mul-1-neg92.0%
remove-double-neg92.0%
*-commutative92.0%
Simplified92.0%
associate-/r*92.1%
div-inv92.1%
div-inv92.1%
pow-to-exp92.1%
Applied egg-rr92.1%
un-div-inv92.1%
Applied egg-rr92.1%
if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9Initial program 33.4%
Taylor expanded in n around inf 86.7%
log1p-def86.7%
Simplified86.7%
div-inv86.7%
*-commutative86.7%
Applied egg-rr86.7%
add-log-exp33.4%
*-commutative33.4%
exp-prod33.4%
exp-diff33.4%
log1p-udef33.4%
add-exp-log33.4%
add-exp-log33.4%
Applied egg-rr33.4%
log-pow86.7%
Simplified86.7%
if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187Initial program 78.9%
Taylor expanded in x around 0 79.0%
if 1.99999999999999981e187 < (/.f64 1 n) Initial program 3.1%
Taylor expanded in n around inf 7.4%
log1p-def7.4%
Simplified7.4%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification88.8%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -5e-151)
(/ (/ t_0 x) n)
(if (<= (/ 1.0 n) 5e-9)
(* (/ 1.0 n) (log (/ (+ 1.0 x) x)))
(if (<= (/ 1.0 n) 2e+187) (- 1.0 t_0) (/ 1.0 (* n x)))))))
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (1.0 / n) * log(((1.0 + x) / x));
} else if ((1.0 / n) <= 2e+187) {
tmp = 1.0 - t_0;
} else {
tmp = 1.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) :: tmp
t_0 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-5d-151)) then
tmp = (t_0 / x) / n
else if ((1.0d0 / n) <= 5d-9) then
tmp = (1.0d0 / n) * log(((1.0d0 + x) / x))
else if ((1.0d0 / n) <= 2d+187) then
tmp = 1.0d0 - t_0
else
tmp = 1.0d0 / (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 tmp;
if ((1.0 / n) <= -5e-151) {
tmp = (t_0 / x) / n;
} else if ((1.0 / n) <= 5e-9) {
tmp = (1.0 / n) * Math.log(((1.0 + x) / x));
} else if ((1.0 / n) <= 2e+187) {
tmp = 1.0 - t_0;
} else {
tmp = 1.0 / (n * x);
}
return tmp;
}
def code(x, n): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -5e-151: tmp = (t_0 / x) / n elif (1.0 / n) <= 5e-9: tmp = (1.0 / n) * math.log(((1.0 + x) / x)) elif (1.0 / n) <= 2e+187: tmp = 1.0 - t_0 else: tmp = 1.0 / (n * x) return tmp
function code(x, n) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -5e-151) tmp = Float64(Float64(t_0 / x) / n); elseif (Float64(1.0 / n) <= 5e-9) tmp = Float64(Float64(1.0 / n) * log(Float64(Float64(1.0 + x) / x))); elseif (Float64(1.0 / n) <= 2e+187) tmp = Float64(1.0 - t_0); else tmp = Float64(1.0 / Float64(n * x)); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -5e-151) tmp = (t_0 / x) / n; elseif ((1.0 / n) <= 5e-9) tmp = (1.0 / n) * log(((1.0 + x) / x)); elseif ((1.0 / n) <= 2e+187) tmp = 1.0 - t_0; else tmp = 1.0 / (n * x); 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], -5e-151], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 5e-9], N[(N[(1.0 / n), $MachinePrecision] * N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 2e+187], N[(1.0 - t$95$0), $MachinePrecision], N[(1.0 / N[(n * x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -5 \cdot 10^{-151}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{n} \cdot \log \left(\frac{1 + x}{x}\right)\\
\mathbf{elif}\;\frac{1}{n} \leq 2 \cdot 10^{+187}:\\
\;\;\;\;1 - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n \cdot x}\\
\end{array}
\end{array}
if (/.f64 1 n) < -5.00000000000000003e-151Initial program 75.0%
Taylor expanded in x around inf 92.0%
mul-1-neg92.0%
log-rec92.0%
mul-1-neg92.0%
distribute-neg-frac92.0%
mul-1-neg92.0%
remove-double-neg92.0%
*-commutative92.0%
Simplified92.0%
associate-/r*92.1%
div-inv92.1%
div-inv92.1%
pow-to-exp92.1%
Applied egg-rr92.1%
un-div-inv92.1%
Applied egg-rr92.1%
if -5.00000000000000003e-151 < (/.f64 1 n) < 5.0000000000000001e-9Initial program 33.4%
Taylor expanded in n around inf 86.7%
log1p-def86.7%
Simplified86.7%
div-inv86.7%
*-commutative86.7%
Applied egg-rr86.7%
add-log-exp33.4%
*-commutative33.4%
exp-prod33.4%
exp-diff33.4%
log1p-udef33.4%
add-exp-log33.4%
add-exp-log33.4%
Applied egg-rr33.4%
log-pow86.7%
Simplified86.7%
if 5.0000000000000001e-9 < (/.f64 1 n) < 1.99999999999999981e187Initial program 78.9%
Taylor expanded in x around 0 78.9%
if 1.99999999999999981e187 < (/.f64 1 n) Initial program 3.1%
Taylor expanded in n around inf 7.4%
log1p-def7.4%
Simplified7.4%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification88.8%
(FPCore (x n)
:precision binary64
(if (<= n -1.45e+197)
(* (log x) (/ -1.0 n))
(if (<= n -10.5)
(* (/ 1.0 n) (/ 1.0 x))
(if (<= n 2.5e-188)
(/ 0.3333333333333333 (* n (pow x 3.0)))
(if (<= n 230000000.0) (- 1.0 (pow x (/ 1.0 n))) (/ (pow n -1.0) x))))))
double code(double x, double n) {
double tmp;
if (n <= -1.45e+197) {
tmp = log(x) * (-1.0 / n);
} else if (n <= -10.5) {
tmp = (1.0 / n) * (1.0 / x);
} else if (n <= 2.5e-188) {
tmp = 0.3333333333333333 / (n * pow(x, 3.0));
} else if (n <= 230000000.0) {
tmp = 1.0 - pow(x, (1.0 / n));
} else {
tmp = pow(n, -1.0) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (n <= (-1.45d+197)) then
tmp = log(x) * ((-1.0d0) / n)
else if (n <= (-10.5d0)) then
tmp = (1.0d0 / n) * (1.0d0 / x)
else if (n <= 2.5d-188) then
tmp = 0.3333333333333333d0 / (n * (x ** 3.0d0))
else if (n <= 230000000.0d0) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else
tmp = (n ** (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (n <= -1.45e+197) {
tmp = Math.log(x) * (-1.0 / n);
} else if (n <= -10.5) {
tmp = (1.0 / n) * (1.0 / x);
} else if (n <= 2.5e-188) {
tmp = 0.3333333333333333 / (n * Math.pow(x, 3.0));
} else if (n <= 230000000.0) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else {
tmp = Math.pow(n, -1.0) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if n <= -1.45e+197: tmp = math.log(x) * (-1.0 / n) elif n <= -10.5: tmp = (1.0 / n) * (1.0 / x) elif n <= 2.5e-188: tmp = 0.3333333333333333 / (n * math.pow(x, 3.0)) elif n <= 230000000.0: tmp = 1.0 - math.pow(x, (1.0 / n)) else: tmp = math.pow(n, -1.0) / x return tmp
function code(x, n) tmp = 0.0 if (n <= -1.45e+197) tmp = Float64(log(x) * Float64(-1.0 / n)); elseif (n <= -10.5) tmp = Float64(Float64(1.0 / n) * Float64(1.0 / x)); elseif (n <= 2.5e-188) tmp = Float64(0.3333333333333333 / Float64(n * (x ^ 3.0))); elseif (n <= 230000000.0) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); else tmp = Float64((n ^ -1.0) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (n <= -1.45e+197) tmp = log(x) * (-1.0 / n); elseif (n <= -10.5) tmp = (1.0 / n) * (1.0 / x); elseif (n <= 2.5e-188) tmp = 0.3333333333333333 / (n * (x ^ 3.0)); elseif (n <= 230000000.0) tmp = 1.0 - (x ^ (1.0 / n)); else tmp = (n ^ -1.0) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[n, -1.45e+197], N[(N[Log[x], $MachinePrecision] * N[(-1.0 / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, -10.5], N[(N[(1.0 / n), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 2.5e-188], N[(0.3333333333333333 / N[(n * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 230000000.0], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.45 \cdot 10^{+197}:\\
\;\;\;\;\log x \cdot \frac{-1}{n}\\
\mathbf{elif}\;n \leq -10.5:\\
\;\;\;\;\frac{1}{n} \cdot \frac{1}{x}\\
\mathbf{elif}\;n \leq 2.5 \cdot 10^{-188}:\\
\;\;\;\;\frac{0.3333333333333333}{n \cdot {x}^{3}}\\
\mathbf{elif}\;n \leq 230000000:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\end{array}
\end{array}
if n < -1.45000000000000001e197Initial program 31.3%
Taylor expanded in n around inf 98.8%
log1p-def98.8%
Simplified98.8%
div-inv98.9%
*-commutative98.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 68.0%
mul-1-neg67.9%
Simplified68.0%
if -1.45000000000000001e197 < n < -10.5Initial program 16.1%
Taylor expanded in n around inf 47.5%
log1p-def47.5%
Simplified47.5%
Taylor expanded in x around inf 65.3%
*-commutative65.3%
Simplified65.3%
associate-/r*65.4%
div-inv65.4%
Applied egg-rr65.4%
if -10.5 < n < 2.5e-188Initial program 88.3%
Taylor expanded in n around inf 51.7%
log1p-def51.7%
Simplified51.7%
Taylor expanded in x around inf 6.4%
Taylor expanded in x around 0 80.8%
if 2.5e-188 < n < 2.3e8Initial program 78.9%
Taylor expanded in x around 0 78.9%
if 2.3e8 < n Initial program 33.1%
Taylor expanded in n around inf 81.8%
log1p-def81.8%
Simplified81.8%
Taylor expanded in x around inf 51.4%
div-inv51.4%
add-sqr-sqrt51.3%
associate-*r*51.3%
inv-pow51.3%
metadata-eval51.3%
sqrt-pow151.3%
metadata-eval51.3%
metadata-eval51.3%
inv-pow51.3%
metadata-eval51.3%
sqrt-pow151.3%
metadata-eval51.3%
metadata-eval51.3%
Applied egg-rr51.3%
associate-*l/51.3%
associate-*l/51.3%
*-lft-identity51.3%
pow-sqr51.4%
metadata-eval51.4%
Simplified51.4%
Final simplification68.2%
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))))
(if (<= x 6.2e-164)
(- 1.0 t_0)
(if (<= x 0.095) (- (/ x n) (/ (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 <= 6.2e-164) {
tmp = 1.0 - t_0;
} else if (x <= 0.095) {
tmp = (x / n) - (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 <= 6.2d-164) then
tmp = 1.0d0 - t_0
else if (x <= 0.095d0) then
tmp = (x / n) - (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 <= 6.2e-164) {
tmp = 1.0 - t_0;
} else if (x <= 0.095) {
tmp = (x / n) - (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 <= 6.2e-164: tmp = 1.0 - t_0 elif x <= 0.095: tmp = (x / n) - (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 <= 6.2e-164) tmp = Float64(1.0 - t_0); elseif (x <= 0.095) tmp = Float64(Float64(x / n) - Float64(log(x) / n)); else tmp = Float64(Float64(t_0 / x) / n); end return tmp end
function tmp_2 = code(x, n) t_0 = x ^ (1.0 / n); tmp = 0.0; if (x <= 6.2e-164) tmp = 1.0 - t_0; elseif (x <= 0.095) tmp = (x / n) - (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, 6.2e-164], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[x, 0.095], N[(N[(x / n), $MachinePrecision] - N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / x), $MachinePrecision] / n), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 6.2 \cdot 10^{-164}:\\
\;\;\;\;1 - t_0\\
\mathbf{elif}\;x \leq 0.095:\\
\;\;\;\;\frac{x}{n} - \frac{\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{n}\\
\end{array}
\end{array}
if x < 6.2000000000000001e-164Initial program 55.1%
Taylor expanded in x around 0 55.1%
if 6.2000000000000001e-164 < x < 0.095000000000000001Initial program 27.5%
Taylor expanded in n around inf 64.8%
log1p-def64.8%
Simplified64.8%
div-sub64.8%
Applied egg-rr64.8%
Taylor expanded in x around 0 61.9%
if 0.095000000000000001 < x Initial program 69.6%
Taylor expanded in x around inf 96.4%
mul-1-neg96.4%
log-rec96.4%
mul-1-neg96.4%
distribute-neg-frac96.4%
mul-1-neg96.4%
remove-double-neg96.4%
*-commutative96.4%
Simplified96.4%
associate-/r*97.9%
div-inv97.9%
div-inv97.9%
pow-to-exp97.9%
Applied egg-rr97.9%
un-div-inv97.9%
Applied egg-rr97.9%
Final simplification77.1%
(FPCore (x n) :precision binary64 (if (<= x 4e-164) (- 1.0 (pow x (/ 1.0 n))) (if (<= x 0.54) (/ (- (log x)) n) (/ (pow n -1.0) x))))
double code(double x, double n) {
double tmp;
if (x <= 4e-164) {
tmp = 1.0 - pow(x, (1.0 / n));
} else if (x <= 0.54) {
tmp = -log(x) / n;
} else {
tmp = pow(n, -1.0) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 4d-164) then
tmp = 1.0d0 - (x ** (1.0d0 / n))
else if (x <= 0.54d0) then
tmp = -log(x) / n
else
tmp = (n ** (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 4e-164) {
tmp = 1.0 - Math.pow(x, (1.0 / n));
} else if (x <= 0.54) {
tmp = -Math.log(x) / n;
} else {
tmp = Math.pow(n, -1.0) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 4e-164: tmp = 1.0 - math.pow(x, (1.0 / n)) elif x <= 0.54: tmp = -math.log(x) / n else: tmp = math.pow(n, -1.0) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 4e-164) tmp = Float64(1.0 - (x ^ Float64(1.0 / n))); elseif (x <= 0.54) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64((n ^ -1.0) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 4e-164) tmp = 1.0 - (x ^ (1.0 / n)); elseif (x <= 0.54) tmp = -log(x) / n; else tmp = (n ^ -1.0) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 4e-164], N[(1.0 - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.54], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-164}:\\
\;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{elif}\;x \leq 0.54:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\end{array}
\end{array}
if x < 3.99999999999999985e-164Initial program 55.1%
Taylor expanded in x around 0 55.1%
if 3.99999999999999985e-164 < x < 0.54000000000000004Initial program 27.5%
Taylor expanded in n around inf 64.8%
log1p-def64.8%
Simplified64.8%
Taylor expanded in x around 0 60.2%
mul-1-neg60.2%
Simplified60.2%
if 0.54000000000000004 < x Initial program 69.6%
Taylor expanded in n around inf 69.5%
log1p-def69.5%
Simplified69.5%
Taylor expanded in x around inf 58.0%
div-inv58.0%
add-sqr-sqrt30.5%
associate-*r*30.5%
inv-pow30.5%
metadata-eval30.5%
sqrt-pow130.5%
metadata-eval30.5%
metadata-eval30.5%
inv-pow30.5%
metadata-eval30.5%
sqrt-pow130.5%
metadata-eval30.5%
metadata-eval30.5%
Applied egg-rr30.5%
associate-*l/30.5%
associate-*l/30.5%
*-lft-identity30.5%
pow-sqr58.0%
metadata-eval58.0%
Simplified58.0%
Final simplification57.9%
(FPCore (x n) :precision binary64 (if (<= x 0.54) (/ (- (log x)) n) (* (/ 1.0 n) (/ 1.0 x))))
double code(double x, double n) {
double tmp;
if (x <= 0.54) {
tmp = -log(x) / n;
} else {
tmp = (1.0 / n) * (1.0 / x);
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 0.54d0) then
tmp = -log(x) / n
else
tmp = (1.0d0 / n) * (1.0d0 / x)
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.54) {
tmp = -Math.log(x) / n;
} else {
tmp = (1.0 / n) * (1.0 / x);
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.54: tmp = -math.log(x) / n else: tmp = (1.0 / n) * (1.0 / x) return tmp
function code(x, n) tmp = 0.0 if (x <= 0.54) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64(Float64(1.0 / n) * Float64(1.0 / x)); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.54) tmp = -log(x) / n; else tmp = (1.0 / n) * (1.0 / x); end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.54], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[(1.0 / n), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.54:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n} \cdot \frac{1}{x}\\
\end{array}
\end{array}
if x < 0.54000000000000004Initial program 40.3%
Taylor expanded in n around inf 54.6%
log1p-def54.6%
Simplified54.6%
Taylor expanded in x around 0 52.2%
mul-1-neg52.2%
Simplified52.2%
if 0.54000000000000004 < x Initial program 69.6%
Taylor expanded in n around inf 69.5%
log1p-def69.5%
Simplified69.5%
Taylor expanded in x around inf 56.5%
*-commutative56.5%
Simplified56.5%
associate-/r*58.0%
div-inv58.0%
Applied egg-rr58.0%
Final simplification54.9%
(FPCore (x n) :precision binary64 (if (<= x 0.55) (/ (- (log x)) n) (/ (pow n -1.0) x)))
double code(double x, double n) {
double tmp;
if (x <= 0.55) {
tmp = -log(x) / n;
} else {
tmp = pow(n, -1.0) / x;
}
return tmp;
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
real(8) :: tmp
if (x <= 0.55d0) then
tmp = -log(x) / n
else
tmp = (n ** (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x, double n) {
double tmp;
if (x <= 0.55) {
tmp = -Math.log(x) / n;
} else {
tmp = Math.pow(n, -1.0) / x;
}
return tmp;
}
def code(x, n): tmp = 0 if x <= 0.55: tmp = -math.log(x) / n else: tmp = math.pow(n, -1.0) / x return tmp
function code(x, n) tmp = 0.0 if (x <= 0.55) tmp = Float64(Float64(-log(x)) / n); else tmp = Float64((n ^ -1.0) / x); end return tmp end
function tmp_2 = code(x, n) tmp = 0.0; if (x <= 0.55) tmp = -log(x) / n; else tmp = (n ^ -1.0) / x; end tmp_2 = tmp; end
code[x_, n_] := If[LessEqual[x, 0.55], N[((-N[Log[x], $MachinePrecision]) / n), $MachinePrecision], N[(N[Power[n, -1.0], $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.55:\\
\;\;\;\;\frac{-\log x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{-1}}{x}\\
\end{array}
\end{array}
if x < 0.55000000000000004Initial program 40.3%
Taylor expanded in n around inf 54.6%
log1p-def54.6%
Simplified54.6%
Taylor expanded in x around 0 52.2%
mul-1-neg52.2%
Simplified52.2%
if 0.55000000000000004 < x Initial program 69.6%
Taylor expanded in n around inf 69.5%
log1p-def69.5%
Simplified69.5%
Taylor expanded in x around inf 58.0%
div-inv58.0%
add-sqr-sqrt30.5%
associate-*r*30.5%
inv-pow30.5%
metadata-eval30.5%
sqrt-pow130.5%
metadata-eval30.5%
metadata-eval30.5%
inv-pow30.5%
metadata-eval30.5%
sqrt-pow130.5%
metadata-eval30.5%
metadata-eval30.5%
Applied egg-rr30.5%
associate-*l/30.5%
associate-*l/30.5%
*-lft-identity30.5%
pow-sqr58.0%
metadata-eval58.0%
Simplified58.0%
Final simplification54.9%
(FPCore (x n) :precision binary64 (* (/ 1.0 n) (/ 1.0 x)))
double code(double x, double n) {
return (1.0 / n) * (1.0 / x);
}
real(8) function code(x, n)
real(8), intent (in) :: x
real(8), intent (in) :: n
code = (1.0d0 / n) * (1.0d0 / x)
end function
public static double code(double x, double n) {
return (1.0 / n) * (1.0 / x);
}
def code(x, n): return (1.0 / n) * (1.0 / x)
function code(x, n) return Float64(Float64(1.0 / n) * Float64(1.0 / x)) end
function tmp = code(x, n) tmp = (1.0 / n) * (1.0 / x); end
code[x_, n_] := N[(N[(1.0 / n), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{n} \cdot \frac{1}{x}
\end{array}
Initial program 54.0%
Taylor expanded in n around inf 61.6%
log1p-def61.6%
Simplified61.6%
Taylor expanded in x around inf 39.4%
*-commutative39.4%
Simplified39.4%
associate-/r*40.1%
div-inv40.1%
Applied egg-rr40.1%
Final simplification40.1%
(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 54.0%
Taylor expanded in n around inf 61.6%
log1p-def61.6%
Simplified61.6%
Taylor expanded in x around inf 39.4%
*-commutative39.4%
Simplified39.4%
Final simplification39.4%
(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 54.0%
Taylor expanded in n around inf 61.6%
log1p-def61.6%
Simplified61.6%
Taylor expanded in x around inf 40.1%
Final simplification40.1%
herbie shell --seed 2023301
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))