
(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 (* n (* 2.0 PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((n * (2.0 * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (2.0 * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (2.0 * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (2.0 * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.7%
*-lft-identity99.7%
sqr-pow99.5%
pow-sqr99.7%
*-commutative99.7%
associate-*l/99.7%
associate-/l*99.7%
metadata-eval99.7%
/-rgt-identity99.7%
div-sub99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 1.76e+189) (pow (* 0.5 (/ k (* PI n))) -0.5) (pow (* (pow (* n (/ PI k)) 2.0) 4.0) 0.25)))
double code(double k, double n) {
double tmp;
if (k <= 1.76e+189) {
tmp = pow((0.5 * (k / (((double) M_PI) * n))), -0.5);
} else {
tmp = pow((pow((n * (((double) M_PI) / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.76e+189) {
tmp = Math.pow((0.5 * (k / (Math.PI * n))), -0.5);
} else {
tmp = Math.pow((Math.pow((n * (Math.PI / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.76e+189: tmp = math.pow((0.5 * (k / (math.pi * n))), -0.5) else: tmp = math.pow((math.pow((n * (math.pi / k)), 2.0) * 4.0), 0.25) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.76e+189) tmp = Float64(0.5 * Float64(k / Float64(pi * n))) ^ -0.5; else tmp = Float64((Float64(n * Float64(pi / k)) ^ 2.0) * 4.0) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.76e+189) tmp = (0.5 * (k / (pi * n))) ^ -0.5; else tmp = (((n * (pi / k)) ^ 2.0) * 4.0) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.76e+189], N[Power[N[(0.5 * N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], N[Power[N[(N[Power[N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 4.0), $MachinePrecision], 0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.76 \cdot 10^{+189}:\\
\;\;\;\;{\left(0.5 \cdot \frac{k}{\pi \cdot n}\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(n \cdot \frac{\pi}{k}\right)}^{2} \cdot 4\right)}^{0.25}\\
\end{array}
\end{array}
if k < 1.75999999999999999e189Initial program 99.5%
expm1-log1p-u95.3%
expm1-udef79.0%
inv-pow79.0%
sqrt-pow279.0%
metadata-eval79.0%
Applied egg-rr79.0%
expm1-def95.3%
expm1-log1p99.6%
Simplified99.6%
metadata-eval99.6%
pow-pow99.3%
add-sqr-sqrt99.2%
sqrt-unprod86.5%
*-commutative86.5%
*-commutative86.5%
swap-sqr86.4%
Applied egg-rr86.9%
pow1/286.9%
pow-flip87.1%
*-commutative87.1%
associate-*r*87.1%
metadata-eval87.1%
Applied egg-rr87.1%
Taylor expanded in k around 0 49.5%
if 1.75999999999999999e189 < k Initial program 100.0%
*-commutative100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
frac-times100.0%
Applied egg-rr100.0%
Taylor expanded in k around 0 2.4%
associate-/l*2.4%
associate-/r/2.4%
Simplified2.4%
pow1/22.4%
metadata-eval2.4%
pow-prod-up2.4%
pow-prod-down11.3%
pow211.3%
*-commutative11.3%
Applied egg-rr11.3%
unpow211.3%
*-commutative11.3%
*-commutative11.3%
swap-sqr11.3%
unpow211.3%
associate-*r/11.3%
associate-*l/11.3%
*-commutative11.3%
metadata-eval11.3%
Simplified11.3%
Final simplification41.6%
(FPCore (k n) :precision binary64 (if (<= k 2.85e+132) (pow (* 0.5 (/ k (* PI n))) -0.5) (pow (pow (/ (* PI n) (/ k 2.0)) 3.0) 0.16666666666666666)))
double code(double k, double n) {
double tmp;
if (k <= 2.85e+132) {
tmp = pow((0.5 * (k / (((double) M_PI) * n))), -0.5);
} else {
tmp = pow(pow(((((double) M_PI) * n) / (k / 2.0)), 3.0), 0.16666666666666666);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.85e+132) {
tmp = Math.pow((0.5 * (k / (Math.PI * n))), -0.5);
} else {
tmp = Math.pow(Math.pow(((Math.PI * n) / (k / 2.0)), 3.0), 0.16666666666666666);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 2.85e+132: tmp = math.pow((0.5 * (k / (math.pi * n))), -0.5) else: tmp = math.pow(math.pow(((math.pi * n) / (k / 2.0)), 3.0), 0.16666666666666666) return tmp
function code(k, n) tmp = 0.0 if (k <= 2.85e+132) tmp = Float64(0.5 * Float64(k / Float64(pi * n))) ^ -0.5; else tmp = (Float64(Float64(pi * n) / Float64(k / 2.0)) ^ 3.0) ^ 0.16666666666666666; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 2.85e+132) tmp = (0.5 * (k / (pi * n))) ^ -0.5; else tmp = (((pi * n) / (k / 2.0)) ^ 3.0) ^ 0.16666666666666666; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.85e+132], N[Power[N[(0.5 * N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], N[Power[N[Power[N[(N[(Pi * n), $MachinePrecision] / N[(k / 2.0), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.85 \cdot 10^{+132}:\\
\;\;\;\;{\left(0.5 \cdot \frac{k}{\pi \cdot n}\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(\frac{\pi \cdot n}{\frac{k}{2}}\right)}^{3}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if k < 2.8499999999999999e132Initial program 99.4%
expm1-log1p-u94.8%
expm1-udef82.3%
inv-pow82.3%
sqrt-pow282.3%
metadata-eval82.3%
Applied egg-rr82.3%
expm1-def94.8%
expm1-log1p99.5%
Simplified99.5%
metadata-eval99.5%
pow-pow99.3%
add-sqr-sqrt99.1%
sqrt-unprod85.1%
*-commutative85.1%
*-commutative85.1%
swap-sqr85.1%
Applied egg-rr85.6%
pow1/285.6%
pow-flip85.7%
*-commutative85.7%
associate-*r*85.7%
metadata-eval85.7%
Applied egg-rr85.7%
Taylor expanded in k around 0 54.3%
if 2.8499999999999999e132 < k Initial program 100.0%
*-commutative100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
frac-times100.0%
Applied egg-rr100.0%
Taylor expanded in k around 0 2.4%
associate-/l*2.4%
associate-/r/2.4%
Simplified2.4%
*-commutative2.4%
clear-num2.4%
un-div-inv2.4%
Applied egg-rr2.4%
pow1/22.4%
div-inv2.4%
clear-num2.4%
metadata-eval2.4%
pow-pow5.0%
sqr-pow5.0%
pow-prod-down12.9%
Applied egg-rr12.9%
*-commutative12.9%
associate-*r*12.9%
associate-*r/12.9%
associate-*l/12.9%
associate-/l*12.9%
associate-*l/12.9%
*-commutative12.9%
Simplified12.9%
Final simplification42.7%
(FPCore (k n) :precision binary64 (pow (/ k (pow (* n (* 2.0 PI)) (- 1.0 k))) -0.5))
double code(double k, double n) {
return pow((k / pow((n * (2.0 * ((double) M_PI))), (1.0 - k))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k / Math.pow((n * (2.0 * Math.PI)), (1.0 - k))), -0.5);
}
def code(k, n): return math.pow((k / math.pow((n * (2.0 * math.pi)), (1.0 - k))), -0.5)
function code(k, n) return Float64(k / (Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k))) ^ -0.5 end
function tmp = code(k, n) tmp = (k / ((n * (2.0 * pi)) ^ (1.0 - k))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k / N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}\right)}^{-0.5}
\end{array}
Initial program 99.6%
expm1-log1p-u96.3%
expm1-udef70.5%
inv-pow70.5%
sqrt-pow270.5%
metadata-eval70.5%
Applied egg-rr70.5%
expm1-def96.3%
expm1-log1p99.7%
Simplified99.7%
metadata-eval99.7%
pow-pow99.5%
add-sqr-sqrt99.4%
sqrt-unprod89.3%
*-commutative89.3%
*-commutative89.3%
swap-sqr89.3%
Applied egg-rr89.6%
pow1/289.6%
pow-flip89.7%
*-commutative89.7%
associate-*r*89.7%
metadata-eval89.7%
Applied egg-rr89.7%
Final simplification89.7%
(FPCore (k n) :precision binary64 (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k)))
double code(double k, double n) {
return sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) / k));
}
def code(k, n): return math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) / k))
function code(k, n) return sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) / k)) end
function tmp = code(k, n) tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
add-sqr-sqrt99.4%
sqrt-unprod89.5%
frac-times89.4%
Applied egg-rr89.5%
Final simplification89.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(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%
expm1-log1p-u96.3%
expm1-udef70.5%
inv-pow70.5%
sqrt-pow270.5%
metadata-eval70.5%
Applied egg-rr70.5%
expm1-def96.3%
expm1-log1p99.7%
Simplified99.7%
metadata-eval99.7%
pow-pow99.5%
add-sqr-sqrt99.4%
sqrt-unprod89.3%
*-commutative89.3%
*-commutative89.3%
swap-sqr89.3%
Applied egg-rr89.6%
pow1/289.6%
pow-flip89.7%
*-commutative89.7%
associate-*r*89.7%
metadata-eval89.7%
Applied egg-rr89.7%
Taylor expanded in k around 0 39.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(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%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
add-sqr-sqrt99.4%
sqrt-unprod89.5%
frac-times89.4%
Applied egg-rr89.5%
Taylor expanded in k around 0 39.5%
associate-/l*39.5%
associate-/r/39.5%
Simplified39.5%
Final simplification39.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.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
add-sqr-sqrt99.4%
sqrt-unprod89.5%
frac-times89.4%
Applied egg-rr89.5%
Taylor expanded in k around 0 39.5%
associate-/l*39.5%
associate-/r/39.5%
Simplified39.5%
*-commutative39.5%
clear-num39.5%
un-div-inv39.5%
Applied egg-rr39.5%
Final simplification39.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%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
add-sqr-sqrt99.4%
sqrt-unprod89.5%
frac-times89.4%
Applied egg-rr89.5%
Taylor expanded in k around 0 39.5%
Final simplification39.5%
(FPCore (k n) :precision binary64 (sqrt (/ (* PI n) (/ k 2.0))))
double code(double k, double n) {
return sqrt(((((double) M_PI) * n) / (k / 2.0)));
}
public static double code(double k, double n) {
return Math.sqrt(((Math.PI * n) / (k / 2.0)));
}
def code(k, n): return math.sqrt(((math.pi * n) / (k / 2.0)))
function code(k, n) return sqrt(Float64(Float64(pi * n) / Float64(k / 2.0))) end
function tmp = code(k, n) tmp = sqrt(((pi * n) / (k / 2.0))); end
code[k_, n_] := N[Sqrt[N[(N[(Pi * n), $MachinePrecision] / N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi \cdot n}{\frac{k}{2}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
add-sqr-sqrt99.4%
sqrt-unprod89.5%
frac-times89.4%
Applied egg-rr89.5%
Taylor expanded in k around 0 39.5%
associate-/l*39.5%
associate-/r/39.5%
Simplified39.5%
*-commutative39.5%
clear-num39.5%
un-div-inv39.5%
Applied egg-rr39.5%
Taylor expanded in k around 0 39.5%
associate-*r/39.5%
*-commutative39.5%
associate-*r*39.5%
associate-*r/39.5%
*-commutative39.5%
associate-/l*39.5%
associate-*l/39.5%
*-commutative39.5%
Simplified39.5%
Final simplification39.5%
herbie shell --seed 2023271
(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))))