
(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 10 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 (* PI (* n 2.0)))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (n * 2.0);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (n * 2.0);
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = math.pi * (n * 2.0) return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(pi * Float64(n * 2.0)) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = pi * (n * 2.0); tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(k * N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(n \cdot 2\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k \cdot {t\_0}^{k}}}
\end{array}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-un-lft-identity99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
div-inv99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
pow1/299.6%
pow-unpow99.6%
pow-prod-down99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
Applied egg-rr99.6%
associate-*r/99.7%
*-rgt-identity99.7%
*-commutative99.7%
associate-*r*99.7%
unpow1/299.7%
*-commutative99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* PI (* n 2.0))))
(if (<= k 1.56e-34)
(/ (sqrt t_0) (sqrt k))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (n * 2.0);
double tmp;
if (k <= 1.56e-34) {
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 = Math.PI * (n * 2.0);
double tmp;
if (k <= 1.56e-34) {
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 = math.pi * (n * 2.0) tmp = 0 if k <= 1.56e-34: 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(pi * Float64(n * 2.0)) tmp = 0.0 if (k <= 1.56e-34) 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 = pi * (n * 2.0); tmp = 0.0; if (k <= 1.56e-34) 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[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 1.56e-34], 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 := \pi \cdot \left(n \cdot 2\right)\\
\mathbf{if}\;k \leq 1.56 \cdot 10^{-34}:\\
\;\;\;\;\frac{\sqrt{t\_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t\_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.55999999999999992e-34Initial program 99.3%
Taylor expanded in k around 0 62.0%
associate-/l*62.0%
Simplified62.0%
pow162.0%
sqrt-unprod62.3%
Applied egg-rr62.3%
unpow162.3%
associate-*l*62.3%
Simplified62.3%
Taylor expanded in n around 0 62.4%
*-commutative62.4%
associate-/l*62.3%
Simplified62.3%
associate-*r/62.4%
associate-*r/62.4%
*-commutative62.4%
associate-*l*62.4%
associate-*r/62.3%
sqrt-prod99.4%
*-commutative99.4%
sqrt-div99.2%
associate-*r/99.2%
*-commutative99.2%
sqrt-prod99.5%
associate-*l*99.5%
*-commutative99.5%
Applied egg-rr99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
if 1.55999999999999992e-34 < k Initial program 99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.0%
*-commutative99.0%
associate-*r*99.0%
div-sub99.0%
metadata-eval99.0%
div-inv99.0%
*-commutative99.0%
Applied egg-rr99.0%
Simplified99.1%
Final simplification99.2%
(FPCore (k n) :precision binary64 (if (<= k 5e+56) (/ (sqrt (* PI (* n 2.0))) (sqrt k)) (sqrt (+ 1.0 (fma PI (* n (/ 2.0 k)) -1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 5e+56) {
tmp = sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
} else {
tmp = sqrt((1.0 + fma(((double) M_PI), (n * (2.0 / k)), -1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 5e+56) tmp = Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)); else tmp = sqrt(Float64(1.0 + fma(pi, Float64(n * Float64(2.0 / k)), -1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 5e+56], N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 + N[(Pi * N[(n * N[(2.0 / k), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5 \cdot 10^{+56}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \mathsf{fma}\left(\pi, n \cdot \frac{2}{k}, -1\right)}\\
\end{array}
\end{array}
if k < 5.00000000000000024e56Initial program 99.1%
Taylor expanded in k around 0 54.9%
associate-/l*54.9%
Simplified54.9%
pow154.9%
sqrt-unprod55.1%
Applied egg-rr55.1%
unpow155.1%
associate-*l*55.1%
Simplified55.1%
Taylor expanded in n around 0 55.2%
*-commutative55.2%
associate-/l*55.1%
Simplified55.1%
associate-*r/55.2%
associate-*r/55.2%
*-commutative55.2%
associate-*l*55.2%
associate-*r/55.1%
sqrt-prod84.3%
*-commutative84.3%
sqrt-div84.1%
associate-*r/84.1%
*-commutative84.1%
sqrt-prod84.4%
associate-*l*84.4%
*-commutative84.4%
Applied egg-rr84.4%
*-commutative84.4%
associate-*r*84.4%
*-commutative84.4%
Simplified84.4%
if 5.00000000000000024e56 < k Initial program 100.0%
Taylor expanded in k around 0 2.8%
associate-/l*2.8%
Simplified2.8%
pow12.8%
sqrt-unprod2.8%
Applied egg-rr2.8%
unpow12.8%
associate-*l*2.8%
Simplified2.8%
div-inv2.8%
Applied egg-rr2.8%
*-commutative2.8%
div-inv2.8%
*-commutative2.8%
associate-*r/2.8%
associate-*l/2.8%
associate-*r/2.8%
expm1-log1p-u2.8%
associate-*r*2.8%
expm1-undefine37.4%
*-commutative37.4%
associate-*l*37.4%
Applied egg-rr37.4%
log1p-undefine37.4%
rem-exp-log37.4%
associate-+r-36.5%
fma-neg36.5%
associate-*l/36.5%
associate-/l*36.5%
metadata-eval36.5%
Simplified36.5%
Final simplification64.7%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* n PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (n * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (n * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (n * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (n * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(n * Pi), $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(n \cdot \pi\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%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (* n 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (n * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (n * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
Taylor expanded in n around 0 33.7%
*-commutative33.7%
associate-/l*33.6%
Simplified33.6%
associate-*r/33.7%
associate-*r/33.7%
*-commutative33.7%
associate-*l*33.7%
associate-*r/33.7%
sqrt-prod50.9%
*-commutative50.9%
sqrt-div50.8%
associate-*r/50.8%
*-commutative50.8%
sqrt-prod50.9%
associate-*l*50.9%
*-commutative50.9%
Applied egg-rr50.9%
*-commutative50.9%
associate-*r*50.9%
*-commutative50.9%
Simplified50.9%
Final simplification50.9%
(FPCore (k n) :precision binary64 (* (sqrt (* n 2.0)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((n * 2.0)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((n * 2.0)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((n * 2.0)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(n * 2.0)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((n * 2.0)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
sqrt-prod50.8%
*-commutative50.8%
sqrt-prod33.7%
associate-*r*33.7%
sqrt-prod50.9%
Applied egg-rr50.9%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 (/ PI k))) (sqrt n)))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / k))) * sqrt(n);
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / k))) * Math.sqrt(n);
}
def code(k, n): return math.sqrt((2.0 * (math.pi / k))) * math.sqrt(n)
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(pi / k))) * sqrt(n)) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / k))) * sqrt(n); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{k}} \cdot \sqrt{n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
sqrt-prod50.8%
*-commutative50.8%
sqrt-prod33.7%
*-commutative33.7%
sqrt-prod50.8%
Applied egg-rr50.8%
(FPCore (k n) :precision binary64 (sqrt (/ (* PI (* n 2.0)) k)))
double code(double k, double n) {
return sqrt(((((double) M_PI) * (n * 2.0)) / k));
}
public static double code(double k, double n) {
return Math.sqrt(((Math.PI * (n * 2.0)) / k));
}
def code(k, n): return math.sqrt(((math.pi * (n * 2.0)) / k))
function code(k, n) return sqrt(Float64(Float64(pi * Float64(n * 2.0)) / k)) end
function tmp = code(k, n) tmp = sqrt(((pi * (n * 2.0)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi \cdot \left(n \cdot 2\right)}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
Taylor expanded in n around 0 33.7%
associate-/l*33.7%
associate-*r*33.7%
Simplified33.7%
Final simplification33.7%
(FPCore (k n) :precision binary64 (sqrt (* n (* PI (/ 2.0 k)))))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * (2.0 / k))));
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * (2.0 / k))));
}
def code(k, n): return math.sqrt((n * (math.pi * (2.0 / k))))
function code(k, n) return sqrt(Float64(n * Float64(pi * Float64(2.0 / k)))) end
function tmp = code(k, n) tmp = sqrt((n * (pi * (2.0 / k)))); end
code[k_, n_] := N[Sqrt[N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot \left(\pi \cdot \frac{2}{k}\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
div-inv33.7%
Applied egg-rr33.7%
Taylor expanded in n around 0 33.7%
associate-*r/33.7%
*-commutative33.7%
*-commutative33.7%
associate-*r/33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
(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 33.5%
associate-/l*33.5%
Simplified33.5%
pow133.5%
sqrt-unprod33.7%
Applied egg-rr33.7%
unpow133.7%
associate-*l*33.7%
Simplified33.7%
Taylor expanded in n around 0 33.7%
*-commutative33.7%
associate-/l*33.6%
Simplified33.6%
herbie shell --seed 2024089
(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))))