
(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 (if (<= k 1.66e-21) (* (sqrt (/ PI k)) (sqrt (* n 2.0))) (/ 1.0 (sqrt (/ k (pow (* PI (* n 2.0)) (- 1.0 k)))))))
double code(double k, double n) {
double tmp;
if (k <= 1.66e-21) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
} else {
tmp = 1.0 / sqrt((k / pow((((double) M_PI) * (n * 2.0)), (1.0 - k))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.66e-21) {
tmp = Math.sqrt((Math.PI / k)) * Math.sqrt((n * 2.0));
} else {
tmp = 1.0 / Math.sqrt((k / Math.pow((Math.PI * (n * 2.0)), (1.0 - k))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.66e-21: tmp = math.sqrt((math.pi / k)) * math.sqrt((n * 2.0)) else: tmp = 1.0 / math.sqrt((k / math.pow((math.pi * (n * 2.0)), (1.0 - k)))) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.66e-21) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))); else tmp = Float64(1.0 / sqrt(Float64(k / (Float64(pi * Float64(n * 2.0)) ^ Float64(1.0 - k))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.66e-21) tmp = sqrt((pi / k)) * sqrt((n * 2.0)); else tmp = 1.0 / sqrt((k / ((pi * (n * 2.0)) ^ (1.0 - k)))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.66e-21], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(k / N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.66 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{k}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(1 - k\right)}}}}\\
\end{array}
\end{array}
if k < 1.65999999999999993e-21Initial program 98.7%
add-sqr-sqrt98.4%
sqrt-unprod77.6%
*-commutative77.6%
*-commutative77.6%
associate-*r*77.6%
div-sub77.6%
metadata-eval77.6%
div-inv77.7%
*-commutative77.7%
Applied egg-rr77.7%
Simplified77.8%
Taylor expanded in k around 0 77.8%
Taylor expanded in n around 0 77.8%
associate-/l*77.8%
Simplified77.8%
associate-*r/77.8%
*-un-lft-identity77.8%
associate-*l/77.8%
clear-num77.9%
sqrt-prod99.4%
Applied egg-rr99.4%
if 1.65999999999999993e-21 < k Initial program 99.5%
add-sqr-sqrt99.4%
sqrt-unprod99.5%
*-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
*-commutative99.5%
Applied egg-rr99.5%
Simplified99.5%
clear-num99.5%
sqrt-div99.5%
metadata-eval99.5%
*-commutative99.5%
*-commutative99.5%
associate-*l*99.5%
Applied egg-rr99.5%
Final simplification99.4%
(FPCore (k n) :precision binary64 (let* ((t_0 (* n (* 2.0 PI)))) (/ (sqrt t_0) (* (pow t_0 (* 0.5 k)) (sqrt k)))))
double code(double k, double n) {
double t_0 = n * (2.0 * ((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 = n * (2.0 * Math.PI);
return Math.sqrt(t_0) / (Math.pow(t_0, (0.5 * k)) * Math.sqrt(k));
}
def code(k, n): t_0 = n * (2.0 * math.pi) return math.sqrt(t_0) / (math.pow(t_0, (0.5 * k)) * math.sqrt(k))
function code(k, n) t_0 = Float64(n * Float64(2.0 * pi)) return Float64(sqrt(t_0) / Float64((t_0 ^ Float64(0.5 * k)) * sqrt(k))) end
function tmp = code(k, n) t_0 = n * (2.0 * pi); tmp = sqrt(t_0) / ((t_0 ^ (0.5 * k)) * sqrt(k)); 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[Power[t$95$0, N[(0.5 * k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(2 \cdot \pi\right)\\
\frac{\sqrt{t_0}}{{t_0}^{\left(0.5 \cdot k\right)} \cdot \sqrt{k}}
\end{array}
\end{array}
Initial program 99.1%
associate-/r/99.0%
*-commutative99.0%
associate-*r*99.0%
div-sub99.0%
metadata-eval99.0%
clear-num99.1%
pow-sub99.3%
pow1/299.3%
associate-/l/99.3%
associate-*r*99.3%
*-commutative99.3%
associate-*l*99.3%
Applied egg-rr99.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (k n) :precision binary64 (if (<= k 2.8e-21) (* (sqrt (/ PI k)) (sqrt (* n 2.0))) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2.8e-21) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
} 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 <= 2.8e-21) {
tmp = Math.sqrt((Math.PI / k)) * Math.sqrt((n * 2.0));
} 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 <= 2.8e-21: tmp = math.sqrt((math.pi / k)) * math.sqrt((n * 2.0)) 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 <= 2.8e-21) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))); 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 <= 2.8e-21) tmp = sqrt((pi / k)) * sqrt((n * 2.0)); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.8e-21], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $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 2.8 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 2.80000000000000004e-21Initial program 98.7%
add-sqr-sqrt98.4%
sqrt-unprod77.6%
*-commutative77.6%
*-commutative77.6%
associate-*r*77.6%
div-sub77.6%
metadata-eval77.6%
div-inv77.7%
*-commutative77.7%
Applied egg-rr77.7%
Simplified77.8%
Taylor expanded in k around 0 77.8%
Taylor expanded in n around 0 77.8%
associate-/l*77.8%
Simplified77.8%
associate-*r/77.8%
*-un-lft-identity77.8%
associate-*l/77.8%
clear-num77.9%
sqrt-prod99.4%
Applied egg-rr99.4%
if 2.80000000000000004e-21 < k Initial program 99.5%
add-sqr-sqrt99.4%
sqrt-unprod99.5%
*-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
*-commutative99.5%
Applied egg-rr99.5%
Simplified99.5%
Final simplification99.4%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* n 2.0)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (n * 2.0)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (n * 2.0)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (n * 2.0)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(n * 2.0)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (n * 2.0)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.1%
associate-*l/99.1%
*-lft-identity99.1%
sqr-pow98.9%
pow-sqr99.1%
*-commutative99.1%
associate-*l*99.1%
associate-*r/99.1%
*-commutative99.1%
associate-/l*99.1%
metadata-eval99.1%
/-rgt-identity99.1%
div-sub99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (sqrt (* n 2.0))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.sqrt((n * 2.0));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.sqrt((n * 2.0))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * sqrt((n * 2.0)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}
\end{array}
Initial program 99.1%
add-sqr-sqrt98.9%
sqrt-unprod88.5%
*-commutative88.5%
*-commutative88.5%
associate-*r*88.5%
div-sub88.5%
metadata-eval88.5%
div-inv88.5%
*-commutative88.5%
Applied egg-rr88.5%
Simplified88.6%
Taylor expanded in k around 0 43.3%
Taylor expanded in n around 0 43.3%
associate-/l*43.3%
Simplified43.3%
associate-*r/43.3%
*-un-lft-identity43.3%
associate-*l/43.3%
clear-num43.3%
sqrt-prod54.3%
Applied egg-rr54.3%
Final simplification54.3%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ (* 0.5 k) (* n PI)))))
double code(double k, double n) {
return 1.0 / sqrt(((0.5 * k) / (n * ((double) M_PI))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((0.5 * k) / (n * Math.PI)));
}
def code(k, n): return 1.0 / math.sqrt(((0.5 * k) / (n * math.pi)))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(0.5 * k) / Float64(n * pi)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((0.5 * k) / (n * pi))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(0.5 * k), $MachinePrecision] / N[(n * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{0.5 \cdot k}{n \cdot \pi}}}
\end{array}
Initial program 99.1%
add-sqr-sqrt98.9%
sqrt-unprod88.5%
*-commutative88.5%
*-commutative88.5%
associate-*r*88.5%
div-sub88.5%
metadata-eval88.5%
div-inv88.5%
*-commutative88.5%
Applied egg-rr88.5%
Simplified88.6%
Taylor expanded in k around 0 43.3%
clear-num43.3%
sqrt-div44.3%
metadata-eval44.3%
*-un-lft-identity44.3%
times-frac44.3%
metadata-eval44.3%
*-commutative44.3%
Applied egg-rr44.3%
associate-*r/44.3%
*-commutative44.3%
Simplified44.3%
Final simplification44.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.1%
add-sqr-sqrt98.9%
sqrt-unprod88.5%
*-commutative88.5%
*-commutative88.5%
associate-*r*88.5%
div-sub88.5%
metadata-eval88.5%
div-inv88.5%
*-commutative88.5%
Applied egg-rr88.5%
Simplified88.6%
Taylor expanded in k around 0 43.3%
Taylor expanded in n around 0 43.3%
associate-/l*43.3%
Simplified43.3%
Final simplification43.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(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.1%
add-sqr-sqrt98.9%
sqrt-unprod88.5%
*-commutative88.5%
*-commutative88.5%
associate-*r*88.5%
div-sub88.5%
metadata-eval88.5%
div-inv88.5%
*-commutative88.5%
Applied egg-rr88.5%
Simplified88.6%
Taylor expanded in k around 0 43.3%
associate-*r*43.3%
*-un-lft-identity43.3%
times-frac43.3%
Applied egg-rr43.3%
Taylor expanded in n around 0 43.3%
associate-*r/43.3%
*-commutative43.3%
associate-*r*43.3%
*-commutative43.3%
Simplified43.3%
Final simplification43.3%
(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(Float64(2.0 * pi) / Float64(k / n))) end
function tmp = code(k, n) tmp = sqrt(((2.0 * pi) / (k / n))); end
code[k_, n_] := N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] / N[(k / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2 \cdot \pi}{\frac{k}{n}}}
\end{array}
Initial program 99.1%
add-sqr-sqrt98.9%
sqrt-unprod88.5%
*-commutative88.5%
*-commutative88.5%
associate-*r*88.5%
div-sub88.5%
metadata-eval88.5%
div-inv88.5%
*-commutative88.5%
Applied egg-rr88.5%
Simplified88.6%
Taylor expanded in k around 0 43.3%
associate-*r*43.3%
*-un-lft-identity43.3%
times-frac43.3%
Applied egg-rr43.3%
frac-times43.3%
associate-*r*43.3%
*-commutative43.3%
associate-*r*43.3%
*-un-lft-identity43.3%
associate-/l*43.4%
Applied egg-rr43.4%
Final simplification43.4%
herbie shell --seed 2024021
(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))))