Knowledge-based systems
A knowledge-based system separates what is known from how it is used. The knowledge base holds facts about the current case and general rules of the domain. The inference engine applies the rules to the facts to derive new facts, and an explanation facility reports which rules led to a conclusion [1]. Because the rules are separate from the engine, experts can read, review and extend the knowledge without changing the program.
Three systems defined the approach. DENDRAL, started at Stanford in the 1960s, generated candidate molecular structures from mass spectrometry data and pruned them with chemical rules; its developers later called it the first expert system for scientific hypothesis formation [2]. MYCIN diagnosed bacterial infections and recommended therapy with about 450 rules, and its evaluation showed performance comparable to specialists [3]. R1, later called XCON, configured computer systems for Digital Equipment Corporation and was among the first expert systems used in daily industrial operation [4]. Building such systems revealed the knowledge acquisition bottleneck: Experts find it hard to state their knowledge as complete and consistent rules, and the rule base needs continuous maintenance as products and practices change [5].
Check your understanding. What is the main architectural idea of a knowledge-based system?
Facts, rules and logic
Propositional logic gives the simplest representation. A fact is a statement that is true or false, such as "the fines content is above 50 percent". A rule states that a conclusion follows when its conditions hold: IF high vibration AND a peak at twice the running speed THEN misalignment is suspected. Rules whose conditions are conjunctions of facts and whose conclusion is a single fact are called Horn clauses, and for them inference is both simple and efficient [6]. The basic inference step is modus ponens: From "A" and "IF A THEN B", conclude "B".
Richer representations exist. First-order logic introduces objects, relations and quantifiers, so that one rule can speak about every pump in a plant. Frames and object-oriented representations group attributes of a concept, and decision tables list combinations of conditions with their actions, a format that engineers know from codes and standards. Whatever the representation, the knowledge must be complete for the intended cases, consistent so that rules do not contradict each other, and specific enough that the engine can test it.
Formulas: Propositional logic as arithmetic
A proposition, such as "the vibration is high", is either true or false. Writing for the truth value of a proposition , with for true and for false, the connectives not (), and (), or () and implies () can be computed with ordinary arithmetic [6]:
The function min returns the smaller and max the larger of its arguments. The last formula states that the rule "IF THEN " is false only when is true and is false, so always has the same truth value as . A rule whose conditions are joined by and,
therefore has the same truth value as the clause
in which only one part, , is not negated. A clause with at most one part that is not negated is a Horn clause [6]. Modus ponens states that and together force . Week 4 keeps the min and max formulas but allows truth values anywhere between 0 and 1 [7].
Worked example: Checking modus ponens and a rule with truth tables
Step 1. The truth table of a rule. All four combinations of and are evaluated with the formula for the implication:
| 0 | 0 | ||
| 0 | 1 | ||
| 1 | 0 | ||
| 1 | 1 |
Step 2. Modus ponens. Only the last row has both and , and in this row . Whenever a fact and a rule that starts from it are both true, the conclusion of the rule is true as well.
Step 3. A tempting error. The second row has and , but . Concluding from and is therefore not valid. For diagnosis this means that a symptom predicted by a fault does not prove the fault, because the same symptom can have another cause.
Step 4. A rule in Horn form. Rule R2 of the pump rule base reads IF high vibration () AND a peak at twice the running speed () THEN misalignment (). Its truth value is for every combination of the three facts:
| , , | Rule R2 |
|---|---|
| 0, 0, 0 | |
| 0, 0, 1 | |
| 0, 1, 0 | |
| 0, 1, 1 | |
| 1, 0, 0 | |
| 1, 0, 1 | |
| 1, 1, 0 | |
| 1, 1, 1 |
The Horn clause has the truth value :
| , , | Horn clause |
|---|---|
| 0, 0, 0 | |
| 0, 0, 1 | |
| 0, 1, 0 | |
| 0, 1, 1 | |
| 1, 0, 0 | |
| 1, 0, 1 | |
| 1, 1, 0 | |
| 1, 1, 1 |
The two tables agree in all eight rows, so the rule and the clause are the same statement. Both are false in one row only, where both conditions hold and the conclusion does not.
Forward and backward chaining
Forward chaining is data driven. The engine repeatedly searches for rules whose conditions are all satisfied by known facts, adds their conclusions to the facts, and stops when no rule adds anything new. It suits monitoring and classification, where measurements arrive and the question is what follows from them. Backward chaining is goal driven. The engine starts from a hypothesis, finds rules that conclude it, and tries to establish their conditions, recursively, until it reaches known facts or must ask the user. It suits diagnosis, where the system checks a suspected fault and asks only the questions that matter for it [1, 6].
When several rules can fire at once, a conflict resolution strategy chooses among them, for example by rule priority, by specificity or by the recency of the facts involved. Large rule bases need efficient matching: The Rete algorithm compiles rule conditions into a network that remembers partial matches, so that each new fact is compared only with the conditions it can affect [8].
Animation: Forward chaining in a pump diagnosis rule base
Select the observed symptoms and step through the inference. Each step fires one rule whose conditions are satisfied and adds its conclusion to the facts.
Check your understanding. A maintenance engineer suspects cavitation and wants the system to ask only the questions relevant to that suspicion. Which inference strategy fits?
Formulas: Forward chaining as a growing set of facts
Let be the set of facts known at the start, the observations. Each rule has a set of conditions and a conclusion . In the formulas below, reads "is contained in", reads "is an element of", reads "is not an element of", and joins two sets into one. At cycle the conflict set holds every rule whose conditions are all known and whose conclusion is still new [6]:
Conflict resolution picks one rule from the conflict set, here the rule with the lowest number, and the engine adds its conclusion to the facts:
The engine stops at the first cycle whose conflict set is empty. Each rule can add its conclusion only once, so a rule base with rules stops after at most firings. For rules in Horn form, forward chaining derives every fact that follows from the observations, and nothing else [6].
Matching is the expensive part. An engine that tests every condition of every rule in every cycle makes, over cycles,
tests, where is the number of conditions of rule . The Rete algorithm instead compiles the conditions into a network that remembers partial matches, so that each new fact is tested only against the conditions that mention it [8].
Backward chaining works from a goal . If is already a fact, the goal is reached. Otherwise the engine takes each rule with in turn and tries to establish every condition in as a new goal. A goal that no rule concludes is an observation, and the engine asks the user about it [5, 6].
Worked example: Forward chaining in the pump rule base
The pump rule base of the animation has ten rules:
| Rule | Conditions | Conclusion |
|---|---|---|
| R1 | high vibration AND peak at 1x running speed | unbalance |
| R2 | high vibration AND peak at 2x running speed | misalignment |
| R3 | crackling noise at the inlet AND low suction pressure | cavitation |
| R4 | high bearing temperature AND high vibration | bearing wear |
| R5 | leak at the shaft seal | seal failure |
| R6 | cavitation | action: raise suction head or reduce flow |
| R7 | unbalance | action: balance the impeller |
| R8 | misalignment | action: realign pump and motor |
| R9 | bearing wear | action: replace bearing |
| R10 | seal failure | action: replace mechanical seal |
The observations in are high vibration, peak at 2x running speed and high bearing temperature. Conflict resolution fires the rule with the lowest number.
Cycle 1 (). The conflict set is . Rule R2 has the lowest number and fires, so .
Cycle 2 (). The conflict set is . Rule R4 has the lowest number and fires, so .
Cycle 3 (). The conflict set is . Rule R8 has the lowest number and fires, so .
Cycle 4 (). The conflict set is . Its only rule, R9, fires, so .
Cycle 5 (). No rule has all its conditions in and a new conclusion, so is empty and the engine stops with 7 facts.
Counting the tests. The ten rules have conditions. Testing all of them in each of the cycles costs tests. An engine that tests each fact only against the conditions that mention it needs one test per mention: High vibration appears in 3 conditions, peak at 2x running speed, high bearing temperature, misalignment and bearing wear in one each, and the two actions in none, which adds up to 7 tests. The saving grows with the number of rules and facts [8].
Worked example: Backward chaining from a suspected fault
An engineer suspects cavitation, so the goal is .
Step 1. Cavitation is not a fact. Only rule R3 concludes it, so its conditions, crackling noise at the inlet and low suction pressure, become new goals.
Step 2. No rule concludes "crackling noise at the inlet", so it is an observation. The engine asks: Is there a crackling noise at the inlet? The answer is yes, and the fact is added.
Step 3. "Low suction pressure" is also an observation. Before answering, the engineer asks why the question matters. The engine answers with the rule it is trying to establish: R3 concludes cavitation when crackling noise and low suction pressure both hold, and crackling noise is already known. The answer is yes.
Step 4. Both conditions of R3 hold, so R3 fires and cavitation is established. Asked how, the engine reports: Cavitation by R3, from crackling noise (answered yes) and low suction pressure (answered yes).
The engine asked two questions instead of all seven observations. Had the first answer been no, R3 would have failed at once and the second question would never have been asked. Part A of the interactive lab runs backward chaining for any goal of this rule base and answers why and how.
Explanation and uncertainty
An expert system can answer two questions that most learned models cannot answer directly. The question how is answered by the chain of rules that produced a conclusion. The question why, asked when the system requests information, is answered by the rule that it is trying to establish. In safety-relevant engineering work, such traceable reasoning supports review, audit and certification.
Real knowledge is uncertain. MYCIN attached a certainty factor between minus one and one to rules and facts [3]. A conclusion receives the certainty of its rule multiplied by the smallest certainty of its conditions, and two rules supporting the same positive conclusion combine as CF = CF1 + CF2 (1 - CF1), so that evidence accumulates but never exceeds one. Certainty factors were a practical engineering compromise rather than a probability theory, and their difficulties motivated both probabilistic reasoning and fuzzy logic. Vague conditions such as "slightly high temperature" cannot be captured by crisp thresholds at all: A reading of 69.9 degrees and one of 70.1 degrees would fire different rules. Week 4 addresses this with fuzzy sets [7].
Check your understanding. Two independent rules support the conclusion "bearing wear" with certainty factors 0.6 and 0.5. What is the combined certainty factor?
Formulas: Certainty factors
A certainty factor CF is a number between and attached to a fact or to a rule. The value 1 means certainly true, certainly false and 0 unknown. In the original MYCIN model the certainty factor of a hypothesis is the difference between a measure of belief MB and a measure of disbelief MD, both between 0 and 1 [3]:
The certainty of a premise with several conditions follows the formulas of logic: The weakest condition limits a conjunction, and the strongest condition carries a disjunction [1, 3]:
A rule IF THEN carries its own certainty factor , given by the expert. When the premise is believed, the rule passes certainty to its conclusion:
MYCIN fired a rule only when the certainty of its premise exceeded 0.2 [3]. When two rules give certainties and for the same conclusion, these are combined by one of three formulas, chosen by their signs [1, 3]:
The vertical bars denote the absolute value, the number without its sign. The result does not depend on the order of the two rules and always stays between and . A third rule is combined with the result of the first two in the same way.
Worked example: Two rules that support the same conclusion
Two independent rules support the conclusion "bearing wear" with certainty factors and , as in the knowledge check above. Both are positive, so the first formula applies:
In the opposite order the result is the same:
The second rule removes part of the remaining doubt, , so the evidence accumulates but never exceeds one.
Worked example: Diagnosing the pump with certainty factors
The observations are believed with , and . Three rules apply: R2 (high vibration AND peak at 2x THEN misalignment) with , R5 (high bearing temperature AND peak at 2x THEN misalignment) with , and R4 (high bearing temperature AND high vibration THEN bearing wear) with .
Step 1. Premises. Each premise is a conjunction, so it takes the smaller certainty: for R2, for R5 and for R4. All three exceed 0.2, so all three rules fire.
Step 2. Conclusions of the single rules.
Step 3. Combining R2 and R5 for misalignment. Both are positive:
Misalignment, with 0.6656, is ranked before bearing wear, with 0.36. Part B of the interactive lab shows the same numbers and updates them when the observations change.
Step 4. Evidence against the conclusion. A laser alignment check finds the shafts aligned, which the engineer believes with . A rule R11, IF the alignment check finds the shafts aligned THEN misalignment, carries :
The signs differ, so the third formula combines this with 0.6656:
Step 5. A second piece of negative evidence. A thermal image shows no hot spot at the coupling, and a rule gives misalignment from it. Both values are now negative, so the second formula applies:
The evidence now speaks against misalignment, and the engineer looks for another cause of the peak at twice the running speed. Part C of the interactive lab repeats every formula of this section for any certainties.
Engineering standards as rule bases: The Unified Soil Classification System
Many engineering standards are rule bases written for people. The Unified Soil Classification System, based on Casagrande's airfield classification and standardised as ASTM D2487, assigns a group symbol to a soil from its grain-size distribution and its Atterberg limits [9, 10]. The rules proceed in stages. A soil is fine grained when at least half of it passes the No. 200 sieve (0.075 mm), and coarse grained otherwise. A coarse soil is a gravel when more than half of its coarse fraction is retained on the No. 4 sieve (4.75 mm), and a sand otherwise. A clean gravel with less than 5 percent fines is well graded (GW) when its coefficient of uniformity is at least 4 and its coefficient of curvature lies between 1 and 3, and poorly graded (GP) otherwise; for sands the uniformity limit is 6. Gravels and sands with more than 12 percent fines are silty (GM, SM) or clayey (GC, SC) depending on the plasticity of the fines, and those with 5 to 12 percent fines receive dual symbols such as GW-GM.
Fine-grained soils are placed on Casagrande's plasticity chart, which plots the plasticity index PI against the liquid limit LL. The A-line, PI = 0.73 (LL - 20), separates clays above it from silts below it. Soils with LL below 50 are lean clays (CL) when PI is above 7 and on or above the A-line, silts (ML) when PI is below 4 or the point lies below the A-line, and silty clays (CL-ML) in the band of PI from 4 to 7 above the A-line. Soils with LL of 50 or more are fat clays (CH) above the A-line and elastic silts (MH) below it [10]. The notebook turns these rules into a function, and the lab shows the reasoning path for any combination of test results.

