On this page:
The CNOT gate acts on two qubits. It flips the target qubit if and only if the control qubit is 1. The CNOT gate is a singly-controlled NOT gate. The CNOT gate is represented by the following matrix:
// One-line notation {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}} // Expanded notation { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0} }
Manipulation of a register takes the form of matrix algebra. In order for the mathematics to take place, matricies of appropriate size must be constructed. This can be a tedious and time consuming process.
Thankfully, there is an easier way to compute these outcomes, as will be demonstrated.
It is not possible to 'step-up' a CNOT gate to an appropriate size via the same method used for the Pauli family of matriced whereby X and I matrices are combined and tensored together in various ways to achieve the desired result. This process is counter-intuitive and difficult to work out manually, and becomes almost impossible when more than 6 or 7 qubits are involved. The following examples will demonstrate this, and will demonstrate why the Column Method is superior for these complex calculations.
The Quantum Console syntax for this operation is:
CNOT(Controln, Targetn);
Where Controln specifies the control qubit, and Targetn specifies the number (or index) of the target qubit we wish to manipulate.
* Note that this index is 0 based, not 1 based as represented in most examples.
As the CNOT gate operates on two qubits, it cannot be used with a single qubit register.
Performing this calculation on a two qubit system is fairly straight forward, as the rules for matrix multiplication (number of columns from matrix A must match the number of rows from matrix B) are satisfied.
For the operation CNOT(0, 1):
For the operation CNOT(1, 0):
For the operation CNOT(0, 1):
// Qubits (A|0› + B|1›) (x) (C|0› + D|1›) // Computational Basis States - Input AC|00› + AD|01› + BC|10› + BD|11› // Quantum Console syntax // Apply CNOT using control qubit 0 and target qubit 1 CNOT(0, 1); // Computational Basis States - Ouput AC|00› + AD|01› + BD|10› + BC|11›
For the operation CNOT(1, 0):
// Qubits (A|0› + B|1›) (x) (C|0› + D|1›) // Computational Basis States - Input AC|00› + AD|01› + BC|10› + BD|11› // Quantum Console syntax // Apply CNOT using control qubit 1 and target qubit 0 CNOT(1, 0); // Computational Basis States - Ouput AC|00› + BD|01› + BC|10› + AD|11›
This time, the state vector is larger again (2n, n = 3), at 8 rows, and due to this a CNOT gate cannot be applied as the number of columns from matrix A (2) does not match the number of rows from matrix B (8).
Using the Pauli family of matrices, normally a matrix produced from the tensor products of X and I matrices would be constructed to perform the appropriate manipulation, however this method simply doesn't work for CNOT operations.
Instead, we will go directly to the Column Method to perform the calculations manually.
You might find that using the column method is easier and faster - it took a while for me to develop, but now I find it easier to use than other methods.
To use the column method:
Applying the column method to the 3 qubit example from above:
// CNOT(0, 1); // Apply the CNOT gate, one element at a time // C denotes the control qubit // T denotes the target qubit CT 012 000 000 001 001 010 010 011 011 100 110 // The target is flipped if and only if the control is 1 101 111 110 100 111 101
Now, all that is left is to take the values from the left column and plug them into the right column:
CT 012 ACE|000 ACE|000 ACF|001 ACF|001 ADE|010 ADE|010 ADF|011 ADF|011 BCE|100 BDE|110 BCF|101 BDF|111 BDE|110 BCE|100 BDF|111 BCF|101
And finally adjust the state vector (using the binary index) to match the new order:
ADE|000 ADF|001 ACE|010 ACF|011 BDE|100 BDF|101 BCE|110 BCF|111
Applying the column method to a 4 qubit example:
// CNOT(1, 2); // Apply the CNOT gate, one element at a time // C denotes the control qubit // T denotes the target qubit CT 0123 0000 0000 0001 0001 0010 0010 0011 0011 0100 0110 // The target is flipped if and only if the control is 1 0101 0111 0110 0100 0111 0101 1000 1000 1001 1001 1010 1010 1011 1011 1100 1110 1101 1111 1110 1100 1111 1101
Now, all that is left is to take the values from the left column and plug them into the right column:
CT 0123 ACEG|0000› ACEG|0000› ACEH|0001› ACEH|0001› ACFG|0010› ACFG|0010› ACFH|0011› ACFH|0011› ADEG|0100› ADFG|0110› ADEH|0101› ADFH|0111› ADFG|0110› ADEG|0100› ADFH|0111› ADEH|0101› BCEG|1000› BCEG|1000› BCEH|1001› BCEH|1001› BCFG|1010› BCFG|1010› BCFH|1011› BCFH|1011› BDEG|1100› BDFG|1110› BDEH|1101› BDFH|1111› BDFG|1110› BDEG|1100› BDFH|1111› BDEH|1101›
And finally adjust the state vector (using the binary index) to match the new order:
ACEG|0000› ACEH|0001› ACFG|0010› ACFH|0011› ADFG|0100› ADFH|0101› ADEG|0110› ADEH|0111› BCEG|1000› BCEH|1001› BCFG|1010› BCFH|1011› BDFG|1100› BDFH|1101› BDFG|1110› BDFH|1111›
The manipulation of the state vector is now complete.
Copyright © 2024 carlbelle.com