
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (pow (* PI (* n 2.0)) (- -0.5 (* k -0.5)))))
double code(double k, double n) {
return pow(k, -0.5) / pow((((double) M_PI) * (n * 2.0)), (-0.5 - (k * -0.5)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) / Math.pow((Math.PI * (n * 2.0)), (-0.5 - (k * -0.5)));
}
def code(k, n): return math.pow(k, -0.5) / math.pow((math.pi * (n * 2.0)), (-0.5 - (k * -0.5)))
function code(k, n) return Float64((k ^ -0.5) / (Float64(pi * Float64(n * 2.0)) ^ Float64(-0.5 - Float64(k * -0.5)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) / ((pi * (n * 2.0)) ^ (-0.5 - (k * -0.5))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(-0.5 - N[(k * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(-0.5 - k \cdot -0.5\right)}}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
add-sqr-sqrt99.5%
pow299.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
Applied egg-rr99.5%
Applied egg-rr99.6%
unpow-199.6%
associate-*r/99.6%
*-rgt-identity99.6%
*-commutative99.6%
associate-*l*99.6%
*-commutative99.6%
neg-sub099.6%
fma-undefine99.6%
*-commutative99.6%
+-commutative99.6%
associate--r+99.6%
metadata-eval99.6%
*-commutative99.6%
Simplified99.6%
(FPCore (k n) :precision binary64 (if (<= k 7.5e-47) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 7.5e-47) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} else {
tmp = sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 7.5e-47) {
tmp = Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 7.5e-47: tmp = math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k) else: tmp = math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 7.5e-47) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); else tmp = sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 7.5e-47) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 7.5e-47], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 7.5 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 7.49999999999999969e-47Initial program 99.3%
Taylor expanded in k around 0 68.5%
*-commutative68.5%
associate-/l*68.6%
Simplified68.6%
pow168.6%
sqrt-unprod68.7%
associate-*r*68.7%
Applied egg-rr68.7%
unpow168.7%
associate-*l*68.7%
associate-*r/68.8%
*-commutative68.8%
associate-/l*68.8%
Simplified68.8%
associate-*r/68.8%
*-commutative68.8%
associate-/l*68.7%
associate-*l*68.7%
associate-*r/68.8%
sqrt-div99.3%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Applied egg-rr99.3%
if 7.49999999999999969e-47 < k Initial program 99.7%
Applied egg-rr99.7%
distribute-rgt-in99.7%
metadata-eval99.7%
associate-*l*99.7%
metadata-eval99.7%
*-commutative99.7%
neg-mul-199.7%
sub-neg99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 2.45e+42) (* (sqrt (/ PI k)) (sqrt (* n 2.0))) (sqrt (+ 1.0 (fma n (/ 2.0 (/ k PI)) -1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 2.45e+42) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
} else {
tmp = sqrt((1.0 + fma(n, (2.0 / (k / ((double) M_PI))), -1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 2.45e+42) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))); else tmp = sqrt(Float64(1.0 + fma(n, Float64(2.0 / Float64(k / pi)), -1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 2.45e+42], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 + N[(n * N[(2.0 / N[(k / Pi), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.45 \cdot 10^{+42}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \mathsf{fma}\left(n, \frac{2}{\frac{k}{\pi}}, -1\right)}\\
\end{array}
\end{array}
if k < 2.4500000000000001e42Initial program 99.0%
Taylor expanded in k around 0 59.8%
*-commutative59.8%
associate-/l*59.8%
Simplified59.8%
pow159.8%
sqrt-unprod60.0%
associate-*r*60.0%
Applied egg-rr60.0%
unpow160.0%
associate-*l*60.0%
associate-*r/60.1%
*-commutative60.1%
associate-/l*60.0%
Simplified60.0%
associate-*r/60.1%
*-commutative60.1%
associate-/l*60.0%
associate-*l*60.0%
*-commutative60.0%
sqrt-prod81.7%
Applied egg-rr81.7%
if 2.4500000000000001e42 < k Initial program 100.0%
Taylor expanded in k around 0 1.7%
*-commutative1.7%
associate-/l*1.8%
Simplified1.8%
pow11.8%
sqrt-unprod1.8%
associate-*r*1.8%
Applied egg-rr1.8%
unpow11.8%
Simplified1.8%
expm1-log1p-u1.8%
expm1-undefine32.3%
associate-*l*32.3%
*-commutative32.3%
associate-/r/32.3%
associate-*r/32.3%
*-commutative32.3%
div-inv32.3%
clear-num32.3%
associate-*l*32.3%
Applied egg-rr32.3%
log1p-undefine32.3%
rem-exp-log32.3%
associate-+r-32.3%
*-commutative32.3%
associate-*r/32.3%
*-commutative32.3%
associate-/r/32.3%
associate-/l*32.3%
fmm-def32.3%
metadata-eval32.3%
Simplified32.3%
Final simplification54.7%
(FPCore (k n) :precision binary64 (if (<= k 2.55e+42) (* (sqrt (/ PI k)) (sqrt (* n 2.0))) (+ -1.0 (+ 1.0 (sqrt (* 2.0 (/ PI (/ k n))))))))
double code(double k, double n) {
double tmp;
if (k <= 2.55e+42) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
} else {
tmp = -1.0 + (1.0 + sqrt((2.0 * (((double) M_PI) / (k / n)))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.55e+42) {
tmp = Math.sqrt((Math.PI / k)) * Math.sqrt((n * 2.0));
} else {
tmp = -1.0 + (1.0 + Math.sqrt((2.0 * (Math.PI / (k / n)))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 2.55e+42: tmp = math.sqrt((math.pi / k)) * math.sqrt((n * 2.0)) else: tmp = -1.0 + (1.0 + math.sqrt((2.0 * (math.pi / (k / n))))) return tmp
function code(k, n) tmp = 0.0 if (k <= 2.55e+42) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))); else tmp = Float64(-1.0 + Float64(1.0 + sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 2.55e+42) tmp = sqrt((pi / k)) * sqrt((n * 2.0)); else tmp = -1.0 + (1.0 + sqrt((2.0 * (pi / (k / n))))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.55e+42], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(1.0 + N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.55 \cdot 10^{+42}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(1 + \sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\right)\\
\end{array}
\end{array}
if k < 2.55e42Initial program 99.0%
Taylor expanded in k around 0 59.8%
*-commutative59.8%
associate-/l*59.8%
Simplified59.8%
pow159.8%
sqrt-unprod60.0%
associate-*r*60.0%
Applied egg-rr60.0%
unpow160.0%
associate-*l*60.0%
associate-*r/60.1%
*-commutative60.1%
associate-/l*60.0%
Simplified60.0%
associate-*r/60.1%
*-commutative60.1%
associate-/l*60.0%
associate-*l*60.0%
*-commutative60.0%
sqrt-prod81.7%
Applied egg-rr81.7%
if 2.55e42 < k Initial program 100.0%
Taylor expanded in k around 0 1.7%
*-commutative1.7%
associate-/l*1.8%
Simplified1.8%
pow11.8%
sqrt-unprod1.8%
associate-*r*1.8%
Applied egg-rr1.8%
unpow11.8%
associate-*l*1.8%
associate-*r/1.7%
*-commutative1.7%
associate-/l*1.8%
Simplified1.8%
associate-*r/1.7%
*-commutative1.7%
associate-/l*1.8%
associate-*l*1.8%
expm1-log1p-u1.8%
expm1-undefine16.7%
log1p-undefine16.7%
rem-exp-log16.7%
associate-*l*16.7%
associate-/l*16.7%
*-commutative16.7%
associate-*r/16.7%
clear-num16.7%
un-div-inv16.7%
Applied egg-rr16.7%
Final simplification46.1%
(FPCore (k n) :precision binary64 (if (<= n 0.155) (sqrt (fabs (* 2.0 (* PI (/ n k))))) (+ -1.0 (+ 1.0 (sqrt (* 2.0 (/ PI (/ k n))))))))
double code(double k, double n) {
double tmp;
if (n <= 0.155) {
tmp = sqrt(fabs((2.0 * (((double) M_PI) * (n / k)))));
} else {
tmp = -1.0 + (1.0 + sqrt((2.0 * (((double) M_PI) / (k / n)))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (n <= 0.155) {
tmp = Math.sqrt(Math.abs((2.0 * (Math.PI * (n / k)))));
} else {
tmp = -1.0 + (1.0 + Math.sqrt((2.0 * (Math.PI / (k / n)))));
}
return tmp;
}
def code(k, n): tmp = 0 if n <= 0.155: tmp = math.sqrt(math.fabs((2.0 * (math.pi * (n / k))))) else: tmp = -1.0 + (1.0 + math.sqrt((2.0 * (math.pi / (k / n))))) return tmp
function code(k, n) tmp = 0.0 if (n <= 0.155) tmp = sqrt(abs(Float64(2.0 * Float64(pi * Float64(n / k))))); else tmp = Float64(-1.0 + Float64(1.0 + sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (n <= 0.155) tmp = sqrt(abs((2.0 * (pi * (n / k))))); else tmp = -1.0 + (1.0 + sqrt((2.0 * (pi / (k / n))))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[n, 0.155], N[Sqrt[N[Abs[N[(2.0 * N[(Pi * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[(-1.0 + N[(1.0 + N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq 0.155:\\
\;\;\;\;\sqrt{\left|2 \cdot \left(\pi \cdot \frac{n}{k}\right)\right|}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(1 + \sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\right)\\
\end{array}
\end{array}
if n < 0.154999999999999999Initial program 99.7%
Taylor expanded in k around 0 24.5%
*-commutative24.5%
associate-/l*24.5%
Simplified24.5%
pow124.5%
sqrt-unprod24.6%
associate-*r*24.6%
Applied egg-rr24.6%
unpow124.6%
Simplified24.6%
add-sqr-sqrt24.6%
pow1/224.6%
pow1/224.7%
pow-prod-down22.4%
associate-*l*22.4%
*-commutative22.4%
associate-*l*22.4%
*-commutative22.4%
swap-sqr22.4%
pow222.4%
*-commutative22.4%
associate-/r/22.4%
div-inv22.3%
clear-num22.4%
metadata-eval22.4%
Applied egg-rr22.4%
unpow1/222.4%
*-commutative22.4%
metadata-eval22.4%
unpow222.4%
swap-sqr22.4%
associate-*r/22.4%
associate-*l/22.4%
associate-/r/22.4%
associate-*r/22.4%
*-commutative22.4%
associate-/r/22.4%
associate-*l/22.4%
associate-*r/22.4%
associate-*r*22.4%
associate-*r/22.4%
associate-*l/22.4%
associate-/r/22.4%
associate-*r/22.4%
*-commutative22.4%
associate-/r/22.4%
associate-*l/22.4%
associate-*r/22.4%
associate-*r*22.4%
Simplified25.8%
if 0.154999999999999999 < n Initial program 99.4%
Taylor expanded in k around 0 32.3%
*-commutative32.3%
associate-/l*32.3%
Simplified32.3%
pow132.3%
sqrt-unprod32.3%
associate-*r*32.3%
Applied egg-rr32.3%
unpow132.3%
associate-*l*32.3%
associate-*r/32.4%
*-commutative32.4%
associate-/l*32.4%
Simplified32.4%
associate-*r/32.4%
*-commutative32.4%
associate-/l*32.3%
associate-*l*32.3%
expm1-log1p-u30.1%
expm1-undefine48.2%
log1p-undefine48.2%
rem-exp-log50.5%
associate-*l*50.5%
associate-/l*50.5%
*-commutative50.5%
associate-*r/50.5%
clear-num50.5%
un-div-inv50.4%
Applied egg-rr50.4%
Final simplification37.0%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* PI n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (((double) M_PI) * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (Math.PI * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (math.pi * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (pi * n)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
(FPCore (k n) :precision binary64 (if (<= n 0.155) (sqrt (* (* n 2.0) (* PI (/ 1.0 k)))) (+ -1.0 (+ 1.0 (sqrt (* 2.0 (/ PI (/ k n))))))))
double code(double k, double n) {
double tmp;
if (n <= 0.155) {
tmp = sqrt(((n * 2.0) * (((double) M_PI) * (1.0 / k))));
} else {
tmp = -1.0 + (1.0 + sqrt((2.0 * (((double) M_PI) / (k / n)))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (n <= 0.155) {
tmp = Math.sqrt(((n * 2.0) * (Math.PI * (1.0 / k))));
} else {
tmp = -1.0 + (1.0 + Math.sqrt((2.0 * (Math.PI / (k / n)))));
}
return tmp;
}
def code(k, n): tmp = 0 if n <= 0.155: tmp = math.sqrt(((n * 2.0) * (math.pi * (1.0 / k)))) else: tmp = -1.0 + (1.0 + math.sqrt((2.0 * (math.pi / (k / n))))) return tmp
function code(k, n) tmp = 0.0 if (n <= 0.155) tmp = sqrt(Float64(Float64(n * 2.0) * Float64(pi * Float64(1.0 / k)))); else tmp = Float64(-1.0 + Float64(1.0 + sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (n <= 0.155) tmp = sqrt(((n * 2.0) * (pi * (1.0 / k)))); else tmp = -1.0 + (1.0 + sqrt((2.0 * (pi / (k / n))))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[n, 0.155], N[Sqrt[N[(N[(n * 2.0), $MachinePrecision] * N[(Pi * N[(1.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(-1.0 + N[(1.0 + N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq 0.155:\\
\;\;\;\;\sqrt{\left(n \cdot 2\right) \cdot \left(\pi \cdot \frac{1}{k}\right)}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(1 + \sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\right)\\
\end{array}
\end{array}
if n < 0.154999999999999999Initial program 99.7%
Taylor expanded in k around 0 24.5%
*-commutative24.5%
associate-/l*24.5%
Simplified24.5%
pow124.5%
sqrt-unprod24.6%
associate-*r*24.6%
Applied egg-rr24.6%
unpow124.6%
Simplified24.6%
div-inv24.7%
Applied egg-rr24.7%
if 0.154999999999999999 < n Initial program 99.4%
Taylor expanded in k around 0 32.3%
*-commutative32.3%
associate-/l*32.3%
Simplified32.3%
pow132.3%
sqrt-unprod32.3%
associate-*r*32.3%
Applied egg-rr32.3%
unpow132.3%
associate-*l*32.3%
associate-*r/32.4%
*-commutative32.4%
associate-/l*32.4%
Simplified32.4%
associate-*r/32.4%
*-commutative32.4%
associate-/l*32.3%
associate-*l*32.3%
expm1-log1p-u30.1%
expm1-undefine48.2%
log1p-undefine48.2%
rem-exp-log50.5%
associate-*l*50.5%
associate-/l*50.5%
*-commutative50.5%
associate-*r/50.5%
clear-num50.5%
un-div-inv50.4%
Applied egg-rr50.4%
Final simplification36.4%
(FPCore (k n) :precision binary64 (sqrt (* (* n 2.0) (* PI (/ 1.0 k)))))
double code(double k, double n) {
return sqrt(((n * 2.0) * (((double) M_PI) * (1.0 / k))));
}
public static double code(double k, double n) {
return Math.sqrt(((n * 2.0) * (Math.PI * (1.0 / k))));
}
def code(k, n): return math.sqrt(((n * 2.0) * (math.pi * (1.0 / k))))
function code(k, n) return sqrt(Float64(Float64(n * 2.0) * Float64(pi * Float64(1.0 / k)))) end
function tmp = code(k, n) tmp = sqrt(((n * 2.0) * (pi * (1.0 / k)))); end
code[k_, n_] := N[Sqrt[N[(N[(n * 2.0), $MachinePrecision] * N[(Pi * N[(1.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(n \cdot 2\right) \cdot \left(\pi \cdot \frac{1}{k}\right)}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 28.1%
*-commutative28.1%
associate-/l*28.1%
Simplified28.1%
pow128.1%
sqrt-unprod28.2%
associate-*r*28.2%
Applied egg-rr28.2%
unpow128.2%
Simplified28.2%
div-inv28.2%
Applied egg-rr28.2%
Final simplification28.2%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (* PI (/ n k)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) * (n / k))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI * (n / k))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi * (n / k))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi * Float64(n / k)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi * (n / k)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(\pi \cdot \frac{n}{k}\right)}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 28.1%
*-commutative28.1%
associate-/l*28.1%
Simplified28.1%
pow128.1%
sqrt-unprod28.2%
associate-*r*28.2%
Applied egg-rr28.2%
unpow128.2%
associate-*l*28.2%
associate-*r/28.2%
*-commutative28.2%
associate-/l*28.2%
Simplified28.2%
herbie shell --seed 2024181
(FPCore (k n)
:name "Migdal et al, Equation (51)"
:precision binary64
(* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))