
(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 (let* ((t_0 (* PI (* n 2.0)))) (/ (sqrt (/ t_0 (pow t_0 k))) (sqrt k))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (n * 2.0);
return sqrt((t_0 / pow(t_0, k))) / sqrt(k);
}
public static double code(double k, double n) {
double t_0 = Math.PI * (n * 2.0);
return Math.sqrt((t_0 / Math.pow(t_0, k))) / Math.sqrt(k);
}
def code(k, n): t_0 = math.pi * (n * 2.0) return math.sqrt((t_0 / math.pow(t_0, k))) / math.sqrt(k)
function code(k, n) t_0 = Float64(pi * Float64(n * 2.0)) return Float64(sqrt(Float64(t_0 / (t_0 ^ k))) / sqrt(k)) end
function tmp = code(k, n) t_0 = pi * (n * 2.0); tmp = sqrt((t_0 / (t_0 ^ k))) / sqrt(k); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[N[(t$95$0 / N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(n \cdot 2\right)\\
\frac{\sqrt{\frac{t_0}{{t_0}^{k}}}}{\sqrt{k}}
\end{array}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
expm1-log1p-u96.2%
expm1-udef85.6%
Applied egg-rr74.6%
expm1-def85.3%
expm1-log1p87.2%
*-commutative87.2%
associate-*r*87.2%
Simplified87.2%
sqrt-div99.5%
associate-*r*99.5%
sqrt-pow199.5%
*-commutative99.5%
sqrt-pow199.5%
add-sqr-sqrt99.2%
*-un-lft-identity99.2%
times-frac99.3%
Applied egg-rr99.3%
/-rgt-identity99.3%
associate-*r/99.3%
pow-sqr99.5%
metadata-eval99.5%
unpow1/299.5%
associate-*r*99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
pow-sub99.7%
pow199.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (sqrt (pow (* PI (* n 2.0)) (- 1.0 k))) (sqrt k)))
double code(double k, double n) {
return sqrt(pow((((double) M_PI) * (n * 2.0)), (1.0 - k))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt(Math.pow((Math.PI * (n * 2.0)), (1.0 - k))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt(math.pow((math.pi * (n * 2.0)), (1.0 - k))) / math.sqrt(k)
function code(k, n) return Float64(sqrt((Float64(pi * Float64(n * 2.0)) ^ Float64(1.0 - k))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt(((pi * (n * 2.0)) ^ (1.0 - k))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(1 - k\right)}}}{\sqrt{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
expm1-log1p-u96.2%
expm1-udef85.6%
Applied egg-rr74.6%
expm1-def85.3%
expm1-log1p87.2%
*-commutative87.2%
associate-*r*87.2%
Simplified87.2%
sqrt-div99.5%
associate-*r*99.5%
sqrt-pow199.5%
*-commutative99.5%
sqrt-pow199.5%
add-sqr-sqrt99.2%
*-un-lft-identity99.2%
times-frac99.3%
Applied egg-rr99.3%
/-rgt-identity99.3%
associate-*r/99.3%
pow-sqr99.5%
metadata-eval99.5%
unpow1/299.5%
associate-*r*99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* PI (* n 2.0))))
(if (<= k 1.3e-47)
(/ (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.3e-47) {
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.3e-47) {
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.3e-47: 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.3e-47) 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.3e-47) 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.3e-47], 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.3 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{t_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.3e-47Initial program 99.2%
Taylor expanded in k around 0 99.1%
expm1-log1p-u93.1%
expm1-udef76.6%
associate-*l/76.6%
*-un-lft-identity76.6%
sqrt-unprod76.6%
Applied egg-rr76.6%
expm1-def93.2%
expm1-log1p99.4%
associate-*r*99.4%
Simplified99.4%
if 1.3e-47 < k Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.6%
expm1-log1p-u99.2%
expm1-udef94.3%
Applied egg-rr94.3%
expm1-def99.2%
expm1-log1p99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* n (* PI 2.0)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((n * (((double) M_PI) * 2.0)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (Math.PI * 2.0)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (math.pi * 2.0)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(pi * 2.0)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (pi * 2.0)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(n \cdot \left(\pi \cdot 2\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.3%
pow-sqr99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (sqrt (* n 2.0))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * sqrt((n * 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.sqrt((n * 2.0));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.sqrt((n * 2.0))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * sqrt(Float64(n * 2.0))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * sqrt((n * 2.0)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{n \cdot 2}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
add-cube-cbrt98.7%
pow398.7%
Applied egg-rr86.5%
Taylor expanded in k around 0 49.9%
Simplified39.5%
pow-pow42.6%
metadata-eval42.6%
pow-to-exp40.0%
associate-/l*40.0%
*-commutative40.0%
Applied egg-rr40.0%
exp-to-pow42.6%
associate-/r/42.6%
unpow-prod-down54.9%
pow1/254.9%
*-commutative54.9%
Applied egg-rr54.9%
unpow1/254.9%
Simplified54.9%
Final simplification54.9%
(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.4%
Taylor expanded in k around 0 54.7%
expm1-log1p-u51.7%
expm1-udef50.4%
associate-*l/50.4%
*-un-lft-identity50.4%
sqrt-unprod50.4%
Applied egg-rr50.4%
expm1-def51.7%
expm1-log1p54.9%
associate-*r*54.9%
Simplified54.9%
Final simplification54.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.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
add-cube-cbrt98.7%
pow398.7%
Applied egg-rr86.5%
Taylor expanded in k around 0 49.9%
Simplified39.5%
expm1-log1p-u39.7%
expm1-udef39.2%
pow-pow39.4%
associate-/l*39.4%
*-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
expm1-def40.7%
expm1-log1p42.6%
unpow1/242.6%
associate-/r/42.6%
associate-*l/42.6%
*-commutative42.6%
associate-*r*42.6%
associate-*r/42.6%
associate-/l*42.6%
associate-/r/42.6%
Simplified42.6%
Final simplification42.6%
(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(Float64(pi * 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[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi \cdot n}{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
add-cube-cbrt98.7%
pow398.7%
Applied egg-rr86.5%
Taylor expanded in k around 0 49.9%
Simplified39.5%
expm1-log1p-u39.7%
expm1-udef39.2%
pow-pow39.4%
associate-/l*39.4%
*-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
expm1-def40.7%
expm1-log1p42.6%
unpow1/242.6%
associate-/r/42.6%
associate-*l/42.6%
*-commutative42.6%
associate-*r*42.6%
associate-*r/42.6%
associate-/l*42.6%
associate-/r/42.6%
Simplified42.6%
Taylor expanded in n around 0 42.6%
Final simplification42.6%
herbie shell --seed 2023274
(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))))