
(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 (if (<= k 6.8e-94) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 6.8e-94) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} 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 <= 6.8e-94) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} 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 <= 6.8e-94: tmp = math.sqrt((2.0 * n)) / math.sqrt((k / math.pi)) 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 <= 6.8e-94) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); 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 <= 6.8e-94) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 6.8e-94], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $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 6.8 \cdot 10^{-94}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 6.7999999999999996e-94Initial program 99.3%
Taylor expanded in k around 0 61.3%
*-commutative61.3%
associate-/l*61.3%
Simplified61.3%
pow161.3%
sqrt-unprod61.4%
*-commutative61.4%
associate-*r*61.4%
Applied egg-rr61.4%
unpow161.4%
associate-*l*61.4%
associate-*l/61.4%
associate-/l*61.5%
Simplified61.5%
associate-*r/61.4%
*-commutative61.4%
associate-/l*61.4%
clear-num61.4%
un-div-inv61.4%
Applied egg-rr61.4%
associate-*r/61.4%
sqrt-div99.5%
*-commutative99.5%
Applied egg-rr99.5%
if 6.7999999999999996e-94 < k Initial program 99.6%
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 4.2e+16) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (+ -1.0 (fma PI (* 2.0 (/ n k)) 1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 4.2e+16) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} else {
tmp = sqrt((-1.0 + fma(((double) M_PI), (2.0 * (n / k)), 1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 4.2e+16) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); else tmp = sqrt(Float64(-1.0 + fma(pi, Float64(2.0 * Float64(n / k)), 1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 4.2e+16], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(Pi * N[(2.0 * N[(n / k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.2 \cdot 10^{+16}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}\\
\end{array}
\end{array}
if k < 4.2e16Initial program 98.9%
Taylor expanded in k around 0 67.9%
*-commutative67.9%
associate-/l*67.8%
Simplified67.8%
pow167.8%
sqrt-unprod68.0%
*-commutative68.0%
associate-*r*68.0%
Applied egg-rr68.0%
unpow168.0%
associate-*l*68.0%
associate-*l/68.0%
associate-/l*68.0%
Simplified68.0%
associate-*r/68.0%
*-commutative68.0%
associate-/l*68.0%
clear-num68.0%
un-div-inv68.0%
Applied egg-rr68.0%
associate-*r/68.0%
sqrt-div91.6%
*-commutative91.6%
Applied egg-rr91.6%
if 4.2e16 < k Initial program 100.0%
Taylor expanded in k around 0 1.9%
*-commutative1.9%
associate-/l*1.9%
Simplified1.9%
pow11.9%
sqrt-unprod1.9%
*-commutative1.9%
associate-*r*1.9%
Applied egg-rr1.9%
unpow11.9%
associate-*l*1.9%
associate-*l/1.9%
associate-/l*1.9%
Simplified1.9%
associate-*r/1.9%
*-commutative1.9%
associate-/l*1.9%
clear-num1.9%
un-div-inv1.9%
Applied egg-rr1.9%
associate-/r/1.9%
clear-num1.9%
associate-*l/1.9%
*-un-lft-identity1.9%
expm1-log1p-u1.9%
associate-/l*1.9%
expm1-undefine34.9%
associate-/r/34.9%
*-commutative34.9%
*-commutative34.9%
associate-/l*34.9%
Applied egg-rr34.9%
sub-neg34.9%
metadata-eval34.9%
+-commutative34.9%
log1p-undefine34.9%
rem-exp-log34.9%
+-commutative34.9%
*-commutative34.9%
associate-*l*34.9%
associate-*l/34.9%
*-commutative34.9%
fma-define34.9%
*-commutative34.9%
associate-*r/34.9%
Simplified34.9%
Final simplification60.1%
(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 (* 2.0 n)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((2.0 * n)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
associate-*r/31.4%
*-commutative31.4%
associate-/l*31.4%
clear-num31.3%
un-div-inv31.4%
Applied egg-rr31.4%
associate-*r/31.4%
sqrt-div41.9%
*-commutative41.9%
Applied egg-rr41.9%
Final simplification41.9%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 (/ PI k))) (sqrt n)))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / k))) * sqrt(n);
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / k))) * Math.sqrt(n);
}
def code(k, n): return math.sqrt((2.0 * (math.pi / k))) * math.sqrt(n)
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(pi / k))) * sqrt(n)) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / k))) * sqrt(n); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{k}} \cdot \sqrt{n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
associate-*r/31.4%
*-commutative31.4%
sqrt-prod31.3%
associate-/l*31.3%
sqrt-prod41.8%
*-commutative41.8%
associate-*r*41.8%
sqrt-unprod41.9%
Applied egg-rr41.9%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (fabs (* n (/ PI k))))))
double code(double k, double n) {
return sqrt((2.0 * fabs((n * (((double) M_PI) / k)))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * Math.abs((n * (Math.PI / k)))));
}
def code(k, n): return math.sqrt((2.0 * math.fabs((n * (math.pi / k)))))
function code(k, n) return sqrt(Float64(2.0 * abs(Float64(n * Float64(pi / k))))) end
function tmp = code(k, n) tmp = sqrt((2.0 * abs((n * (pi / k))))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[Abs[N[(n * N[(Pi / k), $MachinePrecision]), $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 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
associate-*r/31.4%
*-commutative31.4%
add-sqr-sqrt31.3%
pow1/231.3%
pow1/231.3%
pow-prod-down27.3%
pow227.3%
associate-/l*27.3%
Applied egg-rr27.3%
unpow1/227.3%
unpow227.3%
rem-sqrt-square31.9%
Simplified31.9%
(FPCore (k n) :precision binary64 (sqrt (fabs (* n (* PI (/ 2.0 k))))))
double code(double k, double n) {
return sqrt(fabs((n * (((double) M_PI) * (2.0 / k)))));
}
public static double code(double k, double n) {
return Math.sqrt(Math.abs((n * (Math.PI * (2.0 / k)))));
}
def code(k, n): return math.sqrt(math.fabs((n * (math.pi * (2.0 / k)))))
function code(k, n) return sqrt(abs(Float64(n * Float64(pi * Float64(2.0 / k))))) end
function tmp = code(k, n) tmp = sqrt(abs((n * (pi * (2.0 / k))))); end
code[k_, n_] := N[Sqrt[N[Abs[N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left|n \cdot \left(\pi \cdot \frac{2}{k}\right)\right|}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
add-sqr-sqrt31.4%
pow1/231.4%
pow1/231.4%
pow-prod-down27.3%
pow227.3%
associate-*r/27.3%
*-commutative27.3%
associate-/l*27.3%
Applied egg-rr27.3%
unpow1/227.3%
unpow227.3%
rem-sqrt-square31.9%
*-commutative31.9%
associate-*l*31.9%
associate-*l/31.9%
associate-/l*31.8%
Simplified31.8%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ (/ k PI) (* 2.0 n)))))
double code(double k, double n) {
return 1.0 / sqrt(((k / ((double) M_PI)) / (2.0 * n)));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((k / Math.PI) / (2.0 * n)));
}
def code(k, n): return 1.0 / math.sqrt(((k / math.pi) / (2.0 * n)))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(k / pi) / Float64(2.0 * n)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((k / pi) / (2.0 * n))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(k / Pi), $MachinePrecision] / N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{k}{\pi}}{2 \cdot n}}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
associate-*r/31.4%
*-commutative31.4%
associate-/l*31.4%
clear-num31.3%
un-div-inv31.4%
Applied egg-rr31.4%
sqrt-prod31.3%
associate-/r/31.3%
clear-num31.3%
associate-*l/31.3%
*-un-lft-identity31.3%
sqrt-prod31.3%
associate-/l*31.3%
clear-num31.3%
sqrt-div31.5%
metadata-eval31.5%
*-commutative31.5%
associate-/l/31.5%
*-commutative31.5%
Applied egg-rr31.5%
associate-*r*31.5%
associate-/r*31.5%
associate-/l/31.5%
associate-/l/31.5%
Simplified31.5%
(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 31.3%
*-commutative31.3%
associate-/l*31.3%
Simplified31.3%
pow131.3%
sqrt-unprod31.4%
*-commutative31.4%
associate-*r*31.4%
Applied egg-rr31.4%
unpow131.4%
associate-*l*31.4%
associate-*l/31.4%
associate-/l*31.4%
Simplified31.4%
herbie shell --seed 2024182
(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))))