
(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 (* 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.4%
*-commutative99.4%
div-inv99.5%
div-sub99.5%
pow-sub99.7%
sqrt-pow199.7%
pow199.7%
associate-/l/99.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (let* ((t_0 (* PI (* 2.0 n)))) (* (/ 1.0 (sqrt (* k (pow t_0 k)))) (sqrt t_0))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return (1.0 / sqrt((k * pow(t_0, k)))) * sqrt(t_0);
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return (1.0 / Math.sqrt((k * Math.pow(t_0, k)))) * Math.sqrt(t_0);
}
def code(k, n): t_0 = math.pi * (2.0 * n) return (1.0 / math.sqrt((k * math.pow(t_0, k)))) * math.sqrt(t_0)
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64(Float64(1.0 / sqrt(Float64(k * (t_0 ^ k)))) * sqrt(t_0)) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = (1.0 / sqrt((k * (t_0 ^ k)))) * sqrt(t_0); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[N[(k * N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
\frac{1}{\sqrt{k \cdot {t_0}^{k}}} \cdot \sqrt{t_0}
\end{array}
\end{array}
Initial program 99.4%
*-commutative99.4%
div-inv99.5%
div-sub99.5%
pow-sub99.7%
sqrt-pow199.7%
pow199.7%
associate-/l/99.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
div-inv99.7%
*-commutative99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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(n * Float64(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 * Pi), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI n)) (sqrt (/ k 2.0))))
double code(double k, double n) {
return sqrt((((double) M_PI) * n)) / sqrt((k / 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * n)) / Math.sqrt((k / 2.0));
}
def code(k, n): return math.sqrt((math.pi * n)) / math.sqrt((k / 2.0))
function code(k, n) return Float64(sqrt(Float64(pi * n)) / sqrt(Float64(k / 2.0))) end
function tmp = code(k, n) tmp = sqrt((pi * n)) / sqrt((k / 2.0)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot n}}{\sqrt{\frac{k}{2}}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in k around 0 49.4%
associate-/l*49.3%
div-inv49.3%
*-commutative49.3%
sqrt-undiv49.4%
Applied egg-rr49.4%
associate-*r/49.5%
*-rgt-identity49.5%
*-commutative49.5%
Simplified49.5%
Final simplification49.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (* 2.0 n))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 * n))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (2.0 * n))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in k around 0 49.4%
*-commutative49.4%
sqrt-prod49.5%
*-commutative49.5%
add-sqr-sqrt49.2%
*-un-lft-identity49.2%
times-frac49.3%
pow1/249.3%
*-commutative49.3%
sqrt-pow149.3%
*-commutative49.3%
*-commutative49.3%
associate-*l*49.3%
metadata-eval49.3%
Applied egg-rr49.3%
associate-*r/49.3%
/-rgt-identity49.3%
pow-sqr49.5%
metadata-eval49.5%
unpow1/249.5%
Simplified49.5%
Final simplification49.5%
(FPCore (k n) :precision binary64 (pow (* (/ k n) (/ 0.5 PI)) -0.5))
double code(double k, double n) {
return pow(((k / n) * (0.5 / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / n) * (0.5 / Math.PI)), -0.5);
}
def code(k, n): return math.pow(((k / n) * (0.5 / math.pi)), -0.5)
function code(k, n) return Float64(Float64(k / n) * Float64(0.5 / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / n) * (0.5 / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / n), $MachinePrecision] * N[(0.5 / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{n} \cdot \frac{0.5}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in k around 0 49.4%
expm1-log1p-u46.8%
expm1-udef46.4%
Applied egg-rr37.9%
expm1-def38.3%
expm1-log1p40.0%
Simplified40.0%
Taylor expanded in n around 0 40.0%
*-commutative40.0%
associate-*l/40.0%
*-commutative40.0%
associate-*r*40.0%
sqrt-div49.5%
clear-num49.4%
pow149.4%
pow-flip49.4%
sqrt-undiv40.6%
associate-*r*40.6%
*-commutative40.6%
associate-/l/40.6%
sqrt-pow240.6%
div-inv40.6%
times-frac40.6%
metadata-eval40.6%
Applied egg-rr40.6%
Final simplification40.6%
(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.4%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in k around 0 49.4%
expm1-log1p-u46.8%
expm1-udef46.4%
Applied egg-rr37.9%
expm1-def38.3%
expm1-log1p40.0%
Simplified40.0%
Taylor expanded in n around 0 40.0%
expm1-log1p-u38.3%
expm1-udef37.1%
*-commutative37.1%
associate-/l*37.1%
Applied egg-rr37.1%
expm1-def38.3%
expm1-log1p40.0%
associate-/r/39.6%
*-commutative39.6%
Simplified39.6%
Final simplification39.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(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%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in k around 0 49.4%
expm1-log1p-u46.8%
expm1-udef46.4%
Applied egg-rr37.9%
expm1-def38.3%
expm1-log1p40.0%
Simplified40.0%
Taylor expanded in n around 0 40.0%
associate-/l*40.0%
associate-/r/40.0%
Applied egg-rr40.0%
Final simplification40.0%
herbie shell --seed 2023326
(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))))