1

Inspired by this question and my answer.

The standard formula for binomial coefficients is well-known: $$\binom{n}{r} = \frac{n!}{r!\cdot (n-r)!}.$$ And the binomial theorem is one of the more prominent uses of binomial coefficients: $$(x + y)^n = \sum_{r = 0}^n\binom nr x^{n-r}y^{r}.$$ However, when using the binomial theorem modulo some integer $k$ (i.e. when working with polynomials over $\Bbb Z_k$ rather than $\Bbb Z$), one encounters a problem putting these two things together. Specifically, if $n$ is large enough, the fraction in the formula for binomial coefficients is invalid, as the denominator will not be invertible modulo $k$.

Now, one could argue something along the following lines: $\binom nr$ as given in the formula represents an integer. One uses the formula over the integers to find the integer value of the binomial coefficient, and then reduce it modulo $k$. This approach will give the correct answer.

However, this doesn't sit entirely well with me. When expanding $(x + y)^n$ in $\Bbb Z_k[x, y]$, in any intermediate step as well as in the final answer, all coefficients are in $\Bbb Z_k$. The integers never really enter into this1.

So my question is this: Is there a (relatively) compact formula2 for $\binom nr$ modulo $k$? Every arithmetic operation the formula describes ought to be valid modulo $k$, so most importantly there should be no factors of $k$ in any denominators.

A first attempt might be to clear away factors from the original formula. This way we get then: $$ \binom nr = \frac{n(n-1)(n-2)\cdots(n-r+1)}{r!} $$ Once we get to this point, though, any more simplification of factors seems to be very difficult. And while this formula is a bit more robust (its validity is independent of the size of $n$, for one thing), it still won't work for large enough $r$.


1 Many (most?) people, on some level, actually do the modular addition and multiplication required for this expansion the way described above: think integers first, then reduce modulo $k$ afterwards. But my point is that one does not have to do it that way.

2 Say it should be simple enough that using it to calculate binomial coefficients up to around $n = 10$, or with $r$ close to $0$ or to $n$, with pen and paper should not be tedious, whatever that means. And while I don't expect there to be something as short as $\frac{n!}{r!(n-r)!}$, I don't want there to be any problems fitting it in a single line.


Edit: I was made aware of Lucas's theorem in the comments. This neatly solves the problem for prime $k$ (and by the Chinese remainder theorem for square-free $k$). I guess my remaining question is this: Can something be done for $k$ being the power of a prime? And if I'm being greedy, I personally think using the Chinese remainder theorem for calculations is a bit tedious at times. Can one make do without it? (This is in no way a requirement; a full solution using the CRT is completely fine. It might also be just me not having found an algorithm I'm comfortable with, which is another issue enteirely.)

amWhy
  • 210,739
Arthur
  • 204,511

0 Answers0