
(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 n) PI))) (* (/ 1.0 (sqrt k)) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
return (1.0 / sqrt(k)) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (2.0 * n) * Math.PI;
return (1.0 / Math.sqrt(k)) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (2.0 * n) * math.pi return (1.0 / math.sqrt(k)) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(2.0 * n) * pi) return Float64(Float64(1.0 / sqrt(k)) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (2.0 * n) * pi; tmp = (1.0 / sqrt(k)) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot n\right) \cdot \pi\\
\frac{1}{\sqrt{k}} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.4%
div-sub99.4%
metadata-eval99.4%
pow-sub99.7%
pow1/299.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* n (* 2.0 PI)) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return pow(k, -0.5) * pow((n * (2.0 * ((double) M_PI))), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((n * (2.0 * Math.PI)), ((1.0 - k) / 2.0));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((n * (2.0 * math.pi)), ((1.0 - k) / 2.0))
function code(k, n) return Float64((k ^ -0.5) * (Float64(n * Float64(2.0 * pi)) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((n * (2.0 * pi)) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[Power[k, -0.5], $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}
\\
{k}^{-0.5} \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.4%
expm1-log1p-u96.3%
expm1-udef72.0%
pow1/272.0%
pow-flip72.0%
metadata-eval72.0%
Applied egg-rr72.0%
expm1-def96.3%
expm1-log1p99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* (* 2.0 n) PI)))
(if (<= k 3.6e-45)
(* (pow k -0.5) (sqrt t_0))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
double tmp;
if (k <= 3.6e-45) {
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 = (2.0 * n) * Math.PI;
double tmp;
if (k <= 3.6e-45) {
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 = (2.0 * n) * math.pi tmp = 0 if k <= 3.6e-45: 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(Float64(2.0 * n) * pi) tmp = 0.0 if (k <= 3.6e-45) 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 = (2.0 * n) * pi; tmp = 0.0; if (k <= 3.6e-45) 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[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, If[LessEqual[k, 3.6e-45], 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 := \left(2 \cdot n\right) \cdot \pi\\
\mathbf{if}\;k \leq 3.6 \cdot 10^{-45}:\\
\;\;\;\;{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.60000000000000001e-45Initial program 99.4%
expm1-log1p-u91.8%
expm1-udef91.8%
pow1/291.8%
pow-flip91.8%
metadata-eval91.8%
Applied egg-rr91.8%
expm1-def91.8%
expm1-log1p99.5%
Simplified99.5%
Taylor expanded in k around 0 99.2%
expm1-log1p-u96.2%
expm1-udef47.3%
sqrt-unprod47.3%
*-commutative47.3%
Applied egg-rr47.3%
expm1-def96.3%
expm1-log1p99.5%
*-commutative99.5%
associate-*r*99.5%
Simplified99.5%
if 3.60000000000000001e-45 < k Initial program 99.5%
*-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
div-inv99.5%
expm1-log1p-u99.1%
expm1-udef93.8%
Applied egg-rr93.8%
expm1-def99.1%
expm1-log1p99.5%
*-commutative99.5%
associate-*r*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* (* 2.0 n) PI) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow(((2.0 * n) * ((double) M_PI)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow(((2.0 * n) * Math.PI), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow(((2.0 * n) * math.pi), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(Float64(2.0 * n) * pi) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = (((2.0 * n) * pi) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(2 \cdot n\right) \cdot \pi\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (sqrt (* (* 2.0 n) PI))))
double code(double k, double n) {
return pow(k, -0.5) * sqrt(((2.0 * n) * ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.sqrt(((2.0 * n) * Math.PI));
}
def code(k, n): return math.pow(k, -0.5) * math.sqrt(((2.0 * n) * math.pi))
function code(k, n) return Float64((k ^ -0.5) * sqrt(Float64(Float64(2.0 * n) * pi))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * sqrt(((2.0 * n) * pi)); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot \sqrt{\left(2 \cdot n\right) \cdot \pi}
\end{array}
Initial program 99.4%
expm1-log1p-u96.3%
expm1-udef72.0%
pow1/272.0%
pow-flip72.0%
metadata-eval72.0%
Applied egg-rr72.0%
expm1-def96.3%
expm1-log1p99.5%
Simplified99.5%
Taylor expanded in k around 0 46.7%
expm1-log1p-u45.4%
expm1-udef23.5%
sqrt-unprod23.5%
*-commutative23.5%
Applied egg-rr23.5%
expm1-def45.4%
expm1-log1p46.8%
*-commutative46.8%
associate-*r*46.8%
Simplified46.8%
Final simplification46.8%
(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%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.4%
expm1-log1p-u96.9%
expm1-udef85.3%
Applied egg-rr76.4%
expm1-def88.1%
expm1-log1p89.6%
*-commutative89.6%
associate-*r*89.6%
Simplified89.6%
sub-neg89.6%
unpow-prod-up89.9%
pow189.9%
*-commutative89.9%
*-commutative89.9%
Applied egg-rr89.9%
Taylor expanded in k around 0 36.9%
associate-/l*36.9%
associate-/r/36.9%
Simplified36.9%
Final simplification36.9%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ n (/ k 2.0)))))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n / (k / 2.0))));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n / (k / 2.0))));
}
def code(k, n): return math.sqrt((math.pi * (n / (k / 2.0))))
function code(k, n) return sqrt(Float64(pi * Float64(n / Float64(k / 2.0)))) end
function tmp = code(k, n) tmp = sqrt((pi * (n / (k / 2.0)))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(n / N[(k / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{n}{\frac{k}{2}}}
\end{array}
Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.4%
expm1-log1p-u96.9%
expm1-udef85.3%
Applied egg-rr76.4%
expm1-def88.1%
expm1-log1p89.6%
*-commutative89.6%
associate-*r*89.6%
Simplified89.6%
sub-neg89.6%
unpow-prod-up89.9%
pow189.9%
*-commutative89.9%
*-commutative89.9%
Applied egg-rr89.9%
Taylor expanded in k around 0 36.9%
associate-/l*36.9%
associate-/r/36.9%
Simplified36.9%
expm1-log1p-u35.4%
expm1-udef32.8%
*-commutative32.8%
Applied egg-rr32.8%
expm1-def35.4%
expm1-log1p36.9%
associate-*r*36.9%
*-commutative36.9%
associate-*l*36.9%
associate-*r/36.9%
*-commutative36.9%
associate-/l*36.9%
Simplified36.9%
Final simplification36.9%
herbie shell --seed 2023250
(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))))