[proofplan]
Write each summand as an [indicator random variable](/page/Indicator%20Random%20Variable) $X_i=\mathbb{1}_{A_i}$. We expand $\operatorname{Var}(N)$ directly from the second-moment formula for variance, separating diagonal terms from off-diagonal terms. The diagonal terms are the variances of the individual indicators, and the off-diagonal terms are their covariances. Pairwise independence makes every off-diagonal covariance vanish.
[/proofplan]
custom_env
admin
[step:Introduce the indicator summands and their probabilities]
For each $i\in\{1,\ldots,n\}$, define the real-valued [random variable](/page/Random%20Variable)
\begin{align*}
X_i:\Omega\to\mathbb R,\qquad X_i(\omega)=\mathbb{1}_{A_i}(\omega).
\end{align*}
Then $N=\sum_{i=1}^{n}X_i$. Define $p_i:=\mathbb{P}(A_i)$ for each $i\in\{1,\ldots,n\}$. Since each $X_i$ takes values in $\{0,1\}$, the random variable $N$ is bounded by $n$, so $N$ and $N^2$ are integrable. Hence the variance is well-defined. The second-moment formula for variance gives
\begin{align*}
\operatorname{Var}(N)=\mathbb{E}[N^2]-(\mathbb{E}[N])^2.
\end{align*}
[/step]
custom_env
admin
[step:Expand the variance into diagonal and off-diagonal contributions]By the algebraic square formula for a finite sum,
\begin{align*}
N^2=\left(\sum_{i=1}^{n}X_i\right)^2=\sum_{i=1}^{n}X_i^2+2\sum_{1\le i<j\le n}X_iX_j.
\end{align*}
Using finite linearity of expectation,
\begin{align*}
\mathbb{E}[N^2]=\sum_{i=1}^{n}\mathbb{E}[X_i^2]+2\sum_{1\le i<j\le n}\mathbb{E}[X_iX_j].
\end{align*}
Also,
\begin{align*}
\mathbb{E}[N]=\sum_{i=1}^{n}\mathbb{E}[X_i],
\end{align*}
so another application of the finite square formula gives
\begin{align*}
(\mathbb{E}[N])^2=\sum_{i=1}^{n}(\mathbb{E}[X_i])^2+2\sum_{1\le i<j\le n}\mathbb{E}[X_i]\mathbb{E}[X_j].
\end{align*}
Subtracting the last display from the previous expression for $\mathbb{E}[N^2]$ yields
\begin{align*}
\operatorname{Var}(N)=\sum_{i=1}^{n}\left(\mathbb{E}[X_i^2]-(\mathbb{E}[X_i])^2\right)+2\sum_{1\le i<j\le n}\left(\mathbb{E}[X_iX_j]-\mathbb{E}[X_i]\mathbb{E}[X_j]\right).
\end{align*}[/step]
custom_env
admin
[guided]The goal is to separate the contribution of each individual event from the contribution of each pair of events. Since $N$ is a finite sum, this can be done by expanding the second moment directly.
For every $\omega\in\Omega$,
\begin{align*}
N(\omega)=\sum_{i=1}^{n}X_i(\omega).
\end{align*}
Squaring this finite sum gives a diagonal part, where the same index is chosen twice, and an off-diagonal part, where two distinct indices are chosen:
\begin{align*}
N^2=\sum_{i=1}^{n}X_i^2+2\sum_{1\le i<j\le n}X_iX_j.
\end{align*}
The factor $2$ appears because the terms $X_iX_j$ and $X_jX_i$ are equal and both occur in the full double sum when $i\ne j$.
Each random variable in this display is bounded, hence integrable. Finite linearity of expectation therefore gives
\begin{align*}
\mathbb{E}[N^2]=\sum_{i=1}^{n}\mathbb{E}[X_i^2]+2\sum_{1\le i<j\le n}\mathbb{E}[X_iX_j].
\end{align*}
Similarly,
\begin{align*}
\mathbb{E}[N]=\sum_{i=1}^{n}\mathbb{E}[X_i].
\end{align*}
Now square this deterministic real number. The same finite square formula gives
\begin{align*}
(\mathbb{E}[N])^2=\sum_{i=1}^{n}(\mathbb{E}[X_i])^2+2\sum_{1\le i<j\le n}\mathbb{E}[X_i]\mathbb{E}[X_j].
\end{align*}
Finally use the definition of variance:
\begin{align*}
\operatorname{Var}(N)=\mathbb{E}[N^2]-(\mathbb{E}[N])^2.
\end{align*}
Substituting the two expanded expressions and collecting diagonal and off-diagonal terms gives
\begin{align*}
\operatorname{Var}(N)=\sum_{i=1}^{n}\left(\mathbb{E}[X_i^2]-(\mathbb{E}[X_i])^2\right)+2\sum_{1\le i<j\le n}\left(\mathbb{E}[X_iX_j]-\mathbb{E}[X_i]\mathbb{E}[X_j]\right).
\end{align*}
This is the finite covariance expansion specialized to the random variables $X_1,\ldots,X_n$, obtained here directly from the definition of variance.[/guided]
custom_env
admin
[step:Evaluate the diagonal terms using the moments of an indicator]
For each $i\in\{1,\ldots,n\}$, the identity $X_i^2=X_i$ holds pointwise because $X_i$ takes only the values $0$ and $1$. By [citetheorem:10143] applied to the event $A_i$,
\begin{align*}
\mathbb{E}[X_i]=p_i
\end{align*}
and
\begin{align*}
\mathbb{E}[X_i^2]=p_i.
\end{align*}
Therefore,
\begin{align*}
\mathbb{E}[X_i^2]-(\mathbb{E}[X_i])^2=p_i-p_i^2=p_i(1-p_i)=\mathbb{P}(A_i)(1-\mathbb{P}(A_i)).
\end{align*}
[/step]
custom_env
admin
[step:Evaluate the off-diagonal terms using intersections]
Fix indices $i,j\in\{1,\ldots,n\}$ with $i<j$. Since products of indicators are indicators of intersections,
\begin{align*}
X_iX_j=\mathbb{1}_{A_i}\mathbb{1}_{A_j}=\mathbb{1}_{A_i\cap A_j}.
\end{align*}
Equivalently, this is the intersection identity from [citetheorem:10141]. Applying [citetheorem:10139] to the event $A_i\cap A_j\in\mathcal F$ gives
\begin{align*}
\mathbb{E}[X_iX_j]=\mathbb{P}(A_i\cap A_j).
\end{align*}
Together with $\mathbb{E}[X_i]=\mathbb{P}(A_i)$ and $\mathbb{E}[X_j]=\mathbb{P}(A_j)$ from [citetheorem:10143], this gives
\begin{align*}
\mathbb{E}[X_iX_j]-\mathbb{E}[X_i]\mathbb{E}[X_j]=\mathbb{P}(A_i\cap A_j)-\mathbb{P}(A_i)\mathbb{P}(A_j).
\end{align*}
[/step]
custom_env
admin
[step:Substitute the evaluated terms and handle pairwise independence]
Substituting the diagonal and off-diagonal evaluations into the variance expansion gives
\begin{align*}
\operatorname{Var}(N)=\sum_{i=1}^{n}\mathbb{P}(A_i)(1-\mathbb{P}(A_i))+2\sum_{1\le i<j\le n}\left(\mathbb{P}(A_i\cap A_j)-\mathbb{P}(A_i)\mathbb{P}(A_j)\right).
\end{align*}
If $A_1,\ldots,A_n$ are pairwise independent, then for every pair $i,j\in\{1,\ldots,n\}$ with $i<j$,
\begin{align*}
\mathbb{P}(A_i\cap A_j)=\mathbb{P}(A_i)\mathbb{P}(A_j).
\end{align*}
Thus every off-diagonal summand is equal to $0$, and the formula reduces to
\begin{align*}
\operatorname{Var}(N)=\sum_{i=1}^{n}\mathbb{P}(A_i)(1-\mathbb{P}(A_i)).
\end{align*}
This is the claimed specialization under pairwise independence.
[/step]