0% found this document useful (0 votes)
22 views6 pages

Lecture 29

Peter Shor note

Uploaded by

Majid Aghababaie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Lecture 29

Peter Shor note

Uploaded by

Majid Aghababaie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Notes 8.370/18.

435 Fall 2022


Lecture 29 Prof. Peter Shor
Today, we’re talking about the seven-qubit Hamming code. This Hamming code
is probably the simplest CSS code; it’s certainly the shortest CSS code which corrects
one error. In lecture, I tried to present both the Hamming code and CSS codes at the
same time, but thinking about my presentation, I think it would work better to do the
quantum Hamming code first and the more general CSS code construction later, so I’m
doing that in these notes.
First, we need to explain the classical Hamming code. The codewords of the Ham-
ming code are the binary linear combinations of the generator matrix G:
 
0 0 0 1 1 1 1
 0 1 1 0 0 1 1 
G=  1 0 1 0 1 0 1 

1 1 1 1 1 1 1

There are 24 of these combinations, since there are 4 rows.


We consider a code C to be the set of codewords of the code. There are many
different generator matrices that give essentially the same code.
The Hamming code encodes four bits into seven bits. To encode, we take a four-bit
message m and multiply G by it to get the corresponding codeword:

c = mG .

We’ve been working with quantum mechanics, where you use left multiplication, so
it may seem strange to be using right multiplication (the vector is on the left and the
matrix is on the right). However, this is the standard convention in coding theory, and
if I try to reverse it I suspect I would get very confused.
How do you decode it? Choose some set of columns that are linearly independent.
Let’s choose the first four columns. The matrix G restricted to these four columns is
 
0 0 0 1
 0 1 1 0 
Ĝ = 
 1 0 1 0 

1 1 1 1

Because the first four columns are linearly independent, the matrix Ĝ has an inverse
(mod 2), that we will call Ĝ−1 . You can find it using Gaussian elimination. In this case,
 
1 1 0 1
 1 0 1 1 
Ĝ−1 =  1 1 1 1 

1 0 0 0

and Ĝ−1 Ĝ = I (mod 2).

1
To decode, take ĉ, the first four entries of the codeword, and apply Ĝ−1 to it. This
gives m because
ĉĜ−1 = mĜĜ−1 = mI = m
The Hamming code is just the simplest non-trivial example of a large class of clas-
sical error-correcting codes, called linear codes. In these codes, the codewords are
binary linear combinations of the rows of some generator matrix G. In this lecture, we
will talk about classical linear codes, and then discuss the 7-qubit quantum Hamming
code, which encodes one qubit into seven qubits and corrects one error. In the next
lecture, we will talk about quantum CSS codes, which are the simplest generalization
of classical linear codes to quantum codes. A broader generalization, stabilizer codes,
exists, but we won’t discuss them in these notes.
How do we correct errors for the Hamming code? We use the parity check matrix
H, which is a generator matrix for the dual space of the code. If you have a vector
space V , then the dual space is
V ⊥ = {w|w · v = 0 ∀v ∈ V }.
If you’ve used to working with vector spaces over R or C, one thing that is confusing
about binary vector spaces is that the dual can overlap with the original, so some vectors
can be in both V and V ⊥ . However, even though this is true, it is still the case that
dim V + dim V ⊥ = n, as happens in vector spaces over R.
Why can the Hamming correct one error? It’s because the minimum non-zero
codeword has Hamming weight 3. Here, the Hamming weight of a codeword is the
number of non-zero coordinates of a codeword (for binary codewords, the number
of 1’s). The Hamming distance dH (c1 , c2 ) between two codewords c1 and c2 is the
Hamming weight of c1 − c2 , in other words, the number of coordinates where c1 and
c2 differ.
We now prove
Theorem 1. Suppose that the minimum  non-zero weight of a codeword in code C is d.
Then the code C can correct t = d−1

2 errors and detect d − 1 errors.
Proof: We claim that the a word w cannot be within Hamming distance t of two
different codewords c1 and c2 . Suppose it was, then
 
