
(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 7 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 4.1e-16) (* (sqrt (/ PI k)) (sqrt (* 2.0 n))) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 4.1e-16) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
} 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 <= 4.1e-16) {
tmp = Math.sqrt((Math.PI / k)) * Math.sqrt((2.0 * n));
} 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 <= 4.1e-16: tmp = math.sqrt((math.pi / k)) * math.sqrt((2.0 * n)) 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 <= 4.1e-16) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))); 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 <= 4.1e-16) tmp = sqrt((pi / k)) * sqrt((2.0 * n)); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4.1e-16], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $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 4.1 \cdot 10^{-16}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.10000000000000006e-16Initial program 98.8%
add-sqr-sqrt98.2%
sqrt-unprod77.9%
*-commutative77.9%
associate-*r*77.9%
div-sub77.9%
metadata-eval77.9%
div-inv77.9%
*-commutative77.9%
Applied egg-rr78.0%
Simplified78.1%
Taylor expanded in k around 0 78.1%
associate-*r/78.1%
Simplified78.1%
pow1/278.1%
associate-*r*78.1%
unpow-prod-down99.3%
pow1/299.4%
Applied egg-rr99.4%
*-commutative99.4%
unpow1/299.4%
*-commutative99.4%
Simplified99.4%
if 4.10000000000000006e-16 < k Initial program 99.8%
associate-*l/99.8%
*-lft-identity99.8%
associate-*l*99.8%
div-sub99.8%
metadata-eval99.8%
Simplified99.8%
div-inv99.8%
metadata-eval99.8%
div-sub99.8%
sqr-pow99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
associate-/l*99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
pow-sqr99.8%
associate-*r*99.8%
*-commutative99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
Simplified99.8%
add-sqr-sqrt99.8%
sqrt-unprod99.8%
swap-sqr99.8%
pow-unpow99.8%
pow1/299.8%
pow-unpow99.8%
pow1/299.8%
pow-prod-down99.8%
add-sqr-sqrt99.8%
pow-prod-up99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 5e+68) (* (sqrt (/ PI k)) (sqrt (* 2.0 n))) (sqrt (+ -1.0 (fma n (* PI (/ 2.0 k)) 1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 5e+68) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
} else {
tmp = sqrt((-1.0 + fma(n, (((double) M_PI) * (2.0 / k)), 1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 5e+68) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))); else tmp = sqrt(Float64(-1.0 + fma(n, Float64(pi * Float64(2.0 / k)), 1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 5e+68], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5 \cdot 10^{+68}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-1 + \mathsf{fma}\left(n, \pi \cdot \frac{2}{k}, 1\right)}\\
\end{array}
\end{array}
if k < 5.0000000000000004e68Initial program 98.8%
add-sqr-sqrt98.4%
sqrt-unprod81.0%
*-commutative81.0%
associate-*r*81.0%
div-sub81.0%
metadata-eval81.0%
div-inv81.0%
*-commutative81.0%
Applied egg-rr81.1%
Simplified68.0%
Taylor expanded in k around 0 68.2%
associate-*r/68.2%
Simplified68.2%
pow1/268.2%
associate-*r*68.2%
unpow-prod-down86.3%
pow1/286.3%
Applied egg-rr86.3%
*-commutative86.3%
unpow1/286.3%
*-commutative86.3%
Simplified86.3%
if 5.0000000000000004e68 < k Initial program 100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
*-commutative100.0%
associate-*r*100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
*-commutative100.0%
Applied egg-rr100.0%
Simplified1.6%
Taylor expanded in k around 0 2.7%
associate-*r/2.7%
Simplified2.7%
expm1-log1p-u2.7%
expm1-undefine32.5%
Applied egg-rr32.5%
sub-neg32.5%
metadata-eval32.5%
+-commutative32.5%
log1p-undefine32.5%
rem-exp-log32.5%
+-commutative32.5%
associate-*r/32.5%
associate-*l/32.5%
associate-/r/32.5%
associate-/l*32.5%
*-commutative32.5%
associate-/l*32.5%
fma-define32.5%
associate-/r/32.5%
Simplified32.5%
Final simplification66.8%
(FPCore (k n) :precision binary64 (if (<= k 4.8e+68) (* (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 <= 4.8e+68) {
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 <= 4.8e+68) 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, 4.8e+68], 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 4.8 \cdot 10^{+68}:\\
\;\;\;\;\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 < 4.80000000000000016e68Initial program 98.8%
add-sqr-sqrt98.4%
sqrt-unprod81.0%
*-commutative81.0%
associate-*r*81.0%
div-sub81.0%
metadata-eval81.0%
div-inv81.0%
*-commutative81.0%
Applied egg-rr81.1%
Simplified68.0%
Taylor expanded in k around 0 68.2%
associate-*r/68.2%
Simplified68.2%
pow1/268.2%
associate-*r*68.2%
unpow-prod-down86.3%
pow1/286.3%
Applied egg-rr86.3%
*-commutative86.3%
unpow1/286.3%
*-commutative86.3%
Simplified86.3%
if 4.80000000000000016e68 < k Initial program 100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
*-commutative100.0%
associate-*r*100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
*-commutative100.0%
Applied egg-rr100.0%
Simplified1.6%
Taylor expanded in k around 0 2.7%
associate-*r/2.7%
Simplified2.7%
clear-num2.7%
un-div-inv2.7%
Applied egg-rr2.7%
expm1-log1p-u2.7%
expm1-undefine32.5%
div-inv32.5%
clear-num32.5%
Applied egg-rr32.5%
sub-neg32.5%
metadata-eval32.5%
+-commutative32.5%
log1p-undefine32.5%
rem-exp-log32.5%
+-commutative32.5%
fma-define32.5%
Simplified32.5%
Final simplification66.8%
(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.2%
associate-*l/99.3%
*-lft-identity99.3%
associate-*l*99.3%
div-sub99.3%
metadata-eval99.3%
Simplified99.3%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 (/ PI k))) (pow n (+ 0.5 (* k -0.5)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / k))) * pow(n, (0.5 + (k * -0.5)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / k))) * Math.pow(n, (0.5 + (k * -0.5)));
}
def code(k, n): return math.sqrt((2.0 * (math.pi / k))) * math.pow(n, (0.5 + (k * -0.5)))
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(pi / k))) * (n ^ Float64(0.5 + Float64(k * -0.5)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / k))) * (n ^ (0.5 + (k * -0.5))); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[n, N[(0.5 + N[(k * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{k}} \cdot {n}^{\left(0.5 + k \cdot -0.5\right)}
\end{array}
Initial program 99.2%
associate-*l/99.3%
*-lft-identity99.3%
associate-*l*99.3%
div-sub99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r*99.3%
metadata-eval99.3%
div-sub99.3%
unpow-prod-down75.9%
associate-/l*75.9%
div-sub75.9%
metadata-eval75.9%
div-inv75.9%
metadata-eval75.9%
div-sub75.9%
metadata-eval75.9%
div-inv75.9%
metadata-eval75.9%
Applied egg-rr75.9%
clear-num75.9%
un-div-inv76.0%
*-commutative76.0%
*-commutative76.0%
Applied egg-rr76.0%
associate-/r/75.9%
cancel-sign-sub-inv75.9%
metadata-eval75.9%
*-commutative75.9%
cancel-sign-sub-inv75.9%
metadata-eval75.9%
*-commutative75.9%
Simplified75.9%
Taylor expanded in k around 0 99.0%
pow199.0%
sqrt-unprod99.1%
Applied egg-rr99.1%
unpow199.1%
Simplified99.1%
Final simplification99.1%
(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.2%
add-sqr-sqrt99.0%
sqrt-unprod87.9%
*-commutative87.9%
associate-*r*87.9%
div-sub87.9%
metadata-eval87.9%
div-inv87.9%
*-commutative87.9%
Applied egg-rr88.0%
Simplified43.9%
Taylor expanded in k around 0 44.4%
associate-*r/44.4%
Simplified44.4%
pow1/244.4%
associate-*r*44.4%
unpow-prod-down56.0%
pow1/256.0%
Applied egg-rr56.0%
*-commutative56.0%
unpow1/256.0%
*-commutative56.0%
Simplified56.0%
Final simplification56.0%
(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.2%
add-sqr-sqrt99.0%
sqrt-unprod87.9%
*-commutative87.9%
associate-*r*87.9%
div-sub87.9%
metadata-eval87.9%
div-inv87.9%
*-commutative87.9%
Applied egg-rr88.0%
Simplified43.9%
Taylor expanded in k around 0 44.4%
associate-*r/44.4%
Simplified44.4%
herbie shell --seed 2024114
(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))))