
(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 8 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 (if (<= k 1.08e-30) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (/ 1.0 (sqrt (/ k (pow (* n (* 2.0 PI)) (- 1.0 k)))))))
double code(double k, double n) {
double tmp;
if (k <= 1.08e-30) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = 1.0 / sqrt((k / pow((n * (2.0 * ((double) M_PI))), (1.0 - k))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.08e-30) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = 1.0 / Math.sqrt((k / Math.pow((n * (2.0 * Math.PI)), (1.0 - k))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.08e-30: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = 1.0 / math.sqrt((k / math.pow((n * (2.0 * math.pi)), (1.0 - k)))) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.08e-30) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = Float64(1.0 / sqrt(Float64(k / (Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.08e-30) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = 1.0 / sqrt((k / ((n * (2.0 * pi)) ^ (1.0 - k)))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.08e-30], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(k / N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.08 \cdot 10^{-30}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{k}{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}}}\\
\end{array}
\end{array}
if k < 1.08000000000000005e-30Initial program 99.4%
Taylor expanded in k around 0 66.7%
associate-/l*66.6%
Simplified66.6%
sqrt-unprod66.8%
Applied egg-rr66.8%
associate-*l*66.8%
sqrt-prod99.6%
Applied egg-rr99.6%
if 1.08000000000000005e-30 < k Initial program 99.6%
Applied egg-rr99.6%
distribute-lft-in99.6%
metadata-eval99.6%
*-commutative99.6%
associate-*r*99.6%
metadata-eval99.6%
neg-mul-199.6%
sub-neg99.6%
*-commutative99.6%
Simplified99.6%
clear-num99.6%
sqrt-div99.7%
metadata-eval99.7%
*-commutative99.7%
associate-*r*99.7%
Applied egg-rr99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 1.75e-43) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.75e-43) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / 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 <= 1.75e-43) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / 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 <= 1.75e-43: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / 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 <= 1.75e-43) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / 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 <= 1.75e-43) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.75e-43], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $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 1.75 \cdot 10^{-43}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{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 < 1.74999999999999999e-43Initial program 99.4%
Taylor expanded in k around 0 66.1%
associate-/l*66.1%
Simplified66.1%
sqrt-unprod66.2%
Applied egg-rr66.2%
associate-*l*66.2%
sqrt-prod99.6%
Applied egg-rr99.6%
if 1.74999999999999999e-43 < k Initial program 99.6%
Applied egg-rr99.7%
distribute-lft-in99.7%
metadata-eval99.7%
*-commutative99.7%
associate-*r*99.7%
metadata-eval99.7%
neg-mul-199.7%
sub-neg99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 5.8e+35) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (sqrt (+ 1.0 (fma n (* PI (/ 2.0 k)) -1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 5.8e+35) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = sqrt((1.0 + fma(n, (((double) M_PI) * (2.0 / k)), -1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 5.8e+35) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = sqrt(Float64(1.0 + fma(n, Float64(pi * Float64(2.0 / k)), -1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 5.8e+35], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 + N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5.8 \cdot 10^{+35}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \mathsf{fma}\left(n, \pi \cdot \frac{2}{k}, -1\right)}\\
\end{array}
\end{array}
if k < 5.79999999999999989e35Initial program 99.1%
Taylor expanded in k around 0 62.0%
associate-/l*62.0%
Simplified62.0%
sqrt-unprod62.2%
Applied egg-rr62.2%
associate-*l*62.2%
sqrt-prod89.2%
Applied egg-rr89.2%
if 5.79999999999999989e35 < k Initial program 100.0%
Taylor expanded in k around 0 2.5%
associate-/l*2.5%
Simplified2.5%
sqrt-unprod2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-commutative2.5%
Applied egg-rr2.5%
expm1-log1p-u2.5%
expm1-undefine26.8%
associate-*l/26.8%
*-commutative26.8%
*-commutative26.8%
*-commutative26.8%
associate-*r*26.8%
Applied egg-rr26.8%
log1p-undefine26.8%
associate-/l*26.8%
associate-*r*26.8%
*-commutative26.8%
associate-*l/26.8%
associate-*r/26.8%
rem-exp-log26.8%
associate-+r-26.8%
*-commutative26.8%
associate-*l*26.8%
*-commutative26.8%
fmm-def26.8%
associate-*r/26.8%
*-commutative26.8%
associate-/l*26.8%
metadata-eval26.8%
Simplified26.8%
Final simplification60.4%
(FPCore (k n) :precision binary64 (if (<= k 2.25e+260) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (cbrt (pow (* 2.0 (* n (/ PI k))) 1.5))))
double code(double k, double n) {
double tmp;
if (k <= 2.25e+260) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = cbrt(pow((2.0 * (n * (((double) M_PI) / k))), 1.5));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.25e+260) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.cbrt(Math.pow((2.0 * (n * (Math.PI / k))), 1.5));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 2.25e+260) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = cbrt((Float64(2.0 * Float64(n * Float64(pi / k))) ^ 1.5)); end return tmp end
code[k_, n_] := If[LessEqual[k, 2.25e+260], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.25 \cdot 10^{+260}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}^{1.5}}\\
\end{array}
\end{array}
if k < 2.25000000000000011e260Initial program 99.5%
Taylor expanded in k around 0 37.9%
associate-/l*37.9%
Simplified37.9%
sqrt-unprod38.0%
Applied egg-rr38.0%
associate-*l*38.0%
sqrt-prod54.1%
Applied egg-rr54.1%
if 2.25000000000000011e260 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
add-cbrt-cube22.8%
pow1/322.8%
add-sqr-sqrt22.8%
*-commutative22.8%
pow122.8%
*-commutative22.8%
pow1/222.8%
pow-prod-up22.8%
associate-*r*22.8%
clear-num22.8%
un-div-inv22.8%
metadata-eval22.8%
Applied egg-rr22.8%
unpow1/322.8%
associate-/l*22.8%
associate-/r/22.8%
associate-*l/22.8%
associate-/l*22.8%
Simplified22.8%
Final simplification51.2%
(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.5%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((2.0 * (math.pi / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 34.6%
associate-/l*34.6%
Simplified34.6%
sqrt-unprod34.7%
Applied egg-rr34.7%
associate-*l*34.7%
sqrt-prod49.3%
Applied egg-rr49.3%
Final simplification49.3%
(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(Float64(pi * 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[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi \cdot n}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 34.6%
associate-/l*34.6%
Simplified34.6%
sqrt-unprod34.7%
Applied egg-rr34.7%
associate-*r/34.7%
*-commutative34.7%
Applied egg-rr34.7%
Final simplification34.7%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (* n (/ PI k)))))
double code(double k, double n) {
return sqrt((2.0 * (n * (((double) M_PI) / k))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n * (Math.PI / k))));
}
def code(k, n): return math.sqrt((2.0 * (n * (math.pi / k))))
function code(k, n) return sqrt(Float64(2.0 * Float64(n * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n * (pi / k)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 34.6%
associate-/l*34.6%
Simplified34.6%
sqrt-unprod34.7%
Applied egg-rr34.7%
Final simplification34.7%
herbie shell --seed 2024149
(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))))