games, hats, and codes mira bernstein wellesley college sums 2005

104
Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Upload: aileen-georgiana-king

Post on 23-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Games, Hats, and Codes

Mira Bernstein

Wellesley College

SUMS 2005

Page 2: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A game with hats (N=3)

Each player is randomly assigned a red or blue hat.

Page 3: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A game with hats (N=3)

Each player can see the color of his teammates’ hats but not his own.

Page 4: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A game with hats (N=3)

BLUE REDPASS

Players simultaneously guess the colors of their own hats. Passing is allowed.

Page 5: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A game with hats (N=3)

BLUE REDPASS

At least one correct guessNo incorrect guesses

WIN!

Page 6: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Some observations

• A player gets NO information about his own hat from looking at his teammates’ hats

• NO strategy can guarantee victory

• Easy strategy: one player guesses, everyone else passes.

• Can the players do better than 50%?

Page 7: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A better strategy for N=3

Instructions for all players:

If you see two hats of the same color, guess the other color.

If you see two different colors, pass.

Page 8: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses#1 #2 #3

Page 9: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED

#1 #2 #3

Page 10: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED

BLUE

#1 #2 #3

Page 11: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED

BLUE

RED

#1 #2 #3

Page 12: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED

BLUE

RED

BLUE

#1 #2 #3

Page 13: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED RED

RED

BLUE

RED

BLUE

BLUE BLUE

#1 #2 #3

Page 14: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED RED RED

RED

RED

BLUE

RED

BLUE

BLUE

BLUE BLUE BLUE

#1 #2 #3

√√√√√√

X

X

Page 15: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

√√√√√√

X

X

Probability of winning:

75%

•How is this possible?

•Can we do better?

•What about N >3?

Page 16: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Possible hatconfigurations

Guesses

RED RED RED

RED

RED

BLUE

RED

BLUE

BLUE

BLUE BLUE BLUE

#1 #2 #3

Page 17: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

6 correct guesses

6 incorrect guesses

# correct = # incorrect

RED RED RED

RED

RED

BLUE

RED

BLUE

BLUE

BLUE BLUE BLUE

#1 #2 #3

Guesses

Page 18: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Why?

The same instructions that lead to a correctguess in one situation…

… will lead to an incorrect guess in another.

BLUE

Player #3

BLUE

Player #3

Page 19: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

In general…

If the game is played once with each possible configuration of hats, then

# correct guesses = # incorrect guesses

True for any number of people N

True for any deterministic strategy S

Page 20: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Why does the N=3 strategy work?

It takes only one correct guess to win!

Strategy:

Spread out the good guesses.

Concentrate the bad guesses.

#1 #2 #3

Page 21: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

In general…• When played over all hat combinations

with N players, any strategy produces k correct guesses and k incorrect guesses. (The value of k depends on the strategy.)

• Best possible guess arrangement:– 1 correct guess per winning combination– N incorrect guesses per losing combination

• A strategy which achieves this is called a perfect strategy.

Page 22: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Do perfect strategies actually exist?

N = 3: Yes!

Other N?

#1 #2 #3

Page 23: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Some terminology

H: set of all possible hat configurations

(sequences of 0s and 1s)

Distance in H: number of places in which two elements of H differ.

1 0 0 1 0 1 1 0 1

1 0 1 1 0 1 0 0 1

Distance: 2

Page 24: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Some terminology

Ball of radius r around h H: the set of allconfigurations whose distance from h is at most r.

h: 1 0 0 1

B1(h): 0 0 0 1 1 1 0 1 1 0 1 1

1 0 0 0 | B1(h)| = N+1 center 1 0 0 1

Page 25: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Some terminology

• S: a (deterministic) strategy

• L: set of all hat configurations where a team playing according to S loses

• W: set of all hat configurations where a team playing according to S wins

L W = H

Page 26: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

An important fact

Suppose h and h’ are elements of H that differ only in the i th entry.

If, according to strategy S, Player i guesses correctly in h, then he guesses incorrectly in h’, and vice versa.

4th player’s guess

h: 0 1 0 0 1 0 √

h’: 0 1 0 1 1 0 X

Page 27: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Corollaries

