Permutation matrix

In mathematics, particularly in matrix theory, a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column with all other entries 0. An $n × n$ permutation matrix can represent a permutation of $n$ elements. Pre-multiplying an $n$-row matrix $M$ by a permutation matrix $P$, forming $PM$, results in permuting the rows of $M$, while post-multiplying an $n$-column matrix $M$, forming $MP$, permutes the columns of $M$.

Every permutation matrix P is orthogonal, with its inverse equal to its transpose: $$P^{-1}=P^\mathsf{T}$$. Indeed, permutation matrices can be characterized as the orthogonal matrices whose entries are all non-negative.

The two permutation/matrix correspondences
There are two natural one-to-one correspondences between permutations and permutation matrices, one of which works along the rows of the matrix, the other along its columns. Here is an example, starting with a permutation $\pi$ in two-line form at the upper left:
 * $$\begin{matrix}

\pi\colon\begin{pmatrix}1&2&3&4\\3&2&4&1\end{pmatrix} & \longleftrightarrow & R_\pi\colon\begin{pmatrix} 0&0&1&0\\ 0&1&0&0\\ 0&0&0&1\\ 1&0&0&0\end{pmatrix}\\[5pt] \Big\updownarrow && \Big\updownarrow\\[5pt] C_\pi\colon\begin{pmatrix} 0&0&0&1\\ 0&1&0&0\\ 1&0&0&0\\ 0&0&1&0\end{pmatrix} & \longleftrightarrow & \pi^{-1}\colon\begin{pmatrix}1&2&3&4\\4&2&1&3\end{pmatrix}\end{matrix}$$ The row-based correspondence takes the permutation π to the matrix $$R_\pi$$ at the upper right. The first row of $$R_\pi$$ has its 1 in the third column because $$\pi(1)=3$$. More generally, we have $$R_\pi=(r_{ij})$$ where $$r_{ij}=1$$ when $$j=\pi(i)$$ and $$r_{ij}=0$$ otherwise.

The column-based correspondence takes π to the matrix $$C_\pi$$ at the lower left. The first column of $$C_\pi$$ has its 1 in the third row because $$\pi(1)=3$$. More generally, we have $$C_\pi=(c_{ij})$$ where $$c_{ij}$$ is 1 when $$i=\pi(j)$$ and 0 otherwise. Since the two recipes differ only by swapping i with j, the matrix $$C_\pi$$ is the transpose of $$R_\pi$$; and, since $$R_\pi$$ is a permutation matrix, we have $$C_\pi=R_\pi^\mathsf{T}=R_\pi^{-1}$$. Tracing the other two sides of the big square, we have $$R_{\pi^{-1}}=C_\pi=R_\pi^{-1}$$ and $$C_{\pi^{-1}}=R_\pi$$.

Permutation matrices permute rows or columns
Multiplying a matrix M by either $$R_\pi$$ or $$C_\pi$$ on either the left or the right will permute either the rows or columns of M by either π or π−1. The details are a bit tricky.

To begin with, when we permute the entries of a vector $$(v_1,\ldots,v_n)$$ by some permutation π, we move the $$i^\text{th}$$ entry $$v_i$$ of the input vector into the $$\pi(i)^\text{th}$$ slot of the output vector. Which entry then ends up in, say, the first slot of the output? Answer: The entry $$v_j$$ for which $$\pi(j)=1$$, and hence $$j=\pi^{-1}(1)$$. Arguing similarly about each of the slots, we find that the output vector is
 * $$ \big(v_{\pi^{-1}(1)},v_{\pi^{-1}(2)},\ldots,v_{\pi^{-1}(n)}\big),$$

even though we are permuting by $$\pi$$, not by $$\pi^{-1}$$. Thus, in order to permute the entries by $$\pi$$, we must permute the indices by $$\pi^{-1}$$. (Permuting the entries by $$\pi$$ is sometimes called taking the alibi viewpoint, while permuting the indices by $$\pi$$ would take the alias viewpoint. )

Now, suppose that we pre-multiply some n-row matrix $$M=(m_{i,j})$$ by the permutation matrix $$C_\pi$$. By the rule for matrix multiplication, the $$(i,j)^\text{th}$$ entry in the product $$C_\pi M$$ is
 * $$\sum_{k=1}^n c_{i,k}m_{k,j},$$

