
(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 (* (* 2.0 PI) n))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (2.0 * ((double) M_PI)) * n;
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (2.0 * Math.PI) * n;
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (2.0 * math.pi) * n return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(2.0 * pi) * n) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (2.0 * pi) * n; tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * Pi), $MachinePrecision] * n), $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 := \left(2 \cdot \pi\right) \cdot n\\
\frac{\sqrt{t\_0}}{\sqrt{k} \cdot {t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-un-lft-identity99.7%
unpow-prod-down73.2%
unpow-prod-down99.7%
div-sub99.7%
metadata-eval99.7%
pow-div99.7%
pow1/299.7%
associate-/l/99.8%
associate-*l*99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (k n) :precision binary64 (if (<= k 1.15e-95) (* (sqrt (* 2.0 n)) (sqrt (/ PI k))) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.15e-95) {
tmp = sqrt((2.0 * n)) * sqrt((((double) M_PI) / 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.15e-95) {
tmp = Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / 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.15e-95: tmp = math.sqrt((2.0 * n)) * math.sqrt((math.pi / 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.15e-95) tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / 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.15e-95) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.15e-95], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $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.15 \cdot 10^{-95}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{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.15e-95Initial program 99.3%
associate-*l/99.4%
*-un-lft-identity99.4%
unpow-prod-down98.8%
unpow-prod-down99.4%
div-sub99.4%
metadata-eval99.4%
pow-div99.4%
pow1/299.4%
associate-/l/99.4%
associate-*l*99.4%
associate-*l*99.4%
div-inv99.4%
metadata-eval99.4%
Applied egg-rr99.4%
associate-*r*99.4%
associate-*r*99.4%
Simplified99.4%
add-sqr-sqrt98.9%
sqrt-unprod68.9%
frac-times68.8%
add-sqr-sqrt68.9%
*-commutative68.9%
associate-*r*68.9%
swap-sqr68.9%
add-sqr-sqrt69.0%
Applied egg-rr69.0%
associate-/l*69.0%
*-commutative69.0%
*-commutative69.0%
Simplified69.0%
Taylor expanded in k around 0 69.0%
associate-/l*69.0%
Simplified69.0%
pow1/269.0%
associate-*r*69.0%
unpow-prod-down99.4%
pow1/299.4%
Applied egg-rr99.4%
unpow1/299.4%
*-commutative99.4%
Simplified99.4%
if 1.15e-95 < k Initial program 99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.7%
*-commutative99.7%
div-sub99.7%
metadata-eval99.7%
div-inv99.8%
*-commutative99.8%
div-sub99.8%
metadata-eval99.8%
div-inv99.8%
Applied egg-rr99.8%
distribute-lft-in99.8%
metadata-eval99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
mul-1-neg99.8%
sub-neg99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.7%
(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(Float64(2.0 * 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[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 n)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((2.0 * n)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-un-lft-identity99.7%
unpow-prod-down73.2%
unpow-prod-down99.7%
div-sub99.7%
metadata-eval99.7%
pow-div99.7%
pow1/299.7%
associate-/l/99.8%
associate-*l*99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
add-sqr-sqrt99.5%
sqrt-unprod88.8%
frac-times88.7%
add-sqr-sqrt88.8%
*-commutative88.8%
associate-*r*88.8%
swap-sqr88.8%
add-sqr-sqrt88.9%
Applied egg-rr88.9%
associate-/l*88.8%
*-commutative88.8%
*-commutative88.8%
Simplified88.8%
Taylor expanded in k around 0 36.5%
associate-/l*36.5%
Simplified36.5%
pow1/236.5%
associate-*r*36.5%
unpow-prod-down47.4%
pow1/247.4%
Applied egg-rr47.4%
unpow1/247.4%
*-commutative47.4%
Simplified47.4%
Final simplification47.4%
(FPCore (k n) :precision binary64 (/ (sqrt (* (* 2.0 PI) n)) (sqrt k)))
double code(double k, double n) {
return sqrt(((2.0 * ((double) M_PI)) * n)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt(((2.0 * Math.PI) * n)) / Math.sqrt(k);
}
def code(k, n): return math.sqrt(((2.0 * math.pi) * n)) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(Float64(2.0 * pi) * n)) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt(((2.0 * pi) * n)) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-un-lft-identity99.7%
unpow-prod-down73.2%
unpow-prod-down99.7%
div-sub99.7%
metadata-eval99.7%
pow-div99.7%
pow1/299.7%
associate-/l/99.8%
associate-*l*99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
add-sqr-sqrt99.5%
sqrt-unprod88.8%
frac-times88.7%
add-sqr-sqrt88.8%
*-commutative88.8%
associate-*r*88.8%
swap-sqr88.8%
add-sqr-sqrt88.9%
Applied egg-rr88.9%
associate-/l*88.8%
*-commutative88.8%
*-commutative88.8%
Simplified88.8%
Taylor expanded in k around 0 36.5%
associate-/l*36.5%
Simplified36.5%
associate-*r/36.5%
associate-*r/36.5%
*-commutative36.5%
sqrt-div47.5%
Applied egg-rr47.5%
*-commutative47.5%
*-commutative47.5%
associate-*l*47.5%
*-commutative47.5%
Simplified47.5%
Final simplification47.5%
(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.6%
associate-*l/99.7%
*-un-lft-identity99.7%
unpow-prod-down73.2%
unpow-prod-down99.7%
div-sub99.7%
metadata-eval99.7%
pow-div99.7%
pow1/299.7%
associate-/l/99.8%
associate-*l*99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
add-sqr-sqrt99.5%
sqrt-unprod88.8%
frac-times88.7%
add-sqr-sqrt88.8%
*-commutative88.8%
associate-*r*88.8%
swap-sqr88.8%
add-sqr-sqrt88.9%
Applied egg-rr88.9%
associate-/l*88.8%
*-commutative88.8%
*-commutative88.8%
Simplified88.8%
Taylor expanded in k around 0 36.5%
associate-/l*36.5%
Simplified36.5%
Final simplification36.5%
(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.6%
associate-*l/99.7%
*-un-lft-identity99.7%
unpow-prod-down73.2%
unpow-prod-down99.7%
div-sub99.7%
metadata-eval99.7%
pow-div99.7%
pow1/299.7%
associate-/l/99.8%
associate-*l*99.8%
associate-*l*99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
add-sqr-sqrt99.5%
sqrt-unprod88.8%
frac-times88.7%
add-sqr-sqrt88.8%
*-commutative88.8%
associate-*r*88.8%
swap-sqr88.8%
add-sqr-sqrt88.9%
Applied egg-rr88.9%
associate-/l*88.8%
*-commutative88.8%
*-commutative88.8%
Simplified88.8%
Taylor expanded in k around 0 36.5%
Final simplification36.5%
(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(Float64(Float64(2.0 * pi) * n) / k)) end
function tmp = code(k, n) tmp = sqrt((((2.0 * pi) * n) / k)); end
code[k_, n_] := N[Sqrt[N[(N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\left(2 \cdot \pi\right) \cdot n}{k}}
\end{array}
Initial program 99.6%
add-sqr-sqrt99.4%
sqrt-unprod88.6%
*-commutative88.6%
div-sub88.6%
metadata-eval88.6%
div-inv88.7%
*-commutative88.7%
div-sub88.7%
metadata-eval88.7%
div-inv88.7%
Applied egg-rr88.8%
distribute-lft-in88.8%
metadata-eval88.8%
*-commutative88.8%
associate-*r*88.8%
metadata-eval88.8%
mul-1-neg88.8%
sub-neg88.8%
associate-*r*88.8%
*-commutative88.8%
associate-*l*88.8%
Simplified88.8%
associate-*r*88.8%
*-commutative88.8%
pow-sub88.9%
pow188.9%
div-inv88.9%
*-commutative88.9%
associate-*r*88.9%
*-commutative88.9%
associate-*r*88.9%
Applied egg-rr88.9%
associate-*r/88.9%
*-rgt-identity88.9%
associate-/l*88.9%
associate-/l*88.9%
*-commutative88.9%
associate-*r*88.9%
Simplified88.9%
Taylor expanded in k around 0 36.5%
*-commutative36.5%
associate-*l*36.5%
*-commutative36.5%
Simplified36.5%
Final simplification36.5%
herbie shell --seed 2024052
(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))))