Theorem 1: Every element h W is within distance 1 of some element of h’ L.

Proof: Suppose Player j guesses correctly in h. Let h’ be the hat configuration that differs from h only in the j th entry. Then Player j must guess incorrectly in h’, so h’ is in L.

Page 28: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Corollaries

Theorem 2: In a perfect strategy S, every element h W is within distance 1 of exactly one element of L.

Proof: Suppose h differs from h1 L in the i th entry and from h2 L in the j th entry. Since S is a perfect strategy, all players guess incorrectly in h1 and h2. But then Players i and j must both guess correctly in h, which cannot happen in a perfect strategy.

Page 29: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Corollaries

In other words….

Theorem 1: Every element h H is contained in a ball of radius 1 around some element of L.

Theorem 2: In a perfect strategy S, the balls of radius 1 around elements of L do not overlap.

Page 30: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Codes

A perfect code of length N is a subset L in H such that the balls of radius 1 around points of L

• include all of H

• do not overlap

A perfect strategy yields a perfect code!

Page 31: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

H

A perfect code

Page 32: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

H

= points of L

A perfect code

Page 33: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

H

= points of L

A perfect code

Page 34: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Perfect code perfect strategy

Instructions for Player i:

– If the hat configuration might be in L:

Guess so that if it’s in L, you’ll be wrong.

– If you can tell that the hat configuration is not in L: Pass

Page 35: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Results (for hat configuration h):– If h is in L: Every player guesses wrong.

– If the hat configuration h is not in L:

There is a unique element h’ of L which differs from h in one place -- say the i th place.The i th player can’t tell if the

configuration is h or h’, so he guesses away from h’, correctly. All others pass.

Perfect code perfect strategy

Page 36: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

000

111

100

010

001 101

110

011

Example: N=3

L = {000,111}

Page 37: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Example: N=3

L = {000,111}

000

111

100

010

001 101

110

011

Page 38: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Instructions for Player i:

– If the hat configuration might be in L, guess so that if it’s in L you’ll be wrong.

Translation: If you see two 0’s or two 1’s, guess the opposite number.

Example: N=3

L = {000,111}

Page 39: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Instructions for Player i:

– If you can tell that the hat configuration is not in L, pass.

Translation: If you see two different numbers, pass.

Example: N=3

L = {000,111}

Page 40: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

How good are perfect strategies?

Theorem: If S is a perfect strategy for N players then the probability of winning is N/N+1.

Proof: In every ball, N out of the N+1 points correspond to winning configurations.

Example: If N=3, the probability of winning with a perfect strategy is ¾. There can be no better strategy than the one we found.

Page 41: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Do perfect codes exist for N>3?

Theorem: A perfect code of length N can exist only if N=2m-1 for some integer m.

Proof: A perfect code splits H into disjoint balls of radius 1. Each of the balls has N+1 points and H has 2N points, so 2N is divisible by N+1. Thus N+1 is a power of 2, so N=2m-1.

Example: We know a perfect code of length 3 = 22-1. But what about 7, 15, 31,…?

Page 42: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

11010…

11010…

I love you too!

Page 43: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

11010…

10010…

You what?

Page 44: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

1001100

Page 45: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

1001100

1000100

Page 46: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

1001100

1000100

Page 47: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Error-correcting codes

I love you!

I love you too!

1001100

1001100

Page 48: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

RulesTake any number of stones

from any one pile

A B

Page 49: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

RulesWhoever takes the last stone wins the game

A B

Page 50: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Page 51: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Page 52: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Page 53: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Page 54: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Two equal piles: bad news for whoever is next to move.

Page 55: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

Two equal piles: bad news for whoever is next to move.

Page 56: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

From now on, B simply imitates A’s moves…

Page 57: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

From now on, B simply imitates A’s moves…

Page 58: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

From now on, B simply imitates A’s moves…

Page 59: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

From now on, B simply imitates A’s moves…

Page 60: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A different game: Nim

A B

WINLOSE

… so B is guaranteed to take the last stone.

Page 61: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Nim is…

• Combinatorial: no element of chance

• Impartial: same moves available to each player

• Finite: must end after a finite number of moves

In any Nim position, exactly one of the players has a winning strategy.

