Basis Lab

Bytes, Text and File Formats

Making It Smaller

Last timeRows, Columns and the Separator Problem

Compression removes repetition, so what a file compresses to is a measure of how repetitive it was. The ratio is the number worth knowing before deciding it was worth doing.

Repetition is what is removed

Every exact compressor does two things. It replaces a run that has appeared

before with a short reference to where it appeared, and it gives the commonest

symbols shorter codes than the rare ones. Both are ways of removing repetition,

and neither invents anything.

So whether a file shrinks is a question about the file. English text repeats

heavily, in letters, in words and in phrases, and compresses to about a third.

A table of a column's worth of the same country code repeated a million times

compresses to almost nothing. A file of already compressed video has had its

repetition removed already and will not shrink again, and a file of random bytes

has no repetition to remove and cannot shrink at all.

FIG 1
what is being compressedsize afterwards, as a percentage of the size before
English proseabout 33
the same table written out column by columnabout 8
source codeabout 25
a photograph that is already compressedabout 99
random bytes100

These are rough figures from ordinary files rather than measurements of

anything in particular, and the shape is what matters. The second row is why

the previous lesson and this one belong together: a column holds values of one

kind, so values next to each other repeat, and the same table written column by

column compresses several times better than the same table written row by row.

The last row is the honest limit. Nothing shrinks random data, and any claim to

the contrary is a claim to have got something from nothing.

The last row deserves one more sentence, because it is a proof rather than an

observation. If a method shrank every file, then applying it repeatedly would

shrink every file to one byte, and one byte cannot be unpacked into every

possible file. So any compressor makes some inputs larger, and the ones it makes

smaller are exactly the ones with repetition in them.

The ratio

The ratio is the size before divided by the size after. Two means half as large,

ten means a tenth. Because time to send is size divided by speed, the ratio

divides the transfer time directly, which makes the ratio you need something to

compute rather than guess.

The lesson stops here

4 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Everything Is a Run of Bytes
  2. 02Counting in Twos and Sixteensopening only
  3. 03Letters as Numbersopening only
  4. 04Whole Numbers, and Where They Stopopening only
  5. 05Numbers With Fractions In Themopening only
  6. 06Dates, Times, and the Day It Movedopening only
  7. 07Rows, Columns and the Separator Problemopening only
  8. 08Making It Smalleryou are here

Read alongside