
(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)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
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 * 0.5)));
}
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 * 0.5)));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * 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 := \pi \cdot \left(2 \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.5%
associate-*l/99.6%
*-un-lft-identity99.6%
unpow-prod-down71.6%
unpow-prod-down99.6%
div-sub99.6%
metadata-eval99.6%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 2.6e-43) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2.6e-43) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} 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.6e-43) {
tmp = Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
} 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.6e-43: tmp = math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k) 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.6e-43) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); 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.6e-43) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2.6e-43], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $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.6 \cdot 10^{-43}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\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.6e-43Initial program 99.3%
Taylor expanded in k around 0 99.3%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
associate-*l/99.5%
*-un-lft-identity99.5%
associate-*r*99.5%
Applied egg-rr99.5%
if 2.6e-43 < k Initial program 99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.0%
*-commutative99.0%
div-sub99.0%
metadata-eval99.0%
div-inv99.0%
*-commutative99.0%
div-sub99.0%
metadata-eval99.0%
div-inv99.0%
Applied egg-rr99.0%
associate-*r*99.0%
*-commutative99.0%
associate-*l*99.0%
distribute-lft-in99.0%
metadata-eval99.0%
*-commutative99.0%
associate-*r*99.0%
metadata-eval99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.2%
(FPCore (k n) :precision binary64 (if (<= k 7.2e+76) (/ (sqrt (* n (* PI 2.0))) (sqrt k)) (sqrt (* 2.0 (+ -1.0 (fma n (/ PI k) 1.0))))))
double code(double k, double n) {
double tmp;
if (k <= 7.2e+76) {
tmp = sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
} else {
tmp = sqrt((2.0 * (-1.0 + fma(n, (((double) M_PI) / k), 1.0))));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 7.2e+76) tmp = Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)); else tmp = sqrt(Float64(2.0 * Float64(-1.0 + fma(n, Float64(pi / k), 1.0)))); end return tmp end
code[k_, n_] := If[LessEqual[k, 7.2e+76], N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(2.0 * N[(-1.0 + N[(n * N[(Pi / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 7.2 \cdot 10^{+76}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot \left(-1 + \mathsf{fma}\left(n, \frac{\pi}{k}, 1\right)\right)}\\
\end{array}
\end{array}
if k < 7.2000000000000006e76Initial program 99.2%
Taylor expanded in k around 0 74.9%
associate-*r*74.9%
*-commutative74.9%
Simplified74.9%
associate-*l/75.0%
*-un-lft-identity75.0%
associate-*r*75.0%
Applied egg-rr75.0%
if 7.2000000000000006e76 < k Initial program 100.0%
Taylor expanded in k around 0 2.7%
associate-*r*2.7%
*-commutative2.7%
Simplified2.7%
pow12.7%
associate-*l/2.7%
*-un-lft-identity2.7%
associate-*r*2.7%
*-commutative2.7%
associate-*r*2.7%
sqrt-undiv2.6%
associate-*r*2.6%
*-commutative2.6%
Applied egg-rr2.6%
unpow12.6%
associate-/l*2.6%
*-commutative2.6%
associate-*l*2.6%
Simplified2.6%
Taylor expanded in n around 0 2.6%
associate-*r/2.6%
Simplified2.6%
expm1-log1p-u2.6%
expm1-undefine29.6%
Applied egg-rr29.6%
sub-neg29.6%
metadata-eval29.6%
+-commutative29.6%
log1p-undefine29.6%
rem-exp-log29.6%
+-commutative29.6%
fma-define29.6%
Simplified29.6%
Final simplification57.5%
(FPCore (k n) :precision binary64 (/ (pow (* n (* PI 2.0)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((n * (((double) M_PI) * 2.0)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (Math.PI * 2.0)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (math.pi * 2.0)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(pi * 2.0)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (pi * 2.0)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(Pi * 2.0), $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(\pi \cdot 2\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (sqrt (* 2.0 n)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((2.0 * n)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
pow147.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
*-commutative47.0%
associate-*r*47.0%
sqrt-undiv37.5%
associate-*r*37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow137.5%
associate-/l*37.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Taylor expanded in n around 0 37.5%
associate-*r/37.5%
Simplified37.5%
pow1/237.5%
associate-*r*37.5%
unpow-prod-down47.0%
*-commutative47.0%
pow1/247.0%
Applied egg-rr47.0%
unpow1/247.0%
Simplified47.0%
Final simplification47.0%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI n)) (sqrt (* k 0.5))))
double code(double k, double n) {
return sqrt((((double) M_PI) * n)) / sqrt((k * 0.5));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * n)) / Math.sqrt((k * 0.5));
}
def code(k, n): return math.sqrt((math.pi * n)) / math.sqrt((k * 0.5))
function code(k, n) return Float64(sqrt(Float64(pi * n)) / sqrt(Float64(k * 0.5))) end
function tmp = code(k, n) tmp = sqrt((pi * n)) / sqrt((k * 0.5)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot n}}{\sqrt{k \cdot 0.5}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
pow147.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
*-commutative47.0%
associate-*r*47.0%
sqrt-undiv37.5%
associate-*r*37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow137.5%
associate-/l*37.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Taylor expanded in n around 0 37.5%
associate-*r/37.5%
Simplified37.5%
metadata-eval37.5%
associate-*r/37.5%
times-frac37.5%
*-un-lft-identity37.5%
*-commutative37.5%
clear-num37.5%
metadata-eval37.5%
add-sqr-sqrt37.4%
frac-times37.4%
sqrt-unprod38.0%
add-sqr-sqrt38.1%
sqrt-div46.9%
associate-/r/46.9%
Applied egg-rr46.9%
associate-*l/47.0%
*-lft-identity47.0%
Simplified47.0%
Final simplification47.0%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* PI 2.0))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (math.pi * 2.0))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(pi * 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (pi * 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(\pi \cdot 2\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
Applied egg-rr47.0%
Final simplification47.0%
(FPCore (k n) :precision binary64 (pow (* k (/ 0.5 (* PI n))) -0.5))
double code(double k, double n) {
return pow((k * (0.5 / (((double) M_PI) * n))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * (0.5 / (Math.PI * n))), -0.5);
}
def code(k, n): return math.pow((k * (0.5 / (math.pi * n))), -0.5)
function code(k, n) return Float64(k * Float64(0.5 / Float64(pi * n))) ^ -0.5 end
function tmp = code(k, n) tmp = (k * (0.5 / (pi * n))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[(0.5 / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot \frac{0.5}{\pi \cdot n}\right)}^{-0.5}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
pow147.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
*-commutative47.0%
associate-*r*47.0%
sqrt-undiv37.5%
associate-*r*37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow137.5%
associate-/l*37.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Taylor expanded in n around 0 37.5%
associate-*r/37.5%
Simplified37.5%
metadata-eval37.5%
associate-*r/37.5%
times-frac37.5%
*-un-lft-identity37.5%
*-commutative37.5%
clear-num37.5%
metadata-eval37.5%
add-sqr-sqrt37.4%
frac-times37.4%
sqrt-unprod38.0%
add-sqr-sqrt38.1%
pow1/238.1%
pow-flip38.2%
associate-/l*38.2%
metadata-eval38.2%
Applied egg-rr38.2%
Final simplification38.2%
(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%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
pow147.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
*-commutative47.0%
associate-*r*47.0%
sqrt-undiv37.5%
associate-*r*37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow137.5%
associate-/l*37.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Taylor expanded in n around 0 37.5%
associate-*r/37.5%
Simplified37.5%
Final simplification37.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(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.5%
Taylor expanded in k around 0 47.0%
associate-*r*47.0%
*-commutative47.0%
Simplified47.0%
pow147.0%
associate-*l/47.0%
*-un-lft-identity47.0%
associate-*r*47.0%
*-commutative47.0%
associate-*r*47.0%
sqrt-undiv37.5%
associate-*r*37.5%
*-commutative37.5%
Applied egg-rr37.5%
unpow137.5%
associate-/l*37.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Final simplification37.5%
herbie shell --seed 2024044
(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))))