Page 62: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Who wins?

P-position: Previous player wins

N-position: Next player wins

e.g. the empty game is a P-position

e.g. two equal piles is a P-position

e.g. two unequal piles is an N-position

Nim strategy: Figure out which positions are P-positions and move to them!

Page 63: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

More on P and N

P-position: cannot move to a P-position; move only to an N-position (or not at all)

N-position: can move to at least one P-position

If you combine two Nim games into one:• P + P = P: cannot move to another P+P• N + P = N: can move to P+P• N + N = ? (depends on the games)

Page 64: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Position vectors

A Nim position with all heaps of size N can be described by a vector of length N.

(1,0,0,2,3)1 heap of size 52 heaps of size 23 heaps of size 1

Page 65: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Position vectors

Two equal heaps are a P-position, so we can ignore them (P+P=P, N+P=N).

(1,0,0,2,3)1 heap of size 52 heaps of size 23 heaps of size 1

Page 66: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Position vectors

Thus we can replace all the entries in the position vector with 0’s and 1’s.

Binary vector

1 heap of size 52 heaps of size 23 heaps of size 1

(1,0,0,0,1)

Page 67: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Legal moves

Let X, Y be binary position vectors for Nim.

One can move from X to Y if• X >Y (as binary numbers)• Distance from X to Y is 1 or 2

Examples:

1 0 1 0 1 1

Page 68: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Legal moves

Let X, Y be binary position vectors for Nim.

One can move from X to Y if• X >Y (as binary numbers)• Distance from X to Y is 1 or 2

Examples:

1 0 1 0 0 1

Page 69: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Legal moves

Let X, Y be binary position vectors for Nim.

One can move from X to Y if and only if• X >Y (as binary numbers)• The distance from X to Y is 1 or 2

Examples:

1 0 1 0 0 0

Page 70: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P and N: review

P-position: cannot move to a P-position; move only to an N-position (or not at all)

N-position: can move to at least one P-position

Page 71: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P and N revisited

Theorem: The distance between two P-position vectors is ≥ 3.

Proof: If the distance were 1 or 2, you could move from the larger vector to the smaller one. However, it is impossible to move from a P-position to a P-position.

Corollary: Balls of radius 1 around P-positions do not overlap.

Page 72: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P and N revisited

Theorem: Any vector X with distance ≥ 3 from all smaller P-positions is a P-position.

Proof: Since you cannot move from X to any P-position, X itself must be a P-position.

Corollary: We can look for P-positions inductively.

Page 73: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

How to look for P-positions

• Start with (…,0,0)

• At each step, look for the next smallest sequence that has distance ≥ 3 from every previously-found P-position.

• The preceding theorems guarantee that this procedure will give you all and only P-positions!

Page 74: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Why look for P-positions?

• To win at Nim.

• The set of all P-positions with heaps of size N will give us non-overlapping balls of radius 1. If N=2m-1,we may get a perfect code.

• To find perfect strategies for the hat game.

Page 75: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 Start with 0

0 0 0 0 1 1 1 Smallest v with three 1’s

0 0 0 1 ? ? ? Impossible!

Page 76: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 Start with 0

0 0 0 0 1 1 1 Smallest v with three 1’s

0 0 1 0 ? ? ? Impossible!

Page 77: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 Start with 0

0 0 0 0 1 1 1 Smallest v with three 1’s

0 0 1 1 ? ? ?

Page 78: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 Start with 0

0 0 0 0 1 1 1 Smallest v with three 1’s

0 0 1 1 0 0 1 Next smallest

0 0 1 1 ? ? ?

Page 79: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 ? ? ?

Page 80: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 0 ? ? ? Impossible!

Page 81: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 ? ? ?

Page 82: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 ? ? ? ? ?

Page 83: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 84: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

Can we have any other P-positions that begin

0 1 X X X X X ? D

Then we would have D+A, D+B, etc: 16 total

Can we have 16 P-positions with heaps 6?

(16 balls of radius 1) (7 points per ball) > 26

Impossible!

Page 85: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 86: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0 1 0 0 0 ? ? ?No!

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 87: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0 1 0 0 1 ? ? ?

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 88: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 D

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 0 1 1 1 1 0 A+B

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 89: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 D

