I have 3 urns, each contaning some white and black balls. I need to know all the possible ways i can extract 3 black balls by extracting 1 ball from each urn.
Example:
1st urn: 3 black balls
2nd urn: 2 black balls, 1 white ball
3rd urn: 1 black ball, 1 white ball
I know that if i write this as a multiplication of binomial in x and y, the coefficients will give me the solution:
$(3x)\cdot (2x+y)\cdot (x+y) = 6x^2 + 9x^2\cdot y + 3xy^2$
This means that I have 9 way to extract 2 black and one white ball.
I need a way to express this in a close formula or, at least, in something that i can easily calculate in... TSQL.
In other words, something that, for this example, accepts $((3,0),(2,1),(1,1),2)$ and spits out 9.
Assume you have $$(a_{1}\cdot x +b_{1}\cdot y)\cdot (a_{2}\cdot x +b_{2}\cdot y)\ldots (a_{n}\cdot x +b_{n}\cdot y)$$ and you want to get the coefficient in front of $x^{k}$ (i.e. in front of $x^{k}y^{n-k}$). The formula is
$$\sum_{S\in \binom{n}{k}} (\prod_{i\in S}a_i\cdot \prod_{j\notin S}b_{j}) = \sum_{S\in \binom{n}{k}}\frac{\prod_{i=1}^{i=n}a_i}{\prod_{j\notin S}a_{j}\cdot b_{j}} = \prod_{i=1}^{i=n}a_i \cdot\sum_{S\in \binom{n}{k}}\frac{1}{\prod_{j\notin S}a_{j}\cdot b_{j}}$$