
(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 (let* ((t_0 (* n (* 2.0 PI)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = n * (2.0 * ((double) M_PI));
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = n * (2.0 * Math.PI);
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = n * (2.0 * math.pi) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(n * Float64(2.0 * pi)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = n * (2.0 * pi); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Sqrt[k], $MachinePrecision] * N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(2 \cdot \pi\right)\\
\frac{\sqrt{t_0}}{\sqrt{k} \cdot {t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*r*99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
pow-sub99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 3.1e-77) (/ (sqrt (* PI (* n 2.0))) (sqrt k)) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 3.1e-77) {
tmp = sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
} else {
tmp = sqrt((pow((n * (2.0 * ((double) M_PI))), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 3.1e-77) {
tmp = Math.sqrt((Math.PI * (n * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow((n * (2.0 * Math.PI)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 3.1e-77: tmp = math.sqrt((math.pi * (n * 2.0))) / math.sqrt(k) else: tmp = math.sqrt((math.pow((n * (2.0 * math.pi)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 3.1e-77) tmp = Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)); else tmp = sqrt(Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 3.1e-77) tmp = sqrt((pi * (n * 2.0))) / sqrt(k); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 3.1e-77], N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.1 \cdot 10^{-77}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 3.10000000000000008e-77Initial program 99.3%
Taylor expanded in k around 0 99.1%
associate-*l/99.3%
*-un-lft-identity99.3%
sqrt-unprod99.5%
*-commutative99.5%
rem-exp-log92.6%
*-commutative92.6%
rem-exp-log99.5%
Applied egg-rr99.5%
*-commutative99.5%
associate-*r*99.5%
Simplified99.5%
if 3.10000000000000008e-77 < k Initial program 99.5%
add-sqr-sqrt99.4%
sqrt-unprod99.5%
*-commutative99.5%
div-inv99.5%
*-commutative99.5%
div-inv99.5%
frac-times99.5%
Applied egg-rr99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* n PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (n * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (n * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (n * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (n * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(n * Pi), $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(n \cdot \pi\right)\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%
associate-*l*99.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 1.35e+152) (/ (sqrt (* PI (* n 2.0))) (sqrt k)) (pow (pow (* n (/ (* 2.0 PI) k)) 3.0) 0.16666666666666666)))
double code(double k, double n) {
double tmp;
if (k <= 1.35e+152) {
tmp = sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
} else {
tmp = pow(pow((n * ((2.0 * ((double) M_PI)) / k)), 3.0), 0.16666666666666666);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.35e+152) {
tmp = Math.sqrt((Math.PI * (n * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.pow(Math.pow((n * ((2.0 * Math.PI) / k)), 3.0), 0.16666666666666666);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.35e+152: tmp = math.sqrt((math.pi * (n * 2.0))) / math.sqrt(k) else: tmp = math.pow(math.pow((n * ((2.0 * math.pi) / k)), 3.0), 0.16666666666666666) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.35e+152) tmp = Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)); else tmp = (Float64(n * Float64(Float64(2.0 * pi) / k)) ^ 3.0) ^ 0.16666666666666666; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.35e+152) tmp = sqrt((pi * (n * 2.0))) / sqrt(k); else tmp = ((n * ((2.0 * pi) / k)) ^ 3.0) ^ 0.16666666666666666; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.35e+152], N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(n * N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.35 \cdot 10^{+152}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(n \cdot \frac{2 \cdot \pi}{k}\right)}^{3}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if k < 1.35000000000000007e152Initial program 99.2%
Taylor expanded in k around 0 67.3%
associate-*l/67.4%
*-un-lft-identity67.4%
sqrt-unprod67.5%
*-commutative67.5%
rem-exp-log63.2%
*-commutative63.2%
rem-exp-log67.5%
Applied egg-rr67.5%
*-commutative67.5%
associate-*r*67.5%
Simplified67.5%
if 1.35000000000000007e152 < k Initial program 100.0%
Taylor expanded in k around 0 2.8%
expm1-log1p-u2.8%
expm1-udef36.8%
associate-*l/36.8%
*-un-lft-identity36.8%
sqrt-unprod36.8%
*-commutative36.8%
rem-exp-log36.8%
*-commutative36.8%
sqrt-undiv36.8%
rem-exp-log36.8%
Applied egg-rr36.8%
expm1-def2.7%
expm1-log1p2.7%
associate-*r*2.7%
*-commutative2.7%
*-commutative2.7%
associate-/l*2.7%
*-commutative2.7%
Simplified2.7%
Taylor expanded in n around 0 2.7%
*-commutative2.7%
associate-/l*2.7%
Simplified2.7%
pow1/22.7%
metadata-eval2.7%
associate-*r/2.7%
associate-/l*2.7%
*-commutative2.7%
associate-*r*2.7%
pow-pow5.7%
sqr-pow5.7%
pow-prod-down21.2%
Applied egg-rr21.2%
Final simplification56.3%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((2.0 * (math.pi / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 51.7%
expm1-log1p-u48.7%
expm1-udef49.0%
associate-*l/49.0%
*-un-lft-identity49.0%
sqrt-unprod49.0%
*-commutative49.0%
rem-exp-log48.7%
*-commutative48.7%
sqrt-undiv36.9%
rem-exp-log37.1%
Applied egg-rr37.1%
expm1-def36.9%
expm1-log1p38.7%
associate-*r*38.7%
*-commutative38.7%
*-commutative38.7%
associate-/l*38.8%
*-commutative38.8%
Simplified38.8%
pow1/238.8%
div-inv38.7%
unpow-prod-down51.5%
pow1/251.5%
clear-num51.5%
*-un-lft-identity51.5%
times-frac51.5%
metadata-eval51.5%
Applied egg-rr51.5%
unpow1/251.5%
Simplified51.5%
Final simplification51.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (* n 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (n * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (n * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 51.7%
associate-*l/51.8%
*-un-lft-identity51.8%
sqrt-unprod51.9%
*-commutative51.9%
rem-exp-log48.5%
*-commutative48.5%
rem-exp-log51.9%
Applied egg-rr51.9%
*-commutative51.9%
associate-*r*51.9%
Simplified51.9%
Final simplification51.9%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* k (/ (/ 0.5 n) PI)))))
double code(double k, double n) {
return 1.0 / sqrt((k * ((0.5 / n) / ((double) M_PI))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k * ((0.5 / n) / Math.PI)));
}
def code(k, n): return 1.0 / math.sqrt((k * ((0.5 / n) / math.pi)))
function code(k, n) return Float64(1.0 / sqrt(Float64(k * Float64(Float64(0.5 / n) / pi)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k * ((0.5 / n) / pi))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k * N[(N[(0.5 / n), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k \cdot \frac{\frac{0.5}{n}}{\pi}}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 51.7%
expm1-log1p-u48.7%
expm1-udef49.0%
associate-*l/49.0%
*-un-lft-identity49.0%
sqrt-unprod49.0%
*-commutative49.0%
rem-exp-log48.7%
*-commutative48.7%
sqrt-undiv36.9%
rem-exp-log37.1%
Applied egg-rr37.1%
expm1-def36.9%
expm1-log1p38.7%
associate-*r*38.7%
*-commutative38.7%
*-commutative38.7%
associate-/l*38.8%
*-commutative38.8%
Simplified38.8%
Taylor expanded in n around 0 38.7%
*-commutative38.7%
associate-/l*38.8%
Simplified38.8%
associate-*r/38.8%
associate-/l*38.7%
*-commutative38.7%
associate-*r*38.7%
clear-num38.7%
sqrt-div39.7%
metadata-eval39.7%
*-un-lft-identity39.7%
associate-*r*39.7%
*-commutative39.7%
times-frac39.7%
associate-/r*39.7%
metadata-eval39.7%
Applied egg-rr39.7%
associate-*r/39.7%
associate-*l/39.7%
*-commutative39.7%
associate-/l/39.7%
associate-/r*39.7%
Simplified39.7%
Final simplification39.7%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ PI (/ k n)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / (k / n))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / (k / n))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi / (k / n))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / (k / n)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 51.7%
expm1-log1p-u48.7%
expm1-udef49.0%
associate-*l/49.0%
*-un-lft-identity49.0%
sqrt-unprod49.0%
*-commutative49.0%
rem-exp-log48.7%
*-commutative48.7%
sqrt-undiv36.9%
rem-exp-log37.1%
Applied egg-rr37.1%
expm1-def36.9%
expm1-log1p38.7%
associate-*r*38.7%
*-commutative38.7%
*-commutative38.7%
associate-/l*38.8%
*-commutative38.8%
Simplified38.8%
Taylor expanded in n around 0 38.7%
*-commutative38.7%
associate-/l*38.8%
Simplified38.8%
Final simplification38.8%
(FPCore (k n) :precision binary64 (sqrt (* n (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt((n * (2.0 * (((double) M_PI) / k))));
}
public static double code(double k, double n) {
return Math.sqrt((n * (2.0 * (Math.PI / k))));
}
def code(k, n): return math.sqrt((n * (2.0 * (math.pi / k))))
function code(k, n) return sqrt(Float64(n * Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt((n * (2.0 * (pi / k)))); end
code[k_, n_] := N[Sqrt[N[(n * N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot \left(2 \cdot \frac{\pi}{k}\right)}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 51.7%
expm1-log1p-u48.7%
expm1-udef49.0%
associate-*l/49.0%
*-un-lft-identity49.0%
sqrt-unprod49.0%
*-commutative49.0%
rem-exp-log48.7%
*-commutative48.7%
sqrt-undiv36.9%
rem-exp-log37.1%
Applied egg-rr37.1%
expm1-def36.9%
expm1-log1p38.7%
associate-*r*38.7%
*-commutative38.7%
*-commutative38.7%
associate-/l*38.8%
*-commutative38.8%
Simplified38.8%
Taylor expanded in n around 0 38.7%
associate-*r/38.7%
associate-*r*38.7%
associate-*r/38.8%
*-commutative38.8%
associate-*r*38.8%
Simplified38.8%
Final simplification38.8%
herbie shell --seed 2023311
(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))))