
(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 5.8e-53) (/ (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 <= 5.8e-53) {
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 <= 5.8e-53) {
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 <= 5.8e-53: 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 <= 5.8e-53) 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 <= 5.8e-53) 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, 5.8e-53], 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 5.8 \cdot 10^{-53}:\\
\;\;\;\;\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 < 5.7999999999999996e-53Initial program 99.4%
Taylor expanded in k around 0 67.0%
associate-/l*67.0%
Simplified67.0%
pow167.0%
*-commutative67.0%
sqrt-unprod67.2%
Applied egg-rr67.2%
unpow167.2%
Simplified67.2%
associate-*r*67.2%
sqrt-prod99.4%
*-commutative99.4%
sqrt-div99.0%
associate-*l/99.2%
sqrt-prod99.5%
Applied egg-rr99.5%
if 5.7999999999999996e-53 < k Initial program 99.7%
Applied egg-rr99.8%
*-commutative99.8%
distribute-lft-in99.8%
metadata-eval99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
neg-mul-199.8%
sub-neg99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 5.7e+48) (/ (sqrt (* PI (* 2.0 n))) (sqrt k)) (sqrt (+ -1.0 (fma 2.0 (* n (/ PI k)) 1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 5.7e+48) {
tmp = sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
} else {
tmp = sqrt((-1.0 + fma(2.0, (n * (((double) M_PI) / k)), 1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 5.7e+48) tmp = Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)); else tmp = sqrt(Float64(-1.0 + fma(2.0, Float64(n * Float64(pi / k)), 1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 5.7e+48], N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5.7 \cdot 10^{+48}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-1 + \mathsf{fma}\left(2, n \cdot \frac{\pi}{k}, 1\right)}\\
\end{array}
\end{array}
if k < 5.69999999999999968e48Initial program 99.2%
Taylor expanded in k around 0 59.2%
associate-/l*59.1%
Simplified59.1%
pow159.1%
*-commutative59.1%
sqrt-unprod59.3%
Applied egg-rr59.3%
unpow159.3%
Simplified59.3%
associate-*r*59.3%
sqrt-prod84.1%
*-commutative84.1%
sqrt-div83.8%
associate-*l/83.9%
sqrt-prod84.2%
Applied egg-rr84.2%
if 5.69999999999999968e48 < k Initial program 100.0%
Taylor expanded in k around 0 2.6%
associate-/l*2.6%
Simplified2.6%
pow12.6%
*-commutative2.6%
sqrt-unprod2.6%
Applied egg-rr2.6%
unpow12.6%
Simplified2.6%
expm1-log1p-u2.6%
expm1-undefine26.3%
*-commutative26.3%
associate-/r/26.3%
Applied egg-rr26.3%
sub-neg26.3%
metadata-eval26.3%
+-commutative26.3%
log1p-undefine26.3%
rem-exp-log26.3%
+-commutative26.3%
fma-define26.3%
associate-/r/26.3%
*-commutative26.3%
Simplified26.3%
(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.7%
*-lft-identity99.7%
associate-*l*99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
(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.6%
Taylor expanded in k around 0 33.3%
associate-/l*33.3%
Simplified33.3%
pow133.3%
*-commutative33.3%
sqrt-unprod33.4%
Applied egg-rr33.4%
unpow133.4%
Simplified33.4%
associate-*r*33.4%
sqrt-prod46.9%
*-commutative46.9%
sqrt-div46.8%
associate-*l/46.8%
sqrt-prod47.0%
Applied egg-rr47.0%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (sqrt (* 2.0 n))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.sqrt((2.0 * n));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.sqrt((2.0 * n))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * sqrt((2.0 * n)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 33.3%
associate-/l*33.3%
Simplified33.3%
pow133.3%
*-commutative33.3%
sqrt-unprod33.4%
Applied egg-rr33.4%
unpow133.4%
Simplified33.4%
associate-*r*33.4%
sqrt-prod46.9%
*-commutative46.9%
Applied egg-rr46.9%
(FPCore (k n) :precision binary64 (pow (/ (/ k 2.0) (* PI n)) -0.5))
double code(double k, double n) {
return pow(((k / 2.0) / (((double) M_PI) * n)), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / 2.0) / (Math.PI * n)), -0.5);
}
def code(k, n): return math.pow(((k / 2.0) / (math.pi * n)), -0.5)
function code(k, n) return Float64(Float64(k / 2.0) / Float64(pi * n)) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / 2.0) / (pi * n)) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / 2.0), $MachinePrecision] / N[(Pi * n), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{\frac{k}{2}}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 33.3%
associate-/l*33.3%
Simplified33.3%
pow133.3%
*-commutative33.3%
sqrt-unprod33.4%
Applied egg-rr33.4%
unpow133.4%
Simplified33.4%
*-commutative33.4%
associate-/r/33.4%
clear-num33.4%
un-div-inv33.4%
sqrt-undiv33.6%
clear-num33.6%
inv-pow33.6%
sqrt-undiv33.6%
sqrt-pow233.7%
associate-/l/33.7%
*-commutative33.7%
metadata-eval33.7%
Applied egg-rr33.7%
associate-/r*33.7%
associate-/l/33.7%
associate-/l/33.7%
associate-/r*33.7%
*-commutative33.7%
Simplified33.7%
Final simplification33.7%
(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 33.3%
associate-/l*33.3%
Simplified33.3%
associate-*r/33.3%
*-commutative33.3%
Applied egg-rr33.3%
sqrt-unprod33.4%
*-commutative33.4%
associate-*r/33.4%
*-commutative33.4%
*-commutative33.4%
associate-/r/33.4%
Applied egg-rr33.4%
clear-num33.4%
associate-/r/33.4%
clear-num33.4%
Applied egg-rr33.4%
Final simplification33.4%
(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.6%
Taylor expanded in k around 0 33.3%
associate-/l*33.3%
Simplified33.3%
pow133.3%
*-commutative33.3%
sqrt-unprod33.4%
Applied egg-rr33.4%
unpow133.4%
Simplified33.4%
herbie shell --seed 2024158
(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))))