New representation of density matrix in terms of cartesian basis matrices and their application in the study of symmetric gates