
(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 9 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 (/ 1.0 (* (sqrt k) (pow (* n (* PI 2.0)) (- (fma k -0.5 0.5))))))
double code(double k, double n) {
return 1.0 / (sqrt(k) * pow((n * (((double) M_PI) * 2.0)), -fma(k, -0.5, 0.5)));
}
function code(k, n) return Float64(1.0 / Float64(sqrt(k) * (Float64(n * Float64(pi * 2.0)) ^ Float64(-fma(k, -0.5, 0.5))))) end
code[k_, n_] := N[(1.0 / N[(N[Sqrt[k], $MachinePrecision] * N[Power[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(k * -0.5 + 0.5), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k} \cdot {\left(n \cdot \left(\pi \cdot 2\right)\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}
\end{array}
Initial program 99.6%
associate-/r/99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
*-commutative99.6%
associate-*l*99.6%
sub-neg99.6%
div-inv99.6%
metadata-eval99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Applied egg-rr99.6%
div-inv99.5%
associate-*r*99.5%
*-commutative99.5%
pow-flip99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
+-commutative99.6%
fma-define99.6%
Applied egg-rr99.6%
(FPCore (k n) :precision binary64 (if (<= k 1.02e-45) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (sqrt (/ (pow (* n (* PI 2.0)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.02e-45) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = sqrt((pow((n * (((double) M_PI) * 2.0)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 1.02e-45) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.sqrt((Math.pow((n * (Math.PI * 2.0)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 1.02e-45: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.sqrt((math.pow((n * (math.pi * 2.0)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 1.02e-45) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = sqrt(Float64((Float64(n * Float64(pi * 2.0)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 1.02e-45) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = sqrt((((n * (pi * 2.0)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.02e-45], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.02 \cdot 10^{-45}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(\pi \cdot 2\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.0199999999999999e-45Initial program 99.3%
Taylor expanded in k around 0 75.4%
associate-/l*75.4%
Simplified75.4%
sqrt-unprod75.6%
Applied egg-rr75.6%
associate-*l*75.6%
sqrt-prod99.5%
Applied egg-rr99.5%
if 1.0199999999999999e-45 < k Initial program 99.7%
Taylor expanded in k around 0 99.8%
Applied egg-rr99.1%
Simplified99.2%
Final simplification99.3%
(FPCore (k n) :precision binary64 (if (<= k 4.5e+155) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (pow (* 8.0 (pow (* n (/ PI k)) 3.0)) 0.16666666666666666)))
double code(double k, double n) {
double tmp;
if (k <= 4.5e+155) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = pow((8.0 * pow((n * (((double) M_PI) / k)), 3.0)), 0.16666666666666666);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 4.5e+155) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.pow((8.0 * Math.pow((n * (Math.PI / k)), 3.0)), 0.16666666666666666);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 4.5e+155: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.pow((8.0 * math.pow((n * (math.pi / k)), 3.0)), 0.16666666666666666) return tmp
function code(k, n) tmp = 0.0 if (k <= 4.5e+155) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = Float64(8.0 * (Float64(n * Float64(pi / k)) ^ 3.0)) ^ 0.16666666666666666; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 4.5e+155) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = (8.0 * ((n * (pi / k)) ^ 3.0)) ^ 0.16666666666666666; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4.5e+155], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[(8.0 * N[Power[N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.5 \cdot 10^{+155}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left(8 \cdot {\left(n \cdot \frac{\pi}{k}\right)}^{3}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if k < 4.49999999999999973e155Initial program 99.4%
Taylor expanded in k around 0 50.9%
associate-/l*50.9%
Simplified50.9%
sqrt-unprod51.0%
Applied egg-rr51.0%
associate-*l*51.0%
sqrt-prod65.3%
Applied egg-rr65.3%
if 4.49999999999999973e155 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
Taylor expanded in n around 0 2.9%
pow1/22.9%
associate-/l*2.9%
associate-*r*2.9%
metadata-eval2.9%
pow-pow15.9%
sqr-pow15.9%
pow-prod-down34.4%
pow-prod-up34.4%
metadata-eval34.4%
associate-*l/34.4%
associate-/l*34.4%
metadata-eval34.4%
Applied egg-rr34.4%
*-commutative34.4%
associate-*r/34.4%
associate-*l/34.4%
associate-/l*34.4%
*-commutative34.4%
associate-*r*34.4%
cube-prod34.4%
metadata-eval34.4%
associate-*r/34.4%
associate-*l/34.4%
*-commutative34.4%
Simplified34.4%
Final simplification56.5%
(FPCore (k n) :precision binary64 (let* ((t_0 (* 2.0 (/ PI k)))) (if (<= k 6.2e+255) (* (sqrt n) (sqrt t_0)) (cbrt (pow (* n t_0) 1.5)))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) / k);
double tmp;
if (k <= 6.2e+255) {
tmp = sqrt(n) * sqrt(t_0);
} else {
tmp = cbrt(pow((n * t_0), 1.5));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = 2.0 * (Math.PI / k);
double tmp;
if (k <= 6.2e+255) {
tmp = Math.sqrt(n) * Math.sqrt(t_0);
} else {
tmp = Math.cbrt(Math.pow((n * t_0), 1.5));
}
return tmp;
}
function code(k, n) t_0 = Float64(2.0 * Float64(pi / k)) tmp = 0.0 if (k <= 6.2e+255) tmp = Float64(sqrt(n) * sqrt(t_0)); else tmp = cbrt((Float64(n * t_0) ^ 1.5)); end return tmp end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 6.2e+255], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(n * t$95$0), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \frac{\pi}{k}\\
\mathbf{if}\;k \leq 6.2 \cdot 10^{+255}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(n \cdot t\_0\right)}^{1.5}}\\
\end{array}
\end{array}
if k < 6.2000000000000004e255Initial program 99.5%
Taylor expanded in k around 0 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.6%
Applied egg-rr42.6%
associate-*l*42.6%
sqrt-prod54.3%
Applied egg-rr54.3%
if 6.2000000000000004e255 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
add-cbrt-cube31.1%
add-sqr-sqrt31.1%
pow131.1%
pow1/231.1%
pow-prod-up31.1%
associate-*l*31.1%
metadata-eval31.1%
Applied egg-rr31.1%
Final simplification51.3%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* n PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (n * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (n * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (n * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (n * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(n * Pi), $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(n \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%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((2.0 * (math.pi / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 37.2%
associate-/l*37.2%
Simplified37.2%
sqrt-unprod37.3%
Applied egg-rr37.3%
associate-*l*37.3%
sqrt-prod47.5%
Applied egg-rr47.5%
Final simplification47.5%
(FPCore (k n) :precision binary64 (sqrt (* (* PI 2.0) (/ n k))))
double code(double k, double n) {
return sqrt(((((double) M_PI) * 2.0) * (n / k)));
}
public static double code(double k, double n) {
return Math.sqrt(((Math.PI * 2.0) * (n / k)));
}
def code(k, n): return math.sqrt(((math.pi * 2.0) * (n / k)))
function code(k, n) return sqrt(Float64(Float64(pi * 2.0) * Float64(n / k))) end
function tmp = code(k, n) tmp = sqrt(((pi * 2.0) * (n / k))); end
code[k_, n_] := N[Sqrt[N[(N[(Pi * 2.0), $MachinePrecision] * N[(n / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(\pi \cdot 2\right) \cdot \frac{n}{k}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 37.2%
associate-/l*37.2%
Simplified37.2%
sqrt-unprod37.3%
Applied egg-rr37.3%
add-cbrt-cube32.5%
pow1/330.7%
add-sqr-sqrt30.7%
pow130.7%
pow1/230.7%
pow-prod-up30.7%
associate-*l*30.7%
metadata-eval30.7%
Applied egg-rr30.7%
pow-pow37.3%
associate-*r*37.3%
associate-/l*37.3%
metadata-eval37.3%
pow1/237.3%
*-un-lft-identity37.3%
*-commutative37.3%
associate-/l*37.3%
associate-*r*37.3%
associate-*l/37.3%
associate-/l*37.3%
Applied egg-rr37.3%
*-rgt-identity37.3%
*-commutative37.3%
associate-*r/37.3%
associate-*l/37.3%
associate-/l*37.3%
*-commutative37.3%
Simplified37.3%
Final simplification37.3%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ (* n 2.0) k))))
double code(double k, double n) {
return sqrt((((double) M_PI) * ((n * 2.0) / k)));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * ((n * 2.0) / k)));
}
def code(k, n): return math.sqrt((math.pi * ((n * 2.0) / k)))
function code(k, n) return sqrt(Float64(pi * Float64(Float64(n * 2.0) / k))) end
function tmp = code(k, n) tmp = sqrt((pi * ((n * 2.0) / k))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(N[(n * 2.0), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{n \cdot 2}{k}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 37.2%
associate-/l*37.2%
Simplified37.2%
sqrt-unprod37.3%
Applied egg-rr37.3%
add-cbrt-cube32.5%
pow1/330.7%
add-sqr-sqrt30.7%
pow130.7%
pow1/230.7%
pow-prod-up30.7%
associate-*l*30.7%
metadata-eval30.7%
Applied egg-rr30.7%
pow-pow37.3%
associate-*r*37.3%
associate-/l*37.3%
metadata-eval37.3%
pow1/237.3%
*-un-lft-identity37.3%
*-commutative37.3%
associate-/l*37.3%
associate-*r*37.3%
associate-*l/37.3%
associate-/l*37.3%
Applied egg-rr37.3%
*-rgt-identity37.3%
*-commutative37.3%
associate-*r/37.3%
associate-*l/37.3%
associate-*l*37.3%
*-commutative37.3%
associate-/l*37.3%
Simplified37.3%
(FPCore (k n) :precision binary64 (sqrt (* n (* PI (/ 2.0 k)))))
double code(double k, double n) {
return sqrt((n * (((double) M_PI) * (2.0 / k))));
}
public static double code(double k, double n) {
return Math.sqrt((n * (Math.PI * (2.0 / k))));
}
def code(k, n): return math.sqrt((n * (math.pi * (2.0 / k))))
function code(k, n) return sqrt(Float64(n * Float64(pi * Float64(2.0 / k)))) end
function tmp = code(k, n) tmp = sqrt((n * (pi * (2.0 / k)))); end
code[k_, n_] := N[Sqrt[N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot \left(\pi \cdot \frac{2}{k}\right)}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 37.2%
associate-/l*37.2%
Simplified37.2%
sqrt-unprod37.3%
Applied egg-rr37.3%
add-cbrt-cube32.5%
pow1/330.7%
add-sqr-sqrt30.7%
pow130.7%
pow1/230.7%
pow-prod-up30.7%
associate-*l*30.7%
metadata-eval30.7%
Applied egg-rr30.7%
pow-pow37.3%
metadata-eval37.3%
pow1/237.3%
associate-*l/37.3%
associate-/l*37.3%
Applied egg-rr37.3%
herbie shell --seed 2024113
(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))))