Pauli-Z Gate

QSharp

On this page:

The Pauli-Z Gate

The Pauli-Z gate acts on a single qubit. It leaves the basis state |0› unchanged, and maps |1› -|1›. The Pauli-Z gate is represented by the following matrix:

The Pauli-Z matrix

//	One-line notation
{{1, 0}, {0, -1}}

//	Expanded notation
{
{1, 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.

If you are unfamiliar with either tensor products or matrix multiplication, then I would suggest revising those topics first, otherwise a lot of this will look like magic.

Syntax

The Quantum Console syntax for this operation is:

Z(n);

Where n specifies the number (or index) of the qubit we wish to manipulate.

* Note that this index is 0 based, not 1 based as represented in most examples.

1 Qubit Register

Performing this calculation on a single qubit 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.

In other words, the number of columns in the Pauli-Z matrix match the number of rows in the state vector.

Matrix mathematics

{
{1, 0},
{0,-1}
}
*
{
{A|0›},
{B|1›}
}
=
Show intermediate working
{
{ A|0›},
{-B|1›}
}

Performing the operation in Quantum Console

//	Qubits
(A|0› + B|1›)

//	Computational Basis States - Input
A|0› + B|1›

//	Quantum Console syntax
//	Apply Z to qubit 0
Z(0);

//	Computational Basis States - Ouput
A|0› + -B|1›

2 Qubit Register

Performing this calculation becomes a little bit trickier, as our state vector is now larger (2n, n = 2) at 4 rows.

Consequently, as the state vector now has 4 rows, so a Z gate cannot be applied to it, as the number of columns from matrix A (2) does not match the number of rows from matrix B (4).

To work around this, it is necessary to tensor an I (identity) matrix for each other qubit in order to construct the matrix of the appropriate size.

In this example, the Z gate is applied to the qubit in position 1, and as the identity matrices are inferred, the operation could be written as:

IZ

If the X gate was to be applied to the qubit in position 0, and as the identity matrices are inferred, the operation could be written as:

ZI

Matrix mathematics

First, tensor the gate with an identity matrix:

{
{1, 0},
{0,-1}
}
(x)
{
{1, 0},
{0, 1}
}
=
{
{1, 0, 0, 0}
{0,-1, 0, 0}
{0, 0, 1, 0}
{0, 0, 0,-1}
}

This 'steps up' the Z gate to be appropriately sized for the state vector.

Now the result can be applied to the state vector:

{
{1, 0, 0, 0}
{0,-1, 0, 0}
{0, 0, 1, 0}
{0, 0, 0,-1}
}
*
{
{AC|00›},
{AD|01›},
{BC|10›},
{BD|11›}
}
=
Show intermediate working
{
{ AC|00›},
{-AD|01›},
{ BC|10›},
{-BD|11›}
}

Performing the operation in Quantum Console

//	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 Z to qubit 1
Z(1);

//	Computational Basis States - Ouput
AC|00› + -AD|01› + BC|10› + -BD|11›

3 Qubit Register

This time, the state vector is larger again (2n, n = 3), at 8 rows, and due to this a Z gate cannot be applied as the number of columns from matrix A (2) does not match the number of rows from matrix B (8).

To work around this, as before, tensor an I (identity) matrix for each qubit involved that is not being manipulated in order to construct the matrix of the appropriate size.

In this example, the Z gate is applied to the qubit in position 1, and as the identity matrices are inferred, the operation could be written as:

IZI

If the Z gate was to be applied to the qubit in position 0, and as the identity matrices are inferred, the operation could be written as:

ZII

Matrix mathematics

Tensor the gate with an identity.

Tensor products are produced by applying the left matrix to the right. So in this instance, the I is applied to the Z first, then IZ to I.

I (step 1: tensor) Z (step 2: tensor) I

{
{1, 0},
{0, 1}
}
(x)
{
{1, 0},
{0,-1}
}
=
{
{1, 0, 0, 0}
{0,-1, 0, 0}
{0, 0, 1, 0}
{0, 0, 0,-1}
}

Tensor the product with another identity:

{
{1, 0, 0, 0}
{0,-1, 0, 0}
{0, 0, 1, 0}
{0, 0, 0,-1}
}
(x)
{
{1, 0},
{0, 1}
}
=
{
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0},
{0, 0,-1, 0, 0, 0, 0, 0},
{0, 0, 0,-1, 0, 0, 0, 0}
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0,-1, 0},
{0, 0, 0, 0, 0, 0, 0,-1}
}

