[Math] choose at most k from n

combinatorics

The Problem

Suppose I have a bit string of length $n$ consisting of all zeros. I want to flip some of the zeros to ones, but I am only able to flip at most $k$ bits (i.e., I can flip any number of bits I want, as long as it is not more than $k$). How many ways can I do this?

What I Tried

I believe this is analogous to finding the number of ways to choose at most $k$ things out of a group of $n$, which it seems could be expressed as

\begin{align*}
\sum_{r=0}^k {n \choose r} &= {n \choose 0} + {n \choose 1} + \dots + {n \choose k} \\
&= \frac{n!}{0!n!} + \frac{n!}{1!(n-1)!} + \frac{n!}{2!(n-2)!}
+ \dots + \frac{n!}{k!(n-k)!} \\
\end{align*}

but this is still not very neat, and I don't see where to go from here algebraically. I also see that this is also the same as adding a partial row of Pascal's triangle, but that didn't get me much further. I tried searching for various things both on this site and google involving various combinations of the terms n choose k, at most, summing a row of pascal's triangle, etc., which did not give many applicable results.

The Question

Assuming I translated the problem correctly, is there a cleaner solution than taking the sum over the different choices of $k$? If one exists, I would love to see a combinatorial explanation for it, but an algebraic one would still be sufficient.

Best Answer

For completeness and convenience I have taken the information in the comments and put it here as an answer. Thus, my answer is essentially taken from the accepted answer to this very similar question.

#

Yes, there are various closed form expressions for this summation. However, they are all relatively complex and so in practice using them to calculate the summation may actually me more complicated than just calculating the summation term by term!

If $S= \sum_{k\le K}{n\choose k} $, then in terms of hypergeometric ${}_2F_1 (a,b,c,d)$ functions, $$ S = 2^n - 1 - \binom{n}{1+K} \; {}_2F_1 (1, 1+K-n, 2+K,-1) $$

Denote the fractional part of $z$ as $\lfloor z \rfloor = z - [z]$.

Now , if for any positive integer $j>1$, we let $x = j^{-n}$, then there are the two following intriguing expressions (which are a result of generating functions):

$$ S =\left\lfloor\frac{(j^{K+1}\cdot(1+x))^{n}}{j^{n}-1}-j^{n}\cdot\left\lfloor\frac{(j^{K}\cdot(1+x))^{n}}{j^{n}-1} \right\rfloor\right\rfloor$$

And, $$S=\left\lfloor\frac{(1+x)^n}{x^{K}(1-x)}\right\rfloor \; (\mod 4^n).$$

Related Question