Skip to content

True and False

A question has exactly two answers, so you can write down every case there is and stop guessing.

Every question a program asks has exactly two answers. lives > 0 is either true or it is false. There is no third thing it can be.

That sounds too obvious to be useful. It is the most useful fact in this module, because it means you can write down every case there is and know the list is complete.

The complete map

Take one question. Call it alive. It can be true or it can be false, and that is all.

Write both down:

alivealive
00
11
Two rows, because there are two cases. 0 means false and 1 means true, which is how these tables have always been written.

That grid is a truth table. The left-hand column lists every case, and the columns to the right say what comes out.

Two rows is not much of a map. It matters because of what it promises: there is no case missing. Anything you can say about alive has to be true of one of those rows, and you can check both.

NOT turns it round

NOT alive is the question turned round. Where alive is true, NOT alive is false.

alivealiveNOT alive
001
110
Read across a row. When alive is 0, NOT alive is 1.

Read the table a row at a time. Pick a row, follow it across, and it tells you what happens in that case. Read it a column at a time and you see the whole behaviour of one test at once.

Both readings are useful, and the second is the one that is hard to do in your head.

Why bother writing it down

You did not need a grid to know that NOT flips an answer. For one question, the table is overkill.

The reason to learn it now is that questions do not stay single. Add a second and you have four cases. Add a third and you have eight. That is where being sure stops being possible by staring at the line, and a table stops being overkill.

The rule is worth remembering: each question doubles the rows. One question is two rows, two questions are four, three are eight.

When it’s wrong, see why

  • The table has the wrong number of rows. Count the questions. One is two rows, two is four, three is eight. A missing row is a case you have not thought about.
  • A row repeats. Then it is not a list of every case; something has been written down twice and something else left out.
  • You cannot decide what a row should say. That usually means the question is two questions. Split it and give each its own column.

What you’ve learnt

  • A question has exactly two answers, so the list of cases is always finite.
  • A truth table writes down every case and what comes out of each.
  • 0 is false and 1 is true.
  • NOT turns an answer round.
  • Each extra question doubles the number of rows.

What’s next

One question is a short table. In Unit 2 we put two of them side by side and look at the three ways of joining them.