Quantum states are represented as vectors in a complex vector space. If a vector represents the status of a qubit, a mathematical mechanism is needed to represent the operations that change that status. Just as a function in classical programming might toggle a boolean value from True to False, quantum mechanics uses matrices for these operations.When an operation acts on a qubit, we represent this mathematically by multiplying the state vector by a matrix. However, not just any matrix will do. Quantum evolution must follow specific rules to ensure that the physics remains valid. The class of matrices that governs these valid operations is called unitary matrices.Preserving ProbabilityThe most important rule in quantum mechanics is that the total probability of all possible outcomes must always sum to exactly 1 (or 100%).Recall that the probability of measuring a specific state is related to the squared magnitude (or length) of the state vector. If we used a matrix that stretched the vector, the total probability would exceed 1. If we used a matrix that shrank the vector, the total probability would drop below 1.Therefore, valid quantum operators must be length-preserving. They can rotate the state vector anywhere within the Hilbert space, but they must never change its length. This is the geometric definition of a unitary matrix.{"layout": {"width": 600, "height": 450, "title": {"text": "Unitary Operations as Rotations"}, "xaxis": {"range": [-1.2, 1.2], "title": "Real Part", "zeroline": false}, "yaxis": {"range": [-1.2, 1.2], "title": "Imaginary Part", "zeroline": false}, "shapes": [{"type": "circle", "xref": "x", "yref": "y", "x0": -1, "y0": -1, "x1": 1, "y1": 1, "line": {"color": "#dee2e6"}}], "annotations": [{"ax": 0, "ay": 0, "axref": "x", "ayref": "y", "x": 1.1, "y": -0.2, "xref": "x", "yref": "y", "showarrow": true, "arrowhead": 2, "arrowcolor": "#228be6", "text": "Start State |0>", "textposition": "middle right", "font": {"size": 12}}, {"ax": 0, "ay": 0, "axref": "x", "ayref": "y", "x": 0.707, "y": 0.707, "xref": "x", "yref": "y", "showarrow": true, "arrowhead": 2, "arrowcolor": "#12b886", "text": "", "textposition": "top right"}]}, "data": []}The unit circle represents all valid quantum states with a total probability of 1. A unitary operation rotates the vector (blue to teal) but keeps the tip of the arrow exactly on the circle.The Conjugate TransposeTo define unitary matrices mathematically, we first need to understand the conjugate transpose. In linear algebra texts, this is often denoted by a dagger symbol ($^\dagger$) and is sometimes called the Hermitian conjugate.Calculating the conjugate transpose involves two steps:Transpose: Swap the rows and columns.Conjugate: Take the complex conjugate of every number (flip the sign of the imaginary part, so $a+bi$ becomes $a-bi$).If we have a matrix $A$:$$A = \begin{pmatrix} 1 & 1-i \ 0 & 2i \end{pmatrix}$$The transpose $A^T$ is:$$A^T = \begin{pmatrix} 1 & 0 \ 1-i & 2i \end{pmatrix}$$The conjugate transpose $A^\dagger$ is:$$A^\dagger = \begin{pmatrix} 1 & 0 \ 1+i & -2i \end{pmatrix}$$The Mathematical DefinitionA matrix $U$ is unitary if its conjugate transpose is also its inverse. Mathematically, this is written as:$$U^\dagger U = I$$Where $I$ is the Identity Matrix, a square matrix with 1s on the diagonal and 0s everywhere else. Multiplying by the identity matrix is equivalent to multiplying a number by 1; it leaves the state unchanged.$$I = \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}$$This definition guarantees reversibility. If you apply a quantum gate $U$ to a qubit, you can return to the original state by applying $U^\dagger$. This suggests that, theoretically, quantum information is never lost (until measurement occurs).Verifying Unitary Matrices with NumPyAs an AI engineer, you will often use Python to simulate these operations. We can use NumPy to verify if a matrix is unitary. Let's look at the Pauli X gate, often called the "Quantum NOT" gate, which flips the amplitudes of the state vector.The matrix for Pauli X is:$$X = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$$We can check if this is unitary by calculating $X^\dagger X$ and seeing if we get the identity matrix.import numpy as np # Define the Pauli X matrix X = np.array([[0, 1], [1, 0]]) # Calculate the conjugate transpose (dagger) # .conj() takes the complex conjugate # .T takes the transpose X_dagger = X.conj().T # Perform matrix multiplication (dot product) result = np.dot(X_dagger, X) print("Result of X_dagger * X:") print(result)The output will be:[[1 0] [0 1]]Since the result is the identity matrix, the Pauli X gate is a valid unitary operator.Applying Operations to StatesTo simulate a quantum computation, we apply the matrix to the state vector using the dot product.$$|\psi_{new}\rangle = U |\psi_{current}\rangle$$Let's start with a qubit in the $|0\rangle$ state, represented by the vector $\begin{pmatrix} 1 \ 0 \end{pmatrix}$. We will apply the Pauli X gate.$$X|0\rangle = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} \begin{pmatrix} 1 \ 0 \end{pmatrix} = \begin{pmatrix} (0\cdot1) + (1\cdot0) \ (1\cdot1) + (0\cdot0) \end{pmatrix} = \begin{pmatrix} 0 \ 1 \end{pmatrix} = |1\rangle$$This linear algebra operation confirms that the X gate flips the state from $|0\rangle$ to $|1\rangle$.Here is how we implement this state transition in Python:# Define the initial state |0> state_0 = np.array([[1], [0]]) # Apply the X gate using dot product new_state = np.dot(X, state_0) print("New State Vector:") print(new_state)Visualizing the Operation FlowUnderstanding the flow of data is helpful when constructing algorithms. We start with an input vector, pass it through a series of unitary matrices (gates), and result in an output vector.digraph G { rankdir=LR; node [style=filled, shape=box, fontname="Helvetica"]; start [label="Input State\n|ψ⟩", fillcolor="#e9ecef", color="#adb5bd"]; gate [label="Unitary Operator\nU (Matrix)", fillcolor="#d0bfff", color="#845ef7"]; end [label="Output State\n|ψ'⟩", fillcolor="#b2f2bb", color="#40c057"]; start -> gate [label=" Vector"]; gate -> end [label=" Transformed\nVector"]; }The matrix acts as a function that transforms the input vector into a new output vector while preserving its norm.Summary of PropertiesWhen working with quantum operators, keep these properties in mind:Linearity: If you apply a matrix $U$ to a superposition of states (e.g., $a|0\rangle + b|1\rangle$), the matrix acts on each part individually: $U(a|0\rangle + b|1\rangle) = a(U|0\rangle) + b(U|1\rangle)$.Reversibility: Every unitary quantum gate has an inverse. If you know the output state and the gate used, you can mathematically reconstruct the input state.Norm Preservation: The sum of the squared absolute values of the vector components remains constant.In the next section, we will explore eigenvalues and eigenvectors. These concepts allow us to determine what values we will actually see when we perform a measurement on these transformed states.