On this page:
The CZ gate acts on two qubits. It flips the sign of the target qubit if and only if the control qubit is 1. The CZ gate is a singly-controlled Z gate. The CZ gate is represented by the following matrix:
// One-line notation {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0,-1}} // Expanded notation { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0,-1} }
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 CZ gate to an appropriate size via the same method used for the Pauli family of matrices 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:
CZ(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 CZ 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 CZ(0, 1):
For the operation CZ(1, 0):
For the operation CZ(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 CZ using control qubit 0 and target qubit 1 CZ(0, 1); // Computational Basis States - Ouput AC|00› + AD|01› + BC|10› + -BD|11›
For the operation CZ(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 CZ using control qubit 1 and target qubit 0 CZ(1, 0); // Computational Basis States - Ouput AC|00› + AD|01› + BC|10› + -BD|11›
This time, the state vector is larger again (2n, n = 3), at 8 rows, and due to this a CZ 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 CZ 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:
// CZ(0, 1); // Apply the CZ gate, one element at a time // C denotes the control qubit // T denotes the target qubit CT 012 000 0 00 001 0 01 010 0 10 011 0 11 100 1 00 // The target sign is flipped if and only if the control is 1 101 1 01 110 1-10 111 1-11
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 BCE|100 BCF|101 BCF|101 BDE|110 -BDE|110 BDF|111 -BDF|111
As the state vector is already in the correct order, no further adjustment is required.
Applying the column method to a 4 qubit example:
// CZ(1, 2); // Apply the CZ gate, one element at a time // C denotes the control qubit // T denotes the target qubit CT 0123 0000 00 00 0001 00 01 0010 00 10 0011 00 11 0100 01 00 // The target sign is flipped if and only if the control is 1 0101 01 01 0110 01-10 0111 01-11 1000 10 00 1001 10 01 1010 10 10 1011 10 11 1100 11 00 1101 11 01 1110 11-10 1111 11-11
Now, all that is left is to take the values from the left column and plug them into the right column:
CT 0124 ACEG|0000 ACEG|0000 ACEH|0001 ACEH|0001 ACFG|0010 ACFG|0010 ACFH|0011 ACFH|0011 ADEG|0100 ADEG|0100 ADEH|0101 ADEH|0101 ADFG|0110 -ADFG|0110 ADFH|0111 -ADFH|0111 BCEG|1000 BCEG|1000 BCEH|1001 BCEH|1001 BCFG|1010 BCFG|1010 BCFH|1011 BCFH|1011 BDEG|1100 BDEG|1100 BDEH|1101 BDEH|1101 BDFG|1110 -BDFG|1110 BDFH|1111 -BDFH|1111
As the state vector is already in the correct order, no further adjustment is required.
The manipulation of the state vector is now complete.
Copyright © 2025 carlbelle.com