Serially wired gates Assume that we have two gates
A and
B that both act on n qubits. When
B is put after
A in a series circuit, then the effect of the two gates can be described as a single gate
C. : C = B \cdot A where \cdot is
matrix multiplication. The resulting gate
C will have the same dimensions as
A and
B. The order in which the gates would appear in a circuit diagram is reversed when multiplying them together. For example, putting the Pauli
X gate after the Pauli
Y gate, both of which act on a single qubit, can be described as a single combined gate
C: : C = X \cdot Y = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \cdot \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} = \begin{bmatrix} i & 0 \\ 0 & -i \end{bmatrix} = iZ The product symbol (\cdot) is often omitted.
Exponents of quantum gates All
real exponents of
unitary matrices are also unitary matrices, and all quantum gates are unitary matrices. Positive integer exponents are equivalent to sequences of serially wired gates (e.g. and the real exponents is a generalization of the series circuit. For example, X^\pi and \sqrt{X}=X^{1/2} are both valid quantum gates. U^0=I for any unitary matrix U. The
identity matrix (I) behaves like a
NOP and can be represented as bare wire in quantum circuits, or not shown at all. All gates are unitary matrices, so that U^\dagger U = UU^\dagger = I and {{nowrap|U^\dagger = U^{-1},}} where \dagger is the
conjugate transpose. This means that negative exponents of gates are
unitary inverses of their positively exponentiated counterparts: {{nowrap|U^{-n} = (U^n)^{\dagger}.}} For example, some negative exponents of the
phase shift gates are T^{-1}=T^{\dagger} and {{nowrap|T^{-2}=(T^2)^{\dagger}=S^{\dagger}.}} Note that for a
Hermitian matrix H^\dagger=H, and because of unitarity, HH^\dagger=I, so H^2 = I for all Hermitian gates. They are
involutory. Examples of Hermitian gates are the
Pauli gates,
Hadamard,
CNOT,
SWAP and
Toffoli. Each Hermitian unitary matrix H
has the property that e^{i\theta H}=(\cos \theta)I+(i\sin \theta) H where H=e^{i\frac{\pi}{2}(I-H)}=e^{-i\frac{\pi}{2}(I-H)}. The exponent of a gate is a multiple of the duration of time that the
time evolution operator is applied to a quantum state. E.g., in a
spin qubit quantum computer the \sqrt{\mathrm{SWAP}} gate could be realized via
exchange interaction on the
spin of two
electrons for half the duration of a full exchange interaction.
Hadamard transform The gate H_2 = H \otimes H is the
Hadamard gate applied in parallel on 2 qubits. It can be written as: :H_2 = H \otimes H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} \otimes \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} = \frac{1}{2} \begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{bmatrix} This "two-qubit parallel Hadamard gate" will, when applied to, for example, the two-qubit zero-vector create a quantum state that has equal probability of being observed in any of its four possible outcomes; and We can write this operation as: :H_2 |00\rangle = \frac{1}{2} \begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix} = \frac{1}{2} \begin{bmatrix} 1 \\ 1 \\ 1 \\ 1 \end{bmatrix} = \frac{1}{2} |00\rangle + \frac{1}{2} |01\rangle +\frac{1}{2} |10\rangle +\frac{1}{2} |11\rangle = \frac{|00\rangle + |01\rangle + |10\rangle + |11\rangle}{2}
register Here the amplitude for each measurable state is . The probability to observe any state is the square of the absolute value of the measurable states amplitude, which in the above example means that there is one in four that we observe any one of the individual four cases. See
measurement for details. H_2 performs the
Hadamard transform on two qubits. Similarly the gate \underbrace{ H \otimes H \otimes \dots \otimes H }_{n\text{ times}} = \bigotimes_{i=0}^{n-1} H = H^{\otimes n} = H_n performs a Hadamard transform on a
register of n qubits. When applied to a register of n qubits all initialized to the Hadamard transform puts the quantum register into a superposition with equal probability of being measured in any of its 2^n possible states: :\bigotimes_{i=0}^{n-1}(H|0\rangle) = \frac{1}{\sqrt{2^n}} \begin{bmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{bmatrix} = \frac{1}{\sqrt{2^n}} \Big( |0\rangle + |1\rangle + \dots + |2^n-1\rangle \Big)= \frac{1}{\sqrt{2^n}}\sum_{i=0}^{2^{n}-1}|i\rangle This state is a
uniform superposition and it is generated as the first step in some search algorithms, for example in
amplitude amplification and
phase estimation.
Measuring this state results in a
random number between |0\rangle and How random the number is depends on the
fidelity of the logic gates. If not measured, it is a quantum state with equal
probability amplitude \frac{1}{\sqrt{2^n}} for each of its possible states. The Hadamard transform acts on a register |\psi\rangle with n qubits such that |\psi\rangle = \bigotimes_{i=0}^{n-1} |\psi_i\rangle as follows: :\bigotimes_{i=0}^{n-1}H|\psi\rangle = \bigotimes_{i=0}^{n-1}\frac{|0\rangle + (-1)^{\psi_i}|1\rangle}{\sqrt{2}} = \frac{1}{\sqrt{2^n}}\bigotimes_{i=0}^{n-1}\Big(|0\rangle + (-1)^{\psi_i}|1\rangle\Big) = H|\psi_0\rangle \otimes H|\psi_1\rangle \otimes \cdots \otimes H|\psi_{n-1}\rangle
Application on entangled states If two or more qubits are viewed as a single quantum state, this combined state is equal to the tensor product of the constituent qubits. Any state that can be written as a tensor product from the constituent subsystems are called
separable states. On the other hand, an
entangled state is any state that cannot be tensor-factorized, or in other words:
An entangled state can not be written as a tensor product of its constituent qubits states. Special care must be taken when applying gates to constituent qubits that make up entangled states. If we have a set of
N qubits that are entangled and wish to apply a quantum gate on
M H only act on 1 qubit, but |\psi\rangle is an entangled quantum state that spans 2 qubits. In our example, |\psi\rangle = \frac{|00\rangle + |11\rangle}{\sqrt{2}}. For example, the Hadamard gate acts on a single qubit, but if we feed it the first of the two qubits that constitute the
entangled Bell state {{nowrap|\frac{|00\rangle + |11\rangle}{\sqrt{2}},}} we cannot write that operation easily. We need to extend the Hadamard gate H with the identity gate I so that we can act on quantum states that span
two qubits: :K = H \otimes I = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} \otimes \begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1\end{bmatrix} The gate K can now be applied to any two-qubit state, entangled or otherwise. The gate K will leave the second qubit untouched and apply the Hadamard transform to the first qubit. If applied to the Bell state in our example, we may write that as: :K \frac{|00\rangle + |11\rangle}{\sqrt{2}} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1\end{bmatrix} \frac{1}{\sqrt{2}} \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = \frac{1}{2} \begin{bmatrix} 1 \\ 1 \\ 1 \\ -1 \end{bmatrix} = \frac{|00\rangle + |01\rangle + |10\rangle - |11\rangle}{2}
Computational complexity and the tensor product The
time complexity for multiplying two n \times n-matrices is at least if using a classical machine. Because the size of a gate that operates on q qubits is 2^q \times 2^q it means that the time for simulating a step in a quantum circuit (by means of multiplying the gates) that operates on generic entangled states is {{nowrap|\Omega({2^q}^2 \log({2^q})).}} For this reason it is believed to be
intractable to simulate large entangled quantum systems using classical computers. Subsets of the gates, such as the
Clifford gates, or the trivial case of circuits that only implement classical Boolean functions (e.g. combinations of
X,
CNOT,
Toffoli), can however be efficiently simulated on classical computers. The state vector of a
quantum register with n qubits is 2^n complex entries. Storing the
probability amplitudes as a list of
floating point values is not tractable for large n.
Unitary inversion of gates Because all quantum logical gates are
reversible, any composition of multiple gates is also reversible. All products and tensor products (i.e.
series and
parallel combinations) of
unitary matrices are also unitary matrices. This means that it is possible to construct an inverse of all algorithms and functions, as long as they contain only gates. Initialization, measurement,
I/O and spontaneous
decoherence are
side effects in quantum computers. Gates however are
purely functional and
bijective. If U is a
unitary matrix, then U^\dagger U = UU^\dagger = I and {{nowrap|U^\dagger = U^{-1}.}} The dagger (\dagger) denotes the
conjugate transpose. It is also called the
Hermitian adjoint. If a function F is a product of m gates, the unitary inverse of the function F^\dagger can be constructed: Because (UV)^\dagger = V^\dagger U^\dagger we have, after repeated application on itself :F^\dagger = \left(\prod_{i=1}^{m} A_i\right)^\dagger = \prod_{i=m}^{1} A^\dagger_{i} = A_m^\dagger \cdot \dots \cdot A_2^\dagger \cdot A_1^\dagger Similarly if the function G consists of two gates A and B in parallel, then G=A\otimes B and Gates that are their own unitary inverses are called
Hermitian or
self-adjoint operators. Some elementary gates such as the
Hadamard (
H) and the
Pauli gates (
I,
X,
Y,
Z) are Hermitian operators, while others like the
phase shift (
S,
T,
P,
CPhase) gates generally are not. For example, an algorithm for addition can be used for subtraction, if it is being "run in reverse", as its unitary inverse. The
inverse quantum Fourier transform is the unitary inverse. Unitary inverses can also be used for
uncomputation. Programming languages for quantum computers, such as
Microsoft's
Q#, Bernhard Ömer's
QCL, and
IBM's
Qiskit, contain function inversion as programming concepts. == Measurement ==