TITLE: Approximating commuting matrices by commuting diagonalizable matrices
QUESTION [20 upvotes]: Suppose the matrices $A$ and $B$ commute. Do there exists sequences $A_n$ and $B_n$ of matrices such that

$A_n \rightarrow A$, $B_n \rightarrow B$. 
Each $A_n$ is diagonalizable  and the same for each $B_n$. 
For every $n$, $A_n$ commutes with $B_n$. 

Moreover, it would be nice if the following property was additionally satisfied: if $A,B$ are real, then $A_n,B_n$ can be chosen to be real as well. 
P.S. I asked this question on math.SE a couple of days ago.

REPLY [13 votes]: This result was first proved by Motzkin and Taussky (essentially in all characteristics) depending upon how you state the result:  the set of pairs of n x n matrices (A,B) where
AB = BA and A and B have distinct eigenvalues is Zariski dense in the set of commuting pairs of matrices (which is equivalent to the irreducibility of the commuting variety; both results are in Motzkin-Taussky).  The reference is:  Pairs of matrices with property L. II, Trans. AMS 80 (1955), 387-401.   A trivial consequence of this is that any pair of commuting n x n matrices generates an algebra of dimension at most n.  Gerstenhaber proved a slightly stronger result: any pair of commuting n x n matrices is contained in a commutative n-dimensional subalgebra. See Guralnick, LAMA 31 (1992), 71-75 for a slightly easier proof and also some remarks on commuting 3-tuples (this variety is reducible for n at least 28, irreducible for n at most 10).   So one cannot in general approximate 3 commuting matrices by commuting semismple matrices.   See also Guralnick-Sethuram (Commuting pairs and triples of matrices and related varieties. Linear Algebra Appl. 310 (2000),  139–148) showing that Gerstenhaber's stronger result also follows easily from Motzkin-Taussky.