Two Ways to Build AI: Rules and Learning
Compare rule-based AI with machine learning, see the strengths and weaknesses of each, and decide which approach fits a given real-world problem.
Welcome back!
Step 1 of 12Learn
Two ways to catch a spam email
Imagine you have to build a spam filter in 2003. You have two broad options.
Option 1: write rules. You sit down with experts and write instructions. If the subject contains "FREE MONEY", add 3 points. If the sender's address is a random string of letters, add 2 points. If the email contains more than five exclamation marks, add 1 point. If the total exceeds 5, mark as spam. This is the rule-based or symbolic approach.
It works at first. Then spammers adapt. They write "FR33 M0NEY", use realistic-looking addresses, and drop the exclamation marks. You add more rules. They adapt again. Soon you have thousands of rules that interact in confusing ways, and real emails from your bank start landing in spam.
Option 2: learn from examples. You collect a million emails that users have already marked as spam or not spam. You let an algorithm find the patterns that separate the two groups: words, links, sending times, formatting, and combinations no person would think to check. When spammers change tactics, users mark the new emails, and you retrain the model on fresh examples. This is machine learning.
Modern spam filters lean heavily on learning, often combined with a few simple rules, such as blocking known malicious links. The comparison captures the central shift in AI: from telling computers how to do a task to showing them examples of the task done.
Step 2 of 12Compare
Rule-based AI vs. machine learning
| Aspect | Rule-based (symbolic) AI | Machine learning |
|---|---|---|
| How it gets its behavior | People write explicit if-then rules | An algorithm finds patterns in example data |
| What it needs | Expert knowledge and programming time | Lots of relevant, good-quality data and computing power |
| Explaining a decision | Easy: you can point to the rule that fired | Often hard, especially for large neural networks |
| Handling messy input | Poor: images, speech and slang break rules | Strong, if the training data covered similar cases |
| Adapting to change | Someone must rewrite the rules | Retrain on new data |
| Typical failure | Brittle: breaks on cases nobody anticipated | Learns the wrong pattern or copies bias in the data |
Step 3 of 12Practice · Sort into groups
For each problem, which approach is the better fit?
Tap an item, then tap its group (or drag it there).
Step 4 of 12Learn
The strengths rules still have
It would be easy to conclude that rules are obsolete. They are not. Rule-based logic still runs much of the world's critical software, and for good reasons.
Rules are predictable. If a bank's software must reject any transfer above a legal limit, you want a rule that does exactly that every time, not a model that does it 99.7% of the time.
Rules are explainable. When a rule-based system denies something, you can show the exact rule. In regulated areas such as lending, insurance and healthcare, being able to explain decisions can be a legal requirement.
Rules need no training data. A brand-new policy can be enforced on day one, before any examples exist.
Machine learning shines in the opposite conditions: when the input is messy, the patterns are subtle, plenty of examples exist, and an occasional error is acceptable or can be caught by a person.
Many real systems are hybrids. A self-driving car uses learned models to recognize pedestrians and lane markings, then hard rules such as never exceed the speed limit and stop at red lights on top. A fraud system uses a model to score transactions and rules to block anything from a sanctioned country. A chatbot uses a learned language model but may run rule-based filters to block certain content.
A good question to ask about any AI product: which parts are learned and which parts are rules? The answer tells you where to expect flexibility and where to expect surprises.
Step 5 of 12Practice · Choose one
A hospital wants software that alerts staff whenever a patient's recorded temperature exceeds 104°F. Which approach fits best?
Step 6 of 12Practice · Diagram
Rules or learning? Two questions decide
Before choosing an approach, ask: could a person write the rules down, and do we have plenty of labeled examples?
Where does "transcribing millions of recorded voicemails, with human transcripts available" belong?
Tap the shape that answers the question, then press Check.
- Machine learning
Rules are impossible to write, but there are lots of examples to learn from: recognizing speech or photos.
- Rules (data is a bonus)
A clear policy exists. Use rules; data can still help check them.
- Collect data, keep humans
Neither option works yet. Let people decide while you gather examples.
- Rules
Tax tables, password length checks, refund windows.
Step 7 of 12Learn
Other branches of the AI family
Rules and learning are the two big styles, but AI researchers have built other important tools along the way, and many are still in daily use.
Search and planning. Many problems can be framed as searching through possible moves for a good sequence. A navigation app searches a graph of roads for the fastest route. A chess engine searches millions of future positions per second. Logistics software plans delivery routes and warehouse picking orders. These methods don't learn from data in the usual sense; they explore options systematically and score them.
Optimization. Airlines schedule crews, factories plan production and power companies balance supply using algorithms that find the best answer under constraints. This is AI-adjacent math that rarely makes headlines.
Probabilistic reasoning. Systems that weigh uncertain evidence, such as a diagnostic tool that updates the likelihood of a fault as each test result arrives, use probability theory to reason under uncertainty.
Knowledge graphs. Search engines store facts as connected entities, such as a city linked to its country, population and landmarks, so they can answer questions directly.
The most capable modern systems combine several of these. AlphaGo paired deep neural networks, which judged positions, with a search algorithm that explored possible moves, and improved through reinforcement learning by playing millions of games against itself. Modern AI assistants often combine a language model with search tools, calculators and databases, because each tool covers the others' weaknesses.
Step 8 of 12Practice · Match the pairs
Match each AI technique to a typical use.
Tap an answer, then tap the place where it belongs (or drag it there).
- Search and planning
- Rule-based system
- Machine learning
- Optimization
- Probabilistic reasoning
Step 9 of 12Note
Step 10 of 12Diagram
The AI toolbox
Tap a shape with to see more.
- Artificial intelligence
- Rule-based (symbolic)
Explicit if-then knowledge written by people.
- Expert systems
- Search and planning
Explores possible moves or routes to find a good sequence.
- Optimization
Finds the best schedule or plan under constraints.
- Probabilistic reasoning
Updates beliefs as evidence arrives.
- Machine learning
Learns patterns from example data.
- Deep learning
Machine learning with many-layered neural networks.
- Large language models
Step 11 of 12Practice · True or false
Because machine learning is more modern, it is always a better choice than writing rules.
Step 12 of 12Practice · What would you do?
What would you do?
A small online store wants to stop fraudulent orders. It has 200 past orders, three of which were fraud. The owner asks whether to train a machine learning model. What is the best advice?
Lesson complete!