
(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 (/ (pow (* 2.0 (* PI n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (((double) M_PI) * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (Math.PI * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (math.pi * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (pi * n)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
(FPCore (k n) :precision binary64 (if (<= k 5.2e+39) (* (sqrt (/ PI k)) (sqrt (* 2.0 n))) (sqrt (* 2.0 (+ -1.0 (fma n (/ PI k) 1.0))))))
double code(double k, double n) {
double tmp;
if (k <= 5.2e+39) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
} else {
tmp = sqrt((2.0 * (-1.0 + fma(n, (((double) M_PI) / k), 1.0))));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 5.2e+39) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))); else tmp = sqrt(Float64(2.0 * Float64(-1.0 + fma(n, Float64(pi / k), 1.0)))); end return tmp end
code[k_, n_] := If[LessEqual[k, 5.2e+39], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(2.0 * N[(-1.0 + N[(n * N[(Pi / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5.2 \cdot 10^{+39}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot \left(-1 + \mathsf{fma}\left(n, \frac{\pi}{k}, 1\right)\right)}\\
\end{array}
\end{array}
if k < 5.2e39Initial program 99.0%
Taylor expanded in k around 0 66.5%
associate-/l*66.5%
Simplified66.5%
sqrt-unprod66.7%
*-commutative66.7%
associate-*l*66.7%
Applied egg-rr66.7%
sqrt-prod85.8%
Applied egg-rr85.8%
if 5.2e39 < k Initial program 100.0%
Taylor expanded in k around 0 2.5%
associate-/l*2.5%
Simplified2.5%
sqrt-unprod2.5%
*-commutative2.5%
associate-*l*2.5%
Applied egg-rr2.5%
Taylor expanded in k around 0 2.5%
*-commutative2.5%
associate-/l*2.5%
associate-*r*2.5%
*-commutative2.5%
*-commutative2.5%
associate-*l*2.5%
Simplified2.5%
expm1-log1p-u2.5%
expm1-undefine25.9%
*-commutative25.9%
Applied egg-rr25.9%
sub-neg25.9%
metadata-eval25.9%
+-commutative25.9%
log1p-undefine25.9%
rem-exp-log25.9%
+-commutative25.9%
fma-define25.9%
Simplified25.9%
Final simplification58.0%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (sqrt (* 2.0 n))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.sqrt((2.0 * n));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.sqrt((2.0 * n))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * sqrt((2.0 * n)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
sqrt-prod47.2%
Applied egg-rr47.2%
Final simplification47.2%
(FPCore (k n) :precision binary64 (* (sqrt (/ 2.0 k)) (sqrt (* PI n))))
double code(double k, double n) {
return sqrt((2.0 / k)) * sqrt((((double) M_PI) * n));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 / k)) * Math.sqrt((Math.PI * n));
}
def code(k, n): return math.sqrt((2.0 / k)) * math.sqrt((math.pi * n))
function code(k, n) return Float64(sqrt(Float64(2.0 / k)) * sqrt(Float64(pi * n))) end
function tmp = code(k, n) tmp = sqrt((2.0 / k)) * sqrt((pi * n)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2}{k}} \cdot \sqrt{\pi \cdot n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.9%
associate-*r*36.5%
*-commutative36.5%
*-commutative36.5%
associate-*l*36.9%
Simplified36.9%
sqrt-prod36.8%
associate-*l/36.8%
clear-num36.8%
sqrt-prod36.8%
div-inv36.8%
associate-/r/36.8%
sqrt-prod47.0%
Applied egg-rr47.0%
(FPCore (k n) :precision binary64 (pow (* (/ k n) (/ 0.5 PI)) -0.5))
double code(double k, double n) {
return pow(((k / n) * (0.5 / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / n) * (0.5 / Math.PI)), -0.5);
}
def code(k, n): return math.pow(((k / n) * (0.5 / math.pi)), -0.5)
function code(k, n) return Float64(Float64(k / n) * Float64(0.5 / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / n) * (0.5 / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / n), $MachinePrecision] * N[(0.5 / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{n} \cdot \frac{0.5}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.9%
associate-*r*36.5%
*-commutative36.5%
*-commutative36.5%
associate-*l*36.9%
Simplified36.9%
metadata-eval36.9%
associate-*l/36.9%
times-frac36.8%
*-commutative36.8%
*-un-lft-identity36.8%
clear-num36.8%
metadata-eval36.8%
*-commutative36.8%
add-sqr-sqrt36.8%
frac-times36.8%
sqrt-unprod37.2%
add-sqr-sqrt37.3%
pow1/237.3%
pow-flip37.4%
times-frac37.4%
metadata-eval37.4%
Applied egg-rr37.4%
(FPCore (k n) :precision binary64 (pow (* k (/ 0.5 (* PI n))) -0.5))
double code(double k, double n) {
return pow((k * (0.5 / (((double) M_PI) * n))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * (0.5 / (Math.PI * n))), -0.5);
}
def code(k, n): return math.pow((k * (0.5 / (math.pi * n))), -0.5)
function code(k, n) return Float64(k * Float64(0.5 / Float64(pi * n))) ^ -0.5 end
function tmp = code(k, n) tmp = (k * (0.5 / (pi * n))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[(0.5 / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot \frac{0.5}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.9%
associate-*r*36.5%
*-commutative36.5%
*-commutative36.5%
associate-*l*36.9%
Simplified36.9%
metadata-eval36.9%
associate-*l/36.9%
times-frac36.8%
*-commutative36.8%
*-un-lft-identity36.8%
clear-num36.8%
metadata-eval36.8%
*-commutative36.8%
add-sqr-sqrt36.8%
frac-times36.8%
sqrt-unprod37.2%
add-sqr-sqrt37.3%
pow1/237.3%
pow-flip37.4%
times-frac37.4%
metadata-eval37.4%
Applied egg-rr37.4%
associate-*l/37.4%
associate-*r/37.4%
associate-/l/37.4%
Simplified37.4%
Final simplification37.4%
(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.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.9%
associate-*r*36.5%
*-commutative36.5%
*-commutative36.5%
associate-*l*36.9%
Simplified36.9%
Final simplification36.9%
(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.5%
Taylor expanded in k around 0 36.8%
associate-/l*36.8%
Simplified36.8%
sqrt-unprod36.9%
*-commutative36.9%
associate-*l*36.9%
Applied egg-rr36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.9%
associate-*r*36.5%
*-commutative36.5%
*-commutative36.5%
associate-*l*36.9%
Simplified36.9%
Taylor expanded in k around 0 36.9%
*-commutative36.9%
associate-/l*36.8%
Simplified36.8%
herbie shell --seed 2024137
(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))))