Reordering diagonal blocks in real Schur form

The problem of reordering eigenvalues of a matrix in real Schur form arises in the computation of the invariant subspaces corresponding to a group of eigenvalues of the matrix. A basic step in such reordering is to swapp two neighboring 1 × 1 or 2 × 2 diagonal blocks by an orthogonal transformation. Swapping two 1×1 blocks or swapping 1×1 and 2×2 blocks are well understood [3]. Swapping two 2×2 blocks poses some numerical difficulties. Recently, Bai and Demmel [1] have proposed an algorithm for swapping two 2×2 blocks which is for all practical purposes backward stable. In this note we describe an alternative approach for swapping two 2×2 blocks which is based on an eigenvector calculation. It appears that the method guarantees small rounding errors in the (2,1) block of the transformed 4×4 matrix even if the two 2×2 blocks have almost the same eigenvalues.