
(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 6 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 (/ (pow (* PI (* 2.0 n)) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (let* ((t_0 (* n (* PI 2.0)))) (if (<= k 5e-85) (/ (sqrt t_0) (sqrt k)) (sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = n * (((double) M_PI) * 2.0);
double tmp;
if (k <= 5e-85) {
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 = n * (Math.PI * 2.0);
double tmp;
if (k <= 5e-85) {
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 = n * (math.pi * 2.0) tmp = 0 if k <= 5e-85: 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(n * Float64(pi * 2.0)) tmp = 0.0 if (k <= 5e-85) 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 = n * (pi * 2.0); tmp = 0.0; if (k <= 5e-85) 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 * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 5e-85], 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 := n \cdot \left(\pi \cdot 2\right)\\
\mathbf{if}\;k \leq 5 \cdot 10^{-85}:\\
\;\;\;\;\frac{\sqrt{t_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 5.0000000000000002e-85Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.6%
expm1-log1p-u92.7%
expm1-udef77.9%
Applied egg-rr45.9%
expm1-def60.8%
expm1-log1p63.9%
associate-*r*63.9%
Simplified63.9%
Taylor expanded in k around 0 63.9%
*-commutative63.9%
Simplified63.9%
sqrt-div99.6%
associate-*r*99.6%
Applied egg-rr99.6%
if 5.0000000000000002e-85 < k Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.7%
expm1-log1p-u98.9%
expm1-udef92.9%
Applied egg-rr92.9%
expm1-def98.4%
expm1-log1p99.2%
associate-*r*99.2%
Simplified99.2%
Final simplification99.3%
(FPCore (k n) :precision binary64 (if (<= k 1.3e+181) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (pow (pow (* n (* PI (/ 2.0 k))) 2.0) 0.25)))
double code(double k, double n) {
double tmp;
if (k <= 1.3e+181) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} else {
tmp = pow(pow((n * (((double) M_PI) * (2.0 / k))), 2.0), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.3e+181) {
tmp = Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.pow(Math.pow((n * (Math.PI * (2.0 / k))), 2.0), 0.25);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.3e+181: tmp = math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k) else: tmp = math.pow(math.pow((n * (math.pi * (2.0 / k))), 2.0), 0.25) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.3e+181) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); else tmp = (Float64(n * Float64(pi * Float64(2.0 / k))) ^ 2.0) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.3e+181) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); else tmp = ((n * (pi * (2.0 / k))) ^ 2.0) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.3e+181], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], 0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.3 \cdot 10^{+181}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(n \cdot \left(\pi \cdot \frac{2}{k}\right)\right)}^{2}\right)}^{0.25}\\
\end{array}
\end{array}
if k < 1.3e181Initial program 99.5%
*-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
div-inv99.5%
expm1-log1p-u96.0%
expm1-udef84.8%
Applied egg-rr71.2%
expm1-def82.0%
expm1-log1p84.0%
associate-*r*84.0%
Simplified84.0%
Taylor expanded in k around 0 42.3%
*-commutative42.3%
Simplified42.3%
sqrt-div57.5%
associate-*r*57.5%
Applied egg-rr57.5%
if 1.3e181 < k Initial program 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
div-inv100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in k around 0 2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in n around 0 2.5%
*-commutative2.5%
associate-/l*2.5%
Simplified2.5%
pow1/22.5%
associate-*r/2.5%
associate-/l*2.5%
metadata-eval2.5%
pow-prod-up2.5%
pow-prod-down11.8%
pow211.8%
associate-/l*11.8%
associate-*r/11.8%
associate-/r/11.8%
Applied egg-rr11.8%
associate-*r*11.8%
*-commutative11.8%
associate-*r/11.8%
associate-*l/11.8%
*-commutative11.8%
Simplified11.8%
Final simplification48.4%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* PI 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.8%
expm1-udef87.8%
Applied egg-rr76.9%
expm1-def85.6%
expm1-log1p87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in k around 0 34.4%
*-commutative34.4%
Simplified34.4%
sqrt-div46.5%
associate-*r*46.5%
Applied egg-rr46.5%
Final simplification46.5%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* 0.5 (/ (/ k PI) n)))))
double code(double k, double n) {
return 1.0 / sqrt((0.5 * ((k / ((double) M_PI)) / n)));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((0.5 * ((k / Math.PI) / n)));
}
def code(k, n): return 1.0 / math.sqrt((0.5 * ((k / math.pi) / n)))
function code(k, n) return Float64(1.0 / sqrt(Float64(0.5 * Float64(Float64(k / pi) / n)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((0.5 * ((k / pi) / n))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(0.5 * N[(N[(k / Pi), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{0.5 \cdot \frac{\frac{k}{\pi}}{n}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.8%
expm1-udef87.8%
Applied egg-rr76.9%
expm1-def85.6%
expm1-log1p87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in k around 0 34.4%
*-commutative34.4%
Simplified34.4%
Taylor expanded in n around 0 34.4%
*-commutative34.4%
associate-/l*34.4%
Simplified34.4%
associate-*r/34.4%
associate-/l*34.4%
clear-num34.4%
sqrt-div34.9%
metadata-eval34.9%
*-un-lft-identity34.9%
associate-*l*34.9%
times-frac34.9%
metadata-eval34.9%
Applied egg-rr34.9%
associate-/r*34.9%
Simplified34.9%
Final simplification34.9%
(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(n * Float64(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 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.8%
expm1-udef87.8%
Applied egg-rr76.9%
expm1-def85.6%
expm1-log1p87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in k around 0 34.4%
*-commutative34.4%
Simplified34.4%
Taylor expanded in n around 0 34.4%
*-commutative34.4%
associate-/l*34.4%
Simplified34.4%
associate-/r/34.4%
Applied egg-rr34.4%
Final simplification34.4%
herbie shell --seed 2023254
(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))))