
(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 8 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 (* PI (* n 2.0)))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (n * 2.0);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (n * 2.0);
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = math.pi * (n * 2.0) return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(pi * Float64(n * 2.0)) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = pi * (n * 2.0); tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(n * 2.0), $MachinePrecision]), $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 := \pi \cdot \left(n \cdot 2\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k \cdot {t\_0}^{k}}}
\end{array}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-un-lft-identity99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
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%
pow-unpow99.6%
pow-sqr99.6%
associate-*r*99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*l/99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
(FPCore (k n) :precision binary64 (if (<= k 5e-29) (* (sqrt (* n 2.0)) (sqrt (/ PI k))) (sqrt (* (pow (* 2.0 (* PI n)) (- 1.0 k)) (/ 1.0 k)))))
double code(double k, double n) {
double tmp;
if (k <= 5e-29) {
tmp = sqrt((n * 2.0)) * sqrt((((double) M_PI) / k));
} else {
tmp = sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) * (1.0 / k)));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 5e-29) {
tmp = Math.sqrt((n * 2.0)) * Math.sqrt((Math.PI / k));
} else {
tmp = Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) * (1.0 / k)));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 5e-29: tmp = math.sqrt((n * 2.0)) * math.sqrt((math.pi / k)) else: tmp = math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) * (1.0 / k))) return tmp
function code(k, n) tmp = 0.0 if (k <= 5e-29) tmp = Float64(sqrt(Float64(n * 2.0)) * sqrt(Float64(pi / k))); else tmp = sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) * Float64(1.0 / k))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 5e-29) tmp = sqrt((n * 2.0)) * sqrt((pi / k)); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) * (1.0 / k))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 5e-29], N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] * N[(1.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5 \cdot 10^{-29}:\\
\;\;\;\;\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)} \cdot \frac{1}{k}}\\
\end{array}
\end{array}
if k < 4.99999999999999986e-29Initial program 99.3%
Taylor expanded in k around 0 74.6%
associate-/l*74.6%
Simplified74.6%
*-commutative74.6%
sqrt-unprod74.9%
Applied egg-rr74.9%
associate-*r*74.9%
*-commutative74.9%
sqrt-prod99.6%
Applied egg-rr99.6%
if 4.99999999999999986e-29 < k Initial program 99.7%
associate-*l/99.7%
*-lft-identity99.7%
associate-*l*99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
div-inv99.7%
div-inv99.7%
metadata-eval99.7%
pow1/299.7%
pow-flip99.7%
metadata-eval99.7%
Applied egg-rr99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.7%
swap-sqr99.7%
Applied egg-rr99.7%
(FPCore (k n) :precision binary64 (if (<= k 4e-31) (* (sqrt (* n 2.0)) (sqrt (/ PI k))) (sqrt (/ (pow (* n (* PI 2.0)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 4e-31) {
tmp = sqrt((n * 2.0)) * sqrt((((double) M_PI) / 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 <= 4e-31) {
tmp = Math.sqrt((n * 2.0)) * Math.sqrt((Math.PI / 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 <= 4e-31: tmp = math.sqrt((n * 2.0)) * math.sqrt((math.pi / 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 <= 4e-31) tmp = Float64(sqrt(Float64(n * 2.0)) * sqrt(Float64(pi / 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 <= 4e-31) tmp = sqrt((n * 2.0)) * sqrt((pi / k)); else tmp = sqrt((((n * (pi * 2.0)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4e-31], N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $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 4 \cdot 10^{-31}:\\
\;\;\;\;\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{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 < 4e-31Initial program 99.3%
Taylor expanded in k around 0 74.3%
associate-/l*74.3%
Simplified74.3%
*-commutative74.3%
sqrt-unprod74.5%
Applied egg-rr74.5%
associate-*r*74.5%
*-commutative74.5%
sqrt-prod99.5%
Applied egg-rr99.5%
if 4e-31 < 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.6%
(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.5%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
(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.5%
Taylor expanded in k around 0 41.1%
associate-/l*41.1%
Simplified41.1%
*-commutative41.1%
sqrt-unprod41.3%
Applied egg-rr41.3%
associate-*r*41.3%
*-commutative41.3%
sqrt-prod53.7%
Applied egg-rr53.7%
(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.5%
Taylor expanded in k around 0 41.1%
associate-/l*41.1%
Simplified41.1%
*-commutative41.1%
sqrt-unprod41.3%
Applied egg-rr41.3%
clear-num41.2%
un-div-inv41.3%
Applied egg-rr41.3%
(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.5%
Taylor expanded in k around 0 41.1%
associate-/l*41.1%
Simplified41.1%
*-commutative41.1%
sqrt-unprod41.3%
Applied egg-rr41.3%
Taylor expanded in n around 0 41.2%
*-commutative41.2%
associate-/l*41.3%
Simplified41.3%
(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.5%
Taylor expanded in k around 0 41.1%
associate-/l*41.1%
Simplified41.1%
*-commutative41.1%
sqrt-unprod41.3%
Applied egg-rr41.3%
herbie shell --seed 2024119
(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))))