
(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 (if (<= k 4.1e-56) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 4.1e-56) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} 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.1e-56) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} 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.1e-56: tmp = math.sqrt((2.0 * n)) / math.sqrt((k / math.pi)) 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.1e-56) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); else tmp = sqrt(Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 4.1e-56) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4.1e-56], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.1 \cdot 10^{-56}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.1000000000000001e-56Initial program 98.5%
Taylor expanded in k around 0 67.4%
*-commutative67.4%
associate-/l*67.4%
Simplified67.4%
pow167.4%
sqrt-unprod67.6%
associate-*r/67.6%
*-commutative67.6%
associate-/l*67.6%
Applied egg-rr67.6%
unpow167.6%
*-commutative67.6%
associate-/r/67.6%
Simplified67.6%
associate-*r/67.6%
*-commutative67.6%
sqrt-div99.4%
Applied egg-rr99.4%
if 4.1000000000000001e-56 < k Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
associate-*l*99.4%
div-sub99.4%
metadata-eval99.4%
Simplified99.4%
/-rgt-identity99.4%
clear-num99.4%
inv-pow99.4%
sqrt-pow299.3%
metadata-eval99.3%
Applied egg-rr99.3%
Applied egg-rr99.4%
*-commutative99.4%
associate-*l*99.4%
distribute-lft-in99.4%
metadata-eval99.4%
*-commutative99.4%
associate-*r*99.4%
metadata-eval99.4%
neg-mul-199.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (/ 1.0 (/ (sqrt k) (pow (* 2.0 (* PI n)) (- 0.5 (* k 0.5))))))
double code(double k, double n) {
return 1.0 / (sqrt(k) / pow((2.0 * (((double) M_PI) * n)), (0.5 - (k * 0.5))));
}
public static double code(double k, double n) {
return 1.0 / (Math.sqrt(k) / Math.pow((2.0 * (Math.PI * n)), (0.5 - (k * 0.5))));
}
def code(k, n): return 1.0 / (math.sqrt(k) / math.pow((2.0 * (math.pi * n)), (0.5 - (k * 0.5))))
function code(k, n) return Float64(1.0 / Float64(sqrt(k) / (Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k * 0.5))))) end
function tmp = code(k, n) tmp = 1.0 / (sqrt(k) / ((2.0 * (pi * n)) ^ (0.5 - (k * 0.5)))); end
code[k_, n_] := N[(1.0 / N[(N[Sqrt[k], $MachinePrecision] / N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{k}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - k \cdot 0.5\right)}}}
\end{array}
Initial program 99.0%
associate-/r/99.0%
associate-*r*99.0%
div-sub99.0%
metadata-eval99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* n (* 2.0 PI)) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow((n * (2.0 * ((double) M_PI))), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow((n * (2.0 * Math.PI)), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow((n * (2.0 * math.pi)), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(n * Float64(2.0 * pi)) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * ((n * (2.0 * pi)) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $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}
\\
\frac{1}{\sqrt{k}} \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.0%
Final simplification99.0%
(FPCore (k n) :precision binary64 (if (<= k 2.5e+266) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (cbrt (pow (* n (/ (* 2.0 PI) k)) 1.5))))
double code(double k, double n) {
double tmp;
if (k <= 2.5e+266) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} else {
tmp = cbrt(pow((n * ((2.0 * ((double) M_PI)) / k)), 1.5));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.5e+266) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} else {
tmp = Math.cbrt(Math.pow((n * ((2.0 * Math.PI) / k)), 1.5));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 2.5e+266) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); else tmp = cbrt((Float64(n * Float64(Float64(2.0 * pi) / k)) ^ 1.5)); end return tmp end
code[k_, n_] := If[LessEqual[k, 2.5e+266], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(n * N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.5 \cdot 10^{+266}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(n \cdot \frac{2 \cdot \pi}{k}\right)}^{1.5}}\\
\end{array}
\end{array}
if k < 2.4999999999999999e266Initial program 98.9%
Taylor expanded in k around 0 40.1%
*-commutative40.1%
associate-/l*40.1%
Simplified40.1%
pow140.1%
sqrt-unprod40.2%
associate-*r/40.2%
*-commutative40.2%
associate-/l*40.2%
Applied egg-rr40.2%
unpow140.2%
*-commutative40.2%
associate-/r/40.2%
Simplified40.2%
associate-*r/40.2%
*-commutative40.2%
sqrt-div54.4%
Applied egg-rr54.4%
if 2.4999999999999999e266 < k Initial program 100.0%
Taylor expanded in k around 0 2.6%
*-commutative2.6%
associate-/l*2.6%
Simplified2.6%
sqrt-unprod2.6%
associate-*r/2.6%
*-commutative2.6%
associate-/l*2.6%
Applied egg-rr2.6%
add-cbrt-cube26.5%
pow1/326.5%
add-sqr-sqrt26.5%
pow126.5%
pow1/226.5%
pow-prod-up26.5%
associate-*r*26.5%
*-commutative26.5%
metadata-eval26.5%
Applied egg-rr26.5%
unpow1/326.5%
associate-*r/26.5%
associate-*l/26.5%
*-commutative26.5%
*-commutative26.5%
Simplified26.5%
Final simplification52.2%
(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.0%
associate-*l/99.0%
*-lft-identity99.0%
associate-*l*99.0%
div-sub99.0%
metadata-eval99.0%
Simplified99.0%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((2.0 * n)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.0%
Taylor expanded in k around 0 37.2%
*-commutative37.2%
associate-/l*37.2%
Simplified37.2%
pow137.2%
sqrt-unprod37.3%
associate-*r/37.3%
*-commutative37.3%
associate-/l*37.3%
Applied egg-rr37.3%
unpow137.3%
*-commutative37.3%
associate-/r/37.3%
Simplified37.3%
associate-*r/37.3%
*-commutative37.3%
sqrt-div50.4%
Applied egg-rr50.4%
Final simplification50.4%
(FPCore (k n) :precision binary64 (pow (/ (/ k (* PI n)) 2.0) -0.5))
double code(double k, double n) {
return pow(((k / (((double) M_PI) * n)) / 2.0), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / (Math.PI * n)) / 2.0), -0.5);
}
def code(k, n): return math.pow(((k / (math.pi * n)) / 2.0), -0.5)
function code(k, n) return Float64(Float64(k / Float64(pi * n)) / 2.0) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / (pi * n)) / 2.0) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{\frac{k}{\pi \cdot n}}{2}\right)}^{-0.5}
\end{array}
Initial program 99.0%
Taylor expanded in k around 0 37.2%
*-commutative37.2%
associate-/l*37.2%
Simplified37.2%
pow137.2%
sqrt-unprod37.3%
associate-*r/37.3%
*-commutative37.3%
associate-/l*37.3%
Applied egg-rr37.3%
unpow137.3%
*-commutative37.3%
associate-/r/37.3%
Simplified37.3%
*-commutative37.3%
sqrt-prod37.2%
clear-num37.2%
sqrt-div37.4%
metadata-eval37.4%
associate-/r/37.4%
inv-pow37.4%
sqrt-undiv37.4%
sqrt-pow237.5%
associate-/l/37.5%
metadata-eval37.5%
Applied egg-rr37.5%
Final simplification37.5%
(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.0%
Taylor expanded in k around 0 37.2%
*-commutative37.2%
associate-/l*37.2%
Simplified37.2%
sqrt-unprod37.3%
associate-*r/37.3%
*-commutative37.3%
associate-/l*37.3%
Applied egg-rr37.3%
herbie shell --seed 2024132
(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))))