Success-count and waiting-time duality (source code)

= Success-count and waiting-time duality
{title2=$\{N>n\}=\{B_n<r\}$}

The same stopping rule connects a waiting count to a fixed-length count. Let $N=X+r$ be the trial number of the $r$th success, and let $B_n$ count successes in the first $n$ trials, so $B_n$ has a <binomial distribution>. For any nonnegative <integer> $n$,
$$
\{N>n\}=\{B_n<r\},\qquad
\mathbb P(N>n)=\sum_{k=0}^{\min(r-1,n)}\binom nk p^k(1-p)^{n-k}.
$$
The target is still unmet after $n$ trials exactly when fewer than $r$ successes have occurred. With $r=2$, $p=1/2$ and $n=4$, this gives $\mathbb P(N>4)=(1+4)/16=5/16$; equivalently, $\mathbb P(X\leq2)=1-5/16=11/16$, matching $1/4+1/4+3/16$. At $p=1$, the <event> identity still holds, with $N=r$ and $B_n=n$ deterministically.