
(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 (* (* n PI) 2.0))) (/ (sqrt t_0) (* (pow t_0 (/ k 2.0)) (sqrt k)))))
double code(double k, double n) {
double t_0 = (n * ((double) M_PI)) * 2.0;
return sqrt(t_0) / (pow(t_0, (k / 2.0)) * sqrt(k));
}
public static double code(double k, double n) {
double t_0 = (n * Math.PI) * 2.0;
return Math.sqrt(t_0) / (Math.pow(t_0, (k / 2.0)) * Math.sqrt(k));
}
def code(k, n): t_0 = (n * math.pi) * 2.0 return math.sqrt(t_0) / (math.pow(t_0, (k / 2.0)) * math.sqrt(k))
function code(k, n) t_0 = Float64(Float64(n * pi) * 2.0) return Float64(sqrt(t_0) / Float64((t_0 ^ Float64(k / 2.0)) * sqrt(k))) end
function tmp = code(k, n) t_0 = (n * pi) * 2.0; tmp = sqrt(t_0) / ((t_0 ^ (k / 2.0)) * sqrt(k)); end
code[k_, n_] := Block[{t$95$0 = N[(N[(n * Pi), $MachinePrecision] * 2.0), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Power[t$95$0, N[(k / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(n \cdot \pi\right) \cdot 2\\
\frac{\sqrt{t\_0}}{{t\_0}^{\left(\frac{k}{2}\right)} \cdot \sqrt{k}}
\end{array}
\end{array}
Initial program 99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites99.5%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-/.f64N/A
*-lft-identityN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites99.4%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
Applied rewrites99.7%
lift-/.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
associate-/l/N/A
Applied rewrites99.7%
(FPCore (k n) :precision binary64 (* (pow (pow k -1.0) 0.5) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return pow(pow(k, -1.0), 0.5) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return Math.pow(Math.pow(k, -1.0), 0.5) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return math.pow(math.pow(k, -1.0), 0.5) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(((k ^ -1.0) ^ 0.5) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = ((k ^ -1.0) ^ 0.5) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[Power[N[Power[k, -1.0], $MachinePrecision], 0.5], $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}
\\
{\left({k}^{-1}\right)}^{0.5} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Initial program 99.5%
lift-/.f64N/A
metadata-evalN/A
lift-sqrt.f64N/A
sqrt-divN/A
pow1/2N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f6499.5
Applied rewrites99.5%
(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}
Initial program 99.5%
(FPCore (k n) :precision binary64 (let* ((t_0 (pow (* (* PI 2.0) n) (/ (/ (- 1.0 k) 2.0) 2.0)))) (* (/ 1.0 (sqrt k)) (* t_0 t_0))))
double code(double k, double n) {
double t_0 = pow(((((double) M_PI) * 2.0) * n), (((1.0 - k) / 2.0) / 2.0));
return (1.0 / sqrt(k)) * (t_0 * t_0);
}
public static double code(double k, double n) {
double t_0 = Math.pow(((Math.PI * 2.0) * n), (((1.0 - k) / 2.0) / 2.0));
return (1.0 / Math.sqrt(k)) * (t_0 * t_0);
}
def code(k, n): t_0 = math.pow(((math.pi * 2.0) * n), (((1.0 - k) / 2.0) / 2.0)) return (1.0 / math.sqrt(k)) * (t_0 * t_0)
function code(k, n) t_0 = Float64(Float64(pi * 2.0) * n) ^ Float64(Float64(Float64(1.0 - k) / 2.0) / 2.0) return Float64(Float64(1.0 / sqrt(k)) * Float64(t_0 * t_0)) end
function tmp = code(k, n) t_0 = ((pi * 2.0) * n) ^ (((1.0 - k) / 2.0) / 2.0); tmp = (1.0 / sqrt(k)) * (t_0 * t_0); end
code[k_, n_] := Block[{t$95$0 = N[Power[N[(N[(Pi * 2.0), $MachinePrecision] * n), $MachinePrecision], N[(N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\left(\pi \cdot 2\right) \cdot n\right)}^{\left(\frac{\frac{1 - k}{2}}{2}\right)}\\
\frac{1}{\sqrt{k}} \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
Initial program 99.5%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-/.f64N/A
sqr-powN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-/.f64N/A
lift--.f64N/A
lower-pow.f64N/A
Applied rewrites99.3%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* (* PI 2.0) n))
(t_1 (log t_0))
(t_2 (sqrt (* PI n)))
(t_3
(pow (exp 0.5) (/ (* (fma -1.0 k 1.0) (log (* n (* PI 2.0)))) 2.0))))
(if (<= k 3.7e-6)
(*
(/ 1.0 (sqrt k))
(fma
(fma
(fma
(* (* (* k (pow t_1 3.0)) (sqrt 2.0)) t_2)
-0.020833333333333332
(* (* 0.125 t_2) (* (pow t_1 2.0) (sqrt 2.0))))
k
(* (* -0.5 t_2) (* t_1 (sqrt 2.0))))
k
(sqrt t_0)))
(* (exp (* (log (pow k -1.0)) 0.5)) (* t_3 t_3)))))
double code(double k, double n) {
double t_0 = (((double) M_PI) * 2.0) * n;
double t_1 = log(t_0);
double t_2 = sqrt((((double) M_PI) * n));
double t_3 = pow(exp(0.5), ((fma(-1.0, k, 1.0) * log((n * (((double) M_PI) * 2.0)))) / 2.0));
double tmp;
if (k <= 3.7e-6) {
tmp = (1.0 / sqrt(k)) * fma(fma(fma((((k * pow(t_1, 3.0)) * sqrt(2.0)) * t_2), -0.020833333333333332, ((0.125 * t_2) * (pow(t_1, 2.0) * sqrt(2.0)))), k, ((-0.5 * t_2) * (t_1 * sqrt(2.0)))), k, sqrt(t_0));
} else {
tmp = exp((log(pow(k, -1.0)) * 0.5)) * (t_3 * t_3);
}
return tmp;
}
function code(k, n) t_0 = Float64(Float64(pi * 2.0) * n) t_1 = log(t_0) t_2 = sqrt(Float64(pi * n)) t_3 = exp(0.5) ^ Float64(Float64(fma(-1.0, k, 1.0) * log(Float64(n * Float64(pi * 2.0)))) / 2.0) tmp = 0.0 if (k <= 3.7e-6) tmp = Float64(Float64(1.0 / sqrt(k)) * fma(fma(fma(Float64(Float64(Float64(k * (t_1 ^ 3.0)) * sqrt(2.0)) * t_2), -0.020833333333333332, Float64(Float64(0.125 * t_2) * Float64((t_1 ^ 2.0) * sqrt(2.0)))), k, Float64(Float64(-0.5 * t_2) * Float64(t_1 * sqrt(2.0)))), k, sqrt(t_0))); else tmp = Float64(exp(Float64(log((k ^ -1.0)) * 0.5)) * Float64(t_3 * t_3)); end return tmp end
code[k_, n_] := Block[{t$95$0 = N[(N[(Pi * 2.0), $MachinePrecision] * n), $MachinePrecision]}, Block[{t$95$1 = N[Log[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(Pi * n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Exp[0.5], $MachinePrecision], N[(N[(N[(-1.0 * k + 1.0), $MachinePrecision] * N[Log[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[k, 3.7e-6], N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(N[(k * N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * -0.020833333333333332 + N[(N[(0.125 * t$95$2), $MachinePrecision] * N[(N[Power[t$95$1, 2.0], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * k + N[(N[(-0.5 * t$95$2), $MachinePrecision] * N[(t$95$1 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * k + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Log[N[Power[k, -1.0], $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot 2\right) \cdot n\\
t_1 := \log t\_0\\
t_2 := \sqrt{\pi \cdot n}\\
t_3 := {\left(e^{0.5}\right)}^{\left(\frac{\mathsf{fma}\left(-1, k, 1\right) \cdot \log \left(n \cdot \left(\pi \cdot 2\right)\right)}{2}\right)}\\
\mathbf{if}\;k \leq 3.7 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\sqrt{k}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left(\left(k \cdot {t\_1}^{3}\right) \cdot \sqrt{2}\right) \cdot t\_2, -0.020833333333333332, \left(0.125 \cdot t\_2\right) \cdot \left({t\_1}^{2} \cdot \sqrt{2}\right)\right), k, \left(-0.5 \cdot t\_2\right) \cdot \left(t\_1 \cdot \sqrt{2}\right)\right), k, \sqrt{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left({k}^{-1}\right) \cdot 0.5} \cdot \left(t\_3 \cdot t\_3\right)\\
\end{array}
\end{array}
if k < 3.7000000000000002e-6Initial program 99.2%
Taylor expanded in k around 0
Applied rewrites99.3%
if 3.7000000000000002e-6 < k Initial program 99.7%
Taylor expanded in k around -inf
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-log.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
lift-pow.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-log.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites99.7%
lift-/.f64N/A
metadata-evalN/A
lift-sqrt.f64N/A
sqrt-divN/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (exp 0.5) (* (fma -1.0 k 1.0) (log (* (* PI 2.0) n))))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(exp(0.5), (fma(-1.0, k, 1.0) * log(((((double) M_PI) * 2.0) * n))));
}
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (exp(0.5) ^ Float64(fma(-1.0, k, 1.0) * log(Float64(Float64(pi * 2.0) * n))))) end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[Exp[0.5], $MachinePrecision], N[(N[(-1.0 * k + 1.0), $MachinePrecision] * N[Log[N[(N[(Pi * 2.0), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(e^{0.5}\right)}^{\left(\mathsf{fma}\left(-1, k, 1\right) \cdot \log \left(\left(\pi \cdot 2\right) \cdot n\right)\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around -inf
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-log.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6496.0
Applied rewrites96.0%
(FPCore (k n)
:precision binary64
(let* ((t_0
(pow (exp 0.5) (/ (* (fma -1.0 k 1.0) (log (* n (* PI 2.0)))) 2.0))))
(* (/ 1.0 (sqrt k)) (* t_0 t_0))))
double code(double k, double n) {
double t_0 = pow(exp(0.5), ((fma(-1.0, k, 1.0) * log((n * (((double) M_PI) * 2.0)))) / 2.0));
return (1.0 / sqrt(k)) * (t_0 * t_0);
}
function code(k, n) t_0 = exp(0.5) ^ Float64(Float64(fma(-1.0, k, 1.0) * log(Float64(n * Float64(pi * 2.0)))) / 2.0) return Float64(Float64(1.0 / sqrt(k)) * Float64(t_0 * t_0)) end
code[k_, n_] := Block[{t$95$0 = N[Power[N[Exp[0.5], $MachinePrecision], N[(N[(N[(-1.0 * k + 1.0), $MachinePrecision] * N[Log[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(e^{0.5}\right)}^{\left(\frac{\mathsf{fma}\left(-1, k, 1\right) \cdot \log \left(n \cdot \left(\pi \cdot 2\right)\right)}{2}\right)}\\
\frac{1}{\sqrt{k}} \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in k around -inf
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-log.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6496.0
Applied rewrites96.0%
lift-pow.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-log.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites96.0%
(FPCore (k n)
:precision binary64
(let* ((t_0
(pow (exp 0.5) (/ (* (fma -1.0 k 1.0) (log (* n (* PI 2.0)))) 2.0))))
(* (exp (* (log (pow k -1.0)) 0.5)) (* t_0 t_0))))
double code(double k, double n) {
double t_0 = pow(exp(0.5), ((fma(-1.0, k, 1.0) * log((n * (((double) M_PI) * 2.0)))) / 2.0));
return exp((log(pow(k, -1.0)) * 0.5)) * (t_0 * t_0);
}
function code(k, n) t_0 = exp(0.5) ^ Float64(Float64(fma(-1.0, k, 1.0) * log(Float64(n * Float64(pi * 2.0)))) / 2.0) return Float64(exp(Float64(log((k ^ -1.0)) * 0.5)) * Float64(t_0 * t_0)) end
code[k_, n_] := Block[{t$95$0 = N[Power[N[Exp[0.5], $MachinePrecision], N[(N[(N[(-1.0 * k + 1.0), $MachinePrecision] * N[Log[N[(n * N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[Exp[N[(N[Log[N[Power[k, -1.0], $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(e^{0.5}\right)}^{\left(\frac{\mathsf{fma}\left(-1, k, 1\right) \cdot \log \left(n \cdot \left(\pi \cdot 2\right)\right)}{2}\right)}\\
e^{\log \left({k}^{-1}\right) \cdot 0.5} \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in k around -inf
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-log.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6496.0
Applied rewrites96.0%
lift-pow.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-log.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites96.0%
lift-/.f64N/A
metadata-evalN/A
lift-sqrt.f64N/A
sqrt-divN/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
inv-powN/A
lower-pow.f6495.5
Applied rewrites95.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (log (* (* PI 2.0) n))) (t_1 (* (* PI n) k)) (t_2 (sqrt t_1)))
(if (<=
(* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0)))
4e+149)
(sqrt (* (/ (* PI n) k) 2.0))
(/
(fma
(fma
(fma
(* -0.020833333333333332 (sqrt (* (* (pow k 3.0) n) PI)))
(* (pow t_0 3.0) (sqrt 2.0))
(* (* 0.125 t_2) (* (pow t_0 2.0) (sqrt 2.0))))
k
(* (* -0.5 t_2) (* t_0 (sqrt 2.0))))
k
(sqrt (* t_1 2.0)))
k))))
double code(double k, double n) {
double t_0 = log(((((double) M_PI) * 2.0) * n));
double t_1 = (((double) M_PI) * n) * k;
double t_2 = sqrt(t_1);
double tmp;
if (((1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0))) <= 4e+149) {
tmp = sqrt((((((double) M_PI) * n) / k) * 2.0));
} else {
tmp = fma(fma(fma((-0.020833333333333332 * sqrt(((pow(k, 3.0) * n) * ((double) M_PI)))), (pow(t_0, 3.0) * sqrt(2.0)), ((0.125 * t_2) * (pow(t_0, 2.0) * sqrt(2.0)))), k, ((-0.5 * t_2) * (t_0 * sqrt(2.0)))), k, sqrt((t_1 * 2.0))) / k;
}
return tmp;
}
function code(k, n) t_0 = log(Float64(Float64(pi * 2.0) * n)) t_1 = Float64(Float64(pi * n) * k) t_2 = sqrt(t_1) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) <= 4e+149) tmp = sqrt(Float64(Float64(Float64(pi * n) / k) * 2.0)); else tmp = Float64(fma(fma(fma(Float64(-0.020833333333333332 * sqrt(Float64(Float64((k ^ 3.0) * n) * pi))), Float64((t_0 ^ 3.0) * sqrt(2.0)), Float64(Float64(0.125 * t_2) * Float64((t_0 ^ 2.0) * sqrt(2.0)))), k, Float64(Float64(-0.5 * t_2) * Float64(t_0 * sqrt(2.0)))), k, sqrt(Float64(t_1 * 2.0))) / k); end return tmp end
code[k_, n_] := Block[{t$95$0 = N[Log[N[(N[(Pi * 2.0), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(Pi * n), $MachinePrecision] * k), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[t$95$1], $MachinePrecision]}, If[LessEqual[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], 4e+149], N[Sqrt[N[(N[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision], N[(N[(N[(N[(N[(-0.020833333333333332 * N[Sqrt[N[(N[(N[Power[k, 3.0], $MachinePrecision] * n), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Power[t$95$0, 3.0], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.125 * t$95$2), $MachinePrecision] * N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * k + N[(N[(-0.5 * t$95$2), $MachinePrecision] * N[(t$95$0 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * k + N[Sqrt[N[(t$95$1 * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\left(\pi \cdot 2\right) \cdot n\right)\\
t_1 := \left(\pi \cdot n\right) \cdot k\\
t_2 := \sqrt{t\_1}\\
\mathbf{if}\;\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 4 \cdot 10^{+149}:\\
\;\;\;\;\sqrt{\frac{\pi \cdot n}{k} \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.020833333333333332 \cdot \sqrt{\left({k}^{3} \cdot n\right) \cdot \pi}, {t\_0}^{3} \cdot \sqrt{2}, \left(0.125 \cdot t\_2\right) \cdot \left({t\_0}^{2} \cdot \sqrt{2}\right)\right), k, \left(-0.5 \cdot t\_2\right) \cdot \left(t\_0 \cdot \sqrt{2}\right)\right), k, \sqrt{t\_1 \cdot 2}\right)}{k}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 4.0000000000000002e149Initial program 99.3%
Taylor expanded in k around 0
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6455.4
Applied rewrites55.4%
if 4.0000000000000002e149 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 99.8%
Taylor expanded in k around 0
Applied rewrites78.9%
(FPCore (k n) :precision binary64 (sqrt (* (/ (* PI n) k) 2.0)))
double code(double k, double n) {
return sqrt((((((double) M_PI) * n) / k) * 2.0));
}
public static double code(double k, double n) {
return Math.sqrt((((Math.PI * n) / k) * 2.0));
}
def code(k, n): return math.sqrt((((math.pi * n) / k) * 2.0))
function code(k, n) return sqrt(Float64(Float64(Float64(pi * n) / k) * 2.0)) end
function tmp = code(k, n) tmp = sqrt((((pi * n) / k) * 2.0)); end
code[k_, n_] := N[Sqrt[N[(N[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi \cdot n}{k} \cdot 2}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6437.8
Applied rewrites37.8%
herbie shell --seed 2025057
(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))))