Check your understanding. A fine-grained soil has LL = 38 and PI = 18. The A-line value at LL = 38 is 0.73 x 18 = 13.1. What is its group symbol?
Formulas: Grain size and plasticity
A sieve analysis shakes a dry sample of mass through a stack of sieves, from the coarsest to the finest, and weighs the mass retained on each sieve . The percentage passing sieve is the part of the sample that was retained neither on it nor on any coarser sieve:
The fines content is the percentage passing the No. 200 sieve, , and the gravel content is the percentage retained on the No. 4 sieve, [10]. The coarse fraction is , and a coarse soil is a gravel when more than half of its coarse fraction is gravel:
The grain size is the size than which percent of the soil is finer. It is read from the grading curve, which plots the percentage passing against the sieve opening on a logarithmic scale. Between two neighbouring sieves with openings and percentages passing , the curve is taken as a straight line on that scale, which gives, with the logarithm to base 10,
The coefficient of uniformity and the coefficient of curvature describe the shape of the curve [10]:
A gravel is well graded when and , and a sand when and . The plasticity of the fines is measured by the liquid limit LL and the plastic limit PL, the water contents in percent at which the soil changes from plastic to liquid and from semi-solid to plastic behaviour. Their difference is the plasticity index, the range of water content over which the soil is plastic:
On the plasticity chart, the A-line and the U-line are [9, 10]:
Below the A-line runs horizontally at . The U-line is an approximate upper limit for natural soils, so a point above it suggests that the test results should be checked [10].
Worked example: Classifying a sand from its sieve analysis
A dry sample of g gives the following masses on the sieves, and 60 g reach the pan:
| Sieve | Opening (mm) | Retained (g) | Cumulative (g) | Percent passing |
|---|---|---|---|---|
| 3/4 in | 19 | 0 | 0 | |
| 3/8 in | 9.5 | 60 | 60 | |
| No. 4 | 4.75 | 90 | 150 | |
| No. 10 | 2 | 150 | 300 | |
| No. 20 | 0.85 | 170 | 470 | |
| No. 40 | 0.425 | 160 | 630 | |
| No. 60 | 0.25 | 130 | 760 | |
| No. 100 | 0.15 | 100 | 860 | |
| No. 200 | 0.075 | 80 | 940 |
Step 1. Fines and gravel. percent and percent. Less than half of the soil passes the No. 200 sieve, so the soil is coarse grained. Its coarse fraction is percent, and
is below 0.5, so the soil is a sand.
Step 2. The effective size . It lies between the No. 100 sieve (0.15 mm, 14 percent passing) and the No. 200 sieve (0.075 mm, 6 percent passing). With and :
Step 3. The size . It lies between the No. 40 sieve (0.425 mm, 37 percent passing) and the No. 60 sieve (0.25 mm, 24 percent passing). With and :
Step 4. The size . It lies between the No. 10 sieve (2 mm, 70 percent passing) and the No. 20 sieve (0.85 mm, 53 percent passing). With and :
Step 5. The two coefficients.
The uniformity coefficient passes the limit of 6 for sands, but is below 1, so the sand is poorly graded, SP: The curve has too little material in the middle sizes.
Step 6. The fines. With 5 to 12 percent fines, the soil receives a dual symbol whose second part depends on the plasticity of the fines [10]. The fines have and , so . The A-line at this liquid limit is , and the point lies below it, so the fines are silty, ML, and the soil is SP-SM. Part D of the interactive lab computes the grading curve, the three sizes and the symbol from any sieve masses.
Worked example: Three fine-grained soils on the plasticity chart
Soil a. . The A-line: . The U-line: , above the point, as expected for a natural soil. Since LL is below 50, PI is above 7 and the point lies above the A-line, the group symbol is CL.
Soil b. . The A-line: . The U-line: , above the point, as expected for a natural soil. Since LL is at least 50 and the point lies below the A-line, the group symbol is MH.
Soil c. . The A-line: LL is below 25.5, where the A-line runs horizontally at (the sloping formula would give ). The U-line: , above the point, as expected for a natural soil. Since LL is below 50 and PI lies between 4 and 7 on or above the A-line, the group symbol is CL-ML.
| Soil | LL | PL | PI | A-line | U-line | Group symbol |
|---|---|---|---|---|---|---|
| a | 38 | 20 | 18 | 13.14 | 27 | CL |
| b | 62 | 38 | 24 | 30.66 | 48.6 | MH |
| c | 22 | 16 | 6 | 4 | 12.6 | CL-ML |
Part E of the interactive lab places any pair of limits on the chart and prints the same reasoning path.
Strengths and limits
Knowledge-based systems are transparent, can be verified rule by rule, need no training data, and encode requirements that must hold exactly, such as the limits of a standard. They are brittle outside the cases their authors anticipated, they are expensive to acquire and maintain, and they cannot perceive raw signals or images. Modern practice therefore combines them with learning: A convolutional network may detect a crack, and a rule base derived from a code decides whether the crack width requires repair. Such hybrid systems return in later weeks, for example when a language model retrieves passages from standards in Week 13.
Python step 3: Dictionaries and functions
The Python step of this week is part of the Colab notebook, where every explanation stands next to a cell that runs it and the step closes with a quick check and exercises with immediate feedback. The printable lecture notes contain the same step together with the outputs of its code. The Colab button below opens the notebook at the step. Run the setup cell just above the step first, since the exercises use its check function.
Review cards
Select a card to turn it over.
Continue the week
The week continues with the simulation and the self-assessment of the interactive lab and with the Python step and the hands-on work of the Colab notebook. The week overview lists the discipline challenges, the weekly task and the research assignment.
Interactive lab Colab notebook Self-assessment Week overview and tasks
References
[1] Giarratano, J. C., & Riley, G. D. (2005). Expert Systems: Principles and Programming (4th ed.). Thomson Course Technology.
[2] Lindsay, R. K., Buchanan, B. G., Feigenbaum, E. A., & Lederberg, J. (1993). DENDRAL: A case study of the first expert system for scientific hypothesis formation. Artificial Intelligence, 61(2), 209-261. https://doi.org/10.1016/0004-3702(93)90068-M
[3] Buchanan, B. G., & Shortliffe, E. H. (Eds.) (1984). Rule-Based Expert Systems: The MYCIN Experiments of the Stanford Heuristic Programming Project. Addison-Wesley.
[4] McDermott, J. (1982). R1: A rule-based configurer of computer systems. Artificial Intelligence, 19(1), 39-88. https://doi.org/10.1016/0004-3702(82)90021-2
[5] Hayes-Roth, F., Waterman, D. A., & Lenat, D. B. (Eds.) (1983). Building Expert Systems. Addison-Wesley.
[6] Russell, S., & Norvig, P. (2021). Artificial Intelligence: A Modern Approach (4th ed.). Pearson.
[7] Zadeh, L. A. (1965). Fuzzy sets. Information and Control, 8(3), 338-353. https://doi.org/10.1016/S0019-9958(65)90241-X
[8] Forgy, C. L. (1982). Rete: A fast algorithm for the many pattern/many object pattern match problem. Artificial Intelligence, 19(1), 17-37. https://doi.org/10.1016/0004-3702(82)90020-0
[9] Casagrande, A. (1948). Classification and identification of soils. Transactions of the American Society of Civil Engineers, 113, 901-930.
[10] ASTM International (2017). ASTM D2487-17: Standard Practice for Classification of Soils for Engineering Purposes (Unified Soil Classification System). ASTM International.