
(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 (* PI n)))) (/ (* (pow t_0 (* k -0.5)) (sqrt t_0)) (sqrt k))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) * n);
return (pow(t_0, (k * -0.5)) * sqrt(t_0)) / sqrt(k);
}
public static double code(double k, double n) {
double t_0 = 2.0 * (Math.PI * n);
return (Math.pow(t_0, (k * -0.5)) * Math.sqrt(t_0)) / Math.sqrt(k);
}
def code(k, n): t_0 = 2.0 * (math.pi * n) return (math.pow(t_0, (k * -0.5)) * math.sqrt(t_0)) / math.sqrt(k)
function code(k, n) t_0 = Float64(2.0 * Float64(pi * n)) return Float64(Float64((t_0 ^ Float64(k * -0.5)) * sqrt(t_0)) / sqrt(k)) end
function tmp = code(k, n) t_0 = 2.0 * (pi * n); tmp = ((t_0 ^ (k * -0.5)) * sqrt(t_0)) / sqrt(k); end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[t$95$0, N[(k * -0.5), $MachinePrecision]], $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(\pi \cdot n\right)\\
\frac{{t_0}^{\left(k \cdot -0.5\right)} \cdot \sqrt{t_0}}{\sqrt{k}}
\end{array}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-*l*99.7%
div-sub99.7%
sub-neg99.7%
distribute-frac-neg99.7%
metadata-eval99.7%
neg-mul-199.7%
associate-/l*99.7%
associate-/r/99.7%
metadata-eval99.7%
Simplified99.7%
+-commutative99.7%
unpow-prod-up99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*l*99.8%
*-commutative99.8%
pow1/299.8%
associate-*r*99.8%
*-commutative99.8%
associate-*l*99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (k n) :precision binary64 (if (<= k 2.1e-29) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ 1.0 (/ k (pow (* PI (* 2.0 n)) (- 1.0 k)))))))
double code(double k, double n) {
double tmp;
if (k <= 2.1e-29) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} else {
tmp = sqrt((1.0 / (k / pow((((double) M_PI) * (2.0 * n)), (1.0 - k)))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.1e-29) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} else {
tmp = Math.sqrt((1.0 / (k / Math.pow((Math.PI * (2.0 * n)), (1.0 - k)))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 2.1e-29: tmp = math.sqrt((2.0 * n)) / math.sqrt((k / math.pi)) else: tmp = math.sqrt((1.0 / (k / math.pow((math.pi * (2.0 * n)), (1.0 - k))))) return tmp
function code(k, n) tmp = 0.0 if (k <= 2.1e-29) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); else tmp = sqrt(Float64(1.0 / Float64(k / (Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 2.1e-29) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); else tmp = sqrt((1.0 / (k / ((pi * (2.0 * n)) ^ (1.0 - k))))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.1e-29], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 / N[(k / N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.1 \cdot 10^{-29}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\frac{k}{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}}}\\
\end{array}
\end{array}
if k < 2.09999999999999989e-29Initial program 99.4%
add-sqr-sqrt98.8%
sqrt-unprod76.7%
associate-*l/76.9%
*-un-lft-identity76.9%
associate-*l/76.8%
*-un-lft-identity76.8%
frac-times76.7%
Applied egg-rr76.8%
Simplified76.9%
Taylor expanded in k around 0 76.9%
associate-*r/76.9%
associate-*r*76.9%
*-commutative76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in n around 0 76.9%
associate-/l*77.0%
Simplified77.0%
associate-*r/77.0%
*-commutative77.0%
clear-num76.9%
metadata-eval76.9%
add-sqr-sqrt76.8%
frac-times76.8%
sqrt-unprod78.2%
add-sqr-sqrt78.7%
sqrt-div99.3%
associate-/r/99.4%
Applied egg-rr99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
if 2.09999999999999989e-29 < k Initial program 99.8%
add-sqr-sqrt99.8%
sqrt-unprod99.8%
associate-*l/99.8%
*-un-lft-identity99.8%
associate-*l/99.8%
*-un-lft-identity99.8%
frac-times99.8%
Applied egg-rr99.8%
Simplified99.8%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
unpow-199.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 9.4e-29) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 9.4e-29) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} else {
tmp = sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 9.4e-29) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} else {
tmp = Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 9.4e-29: tmp = math.sqrt((2.0 * n)) / math.sqrt((k / math.pi)) else: tmp = math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 9.4e-29) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); else tmp = sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 9.4e-29) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 9.4e-29], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 9.4 \cdot 10^{-29}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 9.3999999999999997e-29Initial program 99.4%
add-sqr-sqrt98.7%
sqrt-unprod77.0%
associate-*l/77.1%
*-un-lft-identity77.1%
associate-*l/77.1%
*-un-lft-identity77.1%
frac-times76.9%
Applied egg-rr77.0%
Simplified77.1%
Taylor expanded in k around 0 77.1%
associate-*r/77.1%
associate-*r*77.1%
*-commutative77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in n around 0 77.1%
associate-/l*77.2%
Simplified77.2%
associate-*r/77.2%
*-commutative77.2%
clear-num77.1%
metadata-eval77.1%
add-sqr-sqrt77.0%
frac-times77.1%
sqrt-unprod78.4%
add-sqr-sqrt78.9%
sqrt-div99.3%
associate-/r/99.4%
Applied egg-rr99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
if 9.3999999999999997e-29 < k Initial program 99.8%
add-sqr-sqrt99.8%
sqrt-unprod99.8%
associate-*l/99.8%
*-un-lft-identity99.8%
associate-*l/99.8%
*-un-lft-identity99.8%
frac-times99.8%
Applied egg-rr99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* 2.0 n)) (+ 0.5 (* k -0.5))) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), (0.5 + (k * -0.5))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), (0.5 + (k * -0.5))) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), (0.5 + (k * -0.5))) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(0.5 + Float64(k * -0.5))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ (0.5 + (k * -0.5))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(k * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(0.5 + k \cdot -0.5\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-*l*99.7%
div-sub99.7%
sub-neg99.7%
distribute-frac-neg99.7%
metadata-eval99.7%
neg-mul-199.7%
associate-/l*99.7%
associate-/r/99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((2.0 * n)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.4%
sqrt-unprod90.5%
associate-*l/90.6%
*-un-lft-identity90.6%
associate-*l/90.6%
*-un-lft-identity90.6%
frac-times90.5%
Applied egg-rr90.6%
Simplified90.6%
Taylor expanded in k around 0 36.6%
associate-*r/36.6%
associate-*r*36.6%
*-commutative36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in n around 0 36.6%
associate-/l*36.6%
Simplified36.6%
associate-*r/36.6%
*-commutative36.6%
clear-num36.6%
metadata-eval36.6%
add-sqr-sqrt36.5%
frac-times36.6%
sqrt-unprod37.1%
add-sqr-sqrt37.3%
sqrt-div45.6%
associate-/r/45.7%
Applied egg-rr45.7%
associate-*l/45.7%
*-lft-identity45.7%
Simplified45.7%
Final simplification45.7%
(FPCore (k n) :precision binary64 (pow (/ k (* n (* 2.0 PI))) -0.5))
double code(double k, double n) {
return pow((k / (n * (2.0 * ((double) M_PI)))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k / (n * (2.0 * Math.PI))), -0.5);
}
def code(k, n): return math.pow((k / (n * (2.0 * math.pi))), -0.5)
function code(k, n) return Float64(k / Float64(n * Float64(2.0 * pi))) ^ -0.5 end
function tmp = code(k, n) tmp = (k / (n * (2.0 * pi))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k / N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{n \cdot \left(2 \cdot \pi\right)}\right)}^{-0.5}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.4%
sqrt-unprod90.5%
associate-*l/90.6%
*-un-lft-identity90.6%
associate-*l/90.6%
*-un-lft-identity90.6%
frac-times90.5%
Applied egg-rr90.6%
Simplified90.6%
Taylor expanded in k around 0 36.6%
associate-*r/36.6%
associate-*r*36.6%
*-commutative36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in n around 0 36.6%
associate-/l*36.6%
Simplified36.6%
associate-*r/36.6%
*-commutative36.6%
clear-num36.6%
metadata-eval36.6%
add-sqr-sqrt36.5%
frac-times36.6%
sqrt-unprod37.1%
add-sqr-sqrt37.3%
inv-pow37.3%
sqrt-pow237.3%
associate-/l/37.3%
associate-*r*37.3%
*-commutative37.3%
associate-/r*37.3%
metadata-eval37.3%
Applied egg-rr37.3%
associate-/l/37.3%
Simplified37.3%
Final simplification37.3%
(FPCore (k n) :precision binary64 (pow (/ (/ k (* 2.0 PI)) n) -0.5))
double code(double k, double n) {
return pow(((k / (2.0 * ((double) M_PI))) / n), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / (2.0 * Math.PI)) / n), -0.5);
}
def code(k, n): return math.pow(((k / (2.0 * math.pi)) / n), -0.5)
function code(k, n) return Float64(Float64(k / Float64(2.0 * pi)) / n) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / (2.0 * pi)) / n) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{\frac{k}{2 \cdot \pi}}{n}\right)}^{-0.5}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.4%
sqrt-unprod90.5%
associate-*l/90.6%
*-un-lft-identity90.6%
associate-*l/90.6%
*-un-lft-identity90.6%
frac-times90.5%
Applied egg-rr90.6%
Simplified90.6%
Taylor expanded in k around 0 36.6%
associate-*r/36.6%
associate-*r*36.6%
*-commutative36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in n around 0 36.6%
associate-/l*36.6%
Simplified36.6%
associate-*r/36.6%
*-commutative36.6%
clear-num36.6%
metadata-eval36.6%
add-sqr-sqrt36.5%
frac-times36.6%
sqrt-unprod37.1%
add-sqr-sqrt37.3%
inv-pow37.3%
sqrt-pow237.3%
associate-/l/37.3%
associate-*r*37.3%
*-commutative37.3%
associate-/r*37.3%
metadata-eval37.3%
Applied egg-rr37.3%
Final simplification37.3%
(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.6%
add-sqr-sqrt99.4%
sqrt-unprod90.5%
associate-*l/90.6%
*-un-lft-identity90.6%
associate-*l/90.6%
*-un-lft-identity90.6%
frac-times90.5%
Applied egg-rr90.6%
Simplified90.6%
Taylor expanded in k around 0 36.6%
associate-*r/36.6%
associate-*r*36.6%
*-commutative36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in n around 0 36.6%
associate-/l*36.6%
Simplified36.6%
associate-/r/36.6%
Applied egg-rr36.6%
Final simplification36.6%
herbie shell --seed 2023316
(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))))