<s>[INST] What is a closed form for $\sum_{r=1}^k \binom nr$, where $k\leqslant n$. What will be the closed form of the following equation
$$\sum_{r=1}^k C(n,r), $$ where $n$ and $k$ are positive integers with $k\leqslant n$?
 [/INST] $$\begin{align}
S=\sum_{\begin{array}{c}0\le k\le n\\1\le r\le k\end{array}}\binom{n}{r}&=\sum_{k=0}^n\sum_{r=1}^k\binom{n}{r}\\
 &=\left[\binom{n}{1}\right]+\left[\binom{n}{1}+\binom{n}{2}\right]\dotsm+\left[\binom{n}{1}+\dotsm+\binom{n}{n}\right]\\
 &=n\binom{n}{1}+(n-1)\binom{n}{2}+(n-2)\binom{n}{3}+\dotsm+\binom{n}{n}\\
 &=\sum_{i=1}^n(n+1-i)\binom{n}{i}\\
 &=-(n+1)\binom{n}{0}+\sum_{k=0}^n(n+1-i)\binom{n}{i}
\end{align}$$
By the binomial theorem,
$$\begin{align}
(1+x)^n&=\sum_{i=0}^n\binom{n}{i}x^{n-i}&\text{multiply by $x$ ...}\\
x(1+x)^n&=\sum_{i=0}^n\binom{n}{i}x^{n+1-i}&\text{differentiate ...}\\
(1+x)^n+nx(1+x)^{n-1}&=\sum_{i=0}^n(n+1-i)\binom{n}{i}x^{n-i}&\text{set $x=1$ ...}\\
2^n+n2^{n-1}&=\sum_{i=0}^n(n+1-i)\binom{n}{i}
\end{align}$$
and combining these two result gives us
$$
\sum_{\begin{array}{c}0\le k\le n\\1\le r\le k\end{array}}\binom{n}{r}=2^n+n2^{n-1}-1=(n+2)2^{n-1}-(n+1)
$$
</s>