The random variable \( \mathbb{1}_A \) takes the value 1 if \( \omega \in A \) and 0 otherwise.
\(\mathbb{E}[\mathbb{1}_A] = P(A)\)
Indicator functions are very useful for computations as the next example will show.
Example 1.
Consider the hat problem we solved using the inclusion exclusion principle.
Let \( X \) be the random variable, the number of people who get back their own hat.
\( X = 1_{A_1} + 1_{A_2}+…+1_{A_n} \)
We can calculate the mean and variance of \(X\) using linearity of the expectation operator.
\begin{align}
\mathbb{E}[X] = \sum_i^n \mathbb{E}[1_{A_i}] = \sum_{i=1}^n P(A_i) = 1
\end{align}
\begin{align}
X^2 = \sum_i^n 1_{A_i}^2 + 2\sum_{i < j} 1_{A_i} 1_{A_j}
\end{align}
so that
\begin{align}
\mathbb{E}[X^2] &= \sum_i^n P(A_i) + 2\sum_{i < j} P(A_i \cap A_j) \\
&= 1 + 2 \frac{n (n-1)}{2} \frac{1}{n}\frac{1}{n-1} \\
&=2
\end{align}
so \(\text{Var}(X) = 1 \)