
(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 8 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 (* (* 2.0 n) PI))) (/ (sqrt t_0) (* (pow t_0 (* 0.5 k)) (sqrt k)))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
return sqrt(t_0) / (pow(t_0, (0.5 * k)) * sqrt(k));
}
public static double code(double k, double n) {
double t_0 = (2.0 * n) * Math.PI;
return Math.sqrt(t_0) / (Math.pow(t_0, (0.5 * k)) * Math.sqrt(k));
}
def code(k, n): t_0 = (2.0 * n) * math.pi return math.sqrt(t_0) / (math.pow(t_0, (0.5 * k)) * math.sqrt(k))
function code(k, n) t_0 = Float64(Float64(2.0 * n) * pi) return Float64(sqrt(t_0) / Float64((t_0 ^ Float64(0.5 * k)) * sqrt(k))) end
function tmp = code(k, n) t_0 = (2.0 * n) * pi; tmp = sqrt(t_0) / ((t_0 ^ (0.5 * k)) * sqrt(k)); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Power[t$95$0, N[(0.5 * k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot n\right) \cdot \pi\\
\frac{\sqrt{t_0}}{{t_0}^{\left(0.5 \cdot k\right)} \cdot \sqrt{k}}
\end{array}
\end{array}
Initial program 99.2%
unpow-prod-down69.7%
unpow-prod-down99.2%
div-sub99.2%
metadata-eval99.2%
pow-sub99.2%
pow1/299.2%
frac-times99.4%
*-un-lft-identity99.4%
associate-*l*99.4%
associate-*l*99.4%
div-inv99.4%
metadata-eval99.4%
Applied egg-rr99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (let* ((t_0 (* (* 2.0 n) PI))) (if (<= k 5e-61) (/ (sqrt t_0) (sqrt k)) (sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
double tmp;
if (k <= 5e-61) {
tmp = sqrt(t_0) / sqrt(k);
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = (2.0 * n) * Math.PI;
double tmp;
if (k <= 5e-61) {
tmp = Math.sqrt(t_0) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = (2.0 * n) * math.pi tmp = 0 if k <= 5e-61: tmp = math.sqrt(t_0) / math.sqrt(k) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(Float64(2.0 * n) * pi) tmp = 0.0 if (k <= 5e-61) tmp = Float64(sqrt(t_0) / sqrt(k)); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = (2.0 * n) * pi; tmp = 0.0; if (k <= 5e-61) tmp = sqrt(t_0) / sqrt(k); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, If[LessEqual[k, 5e-61], N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[t$95$0, N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot n\right) \cdot \pi\\
\mathbf{if}\;k \leq 5 \cdot 10^{-61}:\\
\;\;\;\;\frac{\sqrt{t_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.9999999999999999e-61Initial program 99.3%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.1%
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%
Taylor expanded in n around 0 91.8%
Taylor expanded in k around 0 91.8%
+-commutative91.8%
log-prod92.4%
*-commutative92.4%
exp-to-pow99.5%
unpow1/299.5%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
if 4.9999999999999999e-61 < k Initial program 99.1%
*-commutative99.1%
div-sub99.1%
metadata-eval99.1%
div-inv99.1%
expm1-log1p-u98.7%
expm1-udef94.0%
Applied egg-rr94.0%
expm1-def98.7%
expm1-log1p99.2%
*-commutative99.2%
associate-*r*99.2%
Simplified99.2%
Final simplification99.3%
(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.2%
associate-*l/99.3%
*-lft-identity99.3%
sqr-pow99.1%
pow-sqr99.3%
*-commutative99.3%
associate-*l/99.3%
associate-/l*99.3%
metadata-eval99.3%
/-rgt-identity99.3%
div-sub99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (k n) :precision binary64 (/ (sqrt (* (* 2.0 n) PI)) (sqrt k)))
double code(double k, double n) {
return sqrt(((2.0 * n) * ((double) M_PI))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt(((2.0 * n) * Math.PI)) / Math.sqrt(k);
}
def code(k, n): return math.sqrt(((2.0 * n) * math.pi)) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(Float64(2.0 * n) * pi)) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt(((2.0 * n) * pi)) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\left(2 \cdot n\right) \cdot \pi}}{\sqrt{k}}
\end{array}
Initial program 99.2%
associate-*l/99.3%
*-lft-identity99.3%
sqr-pow99.1%
pow-sqr99.3%
*-commutative99.3%
associate-*l/99.3%
associate-/l*99.3%
metadata-eval99.3%
/-rgt-identity99.3%
div-sub99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in n around 0 96.3%
Taylor expanded in k around 0 42.6%
+-commutative42.6%
log-prod42.5%
*-commutative42.5%
exp-to-pow45.6%
unpow1/245.6%
associate-*r*45.6%
*-commutative45.6%
Simplified45.6%
Final simplification45.6%
(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.2%
*-commutative99.2%
div-sub99.2%
metadata-eval99.2%
div-inv99.3%
expm1-log1p-u96.8%
expm1-udef87.9%
Applied egg-rr77.6%
expm1-def86.6%
expm1-log1p88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
Taylor expanded in k around 0 34.3%
associate-*r*34.3%
*-commutative34.3%
associate-*l*34.3%
Simplified34.3%
Taylor expanded in n around 0 34.3%
expm1-log1p-u32.9%
expm1-udef37.1%
Applied egg-rr37.1%
expm1-def32.9%
expm1-log1p34.3%
associate-/l*34.3%
associate-/r/34.3%
Simplified34.3%
Final simplification34.3%
(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.2%
*-commutative99.2%
div-sub99.2%
metadata-eval99.2%
div-inv99.3%
expm1-log1p-u96.8%
expm1-udef87.9%
Applied egg-rr77.6%
expm1-def86.6%
expm1-log1p88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
Taylor expanded in k around 0 34.3%
associate-*r*34.3%
*-commutative34.3%
associate-*l*34.3%
Simplified34.3%
Taylor expanded in n around 0 34.3%
expm1-log1p-u32.9%
expm1-udef37.1%
Applied egg-rr37.1%
expm1-def32.9%
expm1-log1p34.3%
associate-/l*34.3%
Simplified34.3%
Final simplification34.3%
(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(Float64(n * 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), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{n \cdot \pi}{k}}
\end{array}
Initial program 99.2%
*-commutative99.2%
div-sub99.2%
metadata-eval99.2%
div-inv99.3%
expm1-log1p-u96.8%
expm1-udef87.9%
Applied egg-rr77.6%
expm1-def86.6%
expm1-log1p88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
Taylor expanded in k around 0 34.3%
associate-*r*34.3%
*-commutative34.3%
associate-*l*34.3%
Simplified34.3%
Taylor expanded in n around 0 34.3%
Final simplification34.3%
(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(Float64(n * Float64(2.0 * pi)) / k)) end
function tmp = code(k, n) tmp = sqrt(((n * (2.0 * pi)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{n \cdot \left(2 \cdot \pi\right)}{k}}
\end{array}
Initial program 99.2%
*-commutative99.2%
div-sub99.2%
metadata-eval99.2%
div-inv99.3%
expm1-log1p-u96.8%
expm1-udef87.9%
Applied egg-rr77.6%
expm1-def86.6%
expm1-log1p88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
Taylor expanded in k around 0 34.3%
associate-*r*34.3%
*-commutative34.3%
associate-*l*34.3%
Simplified34.3%
Final simplification34.3%
herbie shell --seed 2023263
(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))))