ViewWiki

Lesson 1 of 5

Surprise measured in bits.

About 20 minutes · 5 practice questions

What the word information means in computer science: how much uncertainty a message removes, why a fair coin flip carries one bit, and why a rare outcome is more surprising.

Step 1 of 5 · What information is

Step 1 of 5

What information is

A machine flips coins and prints each flip on a tape: 11⁠ for heads, 00⁠ for tails. Before each flip you do not know what the next digit will be, and after it you know exactly. That change, from not knowing to knowing, is what computer science calls information.

This definition, Claude Shannon’s from 1948, does not ask whether a message is important, true or interesting. It asks only how much uncertainty the message removes: how much you did not know before it arrived. A message you could have guessed in advance tells you nothing.

To the question

Step 2 of 5

One bit

Uncertainty is measured in bits. One bit is the answer to one yes-or-no question when both answers are equally likely: exactly what a fair coin gives.

Shannon measured the surprise of an outcome with probability pp⁠ like this:

−log⁡2p=log⁡21p-\log_2 p = \log_2 \frac{1}{p}⁠

log⁡2x\log_2 x⁠ is the power you must raise 22⁠ to in order to get xx⁠. For example, log⁡28=3\log_2 8 = 3⁠, because 23=82^3 = 8⁠. Chance of heads is now fixed at 50%. Work out how much surprise a heads carries.

To the question

Step 3 of 5

A biased coin

Now the coin is biased, and lands heads nine flips out of ten. Watch the tape: it fills with 1s, and you could have written most of it without looking at the coin.

When an outcome is expected, it adds almost no knowledge. When it surprises, it adds a lot. Rare events are big news.

To the question

Step 4 of 5

Every halving is a bit

The formula log⁡21p\log_2 \tfrac{1}{p}⁠ says something simple: every time an outcome’s chance is halved, its surprise grows by one bit. An outcome with chance 12\tfrac12⁠ carries one bit, one with chance 14\tfrac14⁠ two, and one with chance 18\tfrac18⁠ three.

That is also the number of bits it takes to record the outcome: to tell four equal possibilities apart, two binary digits are enough, 00, 01, 10 and 11. And the surprises of independent flips add: two fair flips carry two bits.

To the question

Step 5 of 5

Rare news

Measure and compress is at Entropy: the glass board shows the surprise of each face of the coin. Change Chance of heads and watch the surprise of heads grow as it becomes rare, and shrink as it becomes expected.

To the question

Still of the Information and entropy 3D scene
Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Choose

Two messages reach you. The first says “The sun rose this morning”. The second gives the result of a fair coin flip. Which carries more information, in Shannon’s sense?

To the experiment

Practice · Calculate

The coin is fair: Chance of heads is fixed at 50%. The surprise of an outcome with probability pp⁠ is −log⁡2p-\log_2 p⁠ bits. How many bits of surprise does heads carry?

To the experiment

Practice · Predict, then look

Now the coin is biased: it lands heads in 90% of flips. Which face carries more surprise? Choose, and then Measure and compress moves to Entropy and shows the surprise of each face.

To the experiment

Practice · Calculate

Chance of heads is now fixed at 25%. How many bits of surprise does heads carry?

To the experiment

Practice · Reach the target

Tails on a 90% coin carries log⁡210≈3.32\log_2 10 \approx 3.32⁠ bits. Change Chance of heads until heads carries exactly the same surprise, then press Check.