
(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 (* 2.0 n)))) (* (pow k -0.5) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return pow(k, -0.5) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return Math.pow(k, -0.5) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.pow(k, -0.5) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64((k ^ -0.5) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = (k ^ -0.5) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[k, -0.5], $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 := \pi \cdot \left(2 \cdot n\right)\\
{k}^{-0.5} \cdot \frac{\sqrt{t\_0}}{{t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
pow-div99.7%
pow1/299.7%
associate-*r/99.7%
inv-pow99.7%
sqrt-pow299.7%
metadata-eval99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-/l*99.7%
*-rgt-identity99.7%
associate-*l*99.7%
*-lft-identity99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (let* ((t_0 (* 2.0 (* PI n)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) * n);
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = 2.0 * (Math.PI * n);
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = 2.0 * (math.pi * n) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(2.0 * Float64(pi * n)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = 2.0 * (pi * n); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Sqrt[k], $MachinePrecision] * N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(\pi \cdot n\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k} \cdot {t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-un-lft-identity99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
pow-div99.6%
pow1/299.6%
associate-/l/99.6%
div-inv99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 1.55e+205) (sqrt (* 2.0 (* n (/ PI k)))) (pow (* (pow (* PI (/ n k)) 2.0) 4.0) 0.25)))
double code(double k, double n) {
double tmp;
if (k <= 1.55e+205) {
tmp = sqrt((2.0 * (n * (((double) M_PI) / k))));
} else {
tmp = pow((pow((((double) M_PI) * (n / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.55e+205) {
tmp = Math.sqrt((2.0 * (n * (Math.PI / k))));
} else {
tmp = Math.pow((Math.pow((Math.PI * (n / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.55e+205: tmp = math.sqrt((2.0 * (n * (math.pi / k)))) else: tmp = math.pow((math.pow((math.pi * (n / k)), 2.0) * 4.0), 0.25) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.55e+205) tmp = sqrt(Float64(2.0 * Float64(n * Float64(pi / k)))); else tmp = Float64((Float64(pi * Float64(n / k)) ^ 2.0) * 4.0) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.55e+205) tmp = sqrt((2.0 * (n * (pi / k)))); else tmp = (((pi * (n / k)) ^ 2.0) * 4.0) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.55e+205], N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[(N[Power[N[(Pi * N[(n / k), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 4.0), $MachinePrecision], 0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.55 \cdot 10^{+205}:\\
\;\;\;\;\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(\pi \cdot \frac{n}{k}\right)}^{2} \cdot 4\right)}^{0.25}\\
\end{array}
\end{array}
if k < 1.55000000000000009e205Initial program 99.4%
Taylor expanded in k around 0 48.5%
associate-/l*48.5%
Simplified48.5%
sqrt-unprod48.7%
Applied egg-rr48.7%
if 1.55000000000000009e205 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
pow12.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
unpow12.9%
*-commutative2.9%
associate-*r/2.9%
*-commutative2.9%
associate-/l*2.9%
Simplified2.9%
pow1/22.9%
metadata-eval2.9%
pow-prod-up2.9%
pow-prod-down22.9%
*-commutative22.9%
*-commutative22.9%
swap-sqr22.9%
pow222.9%
associate-*r/22.9%
*-commutative22.9%
associate-/l*22.9%
metadata-eval22.9%
Applied egg-rr22.9%
associate-*r/22.9%
*-commutative22.9%
associate-/l*22.9%
Simplified22.9%
Final simplification44.4%
(FPCore (k n) :precision binary64 (if (<= k 1.7e+218) (sqrt (* 2.0 (* n (/ PI k)))) (cbrt (pow (* PI (* 2.0 (/ n k))) 1.5))))
double code(double k, double n) {
double tmp;
if (k <= 1.7e+218) {
tmp = sqrt((2.0 * (n * (((double) M_PI) / k))));
} else {
tmp = cbrt(pow((((double) M_PI) * (2.0 * (n / k))), 1.5));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.7e+218) {
tmp = Math.sqrt((2.0 * (n * (Math.PI / k))));
} else {
tmp = Math.cbrt(Math.pow((Math.PI * (2.0 * (n / k))), 1.5));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 1.7e+218) tmp = sqrt(Float64(2.0 * Float64(n * Float64(pi / k)))); else tmp = cbrt((Float64(pi * Float64(2.0 * Float64(n / k))) ^ 1.5)); end return tmp end
code[k_, n_] := If[LessEqual[k, 1.7e+218], N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[Power[N[(Pi * N[(2.0 * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.7 \cdot 10^{+218}:\\
\;\;\;\;\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(\pi \cdot \left(2 \cdot \frac{n}{k}\right)\right)}^{1.5}}\\
\end{array}
\end{array}
if k < 1.70000000000000004e218Initial program 99.4%
Taylor expanded in k around 0 46.9%
associate-/l*46.9%
Simplified46.9%
sqrt-unprod47.0%
Applied egg-rr47.0%
if 1.70000000000000004e218 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
pow12.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
unpow12.9%
*-commutative2.9%
associate-*r/2.9%
*-commutative2.9%
associate-/l*2.9%
Simplified2.9%
add-cbrt-cube16.5%
pow1/316.5%
add-sqr-sqrt16.5%
pow116.5%
pow1/216.5%
pow-prod-up16.5%
associate-*r*16.5%
*-commutative16.5%
associate-*l*16.5%
metadata-eval16.5%
Applied egg-rr16.5%
unpow1/316.5%
Simplified16.5%
Final simplification42.9%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* 2.0 (* PI n)) (- 0.5 (* k 0.5)))))
double code(double k, double n) {
return pow(k, -0.5) * pow((2.0 * (((double) M_PI) * n)), (0.5 - (k * 0.5)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((2.0 * (Math.PI * n)), (0.5 - (k * 0.5)));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((2.0 * (math.pi * n)), (0.5 - (k * 0.5)))
function code(k, n) return Float64((k ^ -0.5) * (Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k * 0.5)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((2.0 * (pi * n)) ^ (0.5 - (k * 0.5))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - k \cdot 0.5\right)}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
associate-*l*99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.5%
div-inv99.5%
metadata-eval99.5%
inv-pow99.5%
sqrt-pow299.5%
metadata-eval99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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.5%
*-lft-identity99.5%
associate-*l*99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k)))
double code(double k, double n) {
return sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) / k));
}
def code(k, n): return math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) / k))
function code(k, n) return sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) / k)) end
function tmp = code(k, n) tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
sqrt-unprod88.9%
*-commutative88.9%
associate-*r*88.9%
div-sub88.9%
metadata-eval88.9%
div-inv88.9%
*-commutative88.9%
Applied egg-rr89.0%
Simplified89.0%
Final simplification89.0%
(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 40.8%
associate-/l*40.8%
Simplified40.8%
pow140.8%
sqrt-unprod41.0%
Applied egg-rr41.0%
unpow141.0%
*-commutative41.0%
associate-*r/40.9%
*-commutative40.9%
associate-/l*40.9%
Simplified40.9%
Final simplification40.9%
(FPCore (k n) :precision binary64 (sqrt (* PI (* 2.0 (/ n k)))))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 * (n / k))));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 * (n / k))));
}
def code(k, n): return math.sqrt((math.pi * (2.0 * (n / k))))
function code(k, n) return sqrt(Float64(pi * Float64(2.0 * Float64(n / k)))) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 * (n / k)))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(2.0 * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \left(2 \cdot \frac{n}{k}\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 40.8%
associate-/l*40.8%
Simplified40.8%
pow140.8%
sqrt-unprod41.0%
Applied egg-rr41.0%
unpow141.0%
*-commutative41.0%
associate-*r/40.9%
*-commutative40.9%
associate-/l*40.9%
Simplified40.9%
*-un-lft-identity40.9%
*-commutative40.9%
associate-*r*40.9%
*-commutative40.9%
associate-*l*40.9%
Applied egg-rr40.9%
*-rgt-identity40.9%
Simplified40.9%
Final simplification40.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.5%
Taylor expanded in k around 0 40.8%
associate-/l*40.8%
Simplified40.8%
sqrt-unprod41.0%
Applied egg-rr41.0%
Final simplification41.0%
herbie shell --seed 2024095
(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))))