
(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 7 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(2.0 * Float64(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[(2.0 * N[(Pi * 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 := 2 \cdot \left(\pi \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.6%
unpow-prod-down67.7%
unpow-prod-down99.6%
div-sub99.6%
metadata-eval99.6%
pow-sub99.7%
pow1/299.7%
frac-times99.7%
*-un-lft-identity99.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 5.7e-77) (* (sqrt (/ 1.0 k)) (sqrt (* PI (/ n 0.5)))) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 5.7e-77) {
tmp = sqrt((1.0 / k)) * sqrt((((double) M_PI) * (n / 0.5)));
} else {
tmp = sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 5.7e-77) {
tmp = Math.sqrt((1.0 / k)) * Math.sqrt((Math.PI * (n / 0.5)));
} else {
tmp = Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 5.7e-77: tmp = math.sqrt((1.0 / k)) * math.sqrt((math.pi * (n / 0.5))) else: tmp = math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 5.7e-77) tmp = Float64(sqrt(Float64(1.0 / k)) * sqrt(Float64(pi * Float64(n / 0.5)))); else tmp = sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 5.7e-77) tmp = sqrt((1.0 / k)) * sqrt((pi * (n / 0.5))); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 5.7e-77], N[(N[Sqrt[N[(1.0 / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi * N[(n / 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5.7 \cdot 10^{-77}:\\
\;\;\;\;\sqrt{\frac{1}{k}} \cdot \sqrt{\pi \cdot \frac{n}{0.5}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 5.69999999999999981e-77Initial program 99.3%
*-commutative99.3%
div-sub99.3%
metadata-eval99.3%
div-inv99.4%
add-sqr-sqrt99.0%
sqrt-unprod67.1%
frac-times67.1%
Applied egg-rr67.2%
Taylor expanded in k around 0 67.2%
*-commutative67.2%
*-commutative67.2%
associate-*r*67.2%
Simplified67.2%
pow1/267.2%
div-inv67.2%
unpow-prod-down99.4%
pow1/299.4%
*-commutative99.4%
Applied egg-rr99.4%
unpow1/299.4%
*-commutative99.4%
/-rgt-identity99.4%
*-commutative99.4%
associate-/l*99.4%
metadata-eval99.4%
Simplified99.4%
if 5.69999999999999981e-77 < k Initial program 99.7%
*-commutative99.7%
div-sub99.7%
metadata-eval99.7%
div-inv99.7%
add-sqr-sqrt99.7%
sqrt-unprod99.7%
frac-times99.7%
Applied egg-rr99.7%
Final simplification99.6%
(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.6%
*-lft-identity99.6%
sqr-pow99.5%
pow-sqr99.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 (/ 1.0 k)) (sqrt (* PI (/ n 0.5)))))
double code(double k, double n) {
return sqrt((1.0 / k)) * sqrt((((double) M_PI) * (n / 0.5)));
}
public static double code(double k, double n) {
return Math.sqrt((1.0 / k)) * Math.sqrt((Math.PI * (n / 0.5)));
}
def code(k, n): return math.sqrt((1.0 / k)) * math.sqrt((math.pi * (n / 0.5)))
function code(k, n) return Float64(sqrt(Float64(1.0 / k)) * sqrt(Float64(pi * Float64(n / 0.5)))) end
function tmp = code(k, n) tmp = sqrt((1.0 / k)) * sqrt((pi * (n / 0.5))); end
code[k_, n_] := N[(N[Sqrt[N[(1.0 / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi * N[(n / 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{k}} \cdot \sqrt{\pi \cdot \frac{n}{0.5}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.4%
sqrt-unprod89.0%
frac-times89.0%
Applied egg-rr89.1%
Taylor expanded in k around 0 32.5%
*-commutative32.5%
*-commutative32.5%
associate-*r*32.5%
Simplified32.5%
pow1/232.5%
div-inv32.5%
unpow-prod-down43.1%
pow1/243.1%
*-commutative43.1%
Applied egg-rr43.1%
unpow1/243.1%
*-commutative43.1%
/-rgt-identity43.1%
*-commutative43.1%
associate-/l*43.1%
metadata-eval43.1%
Simplified43.1%
Final simplification43.1%
(FPCore (k n) :precision binary64 (/ 1.0 (/ (sqrt (/ k PI)) (sqrt (+ n n)))))
double code(double k, double n) {
return 1.0 / (sqrt((k / ((double) M_PI))) / sqrt((n + n)));
}
public static double code(double k, double n) {
return 1.0 / (Math.sqrt((k / Math.PI)) / Math.sqrt((n + n)));
}
def code(k, n): return 1.0 / (math.sqrt((k / math.pi)) / math.sqrt((n + n)))
function code(k, n) return Float64(1.0 / Float64(sqrt(Float64(k / pi)) / sqrt(Float64(n + n)))) end
function tmp = code(k, n) tmp = 1.0 / (sqrt((k / pi)) / sqrt((n + n))); end
code[k_, n_] := N[(1.0 / N[(N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(n + n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\frac{k}{\pi}}}{\sqrt{n + n}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.4%
sqrt-unprod89.0%
frac-times89.0%
Applied egg-rr89.1%
Taylor expanded in k around 0 32.5%
*-commutative32.5%
*-commutative32.5%
associate-*r*32.5%
Simplified32.5%
clear-num32.5%
sqrt-div32.5%
metadata-eval32.5%
*-commutative32.5%
Applied egg-rr32.5%
/-rgt-identity32.5%
*-commutative32.5%
associate-/l*32.5%
metadata-eval32.5%
Simplified32.5%
div-inv32.5%
metadata-eval32.5%
associate-/r*32.5%
sqrt-div43.1%
*-commutative43.1%
Applied egg-rr43.1%
rem-log-exp3.8%
log-pow3.8%
unpow23.8%
prod-exp3.9%
rem-log-exp43.1%
Simplified43.1%
Final simplification43.1%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (/ n 0.5))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (n / 0.5))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (n / 0.5))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (n / 0.5))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(n / 0.5))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (n / 0.5))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(n / 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \frac{n}{0.5}}}{\sqrt{k}}
\end{array}
Initial program 99.6%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.4%
sqrt-unprod89.0%
frac-times89.0%
Applied egg-rr89.1%
Taylor expanded in k around 0 32.5%
*-commutative32.5%
*-commutative32.5%
associate-*r*32.5%
Simplified32.5%
sqrt-div43.1%
associate-*r*43.1%
*-commutative43.1%
sqrt-prod43.1%
*-un-lft-identity43.1%
*-commutative43.1%
add-sqr-sqrt42.9%
times-frac43.0%
Applied egg-rr43.0%
/-rgt-identity43.0%
associate-*r/43.0%
rem-square-sqrt43.1%
/-rgt-identity43.1%
*-commutative43.1%
associate-/l*43.1%
metadata-eval43.1%
Simplified43.1%
Final simplification43.1%
(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%
*-commutative99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.6%
add-sqr-sqrt99.4%
sqrt-unprod89.0%
frac-times89.0%
Applied egg-rr89.1%
Taylor expanded in k around 0 32.5%
*-commutative32.5%
*-commutative32.5%
associate-*r*32.5%
Simplified32.5%
Taylor expanded in n around 0 32.5%
associate-/l*32.6%
associate-/r/32.5%
Simplified32.5%
Taylor expanded in n around 0 32.5%
*-commutative32.5%
associate-*l/32.6%
*-commutative32.6%
Simplified32.6%
Final simplification32.6%
herbie shell --seed 2023275
(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))))