
(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 11 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 (* n 2.0)))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (n * 2.0);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (n * 2.0);
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = math.pi * (n * 2.0) return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(pi * Float64(n * 2.0)) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = pi * (n * 2.0); tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(n * 2.0), $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(n \cdot 2\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k \cdot {t\_0}^{k}}}
\end{array}
\end{array}
Initial program 99.6%
associate-*l/99.6%
*-un-lft-identity99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
div-inv99.7%
associate-*r*99.7%
pow1/299.7%
pow-unpow99.7%
pow-prod-down99.7%
associate-*r*99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l*99.7%
unpow1/299.7%
associate-*l*99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
(FPCore (k n) :precision binary64 (if (<= k 8.8e-75) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (/ 1.0 (sqrt (/ k (pow (* PI (* n 2.0)) (- 1.0 k)))))))
double code(double k, double n) {
double tmp;
if (k <= 8.8e-75) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = 1.0 / sqrt((k / pow((((double) M_PI) * (n * 2.0)), (1.0 - k))));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 8.8e-75) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = 1.0 / Math.sqrt((k / Math.pow((Math.PI * (n * 2.0)), (1.0 - k))));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 8.8e-75: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = 1.0 / math.sqrt((k / math.pow((math.pi * (n * 2.0)), (1.0 - k)))) return tmp
function code(k, n) tmp = 0.0 if (k <= 8.8e-75) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = Float64(1.0 / sqrt(Float64(k / (Float64(pi * Float64(n * 2.0)) ^ Float64(1.0 - k))))); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 8.8e-75) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = 1.0 / sqrt((k / ((pi * (n * 2.0)) ^ (1.0 - k)))); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 8.8e-75], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(k / N[Power[N[(Pi * N[(n * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 8.8 \cdot 10^{-75}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{k}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(1 - k\right)}}}}\\
\end{array}
\end{array}
if k < 8.80000000000000022e-75Initial program 99.5%
Taylor expanded in k around 0 74.4%
associate-/l*74.4%
Simplified74.4%
sqrt-unprod73.6%
Applied egg-rr73.6%
associate-*l*73.6%
sqrt-prod99.5%
Applied egg-rr99.5%
if 8.80000000000000022e-75 < k Initial program 99.7%
Applied egg-rr99.7%
*-commutative99.7%
distribute-lft-in99.7%
metadata-eval99.7%
*-commutative99.7%
associate-*r*99.7%
metadata-eval99.7%
neg-mul-199.7%
sub-neg99.7%
Simplified99.7%
clear-num99.7%
sqrt-div99.7%
metadata-eval99.7%
*-commutative99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* 2.0 (* PI n))))
(if (<= k 5.6e-17)
(/ (sqrt t_0) (sqrt k))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) * n);
double tmp;
if (k <= 5.6e-17) {
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 = 2.0 * (Math.PI * n);
double tmp;
if (k <= 5.6e-17) {
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 = 2.0 * (math.pi * n) tmp = 0 if k <= 5.6e-17: 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(2.0 * Float64(pi * n)) tmp = 0.0 if (k <= 5.6e-17) 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 = 2.0 * (pi * n); tmp = 0.0; if (k <= 5.6e-17) 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[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 5.6e-17], 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 := 2 \cdot \left(\pi \cdot n\right)\\
\mathbf{if}\;k \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\frac{\sqrt{t\_0}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t\_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 5.5999999999999998e-17Initial program 99.4%
Taylor expanded in k around 0 79.8%
associate-/l*79.8%
Simplified79.8%
sqrt-unprod79.1%
Applied egg-rr79.1%
Taylor expanded in n around 0 79.2%
associate-*l/79.2%
associate-/r/79.1%
Simplified79.1%
associate-*r/79.1%
*-commutative79.1%
div-inv79.2%
clear-num79.1%
associate-/l*79.2%
sqrt-div99.5%
associate-*l*99.5%
Applied egg-rr99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
if 5.5999999999999998e-17 < k Initial program 99.8%
Applied egg-rr99.8%
*-commutative99.8%
distribute-lft-in99.8%
metadata-eval99.8%
*-commutative99.8%
associate-*r*99.8%
metadata-eval99.8%
neg-mul-199.8%
sub-neg99.8%
Simplified99.8%
Final simplification99.7%
(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.6%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.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%
Taylor expanded in k around 0 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
Taylor expanded in n around 0 42.2%
associate-*l/42.2%
associate-/r/42.1%
Simplified42.1%
associate-*r/42.1%
*-commutative42.1%
div-inv42.2%
clear-num42.2%
associate-/l*42.2%
sqrt-div52.4%
associate-*l*52.4%
Applied egg-rr52.4%
associate-*r*52.4%
*-commutative52.4%
associate-*r*52.4%
*-commutative52.4%
Simplified52.4%
Final simplification52.4%
(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 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
associate-*l*42.2%
sqrt-prod52.4%
Applied egg-rr52.4%
Final simplification52.4%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* PI (/ 2.0 k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((((double) M_PI) * (2.0 / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((Math.PI * (2.0 / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((math.pi * (2.0 / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(pi * Float64(2.0 / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((pi * (2.0 / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{\pi \cdot \frac{2}{k}}
\end{array}
Initial program 99.6%
Taylor expanded in k around 0 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
pow1/242.2%
associate-*l*42.2%
unpow-prod-down52.4%
pow1/252.4%
Applied egg-rr52.4%
unpow1/252.4%
associate-*l/52.4%
associate-/l*52.4%
Simplified52.4%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* (/ k PI) (/ 0.5 n)))))
double code(double k, double n) {
return 1.0 / sqrt(((k / ((double) M_PI)) * (0.5 / n)));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((k / Math.PI) * (0.5 / n)));
}
def code(k, n): return 1.0 / math.sqrt(((k / math.pi) * (0.5 / n)))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(k / pi) * Float64(0.5 / n)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((k / pi) * (0.5 / n))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(k / Pi), $MachinePrecision] * N[(0.5 / n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{\pi} \cdot \frac{0.5}{n}}}
\end{array}
Initial program 99.6%
Applied egg-rr89.4%
*-commutative89.4%
distribute-lft-in89.4%
metadata-eval89.4%
*-commutative89.4%
associate-*r*89.4%
metadata-eval89.4%
neg-mul-189.4%
sub-neg89.4%
Simplified89.4%
clear-num89.4%
sqrt-div89.9%
metadata-eval89.9%
*-commutative89.9%
Applied egg-rr89.9%
*-commutative89.9%
associate-*r*89.9%
*-commutative89.9%
Simplified89.9%
Taylor expanded in k around 0 42.6%
associate-*r/42.6%
*-commutative42.6%
*-commutative42.6%
times-frac42.6%
Simplified42.6%
(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 42.5%
associate-/l*42.5%
Simplified42.5%
pow142.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
unpow142.2%
*-commutative42.2%
associate-*r/42.2%
associate-/l*42.2%
*-commutative42.2%
associate-*l*42.2%
associate-/l*42.2%
*-commutative42.2%
Simplified42.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.6%
Taylor expanded in k around 0 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
Final simplification42.2%
(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%
Taylor expanded in k around 0 42.5%
associate-/l*42.5%
Simplified42.5%
sqrt-unprod42.2%
Applied egg-rr42.2%
Taylor expanded in n around 0 42.2%
associate-*l/42.2%
associate-/r/42.1%
Simplified42.1%
herbie shell --seed 2024191
(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))))