
(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 5 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(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.2%
associate-*l/99.2%
*-lft-identity99.2%
associate-*l*99.2%
div-sub99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (pow (* 2.0 (* PI n)) (- 1.0 k))))))
double code(double k, double n) {
return 1.0 / sqrt((k / pow((2.0 * (((double) M_PI) * n)), (1.0 - k))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / Math.pow((2.0 * (Math.PI * n)), (1.0 - k))));
}
def code(k, n): return 1.0 / math.sqrt((k / math.pow((2.0 * (math.pi * n)), (1.0 - k))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / (Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / ((2.0 * (pi * n)) ^ (1.0 - k)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}}}
\end{array}
Initial program 99.2%
associate-*l/99.2%
*-lft-identity99.2%
associate-*l*99.2%
div-sub99.2%
metadata-eval99.2%
Simplified99.2%
pow1/299.2%
pow-to-exp96.1%
Applied egg-rr96.1%
add-sqr-sqrt96.1%
sqrt-unprod88.2%
frac-times88.2%
Applied egg-rr90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*l*90.6%
distribute-rgt-in90.6%
metadata-eval90.6%
associate-*l*90.6%
metadata-eval90.6%
*-commutative90.6%
neg-mul-190.6%
unsub-neg90.6%
Simplified90.6%
clear-num90.6%
sqrt-div90.8%
metadata-eval90.8%
Applied egg-rr90.8%
associate-*r*90.8%
Simplified90.8%
Final simplification90.8%
(FPCore (k n) :precision binary64 (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k)))
double code(double k, double n) {
return sqrt((pow((n * (2.0 * ((double) M_PI))), (1.0 - k)) / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.pow((n * (2.0 * Math.PI)), (1.0 - k)) / k));
}
def code(k, n): return math.sqrt((math.pow((n * (2.0 * math.pi)), (1.0 - k)) / k))
function code(k, n) return sqrt(Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k)) / k)) end
function tmp = code(k, n) tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}
\end{array}
Initial program 99.2%
associate-*l/99.2%
*-lft-identity99.2%
associate-*l*99.2%
div-sub99.2%
metadata-eval99.2%
Simplified99.2%
metadata-eval99.2%
div-sub99.2%
associate-*r*99.2%
sqr-pow98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
Applied egg-rr98.7%
add-sqr-sqrt98.6%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.6%
associate-*r*90.6%
*-commutative90.6%
*-commutative90.6%
associate-*r*90.6%
metadata-eval90.6%
*-lft-identity90.6%
Simplified90.6%
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt (/ k (* PI n)))) (sqrt 2.0)))
double code(double k, double n) {
return (1.0 / sqrt((k / (((double) M_PI) * n)))) * sqrt(2.0);
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt((k / (Math.PI * n)))) * Math.sqrt(2.0);
}
def code(k, n): return (1.0 / math.sqrt((k / (math.pi * n)))) * math.sqrt(2.0)
function code(k, n) return Float64(Float64(1.0 / sqrt(Float64(k / Float64(pi * n)))) * sqrt(2.0)) end
function tmp = code(k, n) tmp = (1.0 / sqrt((k / (pi * n)))) * sqrt(2.0); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{\pi \cdot n}}} \cdot \sqrt{2}
\end{array}
Initial program 99.2%
associate-*l/99.2%
*-lft-identity99.2%
associate-*l*99.2%
div-sub99.2%
metadata-eval99.2%
Simplified99.2%
metadata-eval99.2%
div-sub99.2%
associate-*r*99.2%
sqr-pow98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
Applied egg-rr98.7%
Taylor expanded in k around 0 36.0%
clear-num36.0%
sqrt-div36.4%
metadata-eval36.4%
Applied egg-rr36.4%
Final simplification36.4%
(FPCore (k n) :precision binary64 (* (sqrt 2.0) (sqrt (* n (/ PI k)))))
double code(double k, double n) {
return sqrt(2.0) * sqrt((n * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(2.0) * Math.sqrt((n * (Math.PI / k)));
}
def code(k, n): return math.sqrt(2.0) * math.sqrt((n * (math.pi / k)))
function code(k, n) return Float64(sqrt(2.0) * sqrt(Float64(n * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(2.0) * sqrt((n * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.2%
associate-*l/99.2%
*-lft-identity99.2%
associate-*l*99.2%
div-sub99.2%
metadata-eval99.2%
Simplified99.2%
metadata-eval99.2%
div-sub99.2%
associate-*r*99.2%
sqr-pow98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
associate-*r*98.7%
div-inv98.7%
metadata-eval98.7%
associate-/l*98.7%
metadata-eval98.7%
Applied egg-rr98.7%
Taylor expanded in k around 0 36.0%
associate-/l*36.0%
Simplified36.0%
Final simplification36.0%
herbie shell --seed 2024111
(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))))