I have found a question for finding the Unitary operator for the following transformation:
I found the solution as well. But I didn't understand how they got the solution!
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityI have found a question for finding the Unitary operator for the following transformation:
I found the solution as well. But I didn't understand how they got the solution!
Firstly, how rude of them to use the word 'obviously' in their solution! If it was obvious then we wouldn't be trying their exercises in the first place!
But anyway, Adam Zalcman described the solution very elegantly and succinctly! But for those wanting a more in-depth explanation of his answer, here it is:
To understand the textbook solution a bit more, let's define an operator $U$ as "if I act $U$ on an input state $|i_k\rangle$, it produces the output state $|o_k\rangle$", or equivalently $$U|i_k\rangle = |o_k\rangle.$$ Let's now consider as set of orthogonal input states $|i_1\rangle, |i_2\rangle,...,|i_n\rangle$ with their corresponding output states $|o_1\rangle, |o_2\rangle,...,|o_n\rangle$. We can now define the operator $U$ explicitly as $$U=|o_1\rangle\langle i_1| + |o_2\rangle\langle i_2| + ... + |o_n\rangle\langle i_n|.$$ To see this with an example, let us compute $U|i_1\rangle$ which should give us $|o_1\rangle$: $$\begin{align} U|i_1\rangle &= \left(|o_1\rangle\langle i_1| + |o_2\rangle\langle i_2| + ... + |o_n\rangle\langle i_n|\right)|i_1\rangle\\ &=|o_1\rangle\underbrace{\langle i_1|i_1\rangle}_{= 1} + |o_2\rangle\underbrace{\langle i_2|i_1\rangle}_{= 0} + ... + |o_n\rangle\underbrace{\langle i_n|i_1\rangle}_{= 0} \\ &=|o_1\rangle. \end{align}$$ Because $|i_1\rangle$ is orthogonal to every term except the first one, all the terms except the first one go to 0 and we are conveniently left with the desired output state $|o_1\rangle$! This is not a coincidence since we have done this by construction. You can try this calculation with any input state $|i_k\rangle$ and you will see it will give you the desired output state $|o_k\rangle$. So going back to the specific case we are looking at, we have defined $U_H$ as $$U_H|0\rangle = \frac{1}{\sqrt{2}}\left(|0\rangle+|1\rangle\right) \\ U_H|1\rangle = \frac{1}{\sqrt{2}}\left(|0\rangle-|1\rangle\right)$$ So we can use the same formulation as above to get $$U_H = \frac{1}{\sqrt{2}}\left(|0\rangle+|1\rangle\right)\langle 0| + \frac{1}{\sqrt{2}}\left(|0\rangle-|1\rangle\right)\langle 1|$$ which gives us the first line of their solution. The second line of their solution comes from taking the equivalent definiton of $U_H$: $$U_H\frac{1}{\sqrt{2}}\left(|0\rangle+|1\rangle\right) = |0\rangle \\ U_H\frac{1}{\sqrt{2}}\left(|0\rangle-|1\rangle\right) = |1\rangle$$ and performing the same steps as above. (Note the last equivalent definition is specific to $U_H$ and doesn't apply to all operators $U$ because it just so happens that $U_H^{\dagger}=U_H$)
Another way to solution:
Hadamard gate changes $|0\rangle$ to $\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) = |+\rangle$ and $|1\rangle$ to $\frac{1}{\sqrt{2}}(|0\rangle - |1\rangle) = |-\rangle$.
In vector notatation $$ \begin{pmatrix} 1 \\ 0 \end{pmatrix} \rightarrow \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1 \end{pmatrix} $$ and $$ \begin{pmatrix} 0 \\ 1 \end{pmatrix} \rightarrow \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ -1 \end{pmatrix} $$
Now, put output vectors to matrix: $$ H= \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}. $$ Clearly $H|0\rangle = |+\rangle$ and $H|1\rangle = |-\rangle$, so $H$ is matrix representation of Hadamard gate.