# How is transformation for measurement in an arbitrary basis derived?

I started with Qiskit today and find it very exciting. As a first question I want to understand how to measure an arbitrary state $$|\Psi\rangle$$ not in the basis of Z ($$|1\rangle$$, $$|0\rangle$$) but in the basis of Y ($$|R\rangle$$, $$|L\rangle$$).

Since measurements on qubits in Qiskit are carried out in the Z-basis (I would understand it in that way), I have to transform the state by a transformation

$$|\Psi'\rangle = U |\Psi\rangle$$

into a new state, on which the measurement is done in the Z-basis. U is to be determined. So I want a "mapping" from $$|R\rangle \rightarrow |0\rangle$$ and $$|L\rangle \rightarrow |1\rangle$$

The requirement on U is, therefore:

• the amplitude of $$|R\rangle$$ in $$|\Psi\rangle$$ equals to the amplitude of $$|0\rangle$$ in $$U|\Psi\rangle$$

• the amplitude of $$|L\rangle$$ in $$|\Psi\rangle$$ equals to the amplitude of $$|1\rangle$$ in $$U|\Psi\rangle$$

So I have

• $$\langle 0|U|\Psi\rangle = \langle R|\Psi\rangle$$
• $$\langle 1|U|\Psi\rangle = \langle L|\Psi\rangle$$

or

• $$U^\dagger|0\rangle = |R\rangle$$
• $$U^\dagger|1\rangle = |L\rangle$$

Therefore, the Z-base matrix-representation is

$$U^\dagger = \begin{pmatrix}1 & 1& \\ i &-i\end{pmatrix}$$

$$U = \begin{pmatrix} 1 & -i& \\ 1 &i\end{pmatrix}$$

This is a well known result: Actually, it can be written as

$$U = H S^\dagger$$

The circuit in Qiskit is as follows

and works as expected:

I think that's all right so far, but I dislike the my clumsy way of bringing up U. Is there a better, more direct approach? It has nothing to with Qiskit, but the way in general.

• For $\langle Y \rangle$ you should note that $(SH)Z(HS^\dagger) = Y$ $$\langle \psi |Y| \psi \rangle = \langle \psi | (SH)Z (HS^\dagger) | \psi \rangle = \langle \psi SH | Z | H S^\dagger \psi \rangle$$ So you want to apply $S^\dagger$ follow by the Hadamard gate $H$ before measurement in computational basis Oct 14 at 21:06
• This is much more elegant, but how should I see the identity Y = ... ? For me this identity is not very intuitive. Oct 15 at 12:44
• See Adam's answer. You should from there see that $\frac{1}{\sqrt2}\begin{bmatrix}1 & -i \\ 1 & i\end{bmatrix} = HS^\dagger$ Oct 15 at 15:58

Yes, there is a simple general formula for the unitary $$U$$ that maps orthonormal basis $$|u_1\rangle, |u_2\rangle, \dots, |u_n\rangle$$ to orthonormal basis $$|v_1\rangle, |v_2\rangle, \dots, |v_n\rangle$$
$$U = |v_1\rangle\langle u_1|+|v_2\rangle\langle u_2|+\dots+|v_n\rangle\langle u_n|=\sum_{i=1}^n|v_i\rangle\langle u_i|.$$
It is easy to check that $$U$$ is indeed unitary and that it maps $$|u_k\rangle$$ to $$|v_k\rangle$$ for each $$k=1,\dots,n$$.
For example, a $$U$$ transforming the $$Y$$ eigenbasis to $$Z$$ eigenbasis is
\begin{align} U &= |0\rangle\langle R| + |1\rangle\langle L| \\ &= \begin{bmatrix}1 \\ 0\end{bmatrix}\begin{bmatrix}\frac{1}{\sqrt2} & -\frac{i}{\sqrt2}\end{bmatrix} + \begin{bmatrix}0 \\ 1\end{bmatrix}\begin{bmatrix}\frac{1}{\sqrt2} & \frac{i}{\sqrt2}\end{bmatrix} \\ &= \frac{1}{\sqrt2}\begin{bmatrix}1 & -i \\ 1 & i\end{bmatrix} \end{align}