Fixed points of permutation groups I was studying permutation groups and I founs this question-

Let $S_n$ be the group of all permutations of the set $X=\{1,2,\dots,n\}$. Given a permutation $\sigma\in S_n$, let $f(\sigma)$ denote the number of fixed points of $\sigma$.
a. Show that the average number of fixed points is $1$, i.e.,
$$\frac 1{|S_n|}\sum_{\sigma\in S_n}f(\sigma)=1$$
b. Find the average value of $f(\sigma)^2$.

All that comes to my mind is to use Inclusion Exclusion Principle to calculate the number of combinations for a given value of $f(\sigma)$. That is, explicitly calculate the number of permutations of $X$ with exactly $r$ fixed points, denoted by $S_n(r)$. But, that is not a very easy task since we are doing it for a general $n$ which means $S_n(r)$ will be in the form of a summation, all of which needs to be summed again over all $r$. Also, this approach is not quite elegant. It becomes a real headache however in b since there you need to take a square as well. Also, we are never really using any property of permutation groups while solving this problem.
Is there any other approach that can make life easier?
While it is suggested in the comments and in an answer to use expectations of random variables, I don't think that is what the question asks of me considering the fact that the course in which I got the problem (it's a group theory course by the way) is far away from that. Is there any other ways to go about it?
 A: As in many cases where a random variable is equal to the number of occurrences of several events, a fruitful technique is to write that random variable as a sum of indicator random variables.
Let $X_i$ be a random variable which is $1$ if $\sigma(i)=i$, and $0$ otherwise. Letting $X=X_1+\dots+X_n$, this means that $f(\sigma)=X$. It follows that
$$
E[f(\sigma)]=E[X]=E[X_1]+\dots+E[X_n]=nE[X_1],
$$
$$
E[f(\sigma)^2]=E[(X_1+\dots+X_n)^2]\stackrel{*}=nE[X_1^2]+n(n-1)E[X_1X_2]
$$
In $\stackrel{*}=$, I expanded out $(X_1+\dots+X_n)^2$, distributed the $E[]$, and then collected identically distributed terms.
All that remains is to compute $E[X_1]$, $E[X_1^2]$, and $E[X_1X_2]$. These random variables only take the values $0$ and $1$, so computing their expectations involves computing a certain probability. I leave the rest to you.
A: Let $G$ be a group, $X$ a set, and:
\begin{alignat}{1}
G\times X&\longrightarrow& X \\
(g,x)&\longmapsto& gx \\
\tag 1
\end{alignat}
a $G$-action on $X$. Then:
Claim. For $X_i=X$ $(i=1,\dots,k)$, $\Pi X:=\prod_{i=1}^kX_i$, and $\bar x:=(x_1,\dots,x_k)\in\Pi X$, the map:
\begin{alignat}{2}
G\times\Pi X&\longrightarrow &&\space\Pi X \\
(g,\bar x)&\longmapsto &&\space g\star \bar x:=(gx_1,\dots,gx_k) \\
\tag 2
\end{alignat}
is a $G$-action on $\Pi X$.
Proof. We have to confirm that the map "$\star$" fulfils the two properties for a group action. In fact:

*

*\begin{alignat}{1}
e\star\bar x &= (ex_1,\dots,ex_k) \\
&= (x_1,\dots,x_k) \\
&= \bar x
\end{alignat}
$\forall\bar x\in \Pi X$;

