# Defining q-binomial coefficients $\binom{n}{k}_q$ symbolic in $n, k$

I would like to verify certain identities involving sums of $q$-binomial coefficients $\binom{n}{k}_q$ and as such, I would like to treat the $q$-binomial coefficients as if they were symbolic in $n$ and $k$. But the version of $q$-binomial coefficients that are implemented in Sage cannot be used as a symbolic variable in $n$ and $k$ according to this thread. So, to this end I defined my own:

var('q,n,k')
qint = lambda n: sum([q^i for i in range(n)])
qfac = lambda n: 1 if n==0 else prod([qint(i) for i in range(1,n+1)])
qbin = lambda n,k:qfac(n)/(qfac(k)*qfac(n-k))


But if I write

sum(qbin(n,k),k,0,n)


I get the following error:

ValueError: cannot convert n + 1 to int


Is there a way to do these types of summations in Sage? I should note that, for my purposes, it would be enough to limit myself to the case when $n$ and $k$ are non-negative integers.

EDIT: As an example, I would like to prove something like the $q$-binomial theorem, which says

$$\sum_{k=0}^n q^{k(k-1)/2} \binom{n}{k}_q x^k = \prod_{k=0}^{n-1} (1+q^k x)$$

EDIT2: Fixed a typo.

edit retag close merge delete

Sort by » oldest newest most voted If you want to make a symbolic sum then all the terms should be symbolic. Your example does not work because qbin(n,k) is not defined for symbolic n.

What you can do is to make qbin a symbolic function with custom typesetting:

var('q')
def qbin_latex(self, n, k):
return '{' + str(n) + ' \choose ' + str(k) + '}_{' + str(q) + '}'
qbin = function('qbin', nargs=2, print_latex_func=qbin_latex)
var('k,n')
show(sum(qbin(n,k),k,0,n))


$$\sum_{k=0}^{n} {n \choose k}_{q}$$

To check the identities that you are interested in, you will probably have to do some substitutions by hand, and/or pass an evalf_func parameter to function in the definition of qbin. Have a look at the documentation for symbolic functions.

more

I will take a look at the documentation and try to make sense of it. What I am really looking for is a way to verify an identity of the form RHS(q,n,k)=LHS(q,n,k), involving some q-binomial coefficients that depend on n and k. Something like the q-binomial theorem. It seems to me that evalf_func evaluates a function numerically, so I could only confirm the identity for many values of q, n, k which is not exactly what I want.