
(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 10 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.5%
associate-*l/99.6%
*-lft-identity99.6%
sqr-pow99.4%
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 (if (<= k 2.1e-26) (* (sqrt (/ PI (/ 0.5 n))) (pow k -0.5)) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2.1e-26) {
tmp = sqrt((((double) M_PI) / (0.5 / n))) * pow(k, -0.5);
} 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 <= 2.1e-26) {
tmp = Math.sqrt((Math.PI / (0.5 / n))) * Math.pow(k, -0.5);
} 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 <= 2.1e-26: tmp = math.sqrt((math.pi / (0.5 / n))) * math.pow(k, -0.5) 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 <= 2.1e-26) tmp = Float64(sqrt(Float64(pi / Float64(0.5 / n))) * (k ^ -0.5)); 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 <= 2.1e-26) tmp = sqrt((pi / (0.5 / n))) * (k ^ -0.5); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.1e-26], N[(N[Sqrt[N[(Pi / N[(0.5 / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[k, -0.5], $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 2.1 \cdot 10^{-26}:\\
\;\;\;\;\sqrt{\frac{\pi}{\frac{0.5}{n}}} \cdot {k}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 2.10000000000000008e-26Initial program 99.3%
Taylor expanded in k around 0 99.2%
*-commutative99.2%
div-inv99.2%
sqrt-unprod99.3%
*-commutative99.3%
*-commutative99.3%
sqrt-undiv76.5%
associate-*r*76.5%
*-commutative76.5%
associate-*r*76.5%
Applied egg-rr76.5%
sqrt-div99.3%
div-inv99.3%
metadata-eval99.3%
sqrt-div99.3%
associate-*r*99.3%
*-commutative99.3%
associate-*l*99.3%
inv-pow99.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
*-commutative99.3%
associate-*l*99.3%
Simplified99.3%
associate-*r*99.3%
metadata-eval99.3%
div-inv99.3%
associate-/l*99.4%
Applied egg-rr99.4%
if 2.10000000000000008e-26 < k Initial program 99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.1%
*-commutative99.1%
div-inv99.1%
*-commutative99.1%
div-inv99.1%
frac-times99.1%
Applied egg-rr99.1%
Simplified99.1%
Final simplification99.2%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI (/ 0.5 n))) (pow k -0.5)))
double code(double k, double n) {
return sqrt((((double) M_PI) / (0.5 / n))) * pow(k, -0.5);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / (0.5 / n))) * Math.pow(k, -0.5);
}
def code(k, n): return math.sqrt((math.pi / (0.5 / n))) * math.pow(k, -0.5)
function code(k, n) return Float64(sqrt(Float64(pi / Float64(0.5 / n))) * (k ^ -0.5)) end
function tmp = code(k, n) tmp = sqrt((pi / (0.5 / n))) * (k ^ -0.5); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / N[(0.5 / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[k, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{\frac{0.5}{n}}} \cdot {k}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
sqrt-div47.9%
div-inv47.9%
metadata-eval47.9%
sqrt-div47.9%
associate-*r*47.9%
*-commutative47.9%
associate-*l*47.9%
inv-pow47.9%
sqrt-pow147.9%
metadata-eval47.9%
Applied egg-rr47.9%
*-commutative47.9%
associate-*l*47.9%
Simplified47.9%
associate-*r*47.9%
metadata-eval47.9%
div-inv47.9%
associate-/l*47.9%
Applied egg-rr47.9%
Final simplification47.9%
(FPCore (k n) :precision binary64 (* (sqrt (/ 2.0 k)) (sqrt (* PI n))))
double code(double k, double n) {
return sqrt((2.0 / k)) * sqrt((((double) M_PI) * n));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 / k)) * Math.sqrt((Math.PI * n));
}
def code(k, n): return math.sqrt((2.0 / k)) * math.sqrt((math.pi * n))
function code(k, n) return Float64(sqrt(Float64(2.0 / k)) * sqrt(Float64(pi * n))) end
function tmp = code(k, n) tmp = sqrt((2.0 / k)) * sqrt((pi * n)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2}{k}} \cdot \sqrt{\pi \cdot n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
associate-*r*37.8%
associate-*r/37.8%
metadata-eval37.8%
div-inv37.8%
associate-/r*37.8%
*-commutative37.8%
clear-num37.7%
metadata-eval37.7%
add-sqr-sqrt37.7%
frac-times37.7%
sqrt-unprod38.2%
add-sqr-sqrt38.5%
sqrt-div47.9%
associate-/r/47.9%
Applied egg-rr47.9%
Final simplification47.9%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (* 2.0 n))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 * n))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (2.0 * n))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
associate-*l/47.8%
*-un-lft-identity47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
associate-*r*47.9%
*-commutative47.9%
associate-*r*47.9%
Applied egg-rr47.9%
Final simplification47.9%
(FPCore (k n) :precision binary64 (pow (* (/ k n) (/ 0.5 PI)) -0.5))
double code(double k, double n) {
return pow(((k / n) * (0.5 / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / n) * (0.5 / Math.PI)), -0.5);
}
def code(k, n): return math.pow(((k / n) * (0.5 / math.pi)), -0.5)
function code(k, n) return Float64(Float64(k / n) * Float64(0.5 / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / n) * (0.5 / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / n), $MachinePrecision] * N[(0.5 / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{n} \cdot \frac{0.5}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
associate-*r*37.8%
associate-*r/37.8%
metadata-eval37.8%
div-inv37.8%
associate-/r*37.8%
*-commutative37.8%
clear-num37.7%
metadata-eval37.7%
add-sqr-sqrt37.7%
frac-times37.7%
sqrt-unprod38.2%
add-sqr-sqrt38.5%
inv-pow38.5%
sqrt-pow238.5%
Applied egg-rr38.5%
associate-*r/38.5%
*-commutative38.5%
*-commutative38.5%
times-frac38.5%
Simplified38.5%
Final simplification38.5%
(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(Float64(0.5 * 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[(N[(0.5 * k), $MachinePrecision] / N[(Pi * n), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{0.5 \cdot k}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
associate-*r*37.8%
associate-*r/37.8%
metadata-eval37.8%
div-inv37.8%
associate-/r*37.8%
*-commutative37.8%
clear-num37.7%
metadata-eval37.7%
add-sqr-sqrt37.7%
frac-times37.7%
sqrt-unprod38.2%
add-sqr-sqrt38.5%
inv-pow38.5%
sqrt-pow238.5%
Applied egg-rr38.5%
associate-*r/38.5%
*-commutative38.5%
*-commutative38.5%
Simplified38.5%
Final simplification38.5%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ PI (/ k n)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / (k / n))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / (k / n))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi / (k / n))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / (k / n)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
Taylor expanded in n around 0 37.8%
*-commutative37.8%
associate-/l*37.8%
Simplified37.8%
Final simplification37.8%
(FPCore (k n) :precision binary64 (sqrt (* PI (* n (/ 2.0 k)))))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n * (2.0 / k))));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n * (2.0 / k))));
}
def code(k, n): return math.sqrt((math.pi * (n * (2.0 / k))))
function code(k, n) return sqrt(Float64(pi * Float64(n * Float64(2.0 / k)))) end
function tmp = code(k, n) tmp = sqrt((pi * (n * (2.0 / k)))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(n * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \left(n \cdot \frac{2}{k}\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
Final simplification37.8%
(FPCore (k n) :precision binary64 (sqrt (/ n (* 0.5 (/ k PI)))))
double code(double k, double n) {
return sqrt((n / (0.5 * (k / ((double) M_PI)))));
}
public static double code(double k, double n) {
return Math.sqrt((n / (0.5 * (k / Math.PI))));
}
def code(k, n): return math.sqrt((n / (0.5 * (k / math.pi))))
function code(k, n) return sqrt(Float64(n / Float64(0.5 * Float64(k / pi)))) end
function tmp = code(k, n) tmp = sqrt((n / (0.5 * (k / pi)))); end
code[k_, n_] := N[Sqrt[N[(n / N[(0.5 * N[(k / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{n}{0.5 \cdot \frac{k}{\pi}}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.8%
*-commutative47.8%
div-inv47.8%
sqrt-unprod47.9%
*-commutative47.9%
*-commutative47.9%
sqrt-undiv37.8%
associate-*r*37.8%
*-commutative37.8%
associate-*r*37.8%
Applied egg-rr37.8%
Taylor expanded in n around 0 37.8%
associate-*l/37.8%
associate-*r*37.8%
associate-*r/37.8%
*-commutative37.8%
*-commutative37.8%
associate-*r/37.8%
Simplified37.8%
associate-*r*37.8%
associate-*r/37.8%
metadata-eval37.8%
div-inv37.8%
associate-/r*37.8%
*-commutative37.8%
*-commutative37.8%
associate-/l*37.8%
*-commutative37.8%
*-un-lft-identity37.8%
times-frac37.8%
metadata-eval37.8%
Applied egg-rr37.8%
Final simplification37.8%
herbie shell --seed 2023307
(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))))