Nexus Learn

Lecture 19: Rules and Expert Systems

Lecture Notes CS-511 Artificial Intelligence 7 min read Updated 8 Nov 2026

↓ Download notes (Word)

On this page
  1. Learning Outcomes
  2. 1. Expert Systems
  3. 2. Reasoning with Rules
  4. 3. Making Rules Practical
  5. 4. Common Mistakes
  6. Word Bank
  7. Self-Check Questions

Learning Outcomes

SLO

After this lecture you will be able to...

CLO

Bloom

SLO 19.1

Explain what an expert system is and the role of each component (knowledge base, inference engine, working memory, explanation)

CLO2

C2 Understand

SLO 19.2

Apply forward and backward chaining to a rule base and trace the reasoning

CLO2

C3 Apply

SLO 19.3

Apply conflict resolution and certainty factors, and explain the limits of rule-based systems

CLO2

C3 Apply

1. Expert Systems

§1.1 What is an expert system?

Slide L19-S06

An expert system is a program that gives expert-level advice in ONE narrow area, using knowledge stored as IF-THEN rules. Famous examples: DENDRAL (1965, chemistry - structure of molecules), MYCIN (1970s, medicine - about 600 rules to choose antibiotics, with certainty factors), XCON / R1 (1980, configured DEC computer orders and saved millions a year). Today: loan approval, insurance claims, tax software, crop-advice apps.

§1.2 Architecture

Slide L19-S07

Component

Job

In Gandum Doctor

Knowledge base

Long-term knowledge: the IF-THEN rules

R1-R9

Working memory

Facts of THIS case; grows as rules fire

yellow stripes, cool humid weather, ...

Inference engine

Matches rules with facts, chooses and fires rules

Forward or backward chaining

Explanation facility

Answers WHY (a question is asked) and HOW (a conclusion was reached)

Chain R8 <- R6 <- R3 <- R1

User interface

Questions and answers in the user's language

Urdu questions for a farmer

Knowledge is kept separate from the inference engine, so rules can be added without changing the program. An engine + interface with no rules is an expert-system SHELL (CLIPS, Drools, Python experta).

§1.3 Who builds it

Slide L19-S08

The domain expert knows the subject; the knowledge engineer interviews the expert and writes and tests the rules; the user answers questions and gets advice. Getting knowledge out of an expert's head is slow - the knowledge acquisition bottleneck. Steps: identify the problem, acquire knowledge, encode rules, test and refine.

2. Reasoning with Rules

§2.1 The Gandum Doctor rule base (simplified, for teaching)

Slide L19-S10

Rule

IF

THEN

R1

yellow stripes on leaves AND powder on stripes

stripe rust suspected

R2

orange-brown spots AND spots scattered

leaf rust suspected

R3

stripe rust suspected AND cool humid weather

stripe rust

R4

leaf rust suspected AND warm humid weather

leaf rust

R5

black powder in ears

loose smut

R6 / R7

stripe rust / leaf rust

rust disease

R8

rust disease AND before flowering

advise fungicide spray

R9

loose smut

advise treated seed next season

§2.2 Forward chaining (data-driven)

Slide L19-S11

Start from the facts; each cycle, find the rules whose IF part is true and whose conclusion is new (the conflict set), fire one and add its conclusion to working memory; stop when nothing new can be added.

def forward(rules, facts, strategy="order", trace=None):

"""Forward chaining (data-driven). Each cycle: build the conflict set (rules whose conditions hold and whose conclusion is

new), pick ONE rule by the strategy, fire it. strategy: 'order' (first in the list), 'specificity' (most conditions),

'priority' (highest priority number), 'recency' (uses the most recently added fact)."""

facts = list(facts); why = {}

cycle = 0

while True:

conflict = [r for r in rules if all(c in facts for c in r[1]) and r[2] not in facts]

if not conflict:

break

if strategy == "order":

chosen = conflict[0]

elif strategy == "specificity":

chosen = max(conflict, key=lambda r: len(r[1]))

elif strategy == "priority":

chosen = max(conflict, key=lambda r: r[3])

elif strategy == "recency":

chosen = max(conflict, key=lambda r: max(facts.index(c) for c in r[1]))

cycle += 1

facts.append(chosen[2]); why[chosen[2]] = chosen

if trace is not None:

trace.append(f"Cycle {cycle}: conflict set {{{', '.join(r[0] for r in conflict)}}} -> fire {chosen[0]}: {chosen[2]}")

return facts, why

Farmer reports: yellow_stripes_on_leaves, powder_on_stripes

cool_humid_weather, before_flowering

Cycle 1: conflict set {R1} -> fire R1: stripe_rust_suspected

Cycle 2: conflict set {R3} -> fire R3: stripe_rust

Cycle 3: conflict set {R6} -> fire R6: rust_disease

Cycle 4: conflict set {R8} -> fire R8: advise_fungicide_spray

Advice: ['advise_fungicide_spray']

