
(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 (let* ((t_0 (* (* n 2.0) PI))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = (n * 2.0) * ((double) M_PI);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = (n * 2.0) * Math.PI;
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = (n * 2.0) * math.pi return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(Float64(n * 2.0) * pi) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = (n * 2.0) * pi; tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(k * N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(n \cdot 2\right) \cdot \pi\\
\frac{\sqrt{t\_0}}{\sqrt{k \cdot {t\_0}^{k}}}
\end{array}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-un-lft-identity99.4%
associate-*r*99.4%
div-sub99.4%
metadata-eval99.4%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
associate-*r*99.7%
Simplified99.7%
div-inv99.6%
associate-*r*99.6%
add-sqr-sqrt99.4%
sqrt-unprod99.6%
swap-sqr99.6%
add-sqr-sqrt99.6%
pow-unpow99.6%
unpow1/299.6%
pow-unpow99.6%
unpow1/299.6%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
associate-*r/99.7%
*-rgt-identity99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 4e-10) (/ (sqrt (* 2.0 (* n PI))) (sqrt k)) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 4e-10) {
tmp = sqrt((2.0 * (n * ((double) M_PI)))) / sqrt(k);
} 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 <= 4e-10) {
tmp = Math.sqrt((2.0 * (n * Math.PI))) / Math.sqrt(k);
} 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 <= 4e-10: tmp = math.sqrt((2.0 * (n * math.pi))) / math.sqrt(k) 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 <= 4e-10) tmp = Float64(sqrt(Float64(2.0 * Float64(n * pi))) / sqrt(k)); 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 <= 4e-10) tmp = sqrt((2.0 * (n * pi))) / sqrt(k); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4e-10], N[(N[Sqrt[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $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 \cdot 10^{-10}:\\
\;\;\;\;\frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{\sqrt{k}}\\
\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.00000000000000015e-10Initial program 99.0%
Taylor expanded in k around 0 71.1%
*-commutative71.1%
associate-/l*71.2%
Simplified71.2%
pow171.2%
sqrt-unprod71.3%
Applied egg-rr71.3%
unpow171.3%
Simplified71.3%
associate-*r/71.4%
div-inv71.4%
associate-*r*71.4%
*-commutative71.4%
add-sqr-sqrt71.2%
sqrt-unprod71.2%
sqrt-unprod71.0%
metadata-eval71.0%
add-sqr-sqrt71.0%
frac-times70.9%
swap-sqr71.0%
*-commutative71.0%
*-commutative71.0%
Applied egg-rr98.3%
/-rgt-identity98.3%
associate-*r/98.2%
pow-sqr98.6%
metadata-eval98.6%
unpow1/298.6%
*-commutative98.6%
associate-*r*98.6%
Simplified98.6%
if 4.00000000000000015e-10 < k Initial program 99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.7%
*-commutative99.7%
associate-*r*99.7%
div-sub99.7%
metadata-eval99.7%
div-inv99.7%
*-commutative99.7%
Applied egg-rr99.7%
Simplified99.7%
Final simplification99.2%
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (pow (* (* n 2.0) PI) (+ -0.5 (* k 0.5)))))
double code(double k, double n) {
return pow(k, -0.5) / pow(((n * 2.0) * ((double) M_PI)), (-0.5 + (k * 0.5)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) / Math.pow(((n * 2.0) * Math.PI), (-0.5 + (k * 0.5)));
}
def code(k, n): return math.pow(k, -0.5) / math.pow(((n * 2.0) * math.pi), (-0.5 + (k * 0.5)))
function code(k, n) return Float64((k ^ -0.5) / (Float64(Float64(n * 2.0) * pi) ^ Float64(-0.5 + Float64(k * 0.5)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) / (((n * 2.0) * pi) ^ (-0.5 + (k * 0.5))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(-0.5 + N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(-0.5 + k \cdot 0.5\right)}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-un-lft-identity99.4%
associate-*r*99.4%
div-sub99.4%
metadata-eval99.4%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
associate-*r*99.7%
Simplified99.7%
div-inv99.6%
associate-*r*99.6%
add-sqr-sqrt99.4%
sqrt-unprod99.6%
swap-sqr99.6%
add-sqr-sqrt99.6%
pow-unpow99.6%
unpow1/299.6%
pow-unpow99.6%
unpow1/299.6%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
associate-*r/99.7%
*-rgt-identity99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
*-un-lft-identity99.7%
sqrt-prod99.7%
times-frac99.6%
pow1/299.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
pow1/299.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
pow-unpow99.6%
pow-sub99.4%
Applied egg-rr99.4%
unpow-199.4%
associate-*r/99.5%
*-rgt-identity99.5%
associate-*r*99.5%
*-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* n PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (n * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (n * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (n * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (n * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(n * Pi), $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(n \cdot \pi\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
associate-*l*99.4%
div-sub99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (* (sqrt (* n 2.0)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((n * 2.0)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((n * 2.0)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((n * 2.0)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(n * 2.0)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((n * 2.0)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 37.5%
*-commutative37.5%
associate-/l*37.5%
Simplified37.5%
pow137.5%
sqrt-unprod37.6%
Applied egg-rr37.6%
unpow137.6%
Simplified37.6%
associate-*r*37.6%
*-commutative37.6%
sqrt-prod51.2%
Applied egg-rr51.2%
Final simplification51.2%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 (* n PI))) (sqrt k)))
double code(double k, double n) {
return sqrt((2.0 * (n * ((double) M_PI)))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n * Math.PI))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((2.0 * (n * math.pi))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(n * pi))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n * pi))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 37.5%
*-commutative37.5%
associate-/l*37.5%
Simplified37.5%
pow137.5%
sqrt-unprod37.6%
Applied egg-rr37.6%
unpow137.6%
Simplified37.6%
associate-*r/37.6%
div-inv37.6%
associate-*r*37.6%
*-commutative37.6%
add-sqr-sqrt37.5%
sqrt-unprod37.5%
sqrt-unprod37.4%
metadata-eval37.4%
add-sqr-sqrt37.4%
frac-times37.4%
swap-sqr37.4%
*-commutative37.4%
*-commutative37.4%
Applied egg-rr51.1%
/-rgt-identity51.1%
associate-*r/51.0%
pow-sqr51.2%
metadata-eval51.2%
unpow1/251.2%
*-commutative51.2%
associate-*r*51.2%
Simplified51.2%
Final simplification51.2%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (* n (/ PI k)))))
double code(double k, double n) {
return sqrt((2.0 * (n * (((double) M_PI) / k))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n * (Math.PI / k))));
}
def code(k, n): return math.sqrt((2.0 * (n * (math.pi / k))))
function code(k, n) return sqrt(Float64(2.0 * Float64(n * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n * (pi / k)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 37.5%
*-commutative37.5%
associate-/l*37.5%
Simplified37.5%
pow137.5%
sqrt-unprod37.6%
Applied egg-rr37.6%
unpow137.6%
Simplified37.6%
Final simplification37.6%
(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%
Taylor expanded in k around 0 37.5%
*-commutative37.5%
associate-/l*37.5%
Simplified37.5%
pow137.5%
sqrt-unprod37.6%
Applied egg-rr37.6%
unpow137.6%
Simplified37.6%
Taylor expanded in n around 0 37.6%
*-commutative37.6%
associate-/l*37.6%
Simplified37.6%
Final simplification37.6%
(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.4%
Taylor expanded in k around 0 37.5%
*-commutative37.5%
associate-/l*37.5%
Simplified37.5%
pow137.5%
sqrt-unprod37.6%
Applied egg-rr37.6%
unpow137.6%
Simplified37.6%
clear-num37.6%
un-div-inv37.6%
Applied egg-rr37.6%
Final simplification37.6%
herbie shell --seed 2024109
(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))))