
(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 8 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 (/ (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.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* PI (* 2.0 n))))
(if (<= k 3.2e-52)
(* (pow k -0.5) (/ 1.0 (pow t_0 -0.5)))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
double tmp;
if (k <= 3.2e-52) {
tmp = pow(k, -0.5) * (1.0 / pow(t_0, -0.5));
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
double tmp;
if (k <= 3.2e-52) {
tmp = Math.pow(k, -0.5) * (1.0 / Math.pow(t_0, -0.5));
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = math.pi * (2.0 * n) tmp = 0 if k <= 3.2e-52: tmp = math.pow(k, -0.5) * (1.0 / math.pow(t_0, -0.5)) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) tmp = 0.0 if (k <= 3.2e-52) tmp = Float64((k ^ -0.5) * Float64(1.0 / (t_0 ^ -0.5))); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = pi * (2.0 * n); tmp = 0.0; if (k <= 3.2e-52) tmp = (k ^ -0.5) * (1.0 / (t_0 ^ -0.5)); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 3.2e-52], N[(N[Power[k, -0.5], $MachinePrecision] * N[(1.0 / N[Power[t$95$0, -0.5], $MachinePrecision]), $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 := \pi \cdot \left(2 \cdot n\right)\\
\mathbf{if}\;k \leq 3.2 \cdot 10^{-52}:\\
\;\;\;\;{k}^{-0.5} \cdot \frac{1}{{t_0}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 3.2000000000000001e-52Initial program 99.1%
associate-*l/99.4%
*-lft-identity99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
div-inv99.1%
*-commutative99.1%
unpow-prod-down99.1%
associate-*r*99.0%
pow1/299.0%
pow-flip99.1%
metadata-eval99.1%
div-sub99.1%
metadata-eval99.1%
div-inv99.1%
metadata-eval99.1%
div-sub99.1%
metadata-eval99.1%
div-inv99.1%
metadata-eval99.1%
Applied egg-rr99.1%
add-sqr-sqrt98.7%
sqrt-unprod61.9%
associate-*l*61.8%
associate-*l*61.8%
swap-sqr61.7%
pow-prod-up61.8%
metadata-eval61.8%
inv-pow61.8%
Applied egg-rr62.1%
sqrt-prod99.3%
sqrt-div99.1%
metadata-eval99.1%
associate-/r/99.3%
inv-pow99.3%
div-inv99.2%
unpow-prod-down99.1%
inv-pow99.1%
pow1/299.1%
pow-flip99.3%
metadata-eval99.3%
Applied egg-rr99.3%
unpow-199.3%
Simplified99.3%
Taylor expanded in k around 0 99.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
Simplified99.3%
if 3.2000000000000001e-52 < k Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.7%
expm1-log1p-u99.2%
expm1-udef92.4%
Applied egg-rr92.4%
expm1-def99.2%
expm1-log1p99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* PI (* 2.0 n))))
(if (<= k 5.8e-52)
(* (pow k -0.5) (sqrt t_0))
(sqrt (/ (pow t_0 (- 1.0 k)) k)))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
double tmp;
if (k <= 5.8e-52) {
tmp = pow(k, -0.5) * sqrt(t_0);
} else {
tmp = sqrt((pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
double tmp;
if (k <= 5.8e-52) {
tmp = Math.pow(k, -0.5) * Math.sqrt(t_0);
} else {
tmp = Math.sqrt((Math.pow(t_0, (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): t_0 = math.pi * (2.0 * n) tmp = 0 if k <= 5.8e-52: tmp = math.pow(k, -0.5) * math.sqrt(t_0) else: tmp = math.sqrt((math.pow(t_0, (1.0 - k)) / k)) return tmp
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) tmp = 0.0 if (k <= 5.8e-52) tmp = Float64((k ^ -0.5) * sqrt(t_0)); else tmp = sqrt(Float64((t_0 ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) t_0 = pi * (2.0 * n); tmp = 0.0; if (k <= 5.8e-52) tmp = (k ^ -0.5) * sqrt(t_0); else tmp = sqrt(((t_0 ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[k, 5.8e-52], N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[t$95$0], $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 := \pi \cdot \left(2 \cdot n\right)\\
\mathbf{if}\;k \leq 5.8 \cdot 10^{-52}:\\
\;\;\;\;{k}^{-0.5} \cdot \sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 5.8000000000000003e-52Initial program 99.1%
expm1-log1p-u91.6%
expm1-udef91.6%
pow1/291.6%
pow-flip91.6%
metadata-eval91.6%
Applied egg-rr91.6%
expm1-def91.6%
expm1-log1p99.3%
Simplified99.3%
Taylor expanded in k around 0 99.2%
expm1-log1p-u95.8%
expm1-udef54.1%
sqrt-unprod54.1%
*-commutative54.1%
Applied egg-rr54.1%
expm1-def95.8%
expm1-log1p99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
if 5.8000000000000003e-52 < k Initial program 99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r*99.6%
div-inv99.7%
expm1-log1p-u99.2%
expm1-udef93.0%
Applied egg-rr93.0%
expm1-def99.2%
expm1-log1p99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (sqrt (* PI (* 2.0 n)))))
double code(double k, double n) {
return pow(k, -0.5) * sqrt((((double) M_PI) * (2.0 * n)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.sqrt((Math.PI * (2.0 * n)));
}
def code(k, n): return math.pow(k, -0.5) * math.sqrt((math.pi * (2.0 * n)))
function code(k, n) return Float64((k ^ -0.5) * sqrt(Float64(pi * Float64(2.0 * n)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * sqrt((pi * (2.0 * n))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot \sqrt{\pi \cdot \left(2 \cdot n\right)}
\end{array}
Initial program 99.4%
expm1-log1p-u96.0%
expm1-udef73.0%
pow1/273.0%
pow-flip73.0%
metadata-eval73.0%
Applied egg-rr73.0%
expm1-def96.0%
expm1-log1p99.5%
Simplified99.5%
Taylor expanded in k around 0 50.0%
expm1-log1p-u48.5%
expm1-udef27.3%
sqrt-unprod27.3%
*-commutative27.3%
Applied egg-rr27.3%
expm1-def48.5%
expm1-log1p50.1%
*-commutative50.1%
associate-*r*50.1%
Simplified50.1%
Final simplification50.1%
(FPCore (k n) :precision binary64 (* (sqrt (* PI n)) (sqrt (/ 2.0 k))))
double code(double k, double n) {
return sqrt((((double) M_PI) * n)) * sqrt((2.0 / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * n)) * Math.sqrt((2.0 / k));
}
def code(k, n): return math.sqrt((math.pi * n)) * math.sqrt((2.0 / k))
function code(k, n) return Float64(sqrt(Float64(pi * n)) * sqrt(Float64(2.0 / k))) end
function tmp = code(k, n) tmp = sqrt((pi * n)) * sqrt((2.0 / k)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot n} \cdot \sqrt{\frac{2}{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
div-inv99.4%
*-commutative99.4%
unpow-prod-down74.0%
associate-*r*74.0%
pow1/274.0%
pow-flip74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
Applied egg-rr74.0%
add-sqr-sqrt73.8%
sqrt-unprod58.7%
associate-*l*58.7%
associate-*l*58.7%
swap-sqr58.7%
pow-prod-up58.7%
metadata-eval58.7%
inv-pow58.7%
Applied egg-rr84.2%
Taylor expanded in k around 0 34.8%
*-commutative34.8%
Simplified34.8%
pow1/234.8%
associate-*r*34.8%
unpow-prod-down49.8%
pow1/249.8%
Applied egg-rr49.8%
*-commutative49.8%
*-commutative49.8%
unpow1/249.8%
associate-*l/49.8%
metadata-eval49.8%
Simplified49.8%
Final simplification49.8%
(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.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
div-inv99.4%
*-commutative99.4%
unpow-prod-down74.0%
associate-*r*74.0%
pow1/274.0%
pow-flip74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
Applied egg-rr74.0%
add-sqr-sqrt73.8%
sqrt-unprod58.7%
associate-*l*58.7%
associate-*l*58.7%
swap-sqr58.7%
pow-prod-up58.7%
metadata-eval58.7%
inv-pow58.7%
Applied egg-rr84.2%
Taylor expanded in k around 0 34.8%
*-commutative34.8%
associate-/l*34.8%
Simplified34.8%
Taylor expanded in k around 0 34.8%
associate-/l*34.8%
associate-/r/34.8%
Simplified34.8%
Final simplification34.8%
(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.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
div-inv99.4%
*-commutative99.4%
unpow-prod-down74.0%
associate-*r*74.0%
pow1/274.0%
pow-flip74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
Applied egg-rr74.0%
add-sqr-sqrt73.8%
sqrt-unprod58.7%
associate-*l*58.7%
associate-*l*58.7%
swap-sqr58.7%
pow-prod-up58.7%
metadata-eval58.7%
inv-pow58.7%
Applied egg-rr84.2%
Taylor expanded in k around 0 34.8%
*-commutative34.8%
associate-/l*34.8%
Simplified34.8%
associate-/r/34.8%
Applied egg-rr34.8%
Final simplification34.8%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ PI (/ k n)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / (k / n))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / (k / n))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi / (k / n))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / (k / n)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
div-inv99.4%
*-commutative99.4%
unpow-prod-down74.0%
associate-*r*74.0%
pow1/274.0%
pow-flip74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
div-sub74.0%
metadata-eval74.0%
div-inv74.0%
metadata-eval74.0%
Applied egg-rr74.0%
add-sqr-sqrt73.8%
sqrt-unprod58.7%
associate-*l*58.7%
associate-*l*58.7%
swap-sqr58.7%
pow-prod-up58.7%
metadata-eval58.7%
inv-pow58.7%
Applied egg-rr84.2%
Taylor expanded in k around 0 34.8%
*-commutative34.8%
associate-/l*34.8%
Simplified34.8%
Final simplification34.8%
herbie shell --seed 2023230
(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))))