Stuck with I.8.2

Hi, I’m back again a bit deeper in the codebook.
I needed some time to get through 1.7 and get a feeling for the RX/RZ/RY gates but I got through them just now I’m feeling a bit stuck with 1.8.2

It looks like you need a H gate and transform the result with an RX gate for the final configuration, so my answer was qml.H(0) and qml.RX(np.pi/6). Where do I take the wrong turn?

For now, I kinda go with my gut feeling and a bit of research because I didn’t work with cos/sin for some time, so I’m not used to throwing them around anymore. Any suggestions how dissect such a problem more throughly to get consisten answers ?

Small questions to 1.8.1 I found the solution but I’m a bit unsure how the 5/4 gets resolved because after my idea it should still be 1/4 at the end of the transformation

Hey @Cap_Cap !

Regarding 1.8.2, the answer is much simpler! All you need is an RX gate with an angle of rotation of \pi / 3 :slight_smile:

R_x (\pi / 3) = \begin{pmatrix} \cos(\pi / 6) & -i\sin(\pi / 6) \\ -i\sin(\pi / 6) & \cos(\pi / 6) \end{pmatrix}
\begin{align*} R_x (\pi / 3) |0 \rangle &= \begin{pmatrix} \cos(\pi / 6) & -i\sin(\pi / 6) \\ -i\sin(\pi / 6) & \cos(\pi / 6) \end{pmatrix} \begin{pmatrix} 1 \\ 0\end{pmatrix} \\ &= \begin{pmatrix} \cos(\pi / 6) \\ -i\sin(\pi / 6) \end{pmatrix} \\ &= \begin{pmatrix} \sqrt{3} / 2 \\ -i/2 \end{pmatrix} \\ &= \frac{\sqrt{3}}{2} | 0 \rangle - \frac{i}{2} | 1 \rangle \end{align*}

For I.8.1, the hint says to look at just the amplitudes first (i.e., ignore the e^{i5\pi/4}). The amplitudes are 1/\sqrt{2} — an equal superposition! The Hadamard gate is the one to use here :slight_smile:. Then, to get e^{i5\pi/4} just on | 1 \rangle you can use an RZ gate with an angle of rotation of 5\pi/4. That’ll get you this:

\frac{1}{\sqrt{2}} \left( e^{-i5\pi/8} | 0 \rangle + e^{i5\pi/8} | 1 \rangle\right)

The problem says you only need to get the correct answer to a global phase. The above ends up being exactly that (up to a global phase of e^{-i5\pi/8}):

\frac{1}{\sqrt{2}} e^{-i5\pi/8} \left(| 0 \rangle + e^{i5\pi/4} | 1 \rangle\right)

Hope this helps!