
(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 (* PI (* 2.0 n)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Sqrt[k], $MachinePrecision] * N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
\frac{\sqrt{t_0}}{\sqrt{k} \cdot {t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.5%
*-commutative99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.6%
pow-sub99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 1.05e-82) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.05e-82) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} else {
tmp = sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.05e-82) {
tmp = Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.05e-82: tmp = math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k) else: tmp = math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.05e-82) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); else tmp = sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.05e-82) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.05e-82], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.05 \cdot 10^{-82}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.05e-82Initial program 99.3%
add-sqr-sqrt98.9%
pow298.9%
Applied egg-rr98.7%
Taylor expanded in k around 0 66.8%
associate-*r/66.8%
*-commutative66.8%
associate-*r*66.8%
*-commutative66.8%
rem-exp-log66.7%
*-commutative66.7%
rem-exp-log62.6%
exp-sum62.4%
+-commutative62.4%
exp-sum62.6%
rem-exp-log66.7%
*-commutative66.7%
rem-exp-log66.8%
*-commutative66.8%
Simplified66.8%
pow-pow67.2%
metadata-eval67.2%
pow1/267.2%
*-commutative67.2%
associate-*r*67.2%
sqrt-div99.5%
associate-*r*99.5%
*-commutative99.5%
Applied egg-rr99.5%
if 1.05e-82 < k Initial program 99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
*-commutative99.6%
div-inv99.6%
*-commutative99.6%
div-inv99.6%
frac-times99.6%
Applied egg-rr99.6%
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%
sqr-pow99.3%
pow-sqr99.6%
associate-*l*99.6%
*-commutative99.6%
associate-*l/99.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%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
Taylor expanded in n around 0 48.1%
Simplified39.7%
associate-*r*39.7%
sqrt-prod52.4%
Applied egg-rr52.4%
Final simplification52.4%
(FPCore (k n) :precision binary64 (/ (sqrt n) (sqrt (/ k (* PI 2.0)))))
double code(double k, double n) {
return sqrt(n) / sqrt((k / (((double) M_PI) * 2.0)));
}
public static double code(double k, double n) {
return Math.sqrt(n) / Math.sqrt((k / (Math.PI * 2.0)));
}
def code(k, n): return math.sqrt(n) / math.sqrt((k / (math.pi * 2.0)))
function code(k, n) return Float64(sqrt(n) / sqrt(Float64(k / Float64(pi * 2.0)))) end
function tmp = code(k, n) tmp = sqrt(n) / sqrt((k / (pi * 2.0))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] / N[Sqrt[N[(k / N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n}}{\sqrt{\frac{k}{\pi \cdot 2}}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
pow-pow39.7%
metadata-eval39.7%
pow1/239.7%
associate-/l*39.7%
sqrt-div52.4%
Applied egg-rr52.4%
Final simplification52.4%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* PI 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
pow-pow39.7%
metadata-eval39.7%
pow1/239.7%
*-commutative39.7%
associate-*r*39.7%
sqrt-div52.5%
associate-*r*52.5%
*-commutative52.5%
Applied egg-rr52.5%
Final simplification52.5%
(FPCore (k n) :precision binary64 (pow (* k (/ 0.5 (* PI n))) -0.5))
double code(double k, double n) {
return pow((k * (0.5 / (((double) M_PI) * n))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * (0.5 / (Math.PI * n))), -0.5);
}
def code(k, n): return math.pow((k * (0.5 / (math.pi * n))), -0.5)
function code(k, n) return Float64(k * Float64(0.5 / Float64(pi * n))) ^ -0.5 end
function tmp = code(k, n) tmp = (k * (0.5 / (pi * n))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[(0.5 / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot \frac{0.5}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
Taylor expanded in n around 0 48.1%
Simplified39.7%
associate-*l/39.7%
*-commutative39.7%
associate-*r/39.7%
*-commutative39.7%
associate-*r*39.7%
*-commutative39.7%
sqrt-undiv52.5%
clear-num52.4%
sqrt-div39.7%
inv-pow39.7%
sqrt-pow239.8%
div-inv39.8%
*-commutative39.8%
associate-*r*39.8%
*-commutative39.8%
associate-/r*39.8%
metadata-eval39.8%
*-commutative39.8%
metadata-eval39.8%
Applied egg-rr39.8%
Final simplification39.8%
(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%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
Taylor expanded in n around 0 48.1%
Simplified39.7%
Final simplification39.7%
(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(Float64(pi * 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[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi \cdot n}{k}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.2%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log37.2%
exp-sum37.0%
+-commutative37.0%
exp-sum37.2%
rem-exp-log39.5%
*-commutative39.5%
rem-exp-log39.6%
*-commutative39.6%
Simplified39.6%
Taylor expanded in n around 0 48.1%
Simplified39.7%
associate-*l/39.7%
Applied egg-rr39.7%
Final simplification39.7%
herbie shell --seed 2023308
(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))))