
(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 (/ (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(Float64(2.0 * 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[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.3%
pow-sqr99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 6.3e-21) (* (sqrt (* 2.0 n)) (sqrt (/ PI k))) (sqrt (* (pow (* PI (* 2.0 n)) (- 1.0 k)) (/ 1.0 k)))))
double code(double k, double n) {
double tmp;
if (k <= 6.3e-21) {
tmp = sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
} else {
tmp = sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) * (1.0 / k)));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 6.3e-21) {
tmp = Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
} else {
tmp = Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) * (1.0 / k)));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 6.3e-21: tmp = math.sqrt((2.0 * n)) * math.sqrt((math.pi / k)) else: tmp = math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) * (1.0 / k))) return tmp
function code(k, n) tmp = 0.0 if (k <= 6.3e-21) tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k))); else tmp = sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) * Float64(1.0 / k))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 6.3e-21) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) * (1.0 / k))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 6.3e-21], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] * N[(1.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 6.3 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)} \cdot \frac{1}{k}}\\
\end{array}
\end{array}
if k < 6.3e-21Initial program 99.3%
*-commutative99.3%
div-sub99.3%
metadata-eval99.3%
div-inv99.4%
add-sqr-sqrt99.0%
sqrt-unprod76.1%
frac-times76.0%
Applied egg-rr76.2%
Taylor expanded in k around 0 76.2%
associate-/l*76.3%
Simplified76.3%
Taylor expanded in n around 0 76.2%
associate-/l*76.3%
*-rgt-identity76.3%
associate-*r/76.2%
associate-/r/76.2%
associate-*l/76.3%
*-lft-identity76.3%
Simplified76.3%
associate-*r*76.3%
sqrt-prod99.4%
Applied egg-rr99.4%
*-commutative99.4%
Simplified99.4%
if 6.3e-21 < k Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
frac-times99.6%
Applied egg-rr99.6%
div-inv99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*l*99.6%
Applied egg-rr99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 6.6e-21) (* (sqrt (* 2.0 n)) (sqrt (/ PI k))) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 6.6e-21) {
tmp = sqrt((2.0 * n)) * sqrt((((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 <= 6.6e-21) {
tmp = Math.sqrt((2.0 * n)) * Math.sqrt((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 <= 6.6e-21: tmp = math.sqrt((2.0 * n)) * math.sqrt((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 <= 6.6e-21) tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(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 <= 6.6e-21) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 6.6e-21], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $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.6 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\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 < 6.60000000000000018e-21Initial program 99.3%
*-commutative99.3%
div-sub99.3%
metadata-eval99.3%
div-inv99.4%
add-sqr-sqrt99.0%
sqrt-unprod76.1%
frac-times76.0%
Applied egg-rr76.2%
Taylor expanded in k around 0 76.2%
associate-/l*76.3%
Simplified76.3%
Taylor expanded in n around 0 76.2%
associate-/l*76.3%
*-rgt-identity76.3%
associate-*r/76.2%
associate-/r/76.2%
associate-*l/76.3%
*-lft-identity76.3%
Simplified76.3%
associate-*r*76.3%
sqrt-prod99.4%
Applied egg-rr99.4%
*-commutative99.4%
Simplified99.4%
if 6.60000000000000018e-21 < k Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
frac-times99.6%
Applied egg-rr99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 1.2e+143) (* (sqrt (* 2.0 n)) (sqrt (/ PI k))) (pow (pow (* PI (* 2.0 (/ n k))) 3.0) 0.16666666666666666)))
double code(double k, double n) {
double tmp;
if (k <= 1.2e+143) {
tmp = sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
} else {
tmp = pow(pow((((double) M_PI) * (2.0 * (n / k))), 3.0), 0.16666666666666666);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.2e+143) {
tmp = Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
} else {
tmp = Math.pow(Math.pow((Math.PI * (2.0 * (n / k))), 3.0), 0.16666666666666666);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.2e+143: tmp = math.sqrt((2.0 * n)) * math.sqrt((math.pi / k)) else: tmp = math.pow(math.pow((math.pi * (2.0 * (n / k))), 3.0), 0.16666666666666666) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.2e+143) tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k))); else tmp = (Float64(pi * Float64(2.0 * Float64(n / k))) ^ 3.0) ^ 0.16666666666666666; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.2e+143) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); else tmp = ((pi * (2.0 * (n / k))) ^ 3.0) ^ 0.16666666666666666; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.2e+143], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(Pi * N[(2.0 * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.2 \cdot 10^{+143}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(\pi \cdot \left(2 \cdot \frac{n}{k}\right)\right)}^{3}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if k < 1.1999999999999999e143Initial program 99.3%
*-commutative99.3%
div-sub99.3%
metadata-eval99.3%
div-inv99.4%
add-sqr-sqrt99.1%
sqrt-unprod84.5%
frac-times84.5%
Applied egg-rr84.6%
Taylor expanded in k around 0 52.8%
associate-/l*52.8%
Simplified52.8%
Taylor expanded in n around 0 52.8%
associate-/l*52.8%
*-rgt-identity52.8%
associate-*r/52.8%
associate-/r/52.8%
associate-*l/52.9%
*-lft-identity52.9%
Simplified52.9%
associate-*r*52.9%
sqrt-prod67.6%
Applied egg-rr67.6%
*-commutative67.6%
Simplified67.6%
if 1.1999999999999999e143 < k Initial program 100.0%
*-commutative100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
frac-times100.0%
Applied egg-rr100.0%
Taylor expanded in k around 0 2.6%
associate-/l*2.6%
Simplified2.6%
Taylor expanded in n around 0 2.6%
associate-/l*2.6%
*-rgt-identity2.6%
associate-*r/2.6%
associate-/r/2.6%
associate-*l/2.6%
*-lft-identity2.6%
Simplified2.6%
pow1/22.6%
associate-*r/2.6%
associate-*l/2.6%
metadata-eval2.6%
pow-pow4.1%
sqr-pow4.1%
pow-prod-down16.7%
pow-prod-up16.7%
associate-*r*16.7%
metadata-eval16.7%
metadata-eval16.7%
Applied egg-rr16.7%
Final simplification55.4%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 n)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((2.0 * n)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod88.2%
frac-times88.2%
Applied egg-rr88.3%
Taylor expanded in k around 0 40.9%
associate-/l*40.9%
Simplified40.9%
Taylor expanded in n around 0 40.9%
associate-/l*40.9%
*-rgt-identity40.9%
associate-*r/40.9%
associate-/r/40.9%
associate-*l/40.9%
*-lft-identity40.9%
Simplified40.9%
associate-*r*40.9%
sqrt-prod52.1%
Applied egg-rr52.1%
*-commutative52.1%
Simplified52.1%
Final simplification52.1%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* 2.0 (* PI n))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (2.0 * (((double) M_PI) * n))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (2.0 * (Math.PI * n))));
}
def code(k, n): return 1.0 / math.sqrt((k / (2.0 * (math.pi * n))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(2.0 * Float64(pi * n))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (2.0 * (pi * n)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{2 \cdot \left(\pi \cdot n\right)}}}
\end{array}
Initial program 99.4%
expm1-log1p-u96.0%
expm1-udef78.0%
inv-pow78.0%
sqrt-pow278.0%
metadata-eval78.0%
Applied egg-rr78.0%
expm1-def96.0%
expm1-log1p99.5%
Simplified99.5%
add-sqr-sqrt99.3%
sqrt-unprod88.2%
swap-sqr88.2%
pow-prod-up88.2%
metadata-eval88.2%
inv-pow88.2%
associate-*r*88.2%
associate-*r*88.2%
sqr-pow88.3%
associate-/r/88.3%
sqrt-div89.5%
Applied egg-rr89.5%
Taylor expanded in k around 0 42.1%
Final simplification42.1%
(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.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod88.2%
frac-times88.2%
Applied egg-rr88.3%
Taylor expanded in k around 0 40.9%
associate-/l*40.9%
Simplified40.9%
Taylor expanded in n around 0 40.9%
associate-/l*40.9%
*-rgt-identity40.9%
associate-*r/40.9%
associate-/r/40.9%
associate-*l/40.9%
*-lft-identity40.9%
Simplified40.9%
Final simplification40.9%
herbie shell --seed 2023283
(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))))