0 0 0 0 1 1 1 A 1 0 0 1 1 0 0 D+A

0 0 1 1 0 0 1 B 1 0 1 0 0 1 0 D+B

0 0 1 1 1 1 0 A+B etc.

0 1 0 1 0 1 0 C

0 1 0 1 1 0 1 C+A

0 1 1 0 0 1 1 C+B

0 1 1 0 1 0 0 C+A+B

Page 90: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

P-positions for heaps of size 7

16 P-positions

8 points per ball A perfect code!

128 = 27 points

A vector space over 2 with basis

0 0 0 0 1 1 1 A

0 0 1 1 0 0 1 B

0 1 0 1 0 1 0 C

1 0 0 1 0 1 1 D

Page 91: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

The Hamming Code for N=7

Our code is the kernel of the matrix

1 1 1 1 0 0 0

A = 1 1 0 0 1 1 0

1 0 1 0 1 0 1 over 2

The columns are the numbers 1-7 in binary!

This code is called the Hamming Code.

Page 92: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

The Hamming Code for N=7

A quick way to check if v ker(A):• Record the numbers corresponding to

the positions where v has a 1• Write these numbers in binary, with

leading zeros if necessary• Add the numbers as binary vectors:

1+1 = 0, no carry!• v ker(A) iff you get 0

Page 93: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

The Hamming Code for N=7

Example: v = ( 1 0 1 0 0 0 1 )

v has 1’s in positions 7,5,1

7 = 1 1 1

5 = 1 0 1

1 = 0 0 1 padding

0 1 1 addition with no carry

The answer is not 0, so v is not in the code.

Page 94: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Finding the nearest code vector

v = ( 1 0 1 0 0 0 1 )

Which coordinate of v should we change?

• When we “added” 7,5, and 1, we got 0 1 1.

• If we change the “3” coordinate of v from 0 to 1, we’ll have to “add” another 0 1 1.

• 0 1 1 + 0 1 1 = 0 0 0 !

v’ = ( 1 0 1 0 1 0 1 ) is in the code.

Page 95: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

The Hamming Code for N=2m-1

Let A be the mN matrix whose columns are the numbers 1 through N, written in binary.

For N=15:

1 1 1 1 1 1 1 1 0 0 0 0 0 0 0

A = 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0

1 1 0 0 1 1 0 0 1 1 0 0 1 1 0

1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

ker(A) is called the Hamming code of length N.

Page 96: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

The Hamming Code for N=2m-1

Every N-vector v is within distance 1 of exactly one code vector v’.

A(v), read as a binary number, gives the coordinate in which v and v’ differ!

The Hamming code is a perfect code, which makes error-correction especially simple!

Page 97: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Homework

• Prove that the Hamming Code really is perfect and that A(v) gives the coordinate of the error.

• Using the Hamming code, find a practical strategy for Nim.

• Using the Hamming code, find a practical strategy for the hat game for 7 players.

Page 98: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A bit more about codes

Not all codes are perfect: – In a general error-correcting code, the balls

around the code points are disjoint, but do not necessarily include every point in the space.

– In a general covering code, the balls cover the whole space, but may overlap.

– A perfect code is both an error-correcting code and a covering code.

Page 99: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

A bit more about codes

• In a general error-correcting code, the balls around the code points may have radius r>1.

• The Hamming codes are (essentially) the only perfect codes with radius 1.

• The is only one other perfect code: the Golay code for N=23, with radius 3.

Page 100: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

Lexicodes

We used the P-positions of a game (Nim)

to construct a code (the Hamming code).

In general, the P-positions of many impartial games correspond to well-known codes!

These can be constructed in increasing lexicographic order, starting at 0 -- hence the name lexicodes!

Page 101: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005

References

• Lexicographic Codes: Error-Correcting Codes from Game Theory, John H. Conway and N.J.A. Sloane, IEEE Trans. Inform. Theory, 1986

http://www.research.att.com/~njas/doc/lex.pdf

• On Hats and Other Covers, H. Lenstra and G. Seroussi, 2002 (preprint)

www.hpl.hp.com/infotheory/hats_extsum.pdf

Page 102: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005
Page 103: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005
Page 104: Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005