Lite / Discovering How the World Works / Week 17
IF this, THEN that: how machines decide
A smart fan switches itself on when you walk into a hot room. Who told it what to do?
Why should I care?
Every automatic machine follows rules a person wrote: thermostats, automatic doors, robot vacuums. Writing those rules clearly, and noticing the situations they miss, is the heart of designing smart machines.
- Describe a machine's behaviour as sense → think → act.
- Write a decision rule using IF, THEN and ELSE.
- Combine conditions in a rule with AND, OR and NOT.
Predict
A fan's rule is: IF someone is in the room AND it's hotter than 26 °C THEN fan on. The room is 30 °C and empty. What happens?
- Fan on
- Fan off
- The fan can't decide
Guess first, then reveal
Fan off. AND needs both conditions; the room is hot but empty, so the condition is false and the rule does nothing (or, with an ELSE, turns the fan off). No energy wasted on an empty room.
Discover
Set someone in the room, 28 °C, window shut. Step through the flowchart and see where it ends. Then change one thing at a time. Can you make the fan finish on OFF in two different ways?
What the interactive shows (text version)
The decision runner shows a smart fan's flowchart as a list of steps: read the sensors; is someone in the room?; is it hotter than the limit?; is the window open?; then fan OFF, LOW or HIGH. You set the inputs, step through one question at a time, and each answer (yes or no) chooses the next step.
Understand
Sense, think, act
Smart machines repeat three steps: sense (read sensors: temperature, motion, light), think (apply rules to decide), act (switch motors, lights, heaters). Then they do it again, many times a second. The 'think' part is where your rules live.
IF … THEN … ELSE
A decision rule has a condition and actions:
IF temperature > 26 THEN fan on ELSE fan off.
The condition is always true or false: a single bit, just like a logic gate's output. Conditions can be combined: IF (someone home) AND (temperature > 26).
Careful with the edges
'Hotter than 26' and '26 or hotter' differ by just one value, but at exactly 26 °C they give different answers. Engineers check these edge cases on purpose. They also add a little gap (on above 26, off below 25) so the fan doesn't flick on and off when the room sits at 26.0.
Explain it another way
Intuitive
Rules are like the instructions you'd leave for a babysitter: 'IF they're hungry, THEN make a sandwich, ELSE let them play.' A machine follows them exactly, with no common sense to fill gaps.
Technical
A conditional evaluates a Boolean expression and selects a branch. In code: if (present && temp > limit) { fan = ON } else { fan = OFF }. Inside a loop, this becomes a simple controller: sense, evaluate, actuate, repeat.
Applied
Automatic doors: IF motion detected OR door button pressed THEN open; IF nothing detected for 5 seconds AND doorway clear THEN close. The 'doorway clear' check is a safety condition that was added after people got bumped.
Worked example 1
Write a rule for a night light that turns on when it's dark, but only if someone is in the room.
IF (NOT bright) AND (someone present) THEN light on ELSE light off. Check: dark + empty → off; dark + someone → on; bright + someone → off.
Common mix-ups
Smart machines understand what you want.
✓ They follow the exact rules they were given. If a situation wasn't thought of, the machine does whatever the rules happen to say.
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
Write IF/THEN/ELSE rules for an automatic pet door that should open for your pet's tag, never for other animals, and stay shut at night. Test your rules on four situations, including one tricky one.
Reflect
Think of a time a machine did something 'stupid'. What rule might it have been following?
Write your answer on paper or in your own notes. Lite never stores what you write.