*\begin{alignat}{1}
g\star(h\star\bar x) &= g\star(hx_1,\dots,hx_k) \\
&= (g(hx_1),\dots,g(hx_k)) \\
&= ((gh)x_1,\dots,(gh)x_k) \\
&=(gh)\star\bar x \\
\end{alignat}
$\forall g,h\in G, \forall\bar x\in \Pi X$. $\space\space\space\Box$
The pointwise stabilizer for the action "$\star$" reads:
\begin{alignat}{1}
\operatorname{Stab}_\star(\bar x) &= \{g\in G\mid g\star\bar x=\bar x\} \\
&= \{g\in G\mid (gx_1=x_1)\wedge\dots\wedge(gx_k=x_k)\} \\
&=\bigcap_{i=1}^k\operatorname{Stab}(x_i) \\
\tag 3
\end{alignat}
Furthermore:
\begin{alignat}{1}
\operatorname{Fix}_\star(g) &= \{\bar x\in \Pi X\mid g\star\bar x=\bar x\} \\
&= \{\bar x\in \Pi X\mid (gx_1=x_1)\wedge\dots\wedge(gx_k=x_k)\} \\
\tag 4
\end{alignat}
whence $\bar x\in \operatorname{Fix}_\star(g)\iff x_i\in\operatorname{Fix}(g), i=1,\dots,k$. So, every $k$-tuple ($=$ ordered arrangement of $k$ elements of a set, where repetition is allowed) of elements of $\operatorname{Fix}(g)$ gives rise to a $\bar x\in \operatorname{Fix}_\star(g)$, and viceversa. Thus, for finite $X$:
$$\left|\operatorname{Fix}_\star(g)\right|=\left|\operatorname{Fix}(g)\right|^k \tag 5$$
(see this Wiki page, section "Permutations with repetition").
For your case b, take $G=S_n$, $X=\{1,\dots,n\}$ and $k=2$. By $(3)$, $\operatorname{Stab}_\star((i,j))=\operatorname{Stab}(i)\cap\operatorname{Stab}(j)$, whence $\left|\operatorname{Stab}_\star((i,j))\right|=(n-1)!$ for $j=i$, and $\left|\operatorname{Stab}_\star((i,j))\right|=(n-2)!$ for $j\ne i$. Therefore, there must be precisely two orbits for the action "$\star$"$^\dagger$. Now, by applying Burnside's Lemma to the action "$\star$":
$$\frac{1}{|S_n|}\sum_{\sigma\in S_n}\left|\operatorname{Fix}_\star(\sigma)\right|=2 \tag 6$$
and finally, by recalling $(5)$:
$$\frac{1}{|S_n|}\sum_{\sigma\in S_n}\left|\operatorname{Fix}(\sigma)\right|^2=2 \tag 7$$
which is your point b. (Your point a is the same result applied to the transitive action on one single copy of $X$.)