d−1
dH (c1 , c2 ) ≤ dH (c1 , w) + dH (w, c2 ) ≤ 2 ≤ d − 1,
2
but c1 − c2 is a codeword, and has Hamming weight dH (c1 , c2 ), which must be at least
d. Since we just showed that dH (c1 , c2 ) < d, this is a contradiction. Thus, for any
word, there is at most one codeword within distance t of it. So if a codeword has t or
fewer errors, we can correct it to the unique codeword within Hamming distance t.
If a codeword has fewer than d − 1 errors, then the errors cannot take it to an-
other codeword, so we can detect that there is an error (although we cannot necessarily
correct it to the original codeword). .
The dual of a code C , is C ⊥ , the set of words that are perpendicular to every
codeword in C. That is,
C ⊥ = {x|x · c = 0∀c ∈ C}.

2
A generator matrix for C ⊥ is the transpose of a parity check matrix for C. We typically
use the variable G to denote a generator matrix and H to denote a parity check matrix.
A parity check matrix for the Hamming code is H T , where
 
0 0 0 1 1 1 1
H =  0 1 1 0 0 1 1 .
1 0 1 0 1 0 1

Note that the rows of H are the same as the first three rows of G, so for the Ham-
ming code, C ⊥ ⊂ C. Since all the rows of H are perpendicular to the rows of G,
the parity check matrix has the property that GH T = 0, which is important for error
correction.
The Hamming code is called a (7, 4, 3) code because it maps 4 bits into 7 bits and
has minimum weight 3. The code whose generator matrix is H is a (7, 3, 4) code. In
fact, every non-zero codeword has Hamming weight 4; this is not hard to see. And
knowing this, when we add the last row of G, we get a codeword where every word
except the zero codeword and the all-ones codeword has Hamming weight either 3 or 4.
How do we correct an error in the Hamming code? The Hamming code can correct
one error, which we will represent as a vector such as e = (0, 0, 1, 0, 0, 0, 0). If the
error is in a single bit, then only one coordinate of e will be 1 and the rest will be 0;
here, the error is in the third bit. Now, let us suppose we receive a coded message with
an error. This received message can be represented as r = mG + e. To correct the
error, we multiply by the matrix H T :

rH T = (mG + e)H T = eH T ,

since GH T = 0. The string eH T is called the syndrome, because this is what we use
to diagnose the error. Since e contains a single 1 in (say) the k’th position, eH will be
the k’th row of H T .
Let’s do an example.
Suppose we receive the noisy codeword (1, 0, 0, 1, 0, 1, 0). How do we find the
error? We multiply by H T , so
 
0 0 1
 0 1 0 
 
 0 1 1  
  
1, 0, 0, 1, 0, 1, 0  1 0 0 

 = 0, 1, 1
 1 0 1 
 
 1 1 0 
1 1 1

Now, rH T = 0, 1, 1 , which is the third row of H T . Thus, the third bit of our 
received codeword is in error. and the correct codeword is 1, 0, 1, 1, 0, 1, 0 .
Linear algebra shows that this is the encoding of message 1, 0, 1, 0
Recall that for the Hamming code, C ⊥ ⊂ C. A code with C ⊆ C ⊥ is called weakly
self-dual, and these codes are important for building quantum error-correcting codes.

3
So what is the quantum Hamming code? It will encode one qubit into seven qubits.
The logical |0i is the superposition of all eight of the codewords in H:
1 X
|0iL = √ |ci .
8 c∈H

The logical |1i is the superposition of the eight codewords that are in G and not in H.
These are the codewords of H XORed with the all 1’s vector:
1 X
|1iL = √ |c ⊕ 1111111i .
8 c∈H
.
Why does this correct an arbitrary one-bit error? To show this, it turns out that we
only need to show that it corrects a single σx error and a single σz error. Because this
code treats σx errors and σz errors separately, it will automatically correct a single σy
error, and from this we can deduce that it will correct an arbitrary single-qubit error.
(This was proven in the lecture notes on the nine-qubit code.)
Why does it correct one bit-flip error? This state is a superposition of elements of
the classical Hamming code, and we can apply the classical Hamming error correction
algorithm to each of these elements so as to correct a single bit-flip error. We do this
by computing the syndrome. If bi is the i’th bit, then the syndrome is:

