Fast q-binomials in Mathematica
Date: Jun 10, 2009
Recently, I have been doing experiments involving q-binomial coefficients in Mathematica. Starting with version 7, Mathematica is prepared for some q-business; in particular, there exists a function named QBinomial giving the q-analog of Binomial. However, this implementation turned out to not be fast enough for my needs. Here is an alternative approach which is not only way faster but provides a full factorization.
qn[n_, q_] :=
Product[If[Mod[n, d] == 0, Cyclotomic[d, q], 1], {d, 2, n}];
qfactorial[n_, q_] :=
Product[Cyclotomic[d, q]^Floor[n/d], {d, 2, n}];
qbinomial[n_, k_, q_] :=
If[k > n, 0,
Product[If[Floor[n/d] == Floor[k/d] + Floor[(n - k)/d], 1,
Cyclotomic[d, q]], {d, 2, n}]];
The above code is based on the following well-known observations. Let
be the n-th cyclotomic polynomial. Then
![]() |
where the product is taken over those 2 ≤ d ≤ n for which
. This follows from
,
![]() |
and
![]() |
Finally, note that
![]() |

![$$ [n]_q ! = \prod_{m = 1}^n \prod_{d|m, d > 1} \Phi_d (q) =<br />
\prod_{d = 2}^n \Phi_d (q)^{\left\lfloor n / d \right\rfloor} $$](/sites/all/files/tex/77c3b6e9de8729b73f427358aa2460529cc6956c.png)
![$$ \left( \begin{array}{c}<br />
n\\<br />
k<br />
\end{array} \right)_q = \frac{[n]_q !}{[k]_q ! [n - k]_q !} = \prod_{d =<br />
2}^n \Phi_d (q)^{\left\lfloor n / d \right\rfloor - \left\lfloor k / d<br />
\right\rfloor - \left\lfloor (n - k) / d \right\rfloor} . $$](/sites/all/files/tex/d0f042a4c805f6267e491b00a3565157f3e934a8.png)

Comments
Post new comment