HOW? (explanation)

advise_fungicide_spray <- R8 because rust_disease AND before_flowering

rust_disease <- R6 because stripe_rust

stripe_rust <- R3 because stripe_rust_suspected AND cool_humid_weather

stripe_rust_suspected <- R1 because yellow_stripes_on_leaves AND powder_on_stripes

yellow_stripes_on_leaves (told by the farmer)

powder_on_stripes (told by the farmer)

cool_humid_weather (told by the farmer)

before_flowering (told by the farmer)

§2.3 Backward chaining (goal-driven)

Slide L19-S12

Start from a goal; find rules that conclude it and prove their conditions as sub-goals; ask the user for facts only they can tell; if a rule fails, backtrack and try the next one (like Prolog, L09). Farmer 2 has leaf rust:

Goal advise_fungicide_spray: try R8

Goal rust_disease: try R6

Goal stripe_rust: try R3

Goal stripe_rust_suspected: try R1

ASK: yellow stripes on leaves? no

stripe_rust_suspected cannot be proved

stripe_rust cannot be proved

Goal rust_disease: try R7

Goal leaf_rust: try R4

Goal leaf_rust_suspected: try R2

ASK: orange brown spots? yes

ASK: spots scattered? yes

R2 proves leaf_rust_suspected

ASK: warm humid weather? yes

R4 proves leaf_rust

R7 proves rust_disease

ASK: before flowering? yes

R8 proves advise_fungicide_spray

Goal advise_fungicide_spray: PROVED

Questions asked: 5 of 8 askable facts

§2.4 Forward or backward?

Slide L19-S13

Forward chaining

Backward chaining

Starts from

Facts

A goal

Asks the user

All data first

Only what the goal needs

Finds

Everything the facts lead to

Whether one goal is true

Good for

Monitoring, alarms, configuration

Diagnosis

Example

XCON

MYCIN, Prolog

3. Making Rules Practical

§3.1 Conflict resolution

Slide L19-S15

Strategy

Picks

Order

First matching rule in the list

Specificity

Rule with the most conditions

Priority (salience)

Highest importance number set by the expert

Recency

Rule using the newest fact

Refractoriness

A rule never fires twice on the same facts

Facts, oldest first:

yellow_leaves, stripes, powder, cool_humid_weather

order first: fire G1: nitrogen_deficiency

specificity first: fire S1: stripe_rust

priority first: fire S1: stripe_rust

recency first: fire W1: rust_risk_high

§3.2 Certainty factors (MYCIN)

Slide L19-S16

CF runs from -1 (certainly false) through 0 (unknown) to +1 (certainly true). One rule: CF = rule CF x min(premise CFs). Two rules for the same conclusion: CF = a + b(1 - a).

R1 (CF 0.7): yellow stripes 0.9 AND powder 0.8 -> stripe rust CF = 0.7 x min(0.9, 0.8) = 0.56

R2 (CF 0.6): lab spore test positive 1.0 -> stripe rust CF = 0.60

Combined: 0.56 + 0.60 x (1 - 0.56) = 0.824

Order does not matter: 0.824

§3.3 Strengths and limits

Slide L19-S17

Strengths

Limits

Available any time, anywhere

Knowledge acquisition bottleneck

Consistent

Brittle outside its narrow area

Explains WHY and HOW

No common sense

Rules easy to read and update

Does not learn by itself

Keeps knowledge when experts retire

Large rule bases hard to maintain

4. Common Mistakes

Wrong idea

Correct idea

The inference engine contains the rules.

Rules are in the knowledge base.

Forward chaining starts from the goal.

Forward: facts; backward: goal.

Backward chaining asks every question.

Only what the goal needs.

Combine CFs by adding.

a + b(1 - a), never above 1.

An expert system learns by itself.

People add and fix rules.

Word Bank

Word

Simple meaning

Example

Expert system

Program giving specialist advice in one area

Gandum Doctor

Knowledge base

Store of rules

R1-R9

Working memory

Facts of the current case

cool humid weather

Inference engine

Applies rules to facts

Forward chaining

Conflict set

Rules that could fire now

{G1, S1, W1}

Certainty factor

Degree of belief from -1 to +1

0.56

Shell

Expert system without rules

CLIPS, Drools

Brittle

Fails badly outside its area

Unknown disease

Self-Check Questions

  1. Name five components of an expert system and their jobs. (see §1.2)
  2. What is the knowledge acquisition bottleneck? (see §1.3)
  3. Forward-chain from: black powder in ears. (see §2.2)
  4. Why did backward chaining ask only 5 questions for farmer 2? (see §2.3)
  5. Which conflict-resolution strategy picks S1 and why? (see §3.1)
  6. Combine CF 0.56 and 0.60. (see §3.2)

Reading: Kaplan Ch 2; Luger Ch 8 (strong method problem solving: expert systems); Russell & Norvig 7.5 (forward and backward chaining).

← All CS-511 material