Example 2.3 Find the number of permutations of $n(n \geqslant 4)$ distinct elements $a_{1}, a_{2}, \cdots, a_{n}$ such that $a_{1}$ and $a_{2}$ are not adjacent, and $a_{3}$ and $a_{4}$ are also not adjacent.
Solution: Let the required number be $N$. Let $S$ denote the set of all permutations of $a_{1}, a_{2}, \cdots, a_{n}$, then $|S|=n!$. Let $A, B$ denote the sets of permutations in $S$ where $a_{1}$ and $a_{2}$ are adjacent, and $a_{3}$ and $a_{4}$ are adjacent, respectively, then

and
$$
\begin{array}{c}
|A|=|B|=2 \cdot(n-1)!, \\
|A \cap B|=4 \cdot(n-2)!,
\end{array}
$$
$$
N=|S-A \cup B| \text {. }
$$

By Theorem 2.1, we get
$$
\begin{aligned}
N & =|S|-|A|-|B|+|A \cap B| \\
& =n!-2 \cdot(n-1)!-2(n-1)!+4 \cdot(n-2)! \\
& =\left(n^{2}-5 n+8\right)(n-2)!.
\end{aligned}
$$