
(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 (if (<= k 2e-45) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2e-45) {
tmp = sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
} 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 <= 2e-45) {
tmp = Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
} 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 <= 2e-45: tmp = math.sqrt((2.0 * n)) / math.sqrt((k / math.pi)) 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 <= 2e-45) tmp = Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))); 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 <= 2e-45) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2e-45], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $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 \cdot 10^{-45}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.99999999999999997e-45Initial program 99.4%
add-sqr-sqrt98.9%
sqrt-unprod69.2%
associate-*l/69.2%
*-un-lft-identity69.2%
associate-*l/69.2%
*-un-lft-identity69.2%
frac-times69.1%
Applied egg-rr69.2%
Simplified69.4%
Taylor expanded in k around 0 69.4%
associate-/l*69.4%
Simplified69.4%
associate-*r/69.4%
sqrt-div99.5%
Applied egg-rr99.5%
*-commutative99.5%
Simplified99.5%
if 1.99999999999999997e-45 < k Initial program 99.5%
add-sqr-sqrt99.4%
sqrt-unprod99.5%
associate-*l/99.5%
*-un-lft-identity99.5%
associate-*l/99.5%
*-un-lft-identity99.5%
frac-times99.5%
Applied egg-rr99.5%
Simplified99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* 2.0 n)) (+ 0.5 (* -0.5 k))) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), (0.5 + (-0.5 * k))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), (0.5 + (-0.5 * k))) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), (0.5 + (-0.5 * k))) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(0.5 + Float64(-0.5 * k))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ (0.5 + (-0.5 * k))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(-0.5 * k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(0.5 + -0.5 \cdot k\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
div-sub99.5%
sub-neg99.5%
distribute-frac-neg99.5%
metadata-eval99.5%
neg-mul-199.5%
associate-/l*99.5%
associate-/r/99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((2.0 * n)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.2%
sqrt-unprod87.4%
associate-*l/87.4%
*-un-lft-identity87.4%
associate-*l/87.5%
*-un-lft-identity87.5%
frac-times87.4%
Applied egg-rr87.5%
Simplified87.5%
Taylor expanded in k around 0 36.9%
associate-/l*36.9%
Simplified36.9%
associate-*r/36.9%
sqrt-div48.9%
Applied egg-rr48.9%
*-commutative48.9%
Simplified48.9%
Final simplification48.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%
add-sqr-sqrt99.2%
sqrt-unprod87.4%
associate-*l/87.4%
*-un-lft-identity87.4%
associate-*l/87.5%
*-un-lft-identity87.5%
frac-times87.4%
Applied egg-rr87.5%
Simplified87.5%
Taylor expanded in k around 0 36.9%
associate-*r/36.9%
associate-*r*36.9%
*-commutative36.9%
sqrt-div48.9%
associate-*r*48.9%
*-commutative48.9%
associate-*l*48.9%
Applied egg-rr48.9%
*-commutative48.9%
associate-*r*48.9%
Simplified48.9%
Final simplification48.9%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* PI (* 2.0 n))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (((double) M_PI) * (2.0 * n))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (Math.PI * (2.0 * n))));
}
def code(k, n): return 1.0 / math.sqrt((k / (math.pi * (2.0 * n))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(pi * Float64(2.0 * n))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (pi * (2.0 * n)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{\pi \cdot \left(2 \cdot n\right)}}}
\end{array}
Initial program 99.5%
expm1-log1p-u96.3%
expm1-udef71.3%
inv-pow71.3%
sqrt-pow271.3%
metadata-eval71.3%
Applied egg-rr71.3%
expm1-def96.3%
expm1-log1p99.5%
Simplified99.5%
metadata-eval99.5%
sqrt-pow299.5%
exp-to-pow96.2%
*-commutative96.2%
associate-*l*96.2%
*-commutative96.2%
associate-*r*96.2%
*-commutative96.2%
*-commutative96.2%
sqrt-pow196.2%
add-sqr-sqrt96.2%
sqrt-unprod96.2%
exp-to-pow96.9%
exp-to-pow99.5%
pow-prod-down99.4%
add-sqr-sqrt99.4%
inv-pow99.4%
Applied egg-rr89.4%
Taylor expanded in k around 0 38.7%
associate-*r*38.7%
Simplified38.7%
Final simplification38.7%
(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.5%
add-sqr-sqrt99.2%
sqrt-unprod87.4%
associate-*l/87.4%
*-un-lft-identity87.4%
associate-*l/87.5%
*-un-lft-identity87.5%
frac-times87.4%
Applied egg-rr87.5%
Simplified87.5%
Taylor expanded in k around 0 36.9%
sqrt-prod36.8%
associate-*l/36.8%
*-commutative36.8%
expm1-log1p-u35.3%
expm1-udef35.6%
add-cube-cbrt35.6%
add-cube-cbrt35.6%
*-commutative35.6%
sqrt-prod35.6%
*-commutative35.6%
Applied egg-rr35.6%
expm1-def35.3%
expm1-log1p36.9%
*-commutative36.9%
associate-*l/36.9%
associate-*r/36.9%
Simplified36.9%
Final simplification36.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.5%
add-sqr-sqrt99.2%
sqrt-unprod87.4%
associate-*l/87.4%
*-un-lft-identity87.4%
associate-*l/87.5%
*-un-lft-identity87.5%
frac-times87.4%
Applied egg-rr87.5%
Simplified87.5%
Taylor expanded in k around 0 36.9%
Final simplification36.9%
herbie shell --seed 2023331
(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))))