
(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 (/ (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.6%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* n (* 2.0 PI))))
(if (<= k 4.4e-24)
(/ (sqrt t_0) (sqrt k))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = n * (2.0 * ((double) M_PI));
double tmp;
if (k <= 4.4e-24) {
tmp = sqrt(t_0) / sqrt(k);
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = n * (2.0 * Math.PI);
double tmp;
if (k <= 4.4e-24) {
tmp = Math.sqrt(t_0) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = n * (2.0 * math.pi) tmp = 0 if k <= 4.4e-24: tmp = math.sqrt(t_0) / math.sqrt(k) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(n * Float64(2.0 * pi)) tmp = 0.0 if (k <= 4.4e-24) tmp = Float64(sqrt(t_0) / sqrt(k)); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = n * (2.0 * pi); tmp = 0.0; if (k <= 4.4e-24) tmp = sqrt(t_0) / sqrt(k); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 4.4e-24], N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[k], $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 := n \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;k \leq 4.4 \cdot 10^{-24}:\\
\;\;\;\;\frac{\sqrt{t\_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t\_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.40000000000000003e-24Initial program 99.5%
Taylor expanded in k around 0 99.2%
associate-*l/99.2%
*-un-lft-identity99.2%
clear-num99.1%
sqrt-unprod99.3%
*-commutative99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
Applied egg-rr99.3%
associate-/r/99.5%
associate-*l/99.5%
*-commutative99.5%
*-rgt-identity99.5%
Simplified99.5%
if 4.40000000000000003e-24 < 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 (if (<= k 1.3e+20) (/ (sqrt (* n (* 2.0 PI))) (sqrt k)) (sqrt (* 2.0 (+ -1.0 (fma PI (/ n k) 1.0))))))
double code(double k, double n) {
double tmp;
if (k <= 1.3e+20) {
tmp = sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
} else {
tmp = sqrt((2.0 * (-1.0 + fma(((double) M_PI), (n / k), 1.0))));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 1.3e+20) tmp = Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)); else tmp = sqrt(Float64(2.0 * Float64(-1.0 + fma(pi, Float64(n / k), 1.0)))); end return tmp end
code[k_, n_] := If[LessEqual[k, 1.3e+20], N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(2.0 * N[(-1.0 + N[(Pi * N[(n / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.3 \cdot 10^{+20}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot \left(-1 + \mathsf{fma}\left(\pi, \frac{n}{k}, 1\right)\right)}\\
\end{array}
\end{array}
if k < 1.3e20Initial program 99.2%
Taylor expanded in k around 0 91.5%
associate-*l/91.5%
*-un-lft-identity91.5%
clear-num91.4%
sqrt-unprod91.6%
*-commutative91.6%
*-commutative91.6%
associate-*r*91.6%
*-commutative91.6%
Applied egg-rr91.6%
associate-/r/91.7%
associate-*l/91.8%
*-commutative91.8%
*-rgt-identity91.8%
Simplified91.8%
if 1.3e20 < k Initial program 100.0%
Taylor expanded in k around 0 2.6%
*-commutative2.6%
associate-/l*2.6%
Simplified2.6%
pow12.6%
sqrt-unprod2.6%
clear-num2.6%
un-div-inv2.6%
Applied egg-rr2.6%
unpow12.6%
associate-/r/2.6%
Simplified2.6%
associate-/r/2.6%
expm1-log1p-u2.6%
expm1-undefine23.7%
associate-/r/23.7%
*-commutative23.7%
Applied egg-rr23.7%
sub-neg23.7%
metadata-eval23.7%
+-commutative23.7%
log1p-undefine23.7%
rem-exp-log23.7%
+-commutative23.7%
fma-define23.7%
Simplified23.7%
Final simplification59.3%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* 2.0 PI))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (2.0 * Math.PI))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (2.0 * math.pi))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (2.0 * pi))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 49.2%
associate-*l/49.2%
*-un-lft-identity49.2%
clear-num49.1%
sqrt-unprod49.2%
*-commutative49.2%
*-commutative49.2%
associate-*r*49.2%
*-commutative49.2%
Applied egg-rr49.2%
associate-/r/49.3%
associate-*l/49.3%
*-commutative49.3%
*-rgt-identity49.3%
Simplified49.3%
Final simplification49.3%
(FPCore (k n) :precision binary64 (pow (* 0.5 (/ k (* PI n))) -0.5))
double code(double k, double n) {
return pow((0.5 * (k / (((double) M_PI) * n))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((0.5 * (k / (Math.PI * n))), -0.5);
}
def code(k, n): return math.pow((0.5 * (k / (math.pi * n))), -0.5)
function code(k, n) return Float64(0.5 * Float64(k / Float64(pi * n))) ^ -0.5 end
function tmp = code(k, n) tmp = (0.5 * (k / (pi * n))) ^ -0.5; end
code[k_, n_] := N[Power[N[(0.5 * N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(0.5 \cdot \frac{k}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 39.3%
*-commutative39.3%
associate-/l*39.3%
Simplified39.3%
pow139.3%
sqrt-unprod39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
unpow139.4%
associate-/r/39.4%
Simplified39.4%
*-commutative39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
metadata-eval39.4%
times-frac39.4%
*-un-lft-identity39.4%
clear-num39.4%
metadata-eval39.4%
add-sqr-sqrt39.3%
frac-times39.3%
sqrt-unprod39.7%
add-sqr-sqrt39.8%
inv-pow39.8%
sqrt-pow239.9%
associate-/l*39.9%
metadata-eval39.9%
Applied egg-rr39.9%
associate-/r*39.9%
Simplified39.9%
Final simplification39.9%
(FPCore (k n) :precision binary64 (pow (* 0.5 (/ (/ k n) PI)) -0.5))
double code(double k, double n) {
return pow((0.5 * ((k / n) / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((0.5 * ((k / n) / Math.PI)), -0.5);
}
def code(k, n): return math.pow((0.5 * ((k / n) / math.pi)), -0.5)
function code(k, n) return Float64(0.5 * Float64(Float64(k / n) / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = (0.5 * ((k / n) / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(0.5 * N[(N[(k / n), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(0.5 \cdot \frac{\frac{k}{n}}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 39.3%
*-commutative39.3%
associate-/l*39.3%
Simplified39.3%
pow139.3%
sqrt-unprod39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
unpow139.4%
associate-/r/39.4%
Simplified39.4%
*-commutative39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
metadata-eval39.4%
times-frac39.4%
*-un-lft-identity39.4%
clear-num39.4%
metadata-eval39.4%
add-sqr-sqrt39.3%
frac-times39.3%
sqrt-unprod39.7%
add-sqr-sqrt39.8%
inv-pow39.8%
sqrt-pow239.9%
associate-/l*39.9%
metadata-eval39.9%
Applied egg-rr39.9%
Final simplification39.9%
(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.6%
Taylor expanded in k around 0 39.3%
*-commutative39.3%
associate-/l*39.3%
Simplified39.3%
pow139.3%
sqrt-unprod39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
unpow139.4%
associate-/r/39.4%
Simplified39.4%
Final simplification39.4%
(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.6%
Taylor expanded in k around 0 39.3%
*-commutative39.3%
associate-/l*39.3%
Simplified39.3%
*-commutative39.3%
sqrt-unprod39.4%
clear-num39.4%
un-div-inv39.4%
Applied egg-rr39.4%
Final simplification39.4%
herbie shell --seed 2024077
(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))))