Roots of Unity Filter Part 3 - Roots of Unity Filter
Note
This is a three part series I wrote back in 2019 on a technique applicable to certain competitive math problems: roots of unity filters. See the first two parts for a recap of complex numbers and roots of unity respectively. This post will go over the technique as well as what kind of problems it can be applied to.
Update: in 2025 this became a four part series after I added a proof section: Roots of Unity Filter Proof.
Guiding Problem
The main problem we are trying to tackle in this section is the following from one of Thomas Mildorf's mock AIMEs:
Example
Problem from Thomas Mildorf's Mock AIME 1: #11
Let denote the value of the sum
Determine
We can tackle this problem in a variety of ways, but the approach discussed here is a technique known as roots of unity filter.
Description
Roots of unity filter is a technique that allows us to find the sum of every th coefficient in a polynomial with any given offset less than . For instance, if you had a polynomial with a degree of , you could find the sum of the 2nd, 5th, 8th, ..., and 20th coefficients. This would correspond to every 3rd coefficient with an offset of .
While on its own the roots of unity filter doesn't have a lot of applications, it is especially powerful when applied to the binomial theorem. For instance, with the guiding problem, we can expand the summation to find the following;
From this, we see the problem is asking us to calculate the sum of every 6th binomial coefficient with an offset of and then subtract the sum of every 6th binomial coefficient with an offset of .
We can apply the roots of unity filter if we had a polynomial that had binomial coefficients as its coefficients. We can obtain this with the following polynomial:
To solve our problem from above, we can utilize the root of unity filter on this polynomial with to determine the sum of every 6th coefficient with offset and the sum of every 6th coefficient with offset . Then, we can subtract the latter from the former and obtain the answer.
No Offset Version
The simplest method to apply roots of unity filter is when you're dealing with an offset of . If you want to find the sum of every th coefficient with an offset of for a polynomial , you can calculate it with the following expression, where represents the smallest root of unity:
Essentially, we plug in the th roots of unity, where is the desired cycle length and take the average of the results.
Intuitive Explanation
To see why this works, we can utilize the following two facts that we proved previously about roots of unity:
With this, we examine what happens when we plug the roots of unity into the polynomial . For this section, we're going to use a polynomial with a degree of and calculate the sum of every third term. However, this can be generalized to any degree polynomial for any cycle length. First of all, let's write a polynomial with a degree of as the following:
When we plug in as our root of unity, we obtain the following:
Using , we can simplify this as:
We first just focus on the first three terms and show that under this consideration, .
We can make the following chart to look at what happens: the columns each correspond to each term of the polynomial, while the rows each correspond to a root of unity we plug in. If we sum all of the columns, we obtain how much each coefficient we shall receive in the sum . From the identity
all of the columns except for the one for end up with a sum of .
Total Sum |
Again, remember that since the roots of unity are cyclic with a period of , the same values and chart will apply for through , through to conclude will result in . To see this, looking at the entire chart is useful.
Total Sum |
Example
Find without calculating any binary coefficients
We can approach this problem by first realizing that we need to find the sum of every 4th coefficient in the polynomial:
By applying the roots of unity filter, we can realize that this is equivalent to the following:
We can then find this sum by converting each of the complex numbers to polar form, applying de Moivre's theorem, and then converting back to rectangular coordinates. While this may seem lengthy for a problem we could have just calculated the binomial coefficients for, it is a general technique that has the same number of terms even as the upper number increases to huge numbers.
We continue the calculation below for the sake of completeness:
To check our answer, we can compute the binomial coefficients manually and get .
Note
A frequent math competition technique is to plug and into a polynomial , add them together, and then divide by to cancel out all of the odd degree terms. This is actually the roots of unity filter being used with since and are the second roots of unity!
With Offset Version
While the previous version of roots of unity filter is already pretty powerful and can solve a lot of math problems, the more general version to find sums with offsets. Note that we still cannot solve our guiding problem because, in that problem, we have to be able to calculate the sum of the coefficients with a period of , but with an offset of .
To get an idea of how this will work, we look at the chart we created earlier.
Total Sum |
Note that the main reason this worked out was that we had appear in every row for the term we wanted: . This time, say that our the desired coefficient is , meaning that we want an offset of instead of . The key is to add some coefficient in front of each term in our sum to ensure that our sum has s in the column for our desired term: . Then, if we called those coefficients , the sum of every 3rd term with an offset of 1 would look like this:
To calculate these coefficients, we can use our table from above. Currently, it would look something like this, where all of our coefficients would be , meaning that the values for each row are not being changed.
Total Sum |
However, by using the crucial property that , we can adjust the coefficients for each row so that the s appear in the column for :
Total Sum |
Then, each sum now produces the values for ! With this, our equation to find the sum of every 3rd term with an offset of looks like the following:
Formally, we can provide the formula for for an offset and cycle length as:
where represents the modulo operator.
Note
I have a followup post that goes over why this is guaranteed to work for any cycle length or any offset since here it seems like magic. Including it in this post would just make this one too long since I just wanted to leave it as a reference / intro to the technique. The general intuition is that these terms have the effect of "shifting" the entire table over spots.
Solving the Guiding Problem
Armed with this knowledge, we can know solve our guiding problem. If you need a refresher, the problem boils down to the following:
To do this, we need to find the sum of every 6th coefficient with an offset of 0 and the sum of every 6th coefficient with an offset of 3 for the polynomial
We will call the first sum and the second sum . We can apply the no offset roots of unity filter to calculate :
While we could plug this in and solve for directly, it would be incredibly difficult. However, we can proceed with calculating to see if we get any nice cancellations. We can apply our offsetted roots of unity filter to calculate . To do so, we first need to find what our coefficients will be to get our column of s to shift to , which will give us the offset of that we need.
Root of Unity | Original | Modified | |
---|---|---|---|
Note that the way we choose the coefficients is that we want the coefficient of to increase so it becomes a multiple of and the coefficient evaluates to .
Then, we can calculate as:
When we combine this with to get our total answer of , we obtain the following:
Now that our sum is greatly simplified, we can plug in and see what we can cancel out. The first thing we can notice is that as derived above, so our middle term cancels out to , so we can ignore that. The next thing we can do is calculate what is in rectangular form so that we can add the to it as part of .
To calculate this, we can use de Moivre's theorem after converting to polar form.
We can do this with as well.
Therefore, our final sum evaluates to:
Note
The original problem was part of a mock AIME and asked for the answer mod . Since this post is about roots of unity filter, we won't cover that part in depth, but to calculate the value mod , you could apply the Euler's Totient Theorem with to find that . Then, the answer is .
Final Notes
Roots of unity filter is a super useful technique on some problems, but it can involve a lot of calculations and is not applicable to everything. For our guiding problem, we were fortunate enough to have all of our complex roots of unities dissipate nicely, which is something that you will frequently see for math competition problems that use roots of unity filter. Roots of unity filter can also be especially powerful when combined with generating functions.
Generally, most problems will use the 4th roots of unity, which makes it incredibly convenient since all of the roots of unities are either entirely imaginary or entirely real. For less convenient problems, a calculator or some other clever insight may be necessary to evaluate the result.
As mentioned previously, the technique was just introduced here without much proof that it works in all cases. I've written a follow up here that goes over proofs so you can safely apply this technique: Roots of Unity Filter Proof.