TITLE: LU decomposition; do permutation matrices commute?
QUESTION [14 upvotes]: I have an assignment for my Numerical Methods class to write a function that finds the PA=LU 
decomposition for a given matrix A and returns P, L, and U.
Nevermind the coding problems for a moment; there is a major mathematical problem I'm having that my professor seems incapable of addressing, and after searching for hours (perhaps inefficiently) I could find no accounting of it. How do we extricate the permutation matrices from the row elimination matrices?
Essentially the idea, if I understand it correctly, is that we perform a series of transformations on a matrix $A$ by applying successive lower triangular matrices that eliminate single elements, thus $L_nL_{n-1}...L_2L_1A = U$. In my understanding, this is computationally useful because lower triangular atomic matrices can be inverted by changing the sign of the off-diagonal element, so $A = L_1^{-1}L_2^{-1}...U$.
That's all fine (assuming I'm correct), but the introduction of pivot matrices between each $L_j$ seems to make the problem intractable. In every accounting I've seen some sorcery occurs that looks like this: 
$$L_nP_nL_{n-1}...P_3L_2P_2L_1P_1A = U \Rightarrow P_nP_{n-1}...P_2P_1L_nL_{n-1}...L_2L_1A = U$$ 
And no one bothers to explain how this happens or in fact even states it explicitly. 
If possible I would like to know
a) Is this operationally acceptable?  
b) What properties of these respective classes of matrices make this kind of willy-nilly commutation legal?  
c) Is my understanding of the method and its advantages accurate?

REPLY [2 votes]: $\require{color}$
I found @Calle explanation interesting but have a hard time following the arguments.
@kuzooroo explanation fits better my way of thinking but the arguments are too dense. I decided to start a new answer since my arguments will not fit in a comment slot.
Following @Calle:
Note that, since each $P_i$ is a one-cycle permutation
(one interchange), 
$P_i^{-1}=P_i$ since doing an interchange twice bring the matrix to the same original form. We now should prove
that $\Lambda$ is a lower triangular matrix with ones in
the diagonal.
$\Lambda_3$ is, of course, a lower triangular with 1 in the diagonal. To prove that $\Lambda_2$ is lower triangular
with ones in the diagonal we take into account the fact that $L_2$ is atomic. That is,
\begin{eqnarray*}
  L_2 = 
  \begin{pmatrix}
    1 & 0 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    0 & 1 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    \vdots & l_{32} & \ddots & \vdots & \vdots  &\vdots & \vdots & \vdots & \vdots\\
    \vdots & \vdots & \cdots & 1  & 0 &  \cdots &\cdots& \cdots & \vdots \\
    \vdots  & l_{i2} & \cdots & 0  & 1 & 0 &\cdots & \cdots & \vdots \\
    \vdots  & \vdots & \cdots & \vdots & \ddots &  \ddots & \ddots & \cdots & \vdots \\
    \vdots & l_{k2} & \vdots & \vdots & \vdots & 0 & 1  & 0 &  \vdots \\
    \vdots & \vdots & \vdots & \vdots & \vdots & \vdots &\ddots & \vdots &  0 \\
    0 &  0 & \cdots & 0 & \cdots & \cdots &\cdots & 0 &  1 
  \end{pmatrix} \nonumber.
\end{eqnarray*}
Let us assume that $P_3$ interchanges rows $i$ with $k$.
(note that both $i$ and $k$ are larger than 2).
We have that
\begin{eqnarray*}
  P_3 L_2 = 
  \begin{pmatrix}
    1 & 0 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    0 & 1 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    \vdots & l_{32} & \ddots & \vdots & \vdots  &\vdots & \vdots & \vdots & \vdots\\
    \vdots & \vdots & \cdots & 1  & 0 &  \cdots &\cdots& \cdots & \vdots \\
    \vdots & \boxed{l_{k2}} & \vdots & \vdots & \textcolor{green}{0} & 0 & \textcolor{blue}{1}  & 0 &  \vdots \\
    \vdots  & \vdots & \cdots & \vdots & \ddots &  \ddots & \ddots & \cdots & \vdots \\
    \vdots  & \boxed{l_{i2}} & \cdots & 0  & \textcolor{green}{1} & 0 & \textcolor{blue}{0} & \cdots & \vdots \\
    \vdots & \vdots & \vdots & \vdots & \vdots & \vdots &\ddots & \vdots &  0 \\
    0 &  0 & \cdots & 0 & \cdots & \cdots &\cdots & 0 &  1 
  \end{pmatrix} \nonumber.
\end{eqnarray*}
Finally $P_3 L_2 P_3^{-1}= P_3 L_2 P_3$ ineterchanges
columns $i$ (green) with $k$ (blue) on $P_3 L_2$. 
The $1$ in column $k$ (blue) takes the place of the 0 
in column $i$ (green) . In the same way the $1$ in green in row $k$ takes the position of the blue $0$ on the same row.
That is
\begin{eqnarray*}
  P_3 L_2 P_3^{-1} = 
  \begin{pmatrix}
    1 & 0 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    0 & 1 & \cdots & 0 & \cdots & \cdots &\cdots & \cdots & 0  \\
    \vdots & l_{32} & \ddots & \vdots & \vdots  &\vdots & \vdots & \vdots & \vdots\\
    \vdots & \vdots & \cdots & 1  & 0 &  \cdots &\cdots& \cdots & \vdots \\
    \vdots & \boxed{l_{k2}} & \vdots & \vdots & \textcolor{green}{1} & 0 & \textcolor{blue}{0}  & 0 &  \vdots \\
    \vdots  & \vdots & \cdots & \vdots & \ddots &  \ddots & \ddots & \cdots & \vdots \\
    \vdots  & \boxed{l_{i2}} & \cdots & 0  & \textcolor{green}{0} & 0 & \textcolor{blue}{1} & \cdots & \vdots \\
    \vdots & \vdots & \vdots & \vdots & \vdots & \vdots &\ddots & \vdots &  0 \\
    0 &  0 & \cdots & 0 & \cdots & \cdots &\cdots & 0 &  1 .
  \end{pmatrix} \nonumber.
\end{eqnarray*}e
This is, again, an atomic matrix with the entries
$l_{i2}$ and $l_{k2}$ interchanged.
In the same way, $P_2 L_1 P_2^{-1}$ is atomic and so it is
$\Lambda_1 =  P_3 P_2 L_1 P_2^{-1} P_3^{-1}$, 
In general for
\begin{eqnarray*}
  U= L_{n-1} P_{n-1} L_{n-2} P_{n-2} \cdots   P_2 L_1 P_1 A,
\end{eqnarray*}
we define
\begin{eqnarray*}
  \Lambda_i =     P_{n-1} \cdots P_{i+2} P_{i+1} L_i P_{i+1}^{-1} P_{i+2}^{-1} 
   \cdots P_{n-1}^{-1}.
\end{eqnarray*}
where we assume $P_0=I$.
The same procedure shown above guarantee that $\Lambda_i$
is atomic and so $\Lambda=\prod \Lambda_i$ is lower triangular with ones in the diagonal.
Hence this completes what is needed to verify that
$PA=LU$.