The matrix is now the correct size to be applied to the state vector:

{
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0},
{0, 0,-1, 0, 0, 0, 0, 0},
{0, 0, 0,-1, 0, 0, 0, 0}
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0,-1, 0},
{0, 0, 0, 0, 0, 0, 0,-1}
}
*
{
{ACE|000›},
{ACF|001›},
{ADE|010›},
{ADF|011›},
{BCE|100›},
{BCF|101›},
{BDE|110›},
{BDF|111›}
}
=
Show intermediate working
{
{ ACE|000›},
{ ACF|001›},
{-ADE|010›},
{-ADF|011›},
{ BCE|100›},
{ BCF|101›},
{-BDE|110›},
{-BDF|111›}
}

Performing the operation in Quantum Console

//	Qubits
(A|0› + B|1›) (x) (C|0› + D|1›) (x) (E|0› + F|1›)

//	Computational Basis States - Input
ACE|000› + ACF|001› + ADE|010› + ADF|011› + BCE|100› + BCF|101› + BDE|110› + BDF|111›

//	Quantum Console syntax
//	Apply Z to qubit 1
Z(1);

//	Computational Basis States - Ouput
ACE|000› + ACF|001› + -ADE|010› + -ADF|011› + BCE|100› + BCF|101› + -BDE|110› + -BDF|111›

n Qubit Register

As you can see from the previous examples, performing manual matrix arthimetic for each step becomes tedious and time consuming, however it is important to acknowledge that this process takes place in the first instance.

Thankfully, there is a much simpler way of working out these operations as we shall discover for an n qubit register.

Suppose a Z gate is to be applied to qubit 1 in a register, as with the previous examples.

For a 2 qubit system, apply the Z logic to the each bit indicated in the operation. Z(1) for example, applies an Z gate to every bit in position 1.

//	State vector
|ψ› = (AC|00› + AD|01› + BC|10› + BD|11›)

//	1 bit positions bolded - these are the bits that will be affected by the Z operation
(AC|00› + AD|01› + BC|10› + BD|11›)

//	Apply the Z to every bit that occupies the 1 position
Z(1);

//	State vector - compare this to the matrix calculations above
|ψ› = (AC|00› + -AD|01› + BC|10› + -BD|11›)

Using the same methodology on a larger system reduces the amount of manual work. For a 3 qubit register:

//	State vector
|ψ› = (ACE|000› + ACF|001› + ADE|010› + ADF|011› + BCE|100› + BCF|101› + BDE|110› + BDF|111›)

//	1 bit positions bolded
(ACE|000› + ACF|001› + ADE|010› + ADF|011› + BCE|100› + BCF|101› + BDE|110› + BDF|111›)

//	Apply the Z to every bit that occupies the 1 position
Z(1);

//	State vector - compare this to the matrix calculations above
|ψ› = (ACE|000› + ACF|001› + -ADE|010› + -ADF|011› + BCE|100› + BCF|101› + -BDE|110› + -BDF|111›)

The Column Method

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:

  1. Write the state vector vertically down the page
  2. Write an index over each bit column
  3. Write the gate over the bit to be operated on
  4. Now, work out the result of the operation, one element at a time, and write these into a new column

Applying the column method to the 3 qubit example from above:

//	Z(1);
//	Apply the Z gate, one element at a time

 Z
012

000  0 00	//	Remember the Z gate leaves 0 unchanged, and takes 1 to -1
001  0 01
010  0-10
011  0-11
100  1 00
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:

     Z
    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

No adjustement of the state vector (using the binary index) to match the new order is required, as the ordering of element is unchanged.

The manipulation of the state vector is now complete.


 

Copyright © 2024 carlbelle.com