where $$c_{i,k}$$ is 0 except when $$i=\pi(k)$$, when it is 1. Thus, the only term in the sum that survives is the term in which $$k=\pi^{-1}(i)$$, and the sum reduces to $$m_{\pi^{-1}(i),j}$$. Since we have permuted the row index by $$\pi^{-1}$$, we have permuted the rows of M themselves by π. A similar argument shows that post-multiplying an n-column matrix M by $$R_\pi$$ permutes its columns by π.

The other two options are pre-multiplying by $$R_\pi$$ or post-multiplying by $$C_\pi$$, and they permute the rows or columns respectively by π−1, instead of by π.

The transpose is also the inverse
A related argument proves that, as we claimed above, the transpose of any permutation matrix P also acts as its inverse, which implies that P is invertible. (Artin leaves that proof as an exercise, which we here solve.)  If $$P=(p_{i,j})$$, then the $$(i,j)^\text{th}$$ entry of its transpose $$P^\mathsf{T}$$ is $$p_{j,i}$$. The $$(i,j)^\text{th}$$ entry of the product $$PP^\mathsf{T}$$ is then
 * $$\sum_{k=1}^n p_{i,k}p_{j,k}.$$

Whenever $$i\ne j$$, the $$k^\text{th}$$ term in this sum is the product of two different entries in the $$k^\text{th}$$ column of P; so all terms are 0, and the sum is 0. When $$i=j$$, we are summing the squares of the entries in the $$i^\text{th}$$ row of P, so the sum is 1. The product $$PP^\mathsf{T}$$ is thus the identity matrix. A symmetric argument shows the same for $$P^\mathsf{T}P$$, implying that P is invertible with $$P^{-1}=P^\mathsf{T}$$.

Multiplying permutation matrices
Given two permutations of $n$ elements $\sigma$ and 𝜏, the product of the corresponding column-based permutation matrices $C_{σ}$ and $C_{τ}$ is given, as you might expect, by $$C_{\sigma} C_{\tau} = C_{\sigma\,\circ\,\tau}, $$ where the composed permutation $$\sigma\circ\tau$$ applies first 𝜏 and then 𝜎, working from right to left: $$(\sigma\circ\tau) (k) = \sigma \left(\tau (k) \right).$$ This follows because pre-multiplying some matrix by $C_{τ}$ and then pre-multiplying the resulting product by $C_{σ}$ gives the same result as pre-multiplying just once by the combined $$C_{\sigma\,\circ\,\tau}$$.

For the row-based matrices, there is a twist: The product of $R_{σ}$ and $R_{τ}$ is given by
 * $$R_{\sigma} R_{\tau} = R_{\tau\,\circ\,\sigma}, $$

with 𝜎 applied before 𝜏 in the composed permutation. This happens because we must post-multiply to avoid inversions under the row-based option, so we would post-multiply first by $R_{σ}$ and then by $R_{τ}$.

Some people, when applying a function to an argument, write the function after the argument (postfix notation), rather than before it. When doing linear algebra, they work with linear spaces of row vectors, and they apply a linear map to an argument by using the map's matrix to post-multiply the argument's row vector. They often use a left-to-right composition operator, which we here denote using a semicolon; so the composition $$ \sigma\,;\,\tau$$ is defined either by
 * $$(\sigma\,;\,\tau)(k) = \tau\left(\sigma(k)\right),$$

or, more elegantly, by
 * $$(k)(\sigma\,;\,\tau) = \left((k)\sigma \right)\tau,$$

with 𝜎 applied first. That notation gives us a simpler rule for multiplying row-based permutation matrices:
 * $$R_{\sigma} R_{\tau} = R_{\sigma\,;\,\tau}. $$

Matrix group
When π is the identity permutation, which has $$\pi(i)=i$$ for all i, both $C_{\pi}$ and $R_{\pi}$ are the identity matrix.

There are $n!$ permutation matrices, since there are $n!$ permutations and the map $$C\colon\pi\mapsto C_\pi$$ is a one-to-one correspondence between permutations and permutation matrices. (The map $$R$$ is another such correspondence.) By the formulas above, those $n × n$ permutation matrices form a group of order $n!$ under matrix multiplication, with the identity matrix as its identity element, a group that we denote $$\mathcal{P}_n$$. The group $$\mathcal{P}_n$$ is a subgroup of the general linear group $$GL_n(\mathbb{R})$$ of invertible $n × n$ matrices of real numbers. Indeed, for any field F, the group $$\mathcal{P}_n$$ is also a subgroup of the group $$GL_n(F)$$, where the matrix entries belong to F. (Every field contains 0 and 1 with $$0+0=0,$$ $$0+1=1,$$ $$0*0=0,$$ $$0*1=0,$$ and $$1*1=1;$$ and that's all we need to multiply permutation matrices. Different fields disagree about whether $$1+1=0$$, but that sum doesn't arise.)

