
(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 7 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.5e-37) (/ (sqrt (* PI (* 2.0 n))) (sqrt k)) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.5e-37) {
tmp = sqrt((((double) M_PI) * (2.0 * n))) / 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 <= 1.5e-37) {
tmp = Math.sqrt((Math.PI * (2.0 * n))) / 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 <= 1.5e-37: tmp = math.sqrt((math.pi * (2.0 * n))) / 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 <= 1.5e-37) tmp = Float64(sqrt(Float64(pi * Float64(2.0 * n))) / 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 <= 1.5e-37) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.5e-37], N[(N[Sqrt[N[(Pi * N[(2.0 * n), $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 1.5 \cdot 10^{-37}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\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 < 1.5e-37Initial program 99.3%
Taylor expanded in k around 0 76.1%
associate-/l*76.1%
Simplified76.1%
pow176.1%
sqrt-unprod76.3%
Applied egg-rr76.3%
unpow176.3%
*-commutative76.3%
associate-*r/76.3%
*-commutative76.3%
associate-/l*76.4%
Simplified76.4%
Taylor expanded in n around 0 76.3%
associate-*r/76.3%
sqrt-div99.4%
*-commutative99.4%
*-commutative99.4%
associate-*l*99.4%
Applied egg-rr99.4%
if 1.5e-37 < k Initial program 99.8%
Applied egg-rr99.8%
distribute-lft-in99.8%
metadata-eval99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
neg-mul-199.8%
sub-neg99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 4.5e+61) (/ (sqrt (* PI (* 2.0 n))) (sqrt k)) (sqrt (+ -1.0 (fma n (/ PI (* 0.5 k)) 1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 4.5e+61) {
tmp = sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
} else {
tmp = sqrt((-1.0 + fma(n, (((double) M_PI) / (0.5 * k)), 1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 4.5e+61) tmp = Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)); else tmp = sqrt(Float64(-1.0 + fma(n, Float64(pi / Float64(0.5 * k)), 1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 4.5e+61], N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(n * N[(Pi / N[(0.5 * k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.5 \cdot 10^{+61}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-1 + \mathsf{fma}\left(n, \frac{\pi}{0.5 \cdot k}, 1\right)}\\
\end{array}
\end{array}
if k < 4.5e61Initial program 99.3%
Taylor expanded in k around 0 66.2%
associate-/l*66.2%
Simplified66.2%
pow166.2%
sqrt-unprod66.4%
Applied egg-rr66.4%
unpow166.4%
*-commutative66.4%
associate-*r/66.4%
*-commutative66.4%
associate-/l*66.4%
Simplified66.4%
Taylor expanded in n around 0 66.4%
associate-*r/66.4%
sqrt-div84.2%
*-commutative84.2%
*-commutative84.2%
associate-*l*84.2%
Applied egg-rr84.2%
if 4.5e61 < k Initial program 100.0%
Taylor expanded in k around 0 2.6%
associate-/l*2.6%
Simplified2.6%
pow12.6%
sqrt-unprod2.6%
Applied egg-rr2.6%
unpow12.6%
*-commutative2.6%
associate-*r/2.6%
*-commutative2.6%
associate-/l*2.6%
Simplified2.6%
Taylor expanded in n around 0 2.6%
expm1-log1p-u2.6%
expm1-undefine24.9%
*-commutative24.9%
associate-/l*24.9%
associate-*l*24.9%
Applied egg-rr24.9%
sub-neg24.9%
metadata-eval24.9%
+-commutative24.9%
log1p-undefine24.9%
rem-exp-log24.9%
+-commutative24.9%
associate-*r*24.9%
metadata-eval24.9%
associate-/l*24.9%
*-rgt-identity24.9%
associate-/l*24.9%
fma-define24.9%
associate-/l/24.9%
*-commutative24.9%
Simplified24.9%
Final simplification63.3%
(FPCore (k n) :precision binary64 (* (pow (* 2.0 (* PI n)) (+ 0.5 (* k -0.5))) (pow k -0.5)))
double code(double k, double n) {
return pow((2.0 * (((double) M_PI) * n)), (0.5 + (k * -0.5))) * pow(k, -0.5);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (Math.PI * n)), (0.5 + (k * -0.5))) * Math.pow(k, -0.5);
}
def code(k, n): return math.pow((2.0 * (math.pi * n)), (0.5 + (k * -0.5))) * math.pow(k, -0.5)
function code(k, n) return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 + Float64(k * -0.5))) * (k ^ -0.5)) end
function tmp = code(k, n) tmp = ((2.0 * (pi * n)) ^ (0.5 + (k * -0.5))) * (k ^ -0.5); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(k * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[k, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 + k \cdot -0.5\right)} \cdot {k}^{-0.5}
\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%
metadata-eval99.6%
div-sub99.6%
associate-*r*99.6%
div-inv99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
sub-neg99.5%
div-inv99.5%
metadata-eval99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
pow1/299.5%
pow-flip99.6%
metadata-eval99.6%
Applied egg-rr99.6%
(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 (* PI (* 2.0 n))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 * n))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (2.0 * n))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 43.8%
associate-/l*43.8%
Simplified43.8%
pow143.8%
sqrt-unprod43.9%
Applied egg-rr43.9%
unpow143.9%
*-commutative43.9%
associate-*r/43.9%
*-commutative43.9%
associate-/l*44.0%
Simplified44.0%
Taylor expanded in n around 0 43.9%
associate-*r/43.9%
sqrt-div55.5%
*-commutative55.5%
*-commutative55.5%
associate-*l*55.5%
Applied egg-rr55.5%
Final simplification55.5%
(FPCore (k n) :precision binary64 (pow (* 0.5 (/ (/ k n) PI)) -0.5))
double code(double k, double n) {
return pow((0.5 * ((k / n) / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((0.5 * ((k / n) / Math.PI)), -0.5);
}
def code(k, n): return math.pow((0.5 * ((k / n) / math.pi)), -0.5)
function code(k, n) return Float64(0.5 * Float64(Float64(k / n) / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = (0.5 * ((k / n) / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(0.5 * N[(N[(k / n), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(0.5 \cdot \frac{\frac{k}{n}}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 43.8%
associate-/l*43.8%
Simplified43.8%
pow143.8%
sqrt-unprod43.9%
Applied egg-rr43.9%
unpow143.9%
*-commutative43.9%
associate-*r/43.9%
*-commutative43.9%
associate-/l*44.0%
Simplified44.0%
Taylor expanded in n around 0 43.9%
clear-num43.9%
un-div-inv43.9%
sqrt-undiv44.4%
clear-num44.3%
inv-pow44.3%
sqrt-undiv44.5%
sqrt-pow244.5%
div-inv44.5%
metadata-eval44.5%
metadata-eval44.5%
Applied egg-rr44.5%
*-commutative44.5%
associate-/r*44.6%
Simplified44.6%
(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.5%
Taylor expanded in k around 0 43.8%
associate-/l*43.8%
Simplified43.8%
pow143.8%
sqrt-unprod43.9%
Applied egg-rr43.9%
unpow143.9%
*-commutative43.9%
associate-*r/43.9%
*-commutative43.9%
associate-/l*44.0%
Simplified44.0%
herbie shell --seed 2024129
(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))))