I4 · Problem Solving and Reasoning: Classical AI

Knowledge Representation and Expert Systems

Knowledge representation is how facts and rules about a domain are stored so a computer can reason with them, using structures such as rules, semantic networks, frames, ontologies and knowledge graphs. An expert system is a program that captures a human expert's knowledge, usually as if-then rules in a knowledge base, and uses an inference engine to reach conclusions and explain its reasoning.

12 min Intermediate · Sublevel Intermediate Jump to the activity

What you need: The earlier topics of this module.

Definition

In the 1970s, a program called MYCIN suggested antibiotics for blood infections and, in tests, did about as well as specialist doctors. It knew nothing about learning from data. It had about 600 rules written by experts.

Knowledge representation is how facts and rules about a domain are stored so a computer can reason with them, using structures such as rules, semantic networks, frames, ontologies and knowledge graphs. An expert system is a program that captures a human expert's knowledge, usually as if-then rules in a knowledge base, and uses an inference engine to reach conclusions and explain its reasoning.

In simple words

An expert system is like an experienced doctor's notebook turned into a program: "if the patient has a fever and a stiff neck, consider meningitis". The program asks questions, follows the rules and can tell you which rules led to its advice.

Overview

  • Knowledge representation is how an AI system stores facts and rules so it can reason with them.
  • An expert system captures a human specialist's knowledge as rules and draws conclusions from facts.
  • Its main parts are a knowledge base, an inference engine, working memory and an explanation facility.
  • MYCIN (1970s, Stanford) diagnosed blood infections with about 600 rules and could explain its reasoning.
  • The knowledge-acquisition bottleneck, getting experts' knowledge into rules, limited classic expert systems.
  • Knowledge graphs and rules are still used today, often combined with machine learning.

Why it matters

Expert systems were AI's first big commercial success, and their ideas live on in business rule engines, tax and eligibility software, medical guidelines and knowledge graphs that power search. Their strengths and failures explain why modern AI combines learned models with structured knowledge.

Key terms

Knowledge base
The stored facts and rules about a domain.
Inference engine
The part that applies rules to facts to derive conclusions.
Forward and backward chaining
Reasoning from facts towards conclusions, or from a goal back to the facts needed.
Semantic network
A graph of concepts linked by labelled relations such as is-a and part-of.
Ontology
A formal description of the concepts in a domain and how they relate.
Knowledge graph
A large network of entities and relationships, such as (Delhi, capital of, India).

Types

Knowledge can be represented in several types of structure, each suited to different kinds of reasoning.

1. Production rules (if-then rules)

Knowledge written as IF conditions THEN conclusions or actions.

  • How it works: An inference engine matches rules against facts in working memory, using forward or backward chaining, and fires those that match.
  • Example: IF fever AND rash AND low platelets THEN suspect dengue.
  • When to use it: Use them when expert knowledge is clear and explainability matters, as in eligibility checks and diagnostics.

2. Semantic networks and knowledge graphs

Graphs whose nodes are concepts or entities and whose labelled edges are relations.

  • How it works: Edges such as is-a and part-of let properties be inherited; modern knowledge graphs store billions of facts as (subject, relation, object) triples.
  • Example: (Taj Mahal, located in, Agra); (Agra, in state, Uttar Pradesh); Google's Knowledge Graph behind search info boxes.
  • When to use it: Use them for linked facts, search, question answering and grounding chatbots.

3. Frames and object-oriented representations

Structures with named slots and default values describing typical objects or situations.

  • How it works: A frame for Restaurant has slots such as cuisine, price range and opening hours; specific restaurants inherit defaults and override them.
  • Example: A Bird frame with can_fly = yes by default, overridden for a penguin.
  • When to use it: Use them to represent typical knowledge with exceptions, much like classes and objects in programming.

4. Ontologies

Formal, shared definitions of the concepts in a domain and the relations between them.

  • How it works: Written in languages such as OWL, they define classes, properties and constraints so that different systems agree on meaning.
  • Example: SNOMED CT, a medical ontology with hundreds of thousands of concepts used in health records.
  • When to use it: Use them when many organisations or systems must share and exchange data consistently.

5. Logic-based representations

Facts and rules stated in propositional or first-order logic.

  • How it works: A theorem prover or logic program (such as Prolog) derives conclusions with guaranteed correctness.
  • Example: Encoding tax rules so a system can prove whether a person qualifies for a deduction.
  • When to use it: Use them where precise, verifiable reasoning is required, such as legal rules and safety checks.

Explained in detail

Ways to represent knowledge

