<s>[INST] Simultaneous triangularization of matrices Let $\mathcal{F}=\{A_1,A_2,\ldots,A_r\}$ be a triangulable commuting family of $n\times n$ matrices (that is, each $A_i$ is triangulable and $A_iA_j=A_jA_i$ for every $i,j$). I know that $\mathcal{F}$ can be simultaneous triangularization, but what is the algorithm of finding the invertible matrix $P$ such that $P^{-1}A_iP$ is triangular? As a working example consider the matrices 
$$
A=
\begin{pmatrix}
-3 & 2 & -4 \\
-1 & 0 & -1\\
 2 & -2 & 3
\end{pmatrix}\qquad
B=
\begin{pmatrix}
3 & -2 & 2 \\
-1 & 2 & -1\\
-2 & 2 & -1
\end{pmatrix}\qquad
C=
\begin{pmatrix}
1 & 0 & 1 \\
1 & 0 & 1\\
0 & 0 & 0
\end{pmatrix}
$$
Here $AB=BA$, $AC=CA$ and $BC=CB$. In addition, the characteristic polynomials of these matrices are
$$
f_A(x)=x(x-1)(x+1)\\
f_B(x)=(x-2)(x-1)^2\\
f_C(x)=x^2(x-1)
$$
so each one of them is triangulable. Thanks! 
 [/INST] Here, it is easy. Since $A$ has $3$ distinct eigenvalues and $B,C$ commute with $A$, we can deduce that $B,C$ are polynomials in $A$ and it suffices to triangularize $A$.
In the general case.
Step 1. Find a common eigenvector of $A,B,C$.
Step 2. Proceed by recurrence.
Moreover, you can choose $P$ as an orthogonal matrix.
</s>