
(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 (let* ((t_0 (* PI (* 2.0 n)))) (* (pow t_0 (* k -0.5)) (/ (sqrt t_0) (sqrt k)))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return pow(t_0, (k * -0.5)) * (sqrt(t_0) / sqrt(k));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return Math.pow(t_0, (k * -0.5)) * (Math.sqrt(t_0) / Math.sqrt(k));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.pow(t_0, (k * -0.5)) * (math.sqrt(t_0) / math.sqrt(k))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64((t_0 ^ Float64(k * -0.5)) * Float64(sqrt(t_0) / sqrt(k))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = (t_0 ^ (k * -0.5)) * (sqrt(t_0) / sqrt(k)); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[t$95$0, N[(k * -0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
{t_0}^{\left(k \cdot -0.5\right)} \cdot \frac{\sqrt{t_0}}{\sqrt{k}}
\end{array}
\end{array}
Initial program 99.4%
associate-*l/99.4%
add-cbrt-cube76.2%
add-sqr-sqrt76.2%
cbrt-prod99.0%
*-un-lft-identity99.0%
associate-/r*98.9%
*-commutative98.9%
associate-*l*98.9%
div-sub98.9%
metadata-eval98.9%
div-inv98.9%
metadata-eval98.9%
Applied egg-rr98.9%
associate-/l/99.0%
sqr-pow99.0%
sqr-pow99.0%
*-commutative99.0%
associate-*r*99.0%
*-commutative99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
*-commutative99.0%
Simplified99.0%
cbrt-unprod76.2%
pow1/374.3%
pow1/274.3%
pow-plus74.3%
metadata-eval74.3%
Applied egg-rr74.3%
associate-*r*74.3%
*-commutative74.3%
pow-prod-up74.5%
pow1/274.5%
*-un-lft-identity74.5%
pow-pow99.7%
metadata-eval99.7%
pow1/299.7%
times-frac99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Applied egg-rr99.7%
times-frac99.7%
*-commutative99.7%
times-frac99.7%
/-rgt-identity99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (let* ((t_0 (* PI (* 2.0 n)))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(k * N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
\frac{\sqrt{t_0}}{\sqrt{k \cdot {t_0}^{k}}}
\end{array}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
clear-num85.3%
sqrt-div86.0%
metadata-eval86.0%
associate-*r*86.0%
*-commutative86.0%
Applied egg-rr86.0%
inv-pow86.0%
sqrt-pow286.1%
associate-*r*86.1%
*-commutative86.1%
*-commutative86.1%
*-commutative86.1%
metadata-eval86.1%
Applied egg-rr86.1%
rem-square-sqrt86.0%
rem-square-sqrt86.1%
*-commutative86.1%
associate-*l*86.1%
*-commutative86.1%
Simplified86.1%
add-sqr-sqrt85.9%
sqrt-unprod85.3%
pow-prod-up85.3%
metadata-eval85.3%
inv-pow85.3%
*-commutative85.3%
pow-sub85.5%
pow185.5%
clear-num85.5%
associate-/l/85.5%
Applied egg-rr99.7%
*-commutative99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (pow (* PI (* 2.0 n)) (- 0.5 (* k 0.5))) (pow k -0.5)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), (0.5 - (k * 0.5))) * pow(k, -0.5);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), (0.5 - (k * 0.5))) * Math.pow(k, -0.5);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), (0.5 - (k * 0.5))) * math.pow(k, -0.5)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(0.5 - Float64(k * 0.5))) * (k ^ -0.5)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ (0.5 - (k * 0.5))) * (k ^ -0.5); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[k, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(0.5 - k \cdot 0.5\right)} \cdot {k}^{-0.5}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.3%
pow-sqr99.4%
associate-*l*99.4%
*-commutative99.4%
associate-*l/99.4%
associate-/l*99.4%
metadata-eval99.4%
/-rgt-identity99.4%
div-sub99.4%
metadata-eval99.4%
Simplified99.4%
div-inv99.4%
associate-*r*99.4%
*-commutative99.4%
associate-*l*99.4%
div-inv99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.3%
pow-sqr99.4%
associate-*l*99.4%
*-commutative99.4%
associate-*l/99.4%
associate-/l*99.4%
metadata-eval99.4%
/-rgt-identity99.4%
div-sub99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (k n) :precision binary64 (pow (* k (pow (* PI (* 2.0 n)) (+ k -1.0))) -0.5))
double code(double k, double n) {
return pow((k * pow((((double) M_PI) * (2.0 * n)), (k + -1.0))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * Math.pow((Math.PI * (2.0 * n)), (k + -1.0))), -0.5);
}
def code(k, n): return math.pow((k * math.pow((math.pi * (2.0 * n)), (k + -1.0))), -0.5)
function code(k, n) return Float64(k * (Float64(pi * Float64(2.0 * n)) ^ Float64(k + -1.0))) ^ -0.5 end
function tmp = code(k, n) tmp = (k * ((pi * (2.0 * n)) ^ (k + -1.0))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(k + -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot {\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(k + -1\right)}\right)}^{-0.5}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
clear-num85.3%
sqrt-div86.0%
metadata-eval86.0%
associate-*r*86.0%
*-commutative86.0%
Applied egg-rr86.0%
inv-pow86.0%
sqrt-pow286.1%
associate-*r*86.1%
*-commutative86.1%
*-commutative86.1%
*-commutative86.1%
metadata-eval86.1%
Applied egg-rr86.1%
rem-square-sqrt86.0%
rem-square-sqrt86.1%
*-commutative86.1%
associate-*l*86.1%
*-commutative86.1%
Simplified86.1%
sqr-pow86.0%
Applied egg-rr86.0%
pow-sqr86.1%
metadata-eval86.1%
*-commutative86.1%
sub-neg86.1%
metadata-eval86.1%
Simplified86.1%
Final simplification86.1%
(FPCore (k n) :precision binary64 (pow (/ k (pow (* PI (* 2.0 n)) (- 1.0 k))) -0.5))
double code(double k, double n) {
return pow((k / pow((((double) M_PI) * (2.0 * n)), (1.0 - k))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k / Math.pow((Math.PI * (2.0 * n)), (1.0 - k))), -0.5);
}
def code(k, n): return math.pow((k / math.pow((math.pi * (2.0 * n)), (1.0 - k))), -0.5)
function code(k, n) return Float64(k / (Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k))) ^ -0.5 end
function tmp = code(k, n) tmp = (k / ((pi * (2.0 * n)) ^ (1.0 - k))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k / N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}\right)}^{-0.5}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
clear-num85.3%
sqrt-div86.0%
metadata-eval86.0%
associate-*r*86.0%
*-commutative86.0%
Applied egg-rr86.0%
inv-pow86.0%
sqrt-pow286.1%
associate-*r*86.1%
*-commutative86.1%
*-commutative86.1%
*-commutative86.1%
metadata-eval86.1%
Applied egg-rr86.1%
rem-square-sqrt86.0%
rem-square-sqrt86.1%
*-commutative86.1%
associate-*l*86.1%
*-commutative86.1%
Simplified86.1%
Final simplification86.1%
(FPCore (k n) :precision binary64 (sqrt (/ (pow (* n (* PI 2.0)) (- 1.0 k)) k)))
double code(double k, double n) {
return sqrt((pow((n * (((double) M_PI) * 2.0)), (1.0 - k)) / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.pow((n * (Math.PI * 2.0)), (1.0 - k)) / k));
}
def code(k, n): return math.sqrt((math.pow((n * (math.pi * 2.0)), (1.0 - k)) / k))
function code(k, n) return sqrt(Float64((Float64(n * Float64(pi * 2.0)) ^ Float64(1.0 - k)) / k)) end
function tmp = code(k, n) tmp = sqrt((((n * (pi * 2.0)) ^ (1.0 - k)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[Power[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{{\left(n \cdot \left(\pi \cdot 2\right)\right)}^{\left(1 - k\right)}}{k}}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
Final simplification85.3%
(FPCore (k n) :precision binary64 (pow (/ k (* PI (* 2.0 n))) -0.5))
double code(double k, double n) {
return pow((k / (((double) M_PI) * (2.0 * n))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k / (Math.PI * (2.0 * n))), -0.5);
}
def code(k, n): return math.pow((k / (math.pi * (2.0 * n))), -0.5)
function code(k, n) return Float64(k / Float64(pi * Float64(2.0 * n))) ^ -0.5 end
function tmp = code(k, n) tmp = (k / (pi * (2.0 * n))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k / N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{\pi \cdot \left(2 \cdot n\right)}\right)}^{-0.5}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
clear-num85.3%
sqrt-div86.0%
metadata-eval86.0%
associate-*r*86.0%
*-commutative86.0%
Applied egg-rr86.0%
inv-pow86.0%
sqrt-pow286.1%
associate-*r*86.1%
*-commutative86.1%
*-commutative86.1%
*-commutative86.1%
metadata-eval86.1%
Applied egg-rr86.1%
rem-square-sqrt86.0%
rem-square-sqrt86.1%
*-commutative86.1%
associate-*l*86.1%
*-commutative86.1%
Simplified86.1%
Taylor expanded in k around 0 32.8%
associate-*r*32.8%
*-commutative32.8%
*-commutative32.8%
Simplified32.8%
Final simplification32.8%
(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.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
pow-sub85.5%
pow185.5%
associate-*r*85.5%
*-commutative85.5%
associate-*r*85.5%
*-commutative85.5%
Applied egg-rr85.5%
Taylor expanded in k around 0 32.0%
associate-/l*31.9%
Simplified31.9%
Final simplification31.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(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.4%
add-sqr-sqrt99.2%
sqrt-unprod85.2%
*-commutative85.2%
div-inv85.2%
*-commutative85.2%
div-inv85.2%
frac-times85.2%
Applied egg-rr85.2%
Simplified85.3%
pow-sub85.5%
pow185.5%
associate-*r*85.5%
*-commutative85.5%
associate-*r*85.5%
*-commutative85.5%
Applied egg-rr85.5%
Taylor expanded in k around 0 32.0%
Final simplification32.0%
herbie shell --seed 2023298
(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))))