RepresentationExampleGood for
Production rulesIF fever AND rash THEN suspect measlesDiagnosis, eligibility checks, configuration
Semantic networkSparrow —is-a→ Bird —has→ WingsInheritance of properties
FramesFrame "Train": slots for number, origin, destination, departure timeStructured records with defaults
OntologyMedical concepts and their relationships in SNOMED CTShared vocabularies across organisations
Knowledge graphBillions of facts such as (Taj Mahal, located in, Agra)Search answers, recommendations, question answering

How an expert system works

A typical expert system has a knowledge base of rules supplied by experts, a working memory of facts about the current case, an inference engine and an explanation facility. Forward chaining starts from known facts and fires every rule whose conditions are met, adding new facts until nothing changes; it suits monitoring and configuration. Backward chaining starts from a hypothesis, such as "the infection is bacterial", and works back to the facts needed to prove it, asking the user questions only when necessary; it suits diagnosis. Because every conclusion comes from named rules, the system can answer "why?" by listing them, which doctors and auditors valued.

Rise and fall, and what survived

  • MYCIN, built at Stanford in the 1970s by Edward Shortliffe and others, performed comparably to infectious-disease experts in evaluations, though it was never used routinely in hospitals.
  • XCON, used by Digital Equipment Corporation from 1980 to configure computer orders, was reported to save the company tens of millions of dollars a year.
  • The knowledge-acquisition bottleneck ended the boom: extracting, writing and maintaining thousands of rules from experts was slow and costly, and systems were brittle outside their narrow domain.
  • What survived: business rule engines for loans, insurance and tax; clinical guidelines encoded as rules; and knowledge graphs, such as the one Google announced in 2012, that answer factual questions.

Today, structured knowledge is often combined with learning. Retrieval-augmented generation feeds documents to language models; knowledge graphs ground recommendations and answers; and rule systems check that a learned model's decisions obey laws and policies. The old lesson still holds: rules are transparent and precise but hard to scale, while learning scales but is harder to explain.

How it works

  1. Interview experts and collect real cases.
  2. Write knowledge as rules, frames or graph relations.
  3. Choose forward chaining for monitoring or backward chaining for diagnosis.
  4. Test on cases the experts have already solved, and check explanations.
  5. Plan for maintenance: who updates the rules when knowledge changes?

In code

expert_system.py
# A tiny backward-chaining expert system for a plant problem.
rules = [
    ("fungal_infection", ["white_powder_on_leaves", "humid_weather"]),
    ("needs_fungicide", ["fungal_infection"]),
    ("overwatering", ["yellow_leaves", "soggy_soil"]),
    ("reduce_watering", ["overwatering"]),
]
answers = {"white_powder_on_leaves": True, "humid_weather": True, "yellow_leaves": False, "soggy_soil": False}
trace = []

def prove(goal, depth=0):
    for head, body in rules:
        if head == goal:
            if all(prove(cond, depth + 1) for cond in body):
                trace.append("  " * depth + f"{goal}: because {' and '.join(body)}")
                return True
    if goal in answers:  # ask the user only for basic facts
        return answers[goal]
    return False

for advice in ["needs_fungicide", "reduce_watering"]:
    trace.clear()
    print(f"{advice}? {prove(advice)}")
    for line in reversed(trace):
        print(line)

Output

needs_fungicide? True
needs_fungicide: because fungal_infection
  fungal_infection: because white_powder_on_leaves and humid_weather
reduce_watering? False

Try it yourself

Why did it say that?

A farmer asks a crop-advice expert system about white powder on his tomato leaves.

Match the representation to the example

Which representation is being used?

  • IF fever AND rash THEN suspect measles
  • Sparrow is-a Bird; Bird has Wings
  • (Taj Mahal, located in, Agra)
  • A Train record with slots for number and departure time

Common mistakes

  • Expecting a rule-based system to handle cases outside its rules.
  • Underestimating the cost of keeping rules up to date.
  • Writing rules that conflict without a way to resolve them.

Check yourself

Question 1

1. What is the knowledge-acquisition bottleneck?

Question 2

2. Backward chaining starts from…

Question 3

3. A major strength of expert systems is…

Summary

  • Knowledge can be represented as rules, semantic networks, frames, ontologies and knowledge graphs.
  • Expert systems use inference engines, forward or backward chaining, and can explain conclusions.
  • They faded because rules are hard to collect and maintain, but rule engines and knowledge graphs remain widely used.

Read it. Now try it yourself.

Open the interactive activity

Finished reading?

Sources: Russell and Norvig, Artificial Intelligence: A Modern Approach (4th edition) · UC Berkeley CS188: Introduction to Artificial Intelligence