Rule-Based Expert Systems: Working Principles and a Cold vs. Flu IF–THEN Rule Base

Rule-Based Expert Systems: Working Principles and a Cold vs. Flu IF–THEN Rule Base

Verified Sources
Nov 4, 2026

A rule-based expert system is typically built around four components: a knowledge base, an inference engine, working memory, and (often) an explanation facility. Conceptually, the system repeatedly matches rule conditions against working memory, then adds newly inferred facts back into working memory until it reaches a goal (e.g., a diagnosis).

Key learning targets for this section:

  • How forward chaining and backward chaining drive inference in rule systems
  • How a small rule base can be authored and executed
  • How to design a consistent IF–THEN rule set for a practical symptom-based diagnosis task

Expert Systems: Forward vs Backward Chaining (Conceptual)

1) Working of rule-based Expert Systems (from inputs to conclusions)

When the system runs, it follows a loop:

  1. Collect facts: The user (or another component) supplies observations (symptoms, durations, temperatures).
  2. Store facts in working memory: Working memory holds both initial and newly inferred facts.
  3. Match rules: The inference engine checks which IF-conditions are satisfied by working memory.
  4. Fire rules: When a rule’s condition is satisfied, the rule’s THEN-part adds conclusions or new facts into working memory.
  5. Repeat until termination: The cycle continues until the system reaches a stopping condition:
    • No more rules can fire, or
    • A diagnosis goal is achieved, or
    • A maximum number of rule firings is reached (to avoid loops).

Forward chaining vs backward chaining

  • Forward chaining is data-driven: you start with known facts and keep applying rules to derive more facts until you reach the diagnosis.
  • Backward chaining is goal-driven: you start with the goal (e.g., “diagnose Flu”) and ask whether rule conditions can be satisfied by searching for supporting facts.

Rule-based expert system inference loop

  1. 1
    Step 1

    Insert user-provided observations (e.g., fever=true, cough=true, symptomDurationDays=2).

  2. 2
    Step 2

    The inference engine searches the knowledge base for rules whose IF-conditions are potentially satisfied.

  3. 3
    Step 3

    For each candidate rule, test whether its condition literals match working memory.

  4. 4
    Step 4

    If conditions are satisfied, execute the THEN part (e.g., set diagnosis=flu). Optionally add intermediate facts (e.g., 'likelyViral=true').

  5. 5
    Step 5

    Add newly inferred facts; this may enable more rules.

  6. 6
    Step 6

    Stop if a diagnosis goal is reached or no more rules can fire.

  7. 7
    Step 7

    Report which rules fired and which facts supported them (when explanation is enabled).

2) Designing an IF–THEN rule base for “common cold vs. flu”

Symptom variables used here

To keep the rule base small and understandable, we’ll use a minimal set of boolean/numeric features:

  • fever (boolean)
  • soreThroat (boolean)
  • bodyAches (boolean)
  • cough (boolean)
  • symptomDurationDays (numeric)
  • nasalCongestion (boolean)

Reasoning strategy (simple, deterministic)

For this small course exercise, we’ll implement:

  • A scoring-like preference using mutually exclusive “set a diagnosis” rules, plus a “tie-breaker” rule based on duration/severity indicators.
  • Explainable decisions: the fired rules directly justify the result.

Note: Real clinical decision-making requires professional evaluation. This is a didactic example of rule-based reasoning, not medical advice.

Medical safety note

This rule base is for learning IF–THEN inference mechanics only. It is not a substitute for healthcare guidance.

3) Example small rule base (IF–THEN rules)

Rule notation

We will write rules in this simplified form:

  • IF (conditions) THEN (conclusion)
  • Conditions are conjunctions (AND).
  • Conclusions are assignments into working memory, e.g., diagnosis := "Flu".

Rule base (common cold vs. flu)

Rule set R (8 rules):

  1. R1 (Strong flu indicator)
    IF fever AND bodyAches THEN diagnosis := "Flu"

  2. R2 (Flu with cough + fever)
    IF fever AND cough AND NOT nasalCongestion THEN diagnosis := "Flu"

  3. R3 (Flu with sore throat)
    IF fever AND soreThroat THEN diagnosis := "Flu"

  4. R4 (Cold with nasal congestion)
    IF nasalCongestion AND cough AND NOT fever THEN diagnosis := "Common Cold"

  5. R5 (Cold with mild/no systemic symptoms)
    IF nasalCongestion AND NOT fever AND NOT bodyAches THEN diagnosis := "Common Cold"

  6. R6 (Early onset + fever suggests flu)
    IF fever AND symptomDurationDays <= 2 THEN diagnosis := "Flu"

  7. R7 (Longer course without fever suggests cold)
    IF NOT fever AND symptomDurationDays >= 3 THEN diagnosis := "Common Cold"

  8. R8 (Tie-breaker if nothing fired cleanly)
    IF diagnosis is undefined AND nasalCongestion THEN diagnosis := "Common Cold"
    ELSE IF diagnosis is undefined AND fever THEN diagnosis := "Flu"

4) Demonstration: executing the rule base by hand

Let’s walk through two short scenarios to see the working of inference and the explanation trace.

Scenario A

User facts (working memory input):

  • fever=true
  • bodyAches=true
  • cough=true
  • nasalCongestion=false
  • soreThroat=true
  • symptomDurationDays=2

Forward chaining (typical):

  • Check R1: fever AND bodyAches → true → fire R1 → diagnosis := Flu
  • Once diagnosis is set, a simple implementation may continue to refine or may stop immediately. For training, we can stop after the first strong diagnosis.

Explanation trace (which rule fired):

  • R1 fired because fever and body aches were both true.

Scenario B

User facts (working memory input):

  • fever=false
  • bodyAches=false
  • cough=true
  • nasalCongestion=true
  • soreThroat=false
  • symptomDurationDays=4

Rule evaluation:

  • R4: nasalCongestion AND cough AND NOT fever → true → fire R4 → diagnosis := Common Cold
  • Stop (or continue) since diagnosis is decided.

Explanation trace:

  • R4 fired because nasal congestion + cough occurred without fever.

Make rules explainable

Record which rules fired (and which facts matched). Explanations are essential for debugging and trust.

5) Visual summary of control flow (inference + explanation)

Which inputs most strongly trigger each diagnosis in the example rule base?

Counts of rules that directly reference each feature in their IF conditions.

Common design issues in rule-based expert systems

Rule-based Expert Systems Quick Deck

1 / 5
Question · Term

What is working memory?

Click to reveal
Answer · Definition

The current set of facts (initial + inferred) used to test rule conditions.

Knowledge Check

Question 1 of 4
Q1Single choice

In a forward-chaining rule-based expert system, reasoning starts with…