
(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 9 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 5.3e-83) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 5.3e-83) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} else {
tmp = sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 5.3e-83) {
tmp = Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 5.3e-83: tmp = math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k) else: tmp = math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 5.3e-83) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); else tmp = sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 5.3e-83) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 5.3e-83], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5.3 \cdot 10^{-83}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 5.3e-83Initial program 99.3%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.1%
pow-sqr99.4%
associate-*l*99.4%
*-commutative99.4%
associate-*l/99.4%
associate-/l*99.4%
metadata-eval99.4%
/-rgt-identity99.4%
div-sub99.4%
metadata-eval99.4%
Simplified99.4%
div-inv99.3%
div-inv99.3%
metadata-eval99.3%
pow1/299.3%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
*-commutative99.4%
associate-*l*99.4%
pow-div99.4%
pow1/299.4%
pow-unpow99.4%
unpow1/299.4%
sqrt-div99.4%
pow199.4%
pow-div99.4%
*-commutative99.4%
metadata-eval99.4%
pow-pow99.1%
add-sqr-sqrt98.8%
sqrt-unprod99.1%
pow-pow99.3%
metadata-eval99.3%
pow-pow99.4%
Applied egg-rr99.4%
Taylor expanded in k around 0 99.4%
*-commutative99.4%
associate-*l*99.4%
*-commutative99.4%
Simplified99.4%
if 5.3e-83 < k Initial program 99.8%
add-sqr-sqrt99.7%
sqrt-unprod99.8%
*-commutative99.8%
div-inv99.8%
*-commutative99.8%
div-inv99.8%
frac-times99.8%
Applied egg-rr99.8%
Simplified99.9%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (sqrt (pow (* PI (* 2.0 n)) (- 1.0 k))) (sqrt k)))
double code(double k, double n) {
return sqrt(pow((((double) M_PI) * (2.0 * n)), (1.0 - k))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt(Math.pow((Math.PI * (2.0 * n)), (1.0 - k))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt(math.pow((math.pi * (2.0 * n)), (1.0 - k))) / math.sqrt(k)
function code(k, n) return Float64(sqrt((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt(((pi * (2.0 * n)) ^ (1.0 - k))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
sqr-pow99.5%
pow-sqr99.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l/99.7%
associate-/l*99.7%
metadata-eval99.7%
/-rgt-identity99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
div-inv99.6%
div-inv99.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*l*99.6%
pow-div99.3%
pow1/299.3%
pow-unpow99.3%
unpow1/299.3%
sqrt-div99.3%
pow199.3%
pow-div99.6%
*-commutative99.6%
metadata-eval99.6%
pow-pow99.5%
add-sqr-sqrt99.3%
sqrt-unprod99.5%
pow-pow99.6%
metadata-eval99.6%
pow-pow99.6%
Applied egg-rr99.7%
Final simplification99.7%
(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.6%
associate-*l/99.7%
*-lft-identity99.7%
sqr-pow99.5%
pow-sqr99.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l/99.7%
associate-/l*99.7%
metadata-eval99.7%
/-rgt-identity99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(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.6%
add-sqr-sqrt99.3%
sqrt-unprod87.2%
*-commutative87.2%
div-inv87.2%
*-commutative87.2%
div-inv87.3%
frac-times87.2%
Applied egg-rr87.2%
Simplified87.4%
Taylor expanded in k around 0 37.1%
*-commutative37.1%
associate-/l*37.1%
Simplified37.1%
Taylor expanded in k around 0 37.1%
associate-/l*37.1%
associate-/r/37.1%
Simplified37.1%
associate-*r*37.1%
associate-*r/37.1%
*-commutative37.1%
associate-/r/37.1%
associate-*r/37.0%
*-commutative37.0%
sqrt-prod49.4%
div-inv49.4%
clear-num49.4%
Applied egg-rr49.4%
Final simplification49.4%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* PI 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
sqr-pow99.5%
pow-sqr99.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l/99.7%
associate-/l*99.7%
metadata-eval99.7%
/-rgt-identity99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
div-inv99.6%
div-inv99.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*l*99.6%
pow-div99.3%
pow1/299.3%
pow-unpow99.3%
unpow1/299.3%
sqrt-div99.3%
pow199.3%
pow-div99.6%
*-commutative99.6%
metadata-eval99.6%
pow-pow99.5%
add-sqr-sqrt99.3%
sqrt-unprod99.5%
pow-pow99.6%
metadata-eval99.6%
pow-pow99.6%
Applied egg-rr99.7%
Taylor expanded in k around 0 49.4%
*-commutative49.4%
associate-*l*49.4%
*-commutative49.4%
Simplified49.4%
Final simplification49.4%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* 2.0 (* PI n))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (2.0 * (((double) M_PI) * n))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (2.0 * (Math.PI * n))));
}
def code(k, n): return 1.0 / math.sqrt((k / (2.0 * (math.pi * n))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(2.0 * Float64(pi * n))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (2.0 * (pi * n)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{2 \cdot \left(\pi \cdot n\right)}}}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.3%
sqrt-unprod87.2%
*-commutative87.2%
div-inv87.2%
*-commutative87.2%
div-inv87.3%
frac-times87.2%
Applied egg-rr87.2%
Simplified87.4%
Taylor expanded in k around 0 37.1%
*-commutative37.1%
associate-/l*37.1%
Simplified37.1%
Taylor expanded in k around 0 37.1%
associate-/l*37.1%
associate-/r/37.1%
Simplified37.1%
*-commutative37.1%
associate-*l/37.1%
associate-*l/37.1%
sqrt-undiv49.4%
sqrt-unprod49.4%
clear-num49.3%
sqrt-unprod49.4%
sqrt-undiv37.5%
*-commutative37.5%
*-commutative37.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.6%
add-sqr-sqrt99.3%
sqrt-unprod87.2%
*-commutative87.2%
div-inv87.2%
*-commutative87.2%
div-inv87.3%
frac-times87.2%
Applied egg-rr87.2%
Simplified87.4%
Taylor expanded in k around 0 37.1%
*-commutative37.1%
associate-/l*37.1%
Simplified37.1%
Taylor expanded in k around 0 37.1%
associate-/l*37.1%
associate-/r/37.1%
Simplified37.1%
Final simplification37.1%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ n (/ k PI)))))
double code(double k, double n) {
return sqrt((2.0 * (n / (k / ((double) M_PI)))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n / (k / Math.PI))));
}
def code(k, n): return math.sqrt((2.0 * (n / (k / math.pi))))
function code(k, n) return sqrt(Float64(2.0 * Float64(n / Float64(k / pi)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n / (k / pi)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(n / N[(k / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{n}{\frac{k}{\pi}}}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.3%
sqrt-unprod87.2%
*-commutative87.2%
div-inv87.2%
*-commutative87.2%
div-inv87.3%
frac-times87.2%
Applied egg-rr87.2%
Simplified87.4%
Taylor expanded in k around 0 37.1%
*-commutative37.1%
associate-/l*37.1%
Simplified37.1%
Taylor expanded in k around 0 37.1%
associate-/l*37.1%
associate-/r/37.1%
Simplified37.1%
associate-*l/37.1%
associate-/l*37.1%
Applied egg-rr37.1%
Final simplification37.1%
(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.6%
add-sqr-sqrt99.3%
sqrt-unprod87.2%
*-commutative87.2%
div-inv87.2%
*-commutative87.2%
div-inv87.3%
frac-times87.2%
Applied egg-rr87.2%
Simplified87.4%
Taylor expanded in k around 0 37.1%
Final simplification37.1%
herbie shell --seed 2023313
(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))))