
(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 (let* ((t_0 (* (* n 2.0) PI))) (* (/ 1.0 (sqrt k)) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (n * 2.0) * ((double) M_PI);
return (1.0 / sqrt(k)) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (n * 2.0) * Math.PI;
return (1.0 / Math.sqrt(k)) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (n * 2.0) * math.pi return (1.0 / math.sqrt(k)) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(n * 2.0) * pi) return Float64(Float64(1.0 / sqrt(k)) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (n * 2.0) * pi; tmp = (1.0 / sqrt(k)) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(n \cdot 2\right) \cdot \pi\\
\frac{1}{\sqrt{k}} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.3%
div-sub99.3%
metadata-eval99.3%
pow-sub99.6%
pow1/299.6%
associate-*l*99.6%
associate-*l*99.6%
div-inv99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* n (* 2.0 PI)) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return pow(k, -0.5) * pow((n * (2.0 * ((double) M_PI))), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((n * (2.0 * Math.PI)), ((1.0 - k) / 2.0));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((n * (2.0 * math.pi)), ((1.0 - k) / 2.0))
function code(k, n) return Float64((k ^ -0.5) * (Float64(n * Float64(2.0 * pi)) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((n * (2.0 * pi)) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.3%
expm1-log1p-u95.9%
expm1-udef76.0%
pow1/276.0%
pow-flip76.0%
metadata-eval76.0%
Applied egg-rr76.0%
expm1-def95.9%
expm1-log1p99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (if (<= k 4.3e-100) (/ (sqrt (* n (* 2.0 PI))) (sqrt k)) (sqrt (/ (pow (* (* n 2.0) PI) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 4.3e-100) {
tmp = sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
} 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.3e-100) {
tmp = Math.sqrt((n * (2.0 * Math.PI))) / Math.sqrt(k);
} 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.3e-100: tmp = math.sqrt((n * (2.0 * math.pi))) / math.sqrt(k) 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.3e-100) tmp = Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)); else tmp = sqrt(Float64((Float64(Float64(n * 2.0) * pi) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 4.3e-100) tmp = sqrt((n * (2.0 * pi))) / sqrt(k); else tmp = sqrt(((((n * 2.0) * pi) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4.3e-100], N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.3 \cdot 10^{-100}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.29999999999999998e-100Initial program 99.2%
*-commutative99.2%
*-commutative99.2%
associate-*r*99.2%
div-inv99.4%
expm1-log1p-u93.1%
expm1-udef74.2%
Applied egg-rr43.7%
expm1-def62.6%
expm1-log1p65.4%
*-commutative65.4%
associate-*r*65.4%
*-commutative65.4%
Simplified65.4%
add-exp-log60.9%
associate-*l*60.9%
*-commutative60.9%
associate-*r*60.9%
add-exp-log60.9%
log-pow60.9%
add-log-exp60.9%
associate-*r*60.9%
*-commutative60.9%
associate-*l*60.9%
*-commutative60.9%
*-commutative60.9%
*-commutative60.9%
Applied egg-rr60.9%
Taylor expanded in k around 0 65.4%
*-commutative65.4%
Simplified65.4%
sqrt-div99.4%
Applied egg-rr99.4%
associate-*r*99.4%
Simplified99.4%
if 4.29999999999999998e-100 < k Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.3%
expm1-log1p-u98.6%
expm1-udef84.5%
Applied egg-rr84.5%
expm1-def98.6%
expm1-log1p99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.4%
(FPCore (k n) :precision binary64 (/ (pow (* (* n 2.0) PI) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow(((n * 2.0) * ((double) M_PI)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow(((n * 2.0) * Math.PI), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow(((n * 2.0) * math.pi), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(Float64(n * 2.0) * pi) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = (((n * 2.0) * pi) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.3%
associate-*l/99.4%
*-lft-identity99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (sqrt (* n (* 2.0 PI)))))
double code(double k, double n) {
return pow(k, -0.5) * sqrt((n * (2.0 * ((double) M_PI))));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.sqrt((n * (2.0 * Math.PI)));
}
def code(k, n): return math.pow(k, -0.5) * math.sqrt((n * (2.0 * math.pi)))
function code(k, n) return Float64((k ^ -0.5) * sqrt(Float64(n * Float64(2.0 * pi)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * sqrt((n * (2.0 * pi))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot \sqrt{n \cdot \left(2 \cdot \pi\right)}
\end{array}
Initial program 99.3%
expm1-log1p-u95.9%
expm1-udef76.0%
pow1/276.0%
pow-flip76.0%
metadata-eval76.0%
Applied egg-rr76.0%
expm1-def95.9%
expm1-log1p99.4%
Simplified99.4%
Taylor expanded in k around 0 52.1%
*-commutative52.1%
sqrt-prod52.1%
expm1-log1p-u50.5%
expm1-udef25.1%
Applied egg-rr25.1%
expm1-def50.5%
expm1-log1p52.1%
associate-*r*52.1%
Simplified52.1%
Final simplification52.1%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* 2.0 PI))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (2.0 * Math.PI))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (2.0 * math.pi))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (2.0 * pi))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}
\end{array}
Initial program 99.3%
*-commutative99.3%
*-commutative99.3%
associate-*r*99.3%
div-inv99.4%
expm1-log1p-u96.8%
expm1-udef81.1%
Applied egg-rr70.9%
expm1-def86.7%
expm1-log1p88.1%
*-commutative88.1%
associate-*r*88.1%
*-commutative88.1%
Simplified88.1%
add-exp-log85.5%
associate-*l*85.5%
*-commutative85.5%
associate-*r*85.5%
add-exp-log85.5%
log-pow85.5%
add-log-exp85.5%
associate-*r*85.5%
*-commutative85.5%
associate-*l*85.5%
*-commutative85.5%
*-commutative85.5%
*-commutative85.5%
Applied egg-rr85.5%
Taylor expanded in k around 0 40.8%
*-commutative40.8%
Simplified40.8%
sqrt-div52.1%
Applied egg-rr52.1%
associate-*r*52.1%
Simplified52.1%
Final simplification52.1%
(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.3%
*-commutative99.3%
*-commutative99.3%
associate-*r*99.3%
div-inv99.4%
expm1-log1p-u96.8%
expm1-udef81.1%
Applied egg-rr70.9%
expm1-def86.7%
expm1-log1p88.1%
*-commutative88.1%
associate-*r*88.1%
*-commutative88.1%
Simplified88.1%
add-exp-log85.5%
associate-*l*85.5%
*-commutative85.5%
associate-*r*85.5%
add-exp-log85.5%
log-pow85.5%
add-log-exp85.5%
associate-*r*85.5%
*-commutative85.5%
associate-*l*85.5%
*-commutative85.5%
*-commutative85.5%
*-commutative85.5%
Applied egg-rr85.5%
Taylor expanded in k around 0 40.8%
*-commutative40.8%
Simplified40.8%
Taylor expanded in n around 0 40.8%
associate-/l*40.7%
associate-/r/40.8%
Simplified40.8%
Final simplification40.8%
herbie shell --seed 2023192
(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))))