# Expressing operator in bra-ket notation, knowing just matrix elements

This is in context of unitary transformations between two othonormal bases $\{ | e_i \rangle\}$ and $\{ | \bar{e}_i \rangle\}$. I define $U$ by

$$U| e_i \rangle = | \bar{e}_i \rangle$$

Now I can write

$$U=U\cdot 1= \sum_i U | e_i \rangle \langle e_i | = \sum_i | \bar{e}_i \rangle \langle e_i |$$

I did not need to calculate the matrix elements, $U_{ij} = \langle e_i | \bar{e}_j \rangle$ in order to write this. But of course they complete define the matrix, so instead of knowing the action of $U$ on the basis, I should be able to reproduce the result $U =\sum_i | \bar{e}_i \rangle \langle e_i |$ with just knowledge of the matrix elements. But I'm stuck. All I can think of is writing

$$U = \sum_{i,j} U_{ij} | e_i \rangle \langle e_j |$$

But this gets me nowhere - I can't get rid of the dot product. I've tried inserting the completeness relation for either basis everywhere but I'm stuck. I have a feeling this is really simple but I just can't get it.

Is this what you want? $$U = \sum_{i,j} U_{ij} |{e_i}\rangle \langle e_j| = \sum_{i,j} |e_i\rangle U_{ij} \langle e_j| \\ = \sum_{i,j} |e_i\rangle \langle e_i|U|e_j\rangle \langle e_j| = \sum_{i,j} |e_i\rangle \langle e_i|\bar{e}_j\rangle \langle e_j| = \sum_j |\bar{e}_j \rangle \langle e_j|$$