
(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 7 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)))) (* (pow k -0.5) (sqrt (/ t_0 (pow t_0 k))))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) * n);
return pow(k, -0.5) * sqrt((t_0 / pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = 2.0 * (Math.PI * n);
return Math.pow(k, -0.5) * Math.sqrt((t_0 / Math.pow(t_0, k)));
}
def code(k, n): t_0 = 2.0 * (math.pi * n) return math.pow(k, -0.5) * math.sqrt((t_0 / math.pow(t_0, k)))
function code(k, n) t_0 = Float64(2.0 * Float64(pi * n)) return Float64((k ^ -0.5) * sqrt(Float64(t_0 / (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = 2.0 * (pi * n); tmp = (k ^ -0.5) * sqrt((t_0 / (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[N[(t$95$0 / N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(\pi \cdot n\right)\\
{k}^{-0.5} \cdot \sqrt{\frac{t_0}{{t_0}^{k}}}
\end{array}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
div-inv99.5%
*-commutative99.5%
add-sqr-sqrt99.3%
inv-pow99.3%
sqrt-pow299.3%
metadata-eval99.3%
sqrt-unprod99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
pow-prod-up99.5%
Applied egg-rr99.5%
pow-sub99.7%
pow199.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* n (* 2.0 PI))))
(if (<= k 7.8e-47)
(* (pow k -0.5) (sqrt t_0))
(/ 1.0 (sqrt (/ k (pow t_0 (- 1.0 k))))))))
double code(double k, double n) {
double t_0 = n * (2.0 * ((double) M_PI));
double tmp;
if (k <= 7.8e-47) {
tmp = pow(k, -0.5) * sqrt(t_0);
} else {
tmp = 1.0 / sqrt((k / pow(t_0, (1.0 - k))));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = n * (2.0 * Math.PI);
double tmp;
if (k <= 7.8e-47) {
tmp = Math.pow(k, -0.5) * Math.sqrt(t_0);
} else {
tmp = 1.0 / Math.sqrt((k / Math.pow(t_0, (1.0 - k))));
}
return tmp;
}
def code(k, n): t_0 = n * (2.0 * math.pi) tmp = 0 if k <= 7.8e-47: tmp = math.pow(k, -0.5) * math.sqrt(t_0) else: tmp = 1.0 / math.sqrt((k / math.pow(t_0, (1.0 - k)))) return tmp
function code(k, n) t_0 = Float64(n * Float64(2.0 * pi)) tmp = 0.0 if (k <= 7.8e-47) tmp = Float64((k ^ -0.5) * sqrt(t_0)); else tmp = Float64(1.0 / sqrt(Float64(k / (t_0 ^ Float64(1.0 - k))))); end return tmp end
function tmp_2 = code(k, n) t_0 = n * (2.0 * pi); tmp = 0.0; if (k <= 7.8e-47) tmp = (k ^ -0.5) * sqrt(t_0); else tmp = 1.0 / sqrt((k / (t_0 ^ (1.0 - k)))); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 7.8e-47], N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(k / N[Power[t$95$0, N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;k \leq 7.8 \cdot 10^{-47}:\\
\;\;\;\;{k}^{-0.5} \cdot \sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{k}{{t_0}^{\left(1 - k\right)}}}}\\
\end{array}
\end{array}
if k < 7.79999999999999956e-47Initial program 99.2%
associate-*l/99.4%
*-lft-identity99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
div-inv99.2%
*-commutative99.2%
add-sqr-sqrt98.9%
inv-pow98.9%
sqrt-pow298.9%
metadata-eval98.9%
sqrt-unprod99.3%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
pow-prod-up99.3%
Applied egg-rr99.3%
Taylor expanded in k around 0 99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
if 7.79999999999999956e-47 < k Initial program 99.7%
associate-*l/99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
div-inv99.7%
*-commutative99.7%
add-sqr-sqrt99.6%
inv-pow99.6%
sqrt-pow299.6%
metadata-eval99.6%
sqrt-unprod99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
pow-prod-up99.7%
Applied egg-rr99.7%
*-commutative99.7%
sqrt-pow199.7%
associate-*r*99.7%
sqrt-pow199.7%
add-sqr-sqrt99.6%
sqrt-unprod99.7%
sqrt-prod99.6%
pow-prod-up99.7%
metadata-eval99.7%
inv-pow99.7%
div-inv99.7%
clear-num99.7%
sqrt-div99.7%
metadata-eval99.7%
associate-*r*99.7%
Applied egg-rr99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* n (* 2.0 PI))))
(if (<= k 3.5e-47)
(* (pow k -0.5) (sqrt t_0))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = n * (2.0 * ((double) M_PI));
double tmp;
if (k <= 3.5e-47) {
tmp = pow(k, -0.5) * sqrt(t_0);
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = n * (2.0 * Math.PI);
double tmp;
if (k <= 3.5e-47) {
tmp = Math.pow(k, -0.5) * Math.sqrt(t_0);
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = n * (2.0 * math.pi) tmp = 0 if k <= 3.5e-47: tmp = math.pow(k, -0.5) * math.sqrt(t_0) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(n * Float64(2.0 * pi)) tmp = 0.0 if (k <= 3.5e-47) tmp = Float64((k ^ -0.5) * sqrt(t_0)); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = n * (2.0 * pi); tmp = 0.0; if (k <= 3.5e-47) tmp = (k ^ -0.5) * sqrt(t_0); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 3.5e-47], N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[t$95$0], $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 := n \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;k \leq 3.5 \cdot 10^{-47}:\\
\;\;\;\;{k}^{-0.5} \cdot \sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 3.4999999999999998e-47Initial program 99.2%
associate-*l/99.4%
*-lft-identity99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
div-inv99.2%
*-commutative99.2%
add-sqr-sqrt98.9%
inv-pow98.9%
sqrt-pow298.9%
metadata-eval98.9%
sqrt-unprod99.3%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
pow-prod-up99.3%
Applied egg-rr99.3%
Taylor expanded in k around 0 99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
if 3.4999999999999998e-47 < k Initial program 99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
div-inv99.7%
expm1-log1p-u99.3%
expm1-udef93.6%
Applied egg-rr93.6%
expm1-def99.3%
expm1-log1p99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* 2.0 n)) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (sqrt (* n (* 2.0 PI)))))
double code(double k, double n) {
return pow(k, -0.5) * sqrt((n * (2.0 * ((double) M_PI))));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.sqrt((n * (2.0 * Math.PI)));
}
def code(k, n): return math.pow(k, -0.5) * math.sqrt((n * (2.0 * math.pi)))
function code(k, n) return Float64((k ^ -0.5) * sqrt(Float64(n * Float64(2.0 * pi)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * sqrt((n * (2.0 * pi))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot \sqrt{n \cdot \left(2 \cdot \pi\right)}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
div-inv99.5%
*-commutative99.5%
add-sqr-sqrt99.3%
inv-pow99.3%
sqrt-pow299.3%
metadata-eval99.3%
sqrt-unprod99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
pow-prod-up99.5%
Applied egg-rr99.5%
Taylor expanded in k around 0 47.1%
*-commutative47.1%
associate-*r*47.1%
Simplified47.1%
Final simplification47.1%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ 2.0 (/ k n)))))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 / (k / n))));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 / (k / n))));
}
def code(k, n): return math.sqrt((math.pi * (2.0 / (k / n))))
function code(k, n) return sqrt(Float64(pi * Float64(2.0 / Float64(k / n)))) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 / (k / n)))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(2.0 / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{2}{\frac{k}{n}}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
div-inv99.5%
*-commutative99.5%
add-sqr-sqrt99.3%
inv-pow99.3%
sqrt-pow299.3%
metadata-eval99.3%
sqrt-unprod99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
pow-prod-up99.5%
Applied egg-rr99.5%
*-commutative99.5%
sqrt-pow199.5%
associate-*r*99.5%
sqrt-pow199.5%
add-sqr-sqrt99.3%
sqrt-unprod99.5%
sqrt-prod88.9%
pow-prod-up89.0%
metadata-eval89.0%
inv-pow89.0%
div-inv89.0%
add-cbrt-cube80.7%
pow1/378.8%
Applied egg-rr78.8%
unpow1/380.7%
associate-*r*80.7%
Simplified80.7%
Taylor expanded in k around 0 29.7%
associate-*r*29.7%
Simplified29.7%
expm1-log1p-u28.8%
expm1-udef28.1%
pow1/328.0%
pow-pow34.4%
metadata-eval34.4%
pow1/234.4%
associate-/l*34.4%
Applied egg-rr34.4%
expm1-def34.9%
expm1-log1p36.6%
associate-/r/36.6%
*-commutative36.6%
associate-/l*36.6%
Simplified36.6%
Final simplification36.6%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ (* 2.0 n) k))))
double code(double k, double n) {
return sqrt((((double) M_PI) * ((2.0 * n) / k)));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * ((2.0 * n) / k)));
}
def code(k, n): return math.sqrt((math.pi * ((2.0 * n) / k)))
function code(k, n) return sqrt(Float64(pi * Float64(Float64(2.0 * n) / k))) end
function tmp = code(k, n) tmp = sqrt((pi * ((2.0 * n) / k))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(N[(2.0 * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{2 \cdot n}{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
div-inv99.5%
*-commutative99.5%
add-sqr-sqrt99.3%
inv-pow99.3%
sqrt-pow299.3%
metadata-eval99.3%
sqrt-unprod99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
pow-prod-up99.5%
Applied egg-rr99.5%
*-commutative99.5%
sqrt-pow199.5%
associate-*r*99.5%
sqrt-pow199.5%
add-sqr-sqrt99.3%
sqrt-unprod99.5%
sqrt-prod88.9%
pow-prod-up89.0%
metadata-eval89.0%
inv-pow89.0%
div-inv89.0%
add-cbrt-cube80.7%
pow1/378.8%
Applied egg-rr78.8%
unpow1/380.7%
associate-*r*80.7%
Simplified80.7%
Taylor expanded in k around 0 29.7%
associate-*r*29.7%
Simplified29.7%
expm1-log1p-u28.8%
expm1-udef28.1%
pow1/328.0%
pow-pow34.4%
metadata-eval34.4%
pow1/234.4%
associate-/l*34.4%
Applied egg-rr34.4%
expm1-def34.9%
expm1-log1p36.6%
associate-/r/36.6%
Simplified36.6%
Final simplification36.6%
herbie shell --seed 2023227
(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))))