# Counting with Coefficients

In Fall 2018, I was taking a combinatorics course, and my final was coming up. My friend Marc tried to antagonize me by asking some dumb combo question he made up on the fly, and I ignored him. However, when we were talking the next day, he brought up the same question unironically; he was stumped.

For anybody who hasn’t watched Avengers: Infinity War, the premise is that a big purple man named Thanos wants to split the universe’s population in half. Marc’s question, dubbed “The Thanos Problem”, went something like this.

Thanos comes to Georgia Tech and wants to get rid of half of the students on campus. However, because Thanos wants everything perfectly balanced, the number of children in each class should also be halved. How many ways are there for Thanos to do this?

As a simplifying assumption, you can assume that every class has an even amount of students in it.

When I first heard the question, I thought it was trivial. If there were classes from $c_{1}$ to $c_{n}$, with each $c_{i}$ representing the number of students in the class, you could just compute $\displaystyle \prod_{i=1}^{n} {c_{i} \choose c_{i} / 2}$, where ${c_{i} \choose c_{i} / 2}$ is the number of ways to pick $c_{i} / 2$ kids from a class of size $c_{i}$ – this is known as a combination

However, I quickly realized that was totally incorrect; it only worked if you assumed no two classes had the same student in it, which is never the case unless everybody at your school only took one class a semester – maybe we could apply this approach to the students at UGA.

## Spoilers Below

It can be super fun to try to think of a solution to this problem yourself, and reading the rest of this article will probably give away the solution (heck, the title of this blog post is already a pretty big hint). Also, there might be solutions better than mine out there, involving graphs or something, that you might discover on your own! You should try to figure out the problem yourself before you continue reading!

## Spoiler as Promised

I sat and pondered for a long time, putting off studying for my combinatorics final to try and solve this problem. I tried graphs, inclusion-exclusion, and everything else I could think of. Eventually, I realized that I could solve this problem with multinomial coefficients, and I instantly wanted to share this problem and solution with the world! However, I’m sure lots of people don’t know how to count with multinomial coefficients – I didn’t really learn it until the end of this semester. This blog post will introduce the core concepts regarding counting with coefficients, and the next post will actually show you how to solve this problem!

## Quick Number Theory

Let’s look at the following factored expression:

When multiplied out, we get this:

But where did the coefficients of $2$ in front of $x$ and $x^2$ come from? This may seem like a silly question – you just multiply each term in the first expression by each in the second and combine like-terms! But what do those values of $2$ mean?

If you think about it, the $2$ in front of $x$ means that there were $2$ different ways to form $x$, and they were summed together to leave us with $2x$. We can see the two ways to form $x$ by looking at the factored form of the polynomials – the $1$ from the first polynomial times the $x$ in the second polynomial is one way, and the $x$ from the first polynomial multiplied by the $1$ in the second polynomial is the other.

What if I told you that calculating the coefficients of the product of polynomials (or more generally, multinomials) is one of the most powerful counting techniques out there?!

## Consider the Following

Like any true patriot, let’s suppose we have red, white, and blue soda cans. We want to pick 10 soda cans subject to the following constraints

• We can only pick an even number of red cans
• We can pick 2, 3, or 4 white cans
• We can pick 0, 5, or 10 blue cans

We could count this out by hand, but that would be extremely tedious, and when somebody adds another type of can, we’ll have to do even more work. What if I told you we could solve this problem using polynomial coefficients?!

Let’s formulate the red cans as $1 + x^2 + x^4 + x^6 + x^8 + x^{10}$, the white cans as $x^2 + x^3 + x^4$, and the blue cans as $1 + x^5 + x^{10}$. Note that the power of each term corresponds to the number of cans we’re allowed.

If we take the product of these three multinomials, we get the following absolute unit of an exponential

$x^2 + x^3 + 2x^4 + x^5 + 2x^6 + 2x^7 + 3x^8 + 3x^9 + 3x^{10} + 3x^{11} + 4x^{12} + 4x^{13}$ $+ 4x^{14} + 3x^{15} + 3x^{16} + 3x^{17} + 3x^{18} + 2x^{19} + 2x^{20} + x^{21} + 2x^{22} + x^{23} + x^{24}$

Looking at the coefficient of $x^{10}$, we see a value of $3$. For any of you brave enough to try to solve this by hand, you will have (hopefully) gotten the same answer. Your valid options for getting $10$ cans are

• $2$ red, $3$ white, $5$ blue
• $6$ red, $4$ white, $0$ blue
• $8$ red, $2$ white, $0$ blue

Observe that $x^0 = 1$, which is how we can represent the option of picking $0$ cans. One might think, “Hey, we can omit the $1$ because it’s $0$ cans and we don’t care about it”. That’s actually wrong! Imagine we did this with the following example and expressed the blue polynomial as $x^5 + x^{10}$. Once we multiply the red polynomial by the white to get the “pink” polynomial of $x^2 + x^3 + 2x^4 + x^5 + 2x^6 + x^7 + 2x^8 + x^9 + 2x^{10} + x^{11} + 2x^{12} + x^{13} + x^{14}$, we would be unable to keep the $2x^{10}$ term, because it would get multiplied by $x^5$ and $x^{10}$ from the blue polynomial. Our resulting answer would only have $x^{10}$ with a coefficient of $1$, which results from multiplying the blue polynomial’s $x^5$ by the “pink” polynomial’s $x^5$.

Each kid is either in the class or not in the class, and we want to count how many ways the class can have 5 children. So, we can represent each kid as $$1 + x$$, and multiply $$10$$ of these representations together; we can express this as $$(1 + x) ^ {10}$$. Now, we find the coefficient of $$x^5$$ in $$(1 + x) ^ {10}$$, which turns out to be $$252$$. Coincidentally, $$252$$ is equal to $${10 \choose 5}$$ which, as we mentioned earlier, is the number of ways to pick $$5$$ kids out of a classroom of $$10$$.
It turns out, the number of ways to pick $$n$$ kids out of your classroom of $$10$$ is just $${10 \choose n}$$!
This may seem like a big coincidence, but it's actually just the binomial theorem at work! The reason the binomial theorem applies here (but not to the soda example above) is because $$1 + x$$ just has two terms; that's where binomial gets its "bi" from.