Let $$S_n^\leftarrow$$ denote the symmetric group, or group of permutations, on {1,2,...,$n$} where the group operation is the standard, right-to-left composition "$$\circ$$"; and let $$S_n^\rightarrow$$ denote the opposite group, which uses the left-to-right composition "$$\,;\,$$". The map $$C\colon S_n^\leftarrow\to GL_n(\mathbb{R})$$ that takes π to its column-based matrix $$C_\pi$$ is a faithful representation, and similarly for the map $$R\colon S_n^\rightarrow\to GL_n(\mathbb{R})$$ that takes π to $$R_\pi$$.

Doubly stochastic matrices
Every permutation matrix is doubly stochastic. The set of all doubly stochastic matrices is called the Birkhoff polytope, and the permutation matrices play a special role in that polytope. The Birkhoff–von Neumann theorem says that every doubly stochastic real matrix is a convex combination of permutation matrices of the same order, with the permutation matrices being precisely the extreme points (the vertices) of the Birkhoff polytope. The Birkhoff polytope is thus the convex hull of the permutation matrices.

Linear-algebraic properties
Just as each permutation is associated with two permutation matrices, each permutation matrix is associated with two permutations, as we can see by relabeling the example in the big square above starting with the matrix P at the upper right:
 * $$\begin{matrix}

\rho_P\colon\begin{pmatrix}1&2&3&4\\3&2&4&1\end{pmatrix} & \longleftrightarrow & P\colon\begin{pmatrix} 0&0&1&0\\ 0&1&0&0\\ 0&0&0&1\\ 1&0&0&0\end{pmatrix}\\[5pt] \Big\updownarrow && \Big\updownarrow\\[5pt] P^{-1}\colon\begin{pmatrix} 0&0&0&1\\ 0&1&0&0\\ 1&0&0&0\\ 0&0&1&0\end{pmatrix} & \longleftrightarrow & \kappa_P\colon\begin{pmatrix}1&2&3&4\\4&2&1&3\end{pmatrix}\end{matrix}$$ So we are here denoting the inverse of C as $$\kappa$$ and the inverse of R as $$\rho$$. We can then compute the linear-algebraic properties of P from some combinatorial properties that are shared by the two permutations $$\kappa_P$$ and $$\rho_P=\kappa_P^{-1}$$.

A point is fixed by $$\kappa_P$$ just when it is fixed by $$\rho_P$$, and the trace of P is the number of such shared fixed points. If the integer k is one of them, then the standard basis vector $e_{k}$ is an eigenvector of P.

To calculate the complex eigenvalues of P, write the permutation $$\kappa_P$$ as a composition of disjoint cycles, say $$\kappa_P= c_{1}c_{2} \cdots c_{t}$$. (Permutations of disjoint subsets commute, so it doesn't matter here whether we are composing right-to-left or left-to-right.) For $$1 \le i \le t$$, let the length of the cycle $$c_i$$ be $$\ell_i$$, and let $$L_{i}$$ be the set of complex solutions of $$x^{\ell_{i}}=1$$, those solutions being the $$\ell_i^{\,\text{th}}$$ roots of unity. The multiset union of the $$L_{i}$$ is then the multiset of eigenvalues of P. Since writing $$\rho_P$$ as a product of cycles would give the same number of cycles of the same lengths, analyzing $$\rho_p$$ would give the same result. The multiplicity of any eigenvalue v is the number of i for which $$L_i$$ contains v. (Since any permutation matrix is normal and any normal matrix is diagonalizable over the complex numbers, the algebraic and geometric multiplicities of an eigenvalue v are the same.) From group theory we know that any permutation may be written as a composition of transpositions. Therefore, any permutation matrix factors as a product of row-switching elementary matrices, each of which has determinant &minus;1. Thus, the determinant of the permutation matrix P is the sign of the permutation $$\kappa_P$$, which is also the sign of $$\rho_P$$.

Restricted forms

 * Costas array, a permutation matrix in which the displacement vectors between the entries are all distinct
 * n-queens puzzle, a permutation matrix in which there is at most one entry in each diagonal and antidiagonal