# How to calculate this summation $\sum_{k=0}^m a^k b^{m-k} {n_1\choose k} {n_2\choose m-k}$?

Question: How to calculate this summation $$S=\sum_{k=0}^m a^k b^{m-k} {n_1\choose k} {n_2\choose m-k}$$? Where $$m

Remark1: When $$a=b$$, I know the above summation $$S=a^m\sum_{k=0}^m {n_1\choose k} {n_2\choose m-k} =a^m {n_1+n_2\choose m}$$.

Remark2: This summation looks somewhat similar to the usual binomial formula $$\sum_{k=0}^m a^k b^{m-k} {m\choose k} =(a+b)^m$$. So is there also a similar formula for $$S$$?

• It is the coefficient of $x^m$ in $(1+ax)^{n_1}(1+bx)^{n_2}$. In general there is no closed form expression without using special functions. Sep 29 at 19:32
• @Fedor Petrov Thank you!
– Dian
Sep 29 at 20:01

In terms of a hypergeometric function you would have $$S=\sum_{k=0}^m a^k b^{m-k} {n_1\choose k} {n_2\choose m-k}=b^m \binom{n_2}{m} \, _2F_1\left(-m,-n_1;-m+n_2+1;a/b\right).$$ I don't see a simpler closed-form expression for arbitrary parameters, but if you fix $$n_1$$ this does simplify to a simple rational function of $$m,n_2,a/b$$.