
(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 3.8e-22) (/ (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 <= 3.8e-22) {
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 <= 3.8e-22) {
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 <= 3.8e-22: 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 <= 3.8e-22) 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 <= 3.8e-22) 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, 3.8e-22], 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 3.8 \cdot 10^{-22}:\\
\;\;\;\;\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 < 3.80000000000000023e-22Initial program 99.1%
*-commutative99.1%
div-sub99.1%
metadata-eval99.1%
div-inv99.2%
add-sqr-sqrt98.9%
sqrt-unprod68.9%
frac-times68.9%
Applied egg-rr69.2%
Taylor expanded in k around 0 69.2%
associate-/l*69.2%
Simplified69.2%
associate-*r/69.2%
sqrt-div99.5%
Applied egg-rr99.5%
if 3.80000000000000023e-22 < k Initial program 99.9%
*-commutative99.9%
div-sub99.9%
metadata-eval99.9%
div-inv99.9%
add-sqr-sqrt99.9%
sqrt-unprod99.9%
frac-times99.9%
Applied egg-rr99.9%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* (* 2.0 (cbrt (pow PI 3.0))) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return pow(k, -0.5) * pow(((2.0 * cbrt(pow(((double) M_PI), 3.0))) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow(((2.0 * Math.cbrt(Math.pow(Math.PI, 3.0))) * n), ((1.0 - k) / 2.0));
}
function code(k, n) return Float64((k ^ -0.5) * (Float64(Float64(2.0 * cbrt((pi ^ 3.0))) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(N[(2.0 * N[Power[N[Power[Pi, 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(\left(2 \cdot \sqrt[3]{{\pi}^{3}}\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.6%
expm1-log1p-u96.5%
expm1-udef71.1%
inv-pow71.1%
sqrt-pow271.1%
metadata-eval71.1%
Applied egg-rr71.1%
expm1-def96.5%
expm1-log1p99.7%
Simplified99.7%
add-cbrt-cube99.7%
pow399.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* n (* 2.0 PI)) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return pow(k, -0.5) * pow((n * (2.0 * ((double) M_PI))), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((n * (2.0 * Math.PI)), ((1.0 - k) / 2.0));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((n * (2.0 * math.pi)), ((1.0 - k) / 2.0))
function code(k, n) return Float64((k ^ -0.5) * (Float64(n * Float64(2.0 * pi)) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((n * (2.0 * pi)) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.6%
expm1-log1p-u96.5%
expm1-udef71.1%
inv-pow71.1%
sqrt-pow271.1%
metadata-eval71.1%
Applied egg-rr71.1%
expm1-def96.5%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (pow (* n (* 2.0 PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((n * (2.0 * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (2.0 * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (2.0 * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (2.0 * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-lft-identity99.6%
sqr-pow99.5%
pow-sqr99.6%
*-commutative99.6%
associate-*l/99.6%
associate-/l*99.6%
metadata-eval99.6%
/-rgt-identity99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.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.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.5%
sqrt-unprod86.8%
frac-times86.8%
Applied egg-rr87.0%
Taylor expanded in k around 0 32.5%
associate-/l*32.5%
Simplified32.5%
associate-*r/32.5%
sqrt-div45.3%
Applied egg-rr45.3%
Final simplification45.3%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* n (* 2.0 PI))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (n * (2.0 * ((double) M_PI)))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (n * (2.0 * Math.PI))));
}
def code(k, n): return 1.0 / math.sqrt((k / (n * (2.0 * math.pi))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(n * Float64(2.0 * pi))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (n * (2.0 * pi)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{n \cdot \left(2 \cdot \pi\right)}}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 45.1%
sqrt-unprod45.1%
*-commutative45.1%
*-commutative45.1%
Applied egg-rr45.1%
add-sqr-sqrt44.9%
sqrt-unprod44.7%
frac-times44.8%
metadata-eval44.8%
add-sqr-sqrt44.8%
Applied egg-rr44.8%
*-commutative44.8%
*-commutative44.8%
*-commutative44.8%
associate-*r*44.8%
sqrt-div45.1%
metadata-eval45.1%
div-inv45.2%
clear-num45.2%
associate-*r*45.2%
*-commutative45.2%
*-commutative45.2%
sqrt-undiv33.3%
*-commutative33.3%
*-commutative33.3%
associate-*r*33.3%
Applied egg-rr33.3%
Final simplification33.3%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ (/ (/ k n) PI) 2.0))))
double code(double k, double n) {
return 1.0 / sqrt((((k / n) / ((double) M_PI)) / 2.0));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((((k / n) / Math.PI) / 2.0));
}
def code(k, n): return 1.0 / math.sqrt((((k / n) / math.pi) / 2.0))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(Float64(k / n) / pi) / 2.0))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((((k / n) / pi) / 2.0)); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(N[(k / n), $MachinePrecision] / Pi), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{\frac{k}{n}}{\pi}}{2}}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 45.1%
expm1-log1p-u42.3%
expm1-udef46.0%
associate-*l/46.0%
*-un-lft-identity46.0%
sqrt-unprod46.0%
*-commutative46.0%
*-commutative46.0%
Applied egg-rr46.0%
expm1-def42.3%
expm1-log1p45.2%
*-commutative45.2%
*-commutative45.2%
associate-*l*45.2%
Simplified45.2%
clear-num45.2%
inv-pow45.2%
associate-*r*45.2%
*-commutative45.2%
*-commutative45.2%
sqrt-undiv33.3%
*-commutative33.3%
*-commutative33.3%
associate-*r*33.3%
Applied egg-rr33.3%
unpow-133.3%
associate-/r*33.4%
associate-/r*33.4%
Simplified33.4%
Final simplification33.4%
(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%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.5%
sqrt-unprod86.8%
frac-times86.8%
Applied egg-rr87.0%
Taylor expanded in k around 0 32.5%
associate-/l*32.5%
associate-/r/32.5%
Simplified32.5%
Final simplification32.5%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ n (/ k PI)))))
double code(double k, double n) {
return sqrt((2.0 * (n / (k / ((double) M_PI)))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n / (k / Math.PI))));
}
def code(k, n): return math.sqrt((2.0 * (n / (k / math.pi))))
function code(k, n) return sqrt(Float64(2.0 * Float64(n / Float64(k / pi)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n / (k / pi)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(n / N[(k / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{n}{\frac{k}{\pi}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.5%
sqrt-unprod86.8%
frac-times86.8%
Applied egg-rr87.0%
Taylor expanded in k around 0 32.5%
associate-/l*32.5%
Simplified32.5%
Final simplification32.5%
herbie shell --seed 2023287
(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))))