Science
Copyright © 2024 Jiri Kriz, www.nosco.ch

10    Rule-based Shell, Diagnosis

Solutions

10.1    Rule-based Shell (Backward Reasoning)

Write a simple shell for rule-based expert systems. The knowledge is represented in if-then rules that have the following syntax:

Rule : if Premise then Conclusion 
/* '#' instead of ':' in SWI Prolog */

Premise can be built out of simpler Premises using

and, or, not

The rule grammar is given by the operator definitions. The needed operators can be defined in the file that is consulted:

define_operators :-
    op( 920, xfy, and),
    op( 930, xfy, or), 
    op( 950, xfx, then), 
    op( 960, fx,  if), 
    op( 970, xfx, #). /* '#' used instead of ':' in SWI Prolog */
:- define_operators.

The shell operates backwards according to the Prolog proof method. A goal G is proven either when it is known to be true, or the user say so, or when there is a rule

R: if G1 then G.  /* Use '#' in SWI Prolog instead of ':' */

and G1 is proven. If the user is be asked he should be asked only once for a specific goal. This means that the user's answers have to be stored.

Solution 10.1

10.2    Rule-based Diagnosis (Hypothesis Testing)

Use the rule-based shell from Example 10.1 for the fault finding according to the method of hypothesis testing. The rules are formulated such that they show from symptoms (observations) to causes (diagnosis, faults). A possible diagnosis (priamary fault) is guessed and then tried to be proven by ackward chaining.

Test this method on the example of a steam iron:

  1. If the cloth is burnt, then the temperature is too high.
  2. If the temperature is too high or to low, then the temperature is wrong.
  3. If the temperature is wrong and the thermostat is set correctly, then the thermostat is faulty.
  4. If the temperature is wrong and the thermostat is not set correctly, then the thermostat should be set correctly.
  5. If no steam comes out, then the temperature is too low or there is a problem in the steam system.
  6. If there is a problem in the steam system, then there is no water or the nozzle is congested.
  7. If the iron result is poor, then the temperature is too low.
  8. If the iron is cold and the control lamp shines, then we need to wait.
  9. If the iron is cold and the control lamp does not shine, then there is no power.

Start with only a few rules. Improve the provided rules and add further rules as you like.

Remark:

The rule 5 can be approximated by two rules:
5a) If no steam comes out, then the temperature is too low.
5b) If no steam comes out, then there is a problem in the steam system.
The interpretation of the implication is: "It could be that ...".

Solution 10.2