Lite / Building Machines That Respond / Week 1
Trace every case with a rule table
A sorting machine reads three yes/no sensors. How many situations must its rules cover, and what happens in the one you forgot?
Why should I care?
Machines meet every possible input eventually, including the ones nobody imagined. A rule table that lists every combination is a simple, powerful way to make sure an algorithm never reaches a case with no answer.
- Count the input combinations a decision must handle.
- Write a complete rule table so every combination has a defined action.
- Use hand tracing of unusual inputs to find gaps in an algorithm.
Predict
A machine reads three yes/no sensors: red?, large?, metal?. How many different combinations can it see?
- 3
- 6
- 8
Guess first, then reveal
Each sensor doubles the number of cases: 2 × 2 × 2 = 8. A rule table with fewer than 8 rows leaves some situation undefined.
Discover
Open the sorting machine at Level 2 and turn the client's brief into the full 8-row rule table: one bin for every combination of red, large and metal. Before you run it, trace two unusual parts by hand (a small red metal part, a large non-red plastic part) and predict their bins.
What the interactive shows (text version)
The sorting machine's Level 2 task is a table with 8 rows, one per combination of red (yes/no), large (yes/no) and metal (yes/no). For each row you choose a bin. The lesson can be done on paper: list the 8 combinations, apply the client's brief to each, and check every row has exactly one bin.
Understand
Count the cases first
With k yes/no inputs there are 2^k combinations: 2, 4, 8, 16, … An input with m settings (a selector switch) multiplies the count by m. Counting tells you how many rows a complete rule table, or a complete set of tests, needs.
A rule table is an algorithm
Each row says: for this combination of inputs, do this. Because the rows cover every combination, there is no situation in which the machine has to guess. A rule table is also the easiest way to show a client exactly what the machine will do.
Trace the strange cases
Bugs hide in combinations nobody pictured: a part that is red and metal, a sensor that says large and small at once. Pick the oddest inputs and trace the algorithm by hand. If you cannot say what it does, the algorithm is incomplete.
Explain it another way
Intuitive
Like checking every door and window before leaving home: you go through them all, not just the ones you usually use.
Technical
A decision over k Boolean inputs is a function from 2^k input combinations to actions. A truth (rule) table enumerates that function completely. Exhaustive testing is feasible when the input space is this small.
Applied
Safety interlocks on industrial machines are specified with tables like this, then every row is tested. In the sorting machine, a forgotten row means a part ends up in the wrong bin or jams the belt.
Worked example 1
Brief: 'Metal parts go to bin A. Large non-metal parts go to bin B. Everything else goes to bin C.' Which bin gets a small red plastic part?
Not metal (so not A), not large (so not B), so bin C. Tracing each rule in order gives one clear answer, so this row is defined. Do this for all 8 rows to prove the brief is complete.
Common mix-ups
Testing the usual cases proves an algorithm works.
✓ Usual cases are where it was designed to work. Proof comes from covering every case, or at least the strange and boundary ones.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Finish the sorting machine's Level 2 rule table and run it. Then add a fourth sensor (wet?) to the brief and work out how many rows the new table needs and which bin wet parts should go to.
Reflect
Which row of your rule table did you nearly forget, and why was it easy to miss?
Write your answer on paper or in your own notes. Lite never stores what you write.