
(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 (if (<= k 1.6e-46) (/ (sqrt (* PI (* n 2.0))) (sqrt k)) (sqrt (/ (pow (* n (* PI 2.0)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.6e-46) {
tmp = sqrt((((double) M_PI) * (n * 2.0))) / sqrt(k);
} else {
tmp = sqrt((pow((n * (((double) M_PI) * 2.0)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.6e-46) {
tmp = Math.sqrt((Math.PI * (n * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow((n * (Math.PI * 2.0)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.6e-46: tmp = math.sqrt((math.pi * (n * 2.0))) / math.sqrt(k) else: tmp = math.sqrt((math.pow((n * (math.pi * 2.0)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.6e-46) tmp = Float64(sqrt(Float64(pi * Float64(n * 2.0))) / sqrt(k)); else tmp = sqrt(Float64((Float64(n * Float64(pi * 2.0)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.6e-46) tmp = sqrt((pi * (n * 2.0))) / sqrt(k); else tmp = sqrt((((n * (pi * 2.0)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.6e-46], N[(N[Sqrt[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.6 \cdot 10^{-46}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(n \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(\pi \cdot 2\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.6e-46Initial program 99.2%
Taylor expanded in k around 0 99.0%
associate-*l/99.3%
*-un-lft-identity99.3%
*-commutative99.3%
*-commutative99.3%
sqrt-prod99.5%
clear-num99.4%
Applied egg-rr99.4%
associate-/l*99.5%
*-lft-identity99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
if 1.6e-46 < k Initial program 99.7%
Taylor expanded in n around 0 98.8%
associate-*r*98.8%
exp-prod98.9%
+-commutative98.9%
log-prod98.9%
associate-*r*98.9%
*-commutative98.9%
*-commutative98.9%
*-commutative98.9%
exp-to-pow99.7%
unpow1/299.7%
Simplified99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.7%
associate-*l/99.7%
*-un-lft-identity99.7%
associate-*l/99.7%
*-un-lft-identity99.7%
frac-times99.7%
Applied egg-rr99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (pow (sqrt (* n (* PI 2.0))) (- 1.0 k)) (sqrt k)))
double code(double k, double n) {
return pow(sqrt((n * (((double) M_PI) * 2.0))), (1.0 - k)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow(Math.sqrt((n * (Math.PI * 2.0))), (1.0 - k)) / Math.sqrt(k);
}
def code(k, n): return math.pow(math.sqrt((n * (math.pi * 2.0))), (1.0 - k)) / math.sqrt(k)
function code(k, n) return Float64((sqrt(Float64(n * Float64(pi * 2.0))) ^ Float64(1.0 - k)) / sqrt(k)) end
function tmp = code(k, n) tmp = (sqrt((n * (pi * 2.0))) ^ (1.0 - k)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\sqrt{n \cdot \left(\pi \cdot 2\right)}\right)}^{\left(1 - k\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in n around 0 95.9%
associate-*r*95.9%
exp-prod95.9%
+-commutative95.9%
log-prod96.2%
associate-*r*96.2%
*-commutative96.2%
*-commutative96.2%
*-commutative96.2%
exp-to-pow99.5%
unpow1/299.5%
Simplified99.5%
associate-*l/99.6%
*-un-lft-identity99.6%
*-commutative99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*l*99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* n 2.0)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (n * 2.0)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (n * 2.0)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (n * 2.0)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(n * 2.0)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (n * 2.0)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
sqr-pow99.5%
pow-sqr99.6%
*-commutative99.6%
associate-*l*99.6%
associate-*r/99.6%
*-commutative99.6%
associate-/l*99.6%
metadata-eval99.6%
/-rgt-identity99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((2.0 * (math.pi / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 50.6%
expm1-log1p-u47.8%
expm1-udef46.9%
associate-*l/46.9%
*-un-lft-identity46.9%
*-commutative46.9%
*-commutative46.9%
sqrt-prod46.9%
sqrt-undiv36.7%
Applied egg-rr36.7%
expm1-def37.7%
expm1-log1p39.5%
associate-/l*39.5%
*-commutative39.5%
Simplified39.5%
Taylor expanded in k around 0 39.5%
*-commutative39.5%
associate-*r/39.5%
associate-*l/39.5%
*-commutative39.5%
associate-*l*39.5%
*-commutative39.5%
associate-*l/39.5%
Simplified39.5%
div-inv39.5%
*-commutative39.5%
associate-*l*39.5%
div-inv39.5%
associate-*l*39.5%
*-commutative39.5%
associate-*r*39.5%
sqrt-prod50.8%
Applied egg-rr50.8%
*-commutative50.8%
associate-*l/50.8%
associate-*r/50.8%
Simplified50.8%
Final simplification50.8%
(FPCore (k n) :precision binary64 (* (sqrt (* PI (/ 2.0 k))) (sqrt n)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 / k))) * sqrt(n);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 / k))) * Math.sqrt(n);
}
def code(k, n): return math.sqrt((math.pi * (2.0 / k))) * math.sqrt(n)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(2.0 / k))) * sqrt(n)) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 / k))) * sqrt(n); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{2}{k}} \cdot \sqrt{n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 50.6%
expm1-log1p-u47.8%
expm1-udef46.9%
associate-*l/46.9%
*-un-lft-identity46.9%
*-commutative46.9%
*-commutative46.9%
sqrt-prod46.9%
sqrt-undiv36.7%
Applied egg-rr36.7%
expm1-def37.7%
expm1-log1p39.5%
associate-/l*39.5%
*-commutative39.5%
Simplified39.5%
Taylor expanded in k around 0 39.5%
*-commutative39.5%
associate-*r/39.5%
associate-*l/39.5%
*-commutative39.5%
associate-*l*39.5%
*-commutative39.5%
associate-*l/39.5%
Simplified39.5%
div-inv39.5%
*-commutative39.5%
associate-*l*39.5%
div-inv39.5%
associate-*l*39.5%
*-commutative39.5%
associate-*r*39.5%
sqrt-prod50.8%
Applied egg-rr50.8%
Final simplification50.8%
(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.5%
Taylor expanded in k around 0 50.6%
associate-*l/50.7%
*-un-lft-identity50.7%
*-commutative50.7%
*-commutative50.7%
sqrt-prod50.8%
clear-num50.7%
Applied egg-rr50.7%
associate-/l*50.8%
*-lft-identity50.8%
associate-*r*50.8%
*-commutative50.8%
associate-*l*50.8%
Simplified50.8%
Final simplification50.8%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* n (* PI 2.0))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (n * (((double) M_PI) * 2.0))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (n * (Math.PI * 2.0))));
}
def code(k, n): return 1.0 / math.sqrt((k / (n * (math.pi * 2.0))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(n * Float64(pi * 2.0))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (n * (pi * 2.0)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{n \cdot \left(\pi \cdot 2\right)}}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
sqr-pow99.5%
pow-sqr99.6%
*-commutative99.6%
associate-*l*99.6%
associate-*r/99.6%
*-commutative99.6%
associate-/l*99.6%
metadata-eval99.6%
/-rgt-identity99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
div-inv99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*l*99.5%
sub-neg99.5%
div-inv99.5%
metadata-eval99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
inv-pow99.5%
sqrt-pow299.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in k around 0 50.7%
*-commutative50.7%
metadata-eval50.7%
pow-flip50.6%
pow1/250.6%
sqrt-prod50.6%
associate-*r*50.6%
sqrt-prod50.6%
sqrt-prod50.7%
*-commutative50.7%
div-inv50.8%
clear-num50.7%
sqrt-undiv39.7%
*-commutative39.7%
associate-*r*39.7%
*-commutative39.7%
associate-*l*39.7%
Applied egg-rr39.7%
Final simplification39.7%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ (/ k (* n 2.0)) PI))))
double code(double k, double n) {
return 1.0 / sqrt(((k / (n * 2.0)) / ((double) M_PI)));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((k / (n * 2.0)) / Math.PI));
}
def code(k, n): return 1.0 / math.sqrt(((k / (n * 2.0)) / math.pi))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(k / Float64(n * 2.0)) / pi))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((k / (n * 2.0)) / pi)); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(k / N[(n * 2.0), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{k}{n \cdot 2}}{\pi}}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 50.6%
expm1-log1p-u47.8%
expm1-udef46.9%
associate-*l/46.9%
*-un-lft-identity46.9%
*-commutative46.9%
*-commutative46.9%
sqrt-prod46.9%
sqrt-undiv36.7%
Applied egg-rr36.7%
expm1-def37.7%
expm1-log1p39.5%
associate-/l*39.5%
*-commutative39.5%
Simplified39.5%
*-un-lft-identity39.5%
times-frac39.4%
Applied egg-rr39.4%
clear-num39.4%
sqrt-div39.6%
metadata-eval39.6%
div-inv39.6%
frac-times39.7%
*-un-lft-identity39.7%
metadata-eval39.7%
Applied egg-rr39.7%
metadata-eval39.7%
times-frac39.7%
*-commutative39.7%
*-rgt-identity39.7%
associate-*r*39.7%
*-commutative39.7%
associate-/r*39.7%
*-commutative39.7%
Simplified39.7%
Final simplification39.7%
(FPCore (k n) :precision binary64 (pow (/ (* n 2.0) (/ k PI)) 0.5))
double code(double k, double n) {
return pow(((n * 2.0) / (k / ((double) M_PI))), 0.5);
}
public static double code(double k, double n) {
return Math.pow(((n * 2.0) / (k / Math.PI)), 0.5);
}
def code(k, n): return math.pow(((n * 2.0) / (k / math.pi)), 0.5)
function code(k, n) return Float64(Float64(n * 2.0) / Float64(k / pi)) ^ 0.5 end
function tmp = code(k, n) tmp = ((n * 2.0) / (k / pi)) ^ 0.5; end
code[k_, n_] := N[Power[N[(N[(n * 2.0), $MachinePrecision] / N[(k / Pi), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{n \cdot 2}{\frac{k}{\pi}}\right)}^{0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 50.6%
expm1-log1p-u47.8%
expm1-udef46.9%
associate-*l/46.9%
*-un-lft-identity46.9%
*-commutative46.9%
*-commutative46.9%
sqrt-prod46.9%
sqrt-undiv36.7%
Applied egg-rr36.7%
expm1-def37.7%
expm1-log1p39.5%
associate-/l*39.5%
*-commutative39.5%
Simplified39.5%
*-un-lft-identity39.5%
times-frac39.4%
Applied egg-rr39.4%
pow1/239.4%
associate-/r*39.5%
div-inv39.5%
clear-num39.5%
/-rgt-identity39.5%
*-commutative39.5%
Applied egg-rr39.5%
Final simplification39.5%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ (* n 2.0) k))))
double code(double k, double n) {
return sqrt((((double) M_PI) * ((n * 2.0) / k)));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * ((n * 2.0) / k)));
}
def code(k, n): return math.sqrt((math.pi * ((n * 2.0) / k)))
function code(k, n) return sqrt(Float64(pi * Float64(Float64(n * 2.0) / k))) end
function tmp = code(k, n) tmp = sqrt((pi * ((n * 2.0) / k))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(N[(n * 2.0), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{n \cdot 2}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 50.6%
expm1-log1p-u47.8%
expm1-udef46.9%
associate-*l/46.9%
*-un-lft-identity46.9%
*-commutative46.9%
*-commutative46.9%
sqrt-prod46.9%
sqrt-undiv36.7%
Applied egg-rr36.7%
expm1-def37.7%
expm1-log1p39.5%
associate-/l*39.5%
*-commutative39.5%
Simplified39.5%
Taylor expanded in k around 0 39.5%
*-commutative39.5%
associate-*r/39.5%
associate-*l/39.5%
*-commutative39.5%
associate-*l*39.5%
*-commutative39.5%
associate-*l/39.5%
Simplified39.5%
Final simplification39.5%
herbie shell --seed 2024014
(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))))