(b4 ⊕ b5 ⊕ b6 ⊕ b7 , b2 ⊕ b3 ⊕ b6 ⊕ b7 , b1 ⊕ b3 ⊕ b5 ⊕ b7 ).

This can be computed by the following quantum circuit:

|ψi

|0i

|0i

|0i

Once the syndrome has been computed, the error needs to be determined and then
corrected. The determination of the error from the syndrome can be done classically.

4
Why does the Hamming code correct one phase-flip error? Recall that the Hadamard
gate H takes bit-flip errors to phase-flip errors and vice versa. So we need to compute
what happens when we apply a Hadamard gate to every qubit of the code. It turns out
that we get the same quantum code back. Thus, the circuit for measuring the syndrome
for phase flips is the same as the circuit for measuring the syndrome for bit flips, except
that we put seven Hadamard gates on the qubits in the quantum code at the front of the
circuit, and seven more at the back of the circuit. Alternatively, we can just use the
identity

H H

H H

to turn all the CNOT gates upside-down.


We haven’t actually done the calculations to show that H ⊗7 gives the same quan-
tum code back. Let’s see what happens when we apply the Hadamard transform to the
quantum code. We have
1 X
|0iL = √ |xi .
8 x∈H
Applying the Hadamard transform gives
1 1 X X
H ⊗7 |0iL = √ √ (−1)x·y |yi .
8 27 x∈H y∈Z 7
2

Now, we need to figure out what x∈H (−1)x·y|yi gives. If y ∈ G, then since every
P
element of G is orthogonal to every element of H, all the phases are +1, and we get
8 |yi. If y 6∈ G, then half of the phases will be −1 and half will be +1, so they cancel
out. Thus,
 
8 1 X 1 X X 1
H ⊗7 |0iL = √ √ |yi =  |yi + |yi = √ |0iL + |1iL )
7
8 2 y∈G 4 2
y∈H y∈G\H

What about H ⊗7 |1iL ? Here,

1 1 X X
H ⊗7 |1iL = √ √ x∈G\H (−1)x·y |yi .
8 2 7
y∈Z 7 2

If y 6∈ G, then the sum is 0 for the same reason. If y ∈ H, then the sum is 8 |yi, and if
y ∈ G \ H, the sum is −8 |yi. This is just because the inner product of two vectors in
G \ H is 1. Thus, we get
1
H ⊗7 |1iL = √ |0iL − |1iL )
2

5
So both H ⊗7 |0iL and H ⊗7 |1iL are states in our quantum Hamming code, and thus
bit-flip errors in H ⊗7 |0iL and H ⊗7 |1iL can be corrected by the error correction proce-
dure. This means that phase-flip errors of |0iL and |1iL can be corrected by applying
H ⊗7 , applying the bit-flip error correction procedure, and applying H ⊗7 again, and
we have shown that the quantum Hamming code is an error-correcting code that can
correct any single-bit error.
There is one last thing I want to say about the quantum Hamming code. How do
we apply a logical σx ? You can turn any codeword in H into a codeword in G \ H and
vice versa by adding the vector 1111111 (actually, adding any codeword in G \ H will
do). So the operation corresponding to a logical |0i is just σx⊗7 .
How do you apply a logical σz ? It turns out that you can apply a σz⊗7 . One way to
see this is using the fact that a Hadamard get applied to each qubit applies a Hadamard
gate to the logical qubit, and similarly a σx gate applied to each qubit also applies a
σx gate to the logical qubit. But you can also see it by realizing that σz⊗7 applies a +1
phase to any |yi for y ∈ H and a −1 phase to any |yi for y ∈ G \ H .

You might also like