
(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 (* (* 2.0 PI) n))) (* (sqrt (/ 1.0 k)) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (2.0 * ((double) M_PI)) * n;
return sqrt((1.0 / k)) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (2.0 * Math.PI) * n;
return Math.sqrt((1.0 / k)) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (2.0 * math.pi) * n return math.sqrt((1.0 / k)) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(2.0 * pi) * n) return Float64(sqrt(Float64(1.0 / k)) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (2.0 * pi) * n; tmp = sqrt((1.0 / k)) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision]}, N[(N[Sqrt[N[(1.0 / k), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot \pi\right) \cdot n\\
\sqrt{\frac{1}{k}} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.6%
div-sub99.6%
metadata-eval99.6%
pow-sub99.7%
pow1/299.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-*r*99.7%
associate-*r*99.7%
Simplified99.7%
add-sqr-sqrt99.5%
sqrt-unprod99.7%
frac-times99.7%
metadata-eval99.7%
add-sqr-sqrt99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 3.2e-72) (/ (sqrt (* 2.0 (* PI n))) (sqrt k)) (sqrt (/ (pow (* (* 2.0 PI) n) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 3.2e-72) {
tmp = sqrt((2.0 * (((double) M_PI) * n))) / sqrt(k);
} else {
tmp = sqrt((pow(((2.0 * ((double) M_PI)) * n), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 3.2e-72) {
tmp = Math.sqrt((2.0 * (Math.PI * n))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(((2.0 * Math.PI) * n), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 3.2e-72: tmp = math.sqrt((2.0 * (math.pi * n))) / math.sqrt(k) else: tmp = math.sqrt((math.pow(((2.0 * math.pi) * n), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 3.2e-72) tmp = Float64(sqrt(Float64(2.0 * Float64(pi * n))) / sqrt(k)); else tmp = sqrt(Float64((Float64(Float64(2.0 * pi) * n) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 3.2e-72) tmp = sqrt((2.0 * (pi * n))) / sqrt(k); else tmp = sqrt(((((2.0 * pi) * n) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 3.2e-72], N[(N[Sqrt[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.2 \cdot 10^{-72}:\\
\;\;\;\;\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 3.19999999999999999e-72Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.6%
expm1-log1p-u92.6%
expm1-udef78.2%
Applied egg-rr48.1%
expm1-def62.6%
expm1-log1p65.9%
associate-*r*65.9%
Simplified65.9%
Taylor expanded in k around 0 65.9%
*-commutative65.9%
*-commutative65.9%
associate-*l*65.9%
Simplified65.9%
sqrt-div99.6%
associate-*r*99.6%
*-commutative99.6%
Applied egg-rr99.6%
if 3.19999999999999999e-72 < k Initial program 99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
div-inv99.7%
expm1-log1p-u99.2%
expm1-udef95.2%
Applied egg-rr95.2%
expm1-def98.6%
expm1-log1p99.1%
associate-*r*99.1%
Simplified99.1%
Final simplification99.3%
(FPCore (k n) :precision binary64 (* (sqrt (/ (* 2.0 PI) k)) (pow n (- 0.5 (* k 0.5)))))
double code(double k, double n) {
return sqrt(((2.0 * ((double) M_PI)) / k)) * pow(n, (0.5 - (k * 0.5)));
}
public static double code(double k, double n) {
return Math.sqrt(((2.0 * Math.PI) / k)) * Math.pow(n, (0.5 - (k * 0.5)));
}
def code(k, n): return math.sqrt(((2.0 * math.pi) / k)) * math.pow(n, (0.5 - (k * 0.5)))
function code(k, n) return Float64(sqrt(Float64(Float64(2.0 * pi) / k)) * (n ^ Float64(0.5 - Float64(k * 0.5)))) end
function tmp = code(k, n) tmp = sqrt(((2.0 * pi) / k)) * (n ^ (0.5 - (k * 0.5))); end
code[k_, n_] := N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[Power[n, N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2 \cdot \pi}{k}} \cdot {n}^{\left(0.5 - k \cdot 0.5\right)}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-un-lft-identity99.6%
unpow-prod-down71.3%
associate-/l*71.3%
div-sub71.3%
metadata-eval71.3%
div-inv71.3%
metadata-eval71.3%
div-sub71.3%
metadata-eval71.3%
div-inv71.3%
metadata-eval71.3%
Applied egg-rr71.3%
Taylor expanded in k around 0 98.3%
associate-/r/98.3%
sqrt-unprod98.2%
sqrt-undiv98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* 2.0 n)) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-lft-identity99.6%
*-commutative99.6%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 (* PI n))) (sqrt k)))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) * n))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI * n))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((2.0 * (math.pi * n))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(pi * n))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi * n))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
sqrt-div46.5%
associate-*r*46.5%
*-commutative46.5%
Applied egg-rr46.5%
Final simplification46.5%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* 2.0 (* PI n))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (2.0 * (((double) M_PI) * n))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (2.0 * (Math.PI * n))));
}
def code(k, n): return 1.0 / math.sqrt((k / (2.0 * (math.pi * n))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(2.0 * Float64(pi * n))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (2.0 * (pi * n)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{2 \cdot \left(\pi \cdot n\right)}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
pow1/233.7%
div-inv33.7%
associate-*r*33.7%
*-commutative33.7%
unpow-prod-down46.4%
pow1/246.4%
inv-pow46.4%
pow-pow46.5%
metadata-eval46.5%
Applied egg-rr46.5%
*-commutative46.5%
*-commutative46.5%
Simplified46.5%
*-commutative46.5%
*-commutative46.5%
add-cube-cbrt46.1%
unpow346.1%
add-sqr-sqrt46.0%
sqrt-unprod46.1%
pow-prod-up46.1%
metadata-eval46.1%
inv-pow46.1%
sqrt-prod33.4%
div-inv33.4%
clear-num33.3%
sqrt-div33.7%
metadata-eval33.7%
unpow333.8%
Applied egg-rr34.0%
Final simplification34.0%
(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(Float64(k / 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[(N[(k / Pi), $MachinePrecision] / N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{k}{\pi}}{2 \cdot n}}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
pow1/233.7%
div-inv33.7%
associate-*r*33.7%
*-commutative33.7%
unpow-prod-down46.4%
pow1/246.4%
inv-pow46.4%
pow-pow46.5%
metadata-eval46.5%
Applied egg-rr46.5%
*-commutative46.5%
*-commutative46.5%
Simplified46.5%
*-commutative46.5%
*-commutative46.5%
add-cube-cbrt46.1%
unpow346.1%
add-sqr-sqrt46.0%
sqrt-unprod46.1%
pow-prod-up46.1%
metadata-eval46.1%
inv-pow46.1%
sqrt-prod33.4%
div-inv33.4%
clear-num33.3%
sqrt-div33.7%
metadata-eval33.7%
unpow333.8%
Applied egg-rr34.0%
*-commutative34.0%
associate-*l*34.0%
*-commutative34.0%
associate-/r*34.0%
Simplified34.0%
Final simplification34.0%
(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.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
Taylor expanded in n around 0 33.7%
associate-/l*33.7%
associate-/r/33.7%
Simplified33.7%
Final simplification33.7%
(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.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
Taylor expanded in n around 0 33.7%
associate-/l*33.7%
Simplified33.7%
Final simplification33.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(Float64(2.0 * n) * Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt(((2.0 * n) * (pi / k))); end
code[k_, n_] := N[Sqrt[N[(N[(2.0 * n), $MachinePrecision] * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot n\right) \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.6%
expm1-log1p-u96.7%
expm1-udef88.8%
Applied egg-rr77.3%
expm1-def85.0%
expm1-log1p86.5%
associate-*r*86.5%
Simplified86.5%
Taylor expanded in k around 0 33.7%
*-commutative33.7%
*-commutative33.7%
associate-*l*33.7%
Simplified33.7%
expm1-log1p-u32.2%
expm1-udef35.0%
associate-/l*35.0%
*-commutative35.0%
Applied egg-rr35.0%
expm1-def32.1%
expm1-log1p33.7%
associate-/r/33.7%
Simplified33.7%
Final simplification33.7%
herbie shell --seed 2023223
(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))))