Bounded weak compositions (source code)

= Bounded weak compositions
{title2=$\sum_{J\subseteq\{0,\ldots,r\}}(-1)^{|J|}\binom{N+r-\sum_{i\in J}a_i}{r}$}

To count nonnegative tuples with $\sum_{i=0}^r n_i=N$ and $n_i<a_i$, mark violations $n_i\geq a_i$. An intersection of violations indexed by $J$ is in <bijection> with unrestricted tuples of sum $N-\sum_{i\in J}a_i$, by subtracting the bounds from those coordinates. <Stars and bars> counts this intersection; the <inclusion-exclusion principle> then gives the displayed formula. A negative remaining sum contributes zero.