Match win probability with a fixed winning score (source code)

= Match win probability with a fixed winning score

Suppose independent <Bernoulli trials> give a player a win with <probability> $p$, and the match ends when either player reaches $r$ wins. The player's match-win probability is
$$
\sum_{n=0}^{r-1}\binom{r+n-1}{r-1}p^r(1-p)^n.
$$
For a win with $n$ losses, the final trial must be a win. The preceding $r+n-1$ trials contain exactly $r-1$ wins and $n$ losses; the <binomial coefficient> counts their arrangements. Because $n<r$, the opponent cannot already have won, and because the player has only $r-1$ previous wins, the match has not ended earlier. Summing the disjoint terminal events gives the formula, a truncated <negative binomial distribution> sum. The constant game-win probability must describe independent games, or equivalently remain the same conditional on every previous history.