$^\dagger$In fact, by the Orbit-Stabilizer Theorem, $\left|\operatorname{Stab}_\star((i,j))\right|=(n-1)!$ implies $\left|O_\star((i,j))\right|=n$, and $\left|\operatorname{Stab}_\star((i,j))\right|=(n-2)!$ implies $\left|O_\star((i,j))\right|=n(n-1)$. But the set of orbits is a partition of the acted on set, whose size is $n^2$, whence $kn+ln(n-1)=n^2$ or, equivalently, $k+l(n-1)=n$. For $n=2$, this yields $k+l=2$; for $n>2$, $l=\frac{n-k}{n-1}$ integer implies $k=1$, which in turn implies $l=1$, and then again $k+l=2$. So, the action "$\star$" has two orbits for every $n\ge 2$.
A: Here's a linear algebra based proof.  It uses Kronecker Products (denoted $\otimes$) and has a hint of representation theory but really doesn't require any knowledge other than basic group theory and somewhat sophisticated linear algebra.
notation: $P_g$ for $g\in S_n$ denotes the standard ($n\times n$) permutation matrix representation for some permutation $g$.
Part 1: Idempotence
$Z := \Big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}P_g\otimes P_g\Big)$
Then $Z$ is idempotent.
Proof:
$Z^2 $
$=\Big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}P_g\otimes P_g\Big) \Big(\frac{1}{\vert S_n\vert}\sum_{g'\in S_n}P_{g'}\otimes P_{g'}\Big)$
$=\frac{1}{\vert S_n\vert^2}\sum_{g\in S_n}\Big(\big(P_g\otimes P_g\big) \sum_{g'\in S_n}P_{g'}\otimes P_{g'}\Big)$
$=\frac{1}{\vert S_n\vert^2}\sum_{g\in S_n}\Big( \sum_{g'\in S_n}(P_gP_{g'})\otimes (P_gP_{g'})\Big)$
$=\frac{1}{\vert S_n\vert^2}\sum_{g\in S_n}\Big( \sum_{g''\in S_n}(P_{g''})\otimes (P_{g''})\Big)$
$=\frac{1}{\vert S_n\vert^2}\sum_{g\in S_n}\Big( \vert S_n\vert\cdot Z\Big)$
$=Z$
so $Z$ has all eigenvalues $0$ or $1$ and
$\text{trace}\big(Z\big) = \frac{1}{\vert S_n\vert}\sum_{g\in S_n}\text{trace}\big(P_g\otimes P_g\big) = \frac{1}{\vert S_n\vert}\sum_{g\in S_n}\text{trace}\big(P_g\big)^2= \frac{1}{\vert S_n\vert}\sum_{g\in S_n}f\big(g\big)^2$
counts the number of eigenvalues equal to 1 for the matrix $Z$. We aim to show this $=2$. In particular since $Z$ is a sum of real non-negative matrices so it is real non-negative and we may use Perron-Frobenius Theory.
Part 2: Perron Roots / Orbits
Via examining the (matrix form of) $S_n$'s action on the standard basis vectors for the vector space $\mathbb R^{n\times n}$
Consider the ordered Set $M$, which contains the standard basis vectors for vector space $\mathbb R^{n\times n}$, with the first $n$ $m_i$ being the 'symmetric' ones (i.e. with trace 1).
Now consider how $S_n$ acts on $M$ by conjugation.  Again using our std permutation representation we have, for $X\in M$
$P_gX P_g^{-1} = P_g X P_g^T\in M$.
In particular the action by conjugation on $M$ is a linear transformation, so we may write
$\mathbf M =\bigg[\begin{array}{c|c|c|c|c}M_1 & M_2 \end{array}\bigg]$
where $M_1$ has the first $n$ vectors placed next to each other and $M_2$ has the others, observing the aforementioned ordering
for $g\in S_n$
$T_g\mathbf M = \mathbf MU_g$
where $U_g$ is the permutation matrix associated with $T_g$'s action on $\mathbf M$.  Focusing on the action of conjugation by elementary type 2 matrices, we can show that all vectors in $M_1$ are in the same conjugacy class (a single elementary type 2 action will do it) and all vectors in $M_2$ are in the same conjugacy class (composing conjugation by 2 elementary type 2 matrices will do it).
So $S_n$ acts transitively on $M_1$ and transitively on $M_2$, i.e.
$\frac{1}{\vert S_n\vert}\sum_{g\in S_n}T_g\mathbf M = \mathbf M \big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}U_g\big)=\begin{bmatrix}C_n & \mathbf 0 \\ 
\mathbf 0 & B_{n^2-n \times n^2-n}
\end{bmatrix}$
i.e. a block diagonal matrix with 2 blocks on the diagonal, each being a positive matrix. Perron-Frobenius theory tells us that the RHS has exactly 2 orthonormal Perron vectors, one for each communicating class, and since the RHS is a convex combination of doubly stochastic matrices, we know the RHS is doubly stochastic.  Hence $C_n\mathbf 1_n = 1 \cdot \mathbf 1_n$ and $B_{n^2-n \times n^2-n}\mathbf 1_{n^2-n}=1 \cdot \mathbf 1_{n^2-n}$.
Making use of the vec operator and Kronecker products, we can concretely close by exploiting the identity
$\text{vec}\big({ABC}\big) = \big( C^T \otimes A\big)\text{vec}\big( {B}\big)$.  I.e. by applying the vec operator to each $X\in M$ and arranging them in the same ordering as before -- calling this new basis $\mathbf M'$, we have
$T_g\mathbf M =\mathbf M U_g\iff  \big(P_g \otimes P_g\big)\mathbf M' =\mathbf M' U_g$
where $U_g$ is the same permutation matrix as before.  So, summing over the group and making use of the fact that $\mathbf M'$ is an invertible matrix we have
$(\mathbf M')^{-1}\big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}\big(P_g \otimes P_g\big)\Big)\mathbf M' = \big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}U_g\Big)=\begin{bmatrix}C_n & \mathbf 0 \\ 
\mathbf 0 & B_{n^2-n \times n^2-n}
\end{bmatrix}$
Thus the matrix $Z$ is similar to (i.e. the RHS) has exactly 2 eigenvalues equal to $1$, hence $Z$ has two eigenvalues equal to $1$ and all else are zero since it is idempotent.
$\implies \text{trace}\big(Z\big)=2$
which completes the proof of the second claim.
Note: the proof of the 1st claim mimics this but is much easier.  Just consider
$Z':= \Big(\frac{1}{\vert S_n\vert}\sum_{g\in S_n}P_g\Big)$
and
(i) show it is idempotent
(ii) show $Z$ is a positive matrix, and being doubly stochastic that means exactly one Perron root $= 1$. It isn't needed but if you like you can consider the way $S_n$ acts on the set of $n$ standard basis vectors and show one orbit.
A: Using combinatorial classes we have the following class $\mathcal{P}$  of
permutations with fixed points marked:
$$\def\textsc#1{\dosc#1\csod}
\def\dosc#1#2\csod{{\rm #1{\small #2}}}
\mathcal{P} = \textsc{SET}(
\mathcal{U} \times \textsc{CYC}_{=1}(\mathcal{Z}) +
\textsc{CYC}_{=2}(\mathcal{Z})  +
\textsc{CYC}_{=3}(\mathcal{Z})  + \cdots).$$
This gives the EGF
$$G(z, u) = \exp\left(uz+\frac{z^2}{2}
+ \frac{z^3}{3}
+ \frac{z^4}{4}
+ \cdots \right)
\\ = \exp\left(\log\frac{1}{1-z} + (u-1)z\right)
= \frac{1}{1-z} \exp\left((u-1)z\right)
\\ = \frac{1}{1-z} \exp\left(-z\right)
\exp\left(uz\right).$$
It follows that for $n\ge 1$ the expectation for the number of fixed points is
$$\mathrm{E}[X] =
\left. [z^n] \frac{\partial}{\partial u} G(z,u) \right|_{u=1}
\\ = [z^n] \frac{1}{1-z} \exp(-z) \exp(z) z
= [z^n] \frac{z}{1-z} = 1.$$
We also get with $n\ge 2$
$$\mathrm{E}[X(X-1)] =
\left. [z^n] 
\left(\frac{\partial}{\partial u}\right)^2 G(z,u) \right|_{u=1}
\\ = [z^n] \frac{1}{1-z} \exp(-z) \exp(z) z^2
= [z^n] \frac{z^2}{1-z} = 1.$$
We thus conclude that with $n\ge 2$
$$\mathrm{E}[X^2] = 2.$$
A: Let then $f(\sigma)$ be the number of fixed points of any permutation in $S_n$. For any $i \in\{1,2,\dots,n\}$ write $\delta_{i,\sigma}=1$ if $\sigma(i)=i$, $0$ otherwise. Then
$$
\sum_\sigma f(\sigma) = \sum_\sigma\sum_i \delta_{i,\sigma} = \sum_i\sum_\sigma \delta_{i,\sigma} = \sum_i (n-1)! =n(n-1)!=n!
$$
for the number of permutations with $\sigma(i)=i$  is just the number of permutations of the $n-1$ remaining elements. Now
$$
\sum_\sigma (f(\sigma))^2 = \sum_\sigma\big(\sum_i \delta_{i,\sigma}\big)^2 = \sum_\sigma \big(\sum_i \delta_{i,\sigma}\big)\big(\sum_j \delta_{j,\sigma}\big)\,.
$$
Note that $\delta_{i,\sigma}\delta_{i,\sigma}=\delta_{i,\sigma}$,  so
$$
\sum_\sigma (f(\sigma))^2 = \sum_\sigma\sum_i \delta_{i,\sigma} + \sum_\sigma \big(\sum_{i\ne j} \delta_{i,\sigma} \delta_{j,\sigma}\big) = n! +  \sum_{i\ne j} \big(\sum_\sigma \delta_{i,\sigma} \delta_{j,\sigma}\big)\,.
$$
As before, a permutation that fixes both $i$ and $j$ is just a permutation of the rest, counting $(n-2)!$. And the number of pairs $(i,j)$ with $i\ne j$ is clearly $n(n-1)$, so
$$
\sum_\sigma (f(\sigma))^2 = n! + \sum_{i\ne j}(n-2)! = n! + n(n-1)(n-2)! = 2\,n!\,.
$$
Summarizing, the average of $f(\sigma)$ is 1, and the average of $(f(\sigma))^2$ is 2.
