MULT20015 Practice Class 4, © L. Hollenberg et al 2020 1
MULT20015 Elements of Quantum Computing
Practice Class 4
Welcome to Practice Class 4 of MULT20015 Elements of Quantum Computing, covering exercises
relevant to the material presented in lectures in Week 4 and 5.
The purpose of this week’s exercises is to:
• Implement classical logic using the Toffoli gate
• Implement multi-qubit circuits, and understand the binary state representation
• Investigate simple arithmetic applications in superposition: the one and two-qubit adders
• Investigate multi-qubit measurement
The exercises in these notes are to assist your understanding of the subject and may require time
outside of the practice class to complete.
4.1 Classical logic using the Toffoli gate
Here we will verify, by direct calculation, how the 3-qubit Toffoli gate allows us to
perform classical logic. In the figure below examples are given together with the truth
tables.
Exercise 4.1.1
In the QUI set up a 3 qubit instance and program a Toffoli gate, as above with qubit-1
and qubit-2 as the controls and qubit-3 as the target. By setting the input states
appropriately verify each entry in the truth tables.
4.2 One Qubit Adder Circuit
MULT20015 Practice Class 4, © L. Hollenberg et al 2020 2
In the lectures we went through the one-bit adder circuit in detail.
Exercise 4.2.1
a) With reference to the one-bit adder circuit above, enter the appropriate values for the
carry bit, the ones (a+b) bit, and the binary representation of the sum in the following
table:
Input Output
a b carry a+b Binary
0 0
0 1
1 0
1 1
b) Implement the one qubit adder circuit in QUI, and verify that it gives the answers as
expected, which you filled in the table above.
c) Place a Hadamard gate before each of the input a alone, so that qubit a is in an equal
superposition. Place an X-gate before input b, so that it is in the state 1. What is the
resulting state after the one qubit adder?
d) Place a Hadamard gate before both inputs, a and b. What is the resulting state from
the QUI?
e) Given the state in part d) explain how the this demonstrates quantum “parallelism”.
MULT20015 Practice Class 4, © L. Hollenberg et al 2020 3
4.3 Two Qubit Adder
We will now extend our understanding of arithmetic on quantum computers to the two-
qubit adder circuit. In this example we will see a circuit which can add two qubit numbers.
Consider the two-bit adder circuit below for S = A + B, where A = a0 + 2a1, B = b0 + + 2b1 and S
= s0 + 2s1 + 4s2.
Exercise 3.5.1
a) Program the two-bit adder in the QUI. Run the circuit (with measurements at the end) and verify
the arithmetic by filling in the following table (least significant bit last).
[a1 a0] [b1 b0] [s2 s1 s0] S (decimal)
[0 0] [0 0] [0 0 0] 0 = 0 + 0
[0 1] [0 0]
[1 0] [0 0]
[1 1] [0 0]
[0 0] [0 1]
[0 1] [0 1]
[1 0] [0 1]
[1 1] [0 1]
[0 0] [1 0]
[0 1] [1 0]
[1 0] [1 0]
[1 1] [1 0]
[0 0] [1 1]
[0 1] [1 1]
[1 0] [1 1]
[1 1] [1 1]
b) Now edit the circuit so that all possible binaries A and B are presented to the adder in a
superposition:
MULT20015 Practice Class 4, © L. Hollenberg et al 2020 4
Write down the resulting state (using decimal notation) at the output. Use the registers, .
c) Explain the resulting state. Can you see how addition is performed on superpositions?
4.4 Multi-qubit Measurement
Finally, we will consider making multi-qubit measurements by constructing the same state which
was mentioned in the lectures and making a measurements of one of the registers.
Exercise 4.4.1
Construct the following quantum circuit using the QUI:
In this circuit, we will consider the first two qubits to be the first register, and the second four qubits
to be the second register.
Exercise 4.4.2
By examining the amplitudes given for each state by the QUI verify that the state produced by this
circuit is:
MULT20015 Practice Class 4, © L. Hollenberg et al 2020 5
Place measurement gates to measure both qubits in the first register.
Exercise 4.4.3
During the lectures we saw that the measurement result (after measuring the first qubit of this
state) should only ever be “1” (or “01” in binary), or “3” (“11” in binary). By computing the result of
the measurement several times, verify that these are the only two measurement outcomes
measured.
Exercise 4.4.4
a) Using the prescription for multi-qubit measurement spelled out in lectures, what will the resulting
state be if “1” (or “01” in binary) is measured on the first register?
b) Using the prescription for multi-qubit measurement spelled out in lectures, what will the
resulting state be if “3” (or “11” in binary) is measured on the first register?
Exercise 4.4.5
Using QUI, and comparing the amplitudes you calculated to those given by QUI, verify the two
states which you worked out in 4.4.4 (a) and (b) are indeed produced when the measurement
outcomes are “1” and “3” respectively.