# Does the matrix representation of a logic gate change according to the basis states?

To expand upon my question, allow me to introduce a problem that I'm attempting:

Suppose $$\lvert+\rangle = \frac{1}{\sqrt{2}}(\lvert0\rangle + \lvert1\rangle)$$ and $$\lvert-\rangle = \frac{1}{\sqrt{2}}(\lvert0\rangle - \lvert1\rangle)$$. Find the action of the CZ gate on the basis states $$\lvert+\rangle\lvert0\rangle$$, $$\lvert-\rangle\lvert0\rangle$$, $$\lvert+\rangle\lvert1\rangle$$, $$\lvert-\rangle\lvert1\rangle$$ and $$\lvert0\rangle\lvert+\rangle$$, $$\lvert0\rangle\lvert-\rangle$$, $$\lvert1\rangle\lvert+\rangle$$, $$\lvert1\rangle\lvert-\rangle$$.

For clarification:

$$\lvert0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \lvert1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$

In this question, I am asked to calculate the action of the CZ matrix on the different basis states. This is a straightforward task, but what I am confused about is the mathematical form of the CZ matrix/operator.

The CZ gate is defined to be a gate that applies the Z Pauli matrix on the target qubit when the control qubit is $$\lvert1\rangle$$. For the basis states $$\lvert00\rangle$$, $$\lvert01\rangle$$, $$\lvert10\rangle$$ and $$\lvert11\rangle$$, the CZ gate has the following matrix form:

$$CZ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{pmatrix} \tag{1}$$

As you can see from the question that I'm working on, the basis states are different. How am I supposed to tackle this question? I have two approaches in mind:

Approach 1: The definition of any logic gate is defined with respect to the basis states $$\lvert0\rangle$$ and $$\lvert1\rangle$$. Therefore, the matrix in equation 1 is still valid for my basis states and I should compute $$CZ\lvert+\rangle\lvert0\rangle$$, $$CZ\lvert-\rangle\lvert0\rangle$$, $$CZ\lvert+\rangle\lvert1\rangle$$, etc.

Approach 2: The definition of a logic gate changes according to the basis states. The matrix form in equation 1 is no longer valid. Instead, I should apply the Z Pauli matrix on the target qubits if the control qubit is $$\lvert1\rangle$$ i.e. I apply the Z Pauli matrix on the target qubits in $$\lvert1\rangle\lvert+\rangle$$ and $$\lvert1\rangle\lvert-\rangle$$ as they are the only basis states which have the control qubit $$\lvert1\rangle$$.

I am new to this topic, so if I have missed out anything important or not explained my point clearly, please comment below so I can update the question.

• to answer the question in the title: yes, of course it does. For example, any gate can be represented as a diagonal matrix with phases in its diagonal, in some basis (the basis of its eigenvectors). – glS Jan 18 at 13:13

Firstly calculate vector description of state $$|+0\rangle$$ in computational basis $$|+0\rangle = |+\rangle \otimes |0\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1 \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ 1 \\0 \end{pmatrix}$$ and now apply your CZ gate, i.e. $$CZ|+0\rangle$$. Similarly for other states.
Note that you can avoid using tensor product: $$|+0\rangle = \frac{1}{\sqrt{2}}(|0\rangle+|1\rangle)|0\rangle= \frac{1}{\sqrt{2}}(|00\rangle+|10\rangle) = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ 1 \\0 \end{pmatrix}$$