
(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))))))
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%
*-commutative99.4%
associate-*r*99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.4%
pow-sub99.7%
pow1/299.7%
associate-/l/99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
expm1-log1p-u96.5%
expm1-udef83.4%
Applied egg-rr83.4%
expm1-def96.5%
expm1-log1p99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (let* ((t_0 (* n (* PI 2.0)))) (if (<= k 2e-30) (/ (sqrt t_0) (sqrt k)) (sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = n * (((double) M_PI) * 2.0);
double tmp;
if (k <= 2e-30) {
tmp = sqrt(t_0) / sqrt(k);
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = n * (Math.PI * 2.0);
double tmp;
if (k <= 2e-30) {
tmp = Math.sqrt(t_0) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = n * (math.pi * 2.0) tmp = 0 if k <= 2e-30: tmp = math.sqrt(t_0) / math.sqrt(k) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(n * Float64(pi * 2.0)) tmp = 0.0 if (k <= 2e-30) tmp = Float64(sqrt(t_0) / sqrt(k)); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = n * (pi * 2.0); tmp = 0.0; if (k <= 2e-30) tmp = sqrt(t_0) / sqrt(k); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 2e-30], N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[t$95$0, N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(\pi \cdot 2\right)\\
\mathbf{if}\;k \leq 2 \cdot 10^{-30}:\\
\;\;\;\;\frac{\sqrt{t_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 2e-30Initial program 99.3%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.1%
pow-sqr99.5%
associate-*l*99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in k around inf 92.3%
Taylor expanded in k around 0 99.2%
expm1-log1p-u95.7%
expm1-udef49.7%
*-commutative49.7%
sqrt-unprod49.7%
*-commutative49.7%
Applied egg-rr49.7%
expm1-def95.8%
expm1-log1p99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
Simplified99.5%
if 2e-30 < k Initial program 99.4%
add-sqr-sqrt99.3%
sqrt-unprod99.4%
*-commutative99.4%
div-inv99.4%
*-commutative99.4%
div-inv99.4%
frac-times99.4%
Applied egg-rr99.4%
Simplified99.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.2%
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 (/ (sqrt (* PI n)) (sqrt (/ k 2.0))))
double code(double k, double n) {
return sqrt((((double) M_PI) * n)) / sqrt((k / 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * n)) / Math.sqrt((k / 2.0));
}
def code(k, n): return math.sqrt((math.pi * n)) / math.sqrt((k / 2.0))
function code(k, n) return Float64(sqrt(Float64(pi * n)) / sqrt(Float64(k / 2.0))) end
function tmp = code(k, n) tmp = sqrt((pi * n)) / sqrt((k / 2.0)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot n}}{\sqrt{\frac{k}{2}}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.2%
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%
Taylor expanded in k around inf 95.7%
Taylor expanded in k around 0 53.3%
associate-/l*53.4%
div-inv53.3%
*-commutative53.3%
sqrt-undiv53.4%
Applied egg-rr53.4%
associate-*r/53.4%
*-rgt-identity53.4%
*-commutative53.4%
Simplified53.4%
Final simplification53.4%
(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.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.2%
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%
Taylor expanded in k around inf 95.7%
Taylor expanded in k around 0 53.3%
expm1-log1p-u51.5%
expm1-udef27.6%
*-commutative27.6%
sqrt-unprod27.6%
*-commutative27.6%
Applied egg-rr27.6%
expm1-def51.6%
expm1-log1p53.5%
*-commutative53.5%
associate-*r*53.5%
*-commutative53.5%
associate-*r*53.5%
Simplified53.5%
Final simplification53.5%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* (/ k n) (/ 1.0 (* PI 2.0))))))
double code(double k, double n) {
return 1.0 / sqrt(((k / n) * (1.0 / (((double) M_PI) * 2.0))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((k / n) * (1.0 / (Math.PI * 2.0))));
}
def code(k, n): return 1.0 / math.sqrt(((k / n) * (1.0 / (math.pi * 2.0))))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(k / n) * Float64(1.0 / Float64(pi * 2.0))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((k / n) * (1.0 / (pi * 2.0)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(k / n), $MachinePrecision] * N[(1.0 / N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{n} \cdot \frac{1}{\pi \cdot 2}}}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod84.0%
*-commutative84.0%
div-inv84.0%
*-commutative84.0%
div-inv84.1%
frac-times84.0%
Applied egg-rr84.0%
Simplified84.1%
clear-num84.1%
sqrt-div85.6%
metadata-eval85.6%
*-commutative85.6%
Applied egg-rr85.6%
*-commutative85.6%
associate-*r*85.6%
Simplified85.6%
Taylor expanded in k around 0 39.6%
associate-*r*39.6%
*-commutative39.6%
associate-*r*39.6%
Simplified39.6%
associate-/r*39.6%
div-inv39.6%
*-commutative39.6%
Applied egg-rr39.6%
Final simplification39.6%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* k (/ 0.5 (* PI n))))))
double code(double k, double n) {
return 1.0 / sqrt((k * (0.5 / (((double) M_PI) * n))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k * (0.5 / (Math.PI * n))));
}
def code(k, n): return 1.0 / math.sqrt((k * (0.5 / (math.pi * n))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k * Float64(0.5 / Float64(pi * n))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k * (0.5 / (pi * n)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k * N[(0.5 / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k \cdot \frac{0.5}{\pi \cdot n}}}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod84.0%
*-commutative84.0%
div-inv84.0%
*-commutative84.0%
div-inv84.1%
frac-times84.0%
Applied egg-rr84.0%
Simplified84.1%
clear-num84.1%
sqrt-div85.6%
metadata-eval85.6%
*-commutative85.6%
Applied egg-rr85.6%
*-commutative85.6%
associate-*r*85.6%
Simplified85.6%
Taylor expanded in k around 0 39.6%
associate-*r*39.6%
*-commutative39.6%
associate-*r*39.6%
Simplified39.6%
Taylor expanded in k around 0 39.6%
associate-*r/39.6%
*-commutative39.6%
associate-*r/39.6%
Simplified39.6%
Final simplification39.6%
(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(Float64(pi * n) * Float64(2.0 / k))) end
function tmp = code(k, n) tmp = sqrt(((pi * n) * (2.0 / k))); end
code[k_, n_] := N[Sqrt[N[(N[(Pi * n), $MachinePrecision] * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(\pi \cdot n\right) \cdot \frac{2}{k}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.2%
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%
Taylor expanded in k around inf 95.7%
Taylor expanded in k around 0 53.3%
expm1-log1p-u50.4%
expm1-udef45.7%
sqrt-unprod45.7%
sqrt-undiv31.9%
associate-*r*31.9%
*-commutative31.9%
*-commutative31.9%
associate-*l*31.9%
Applied egg-rr31.9%
expm1-def36.6%
expm1-log1p38.1%
associate-/l*38.1%
*-commutative38.1%
associate-/r/38.1%
Simplified38.1%
Final simplification38.1%
(FPCore (k n) :precision binary64 (sqrt (/ 2.0 (/ k (* PI n)))))
double code(double k, double n) {
return sqrt((2.0 / (k / (((double) M_PI) * n))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 / (k / (Math.PI * n))));
}
def code(k, n): return math.sqrt((2.0 / (k / (math.pi * n))))
function code(k, n) return sqrt(Float64(2.0 / Float64(k / Float64(pi * n)))) end
function tmp = code(k, n) tmp = sqrt((2.0 / (k / (pi * n)))); end
code[k_, n_] := N[Sqrt[N[(2.0 / N[(k / N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2}{\frac{k}{\pi \cdot n}}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.2%
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%
Taylor expanded in k around inf 95.7%
Taylor expanded in k around 0 53.3%
expm1-log1p-u50.4%
expm1-udef45.7%
sqrt-unprod45.7%
sqrt-undiv31.9%
associate-*r*31.9%
*-commutative31.9%
*-commutative31.9%
associate-*l*31.9%
Applied egg-rr31.9%
expm1-def36.6%
expm1-log1p38.1%
associate-/l*38.1%
*-commutative38.1%
Simplified38.1%
Final simplification38.1%
(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(Float64(2.0 * Float64(pi * n)) / k)) end
function tmp = code(k, n) tmp = sqrt(((2.0 * (pi * n)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2 \cdot \left(\pi \cdot n\right)}{k}}
\end{array}
Initial program 99.4%
associate-*l/99.4%
*-lft-identity99.4%
sqr-pow99.2%
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%
Taylor expanded in k around inf 95.7%
Taylor expanded in k around 0 53.3%
sqrt-unprod53.5%
sqrt-undiv38.1%
associate-*r*38.1%
*-commutative38.1%
*-commutative38.1%
associate-*l*38.1%
Applied egg-rr38.1%
Final simplification38.1%
herbie shell --seed 2023292
(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))))