
(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 (* (* 2.0 n) PI))) (* (/ 1.0 (sqrt k)) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
return (1.0 / sqrt(k)) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (2.0 * n) * Math.PI;
return (1.0 / Math.sqrt(k)) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (2.0 * n) * math.pi return (1.0 / math.sqrt(k)) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(2.0 * n) * pi) return Float64(Float64(1.0 / sqrt(k)) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (2.0 * n) * pi; tmp = (1.0 / sqrt(k)) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot n\right) \cdot \pi\\
\frac{1}{\sqrt{k}} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.4%
div-sub99.4%
metadata-eval99.4%
pow-sub99.6%
pow1/299.6%
associate-*l*99.6%
associate-*l*99.6%
div-inv99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (pow (pow (* 2.0 (* n PI)) (- 1.0 k)) -0.5)))
double code(double k, double n) {
return pow(k, -0.5) / pow(pow((2.0 * (n * ((double) M_PI))), (1.0 - k)), -0.5);
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) / Math.pow(Math.pow((2.0 * (n * Math.PI)), (1.0 - k)), -0.5);
}
def code(k, n): return math.pow(k, -0.5) / math.pow(math.pow((2.0 * (n * math.pi)), (1.0 - k)), -0.5)
function code(k, n) return Float64((k ^ -0.5) / ((Float64(2.0 * Float64(n * pi)) ^ Float64(1.0 - k)) ^ -0.5)) end
function tmp = code(k, n) tmp = (k ^ -0.5) / (((2.0 * (n * pi)) ^ (1.0 - k)) ^ -0.5); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[Power[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{{\left({\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 - k\right)}\right)}^{-0.5}}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*r*99.4%
associate-/r/99.5%
add-sqr-sqrt99.3%
sqrt-unprod99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
pow-prod-up99.5%
Applied egg-rr99.5%
inv-pow99.5%
div-inv99.4%
unpow-prod-down99.4%
pow1/299.4%
pow-pow99.5%
metadata-eval99.5%
pow1/299.5%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
unpow-199.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (* (sqrt (/ 1.0 k)) (pow (* n (* 2.0 PI)) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return sqrt((1.0 / k)) * pow((n * (2.0 * ((double) M_PI))), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((1.0 / k)) * Math.pow((n * (2.0 * Math.PI)), ((1.0 - k) / 2.0));
}
def code(k, n): return math.sqrt((1.0 / k)) * math.pow((n * (2.0 * math.pi)), ((1.0 - k) / 2.0))
function code(k, n) return Float64(sqrt(Float64(1.0 / k)) * (Float64(n * Float64(2.0 * pi)) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = sqrt((1.0 / k)) * ((n * (2.0 * pi)) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[Sqrt[N[(1.0 / k), $MachinePrecision]], $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}
\\
\sqrt{\frac{1}{k}} \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.3%
sqrt-unprod99.4%
frac-times99.4%
metadata-eval99.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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.4%
expm1-log1p-u96.2%
expm1-udef72.8%
pow1/272.8%
pow-flip72.8%
metadata-eval72.8%
Applied egg-rr72.8%
expm1-def96.2%
expm1-log1p99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 2.3e-48) (/ (sqrt (* 2.0 (* n PI))) (sqrt k)) (sqrt (/ (pow (* (* 2.0 n) PI) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2.3e-48) {
tmp = sqrt((2.0 * (n * ((double) M_PI)))) / sqrt(k);
} else {
tmp = sqrt((pow(((2.0 * n) * ((double) M_PI)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.3e-48) {
tmp = Math.sqrt((2.0 * (n * Math.PI))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(((2.0 * n) * Math.PI), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 2.3e-48: tmp = math.sqrt((2.0 * (n * math.pi))) / math.sqrt(k) else: tmp = math.sqrt((math.pow(((2.0 * n) * math.pi), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 2.3e-48) tmp = Float64(sqrt(Float64(2.0 * Float64(n * pi))) / sqrt(k)); else tmp = sqrt(Float64((Float64(Float64(2.0 * n) * pi) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 2.3e-48) tmp = sqrt((2.0 * (n * pi))) / sqrt(k); else tmp = sqrt(((((2.0 * n) * pi) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.3e-48], N[(N[Sqrt[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.3 \cdot 10^{-48}:\\
\;\;\;\;\frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\left(2 \cdot n\right) \cdot \pi\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 2.3000000000000001e-48Initial program 99.2%
Taylor expanded in k around 0 99.0%
expm1-log1p-u92.8%
expm1-udef77.4%
associate-*l/77.4%
*-un-lft-identity77.4%
sqrt-unprod77.4%
*-commutative77.4%
Applied egg-rr77.4%
expm1-def92.9%
expm1-log1p99.3%
Simplified99.3%
if 2.3000000000000001e-48 < k Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u99.3%
expm1-udef93.2%
Applied egg-rr93.2%
expm1-def99.4%
expm1-log1p99.7%
*-commutative99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.5%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (pow (* 2.0 n) (- 0.5 (* k 0.5)))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * pow((2.0 * n), (0.5 - (k * 0.5)));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.pow((2.0 * n), (0.5 - (k * 0.5)));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.pow((2.0 * n), (0.5 - (k * 0.5)))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * (Float64(2.0 * n) ^ Float64(0.5 - Float64(k * 0.5)))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * ((2.0 * n) ^ (0.5 - (k * 0.5))); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Power[N[(2.0 * n), $MachinePrecision], N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot {\left(2 \cdot n\right)}^{\left(0.5 - k \cdot 0.5\right)}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-un-lft-identity99.5%
*-commutative99.5%
associate-*r*99.5%
unpow-prod-down74.0%
associate-/l*74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
Applied egg-rr74.0%
associate-/r/74.0%
Simplified74.0%
Taylor expanded in k around 0 99.3%
expm1-log1p-u96.0%
expm1-udef72.6%
sqrt-undiv72.6%
Applied egg-rr72.6%
expm1-def96.0%
expm1-log1p99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (/ (pow (* (* 2.0 n) PI) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow(((2.0 * n) * ((double) M_PI)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow(((2.0 * n) * Math.PI), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow(((2.0 * n) * math.pi), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(Float64(2.0 * n) * pi) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = (((2.0 * n) * pi) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(2 \cdot n\right) \cdot \pi\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Final simplification99.5%
(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(2.0 * Float64(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[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 49.5%
expm1-log1p-u46.7%
expm1-udef46.5%
associate-*l/46.5%
*-un-lft-identity46.5%
sqrt-unprod46.5%
*-commutative46.5%
Applied egg-rr46.5%
expm1-def46.7%
expm1-log1p49.6%
Simplified49.6%
Final simplification49.6%
(FPCore (k n) :precision binary64 (pow (* k (/ (/ 0.5 n) PI)) -0.5))
double code(double k, double n) {
return pow((k * ((0.5 / n) / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * ((0.5 / n) / Math.PI)), -0.5);
}
def code(k, n): return math.pow((k * ((0.5 / n) / math.pi)), -0.5)
function code(k, n) return Float64(k * Float64(Float64(0.5 / n) / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = (k * ((0.5 / n) / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[(N[(0.5 / n), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot \frac{\frac{0.5}{n}}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.4%
div-sub99.4%
metadata-eval99.4%
pow-sub99.6%
pow1/299.6%
associate-*l*99.6%
associate-*l*99.6%
div-inv99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
associate-*l/99.7%
*-un-lft-identity99.7%
pow-unpow99.7%
unpow1/299.7%
sqrt-div99.7%
pow199.7%
pow-sub99.5%
sqrt-pow199.5%
associate-*l*99.5%
*-commutative99.5%
sqrt-pow199.5%
Applied egg-rr86.4%
Taylor expanded in k around 0 36.4%
*-commutative36.4%
Simplified36.4%
expm1-log1p-u34.9%
expm1-udef34.8%
pow1/234.8%
pow-flip34.8%
metadata-eval34.8%
Applied egg-rr34.8%
expm1-def35.0%
expm1-log1p36.5%
rem-exp-log34.3%
log-div33.7%
*-commutative33.7%
sub-neg33.7%
exp-sum33.8%
rem-exp-log34.2%
rec-exp34.2%
*-commutative34.2%
rem-exp-log36.5%
associate-/r*36.5%
metadata-eval36.5%
*-commutative36.5%
associate-/r*36.5%
Simplified36.5%
Final simplification36.5%
herbie shell --seed 2023224
(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))))