8 A Multitasking Application
(THE COLOR OF CLYDE IS GREY) (THE COLOR OF TWEETY IS YELLOW) (THE STATUS OF WATER-PUMP IS BROKEN)The process of storing facts in the database is called assertion. You can retrieve a fact through a query, which is a method of matching a fact with a pattern. For example, if you query with the pattern
(THE COLOR OF ?WHO IS ?WHAT)and the facts listed above are currently stored in the database, the two facts
(THE COLOR OF CLYDE IS GREY)and
(THE COLOR OF TWEETY IS YELLOW)are found.
A fact matches a pattern if the two lists are identical except for the variables, which are preceded by a question mark (
?) in the pattern. Variables can be matched like a wildcard to any symbol in the corresponding position of the fact. The process of associating a variable with a matching symbol is called binding the variable to the symbol. Matching a fact to a pattern requires finding a binding for each variable in the pattern. By replacing each variable in the pattern with its associated symbol through binding, a pattern can be transformed into a list that is identical with a fact.
The application can also use rules to deduce new facts based on facts currently stored in the database. A rule is a list of the following form:
(IF premises THEN conclusions)Both the premises and the conclusions are one or more fact patterns. These patterns have the same form as query patterns.
For example, you can write a rule about an elephant as follows:
RULE-1: (IF (?ANIMAL IS AN ELEPHANT) THEN (THE SIZE OF ?ANIMAL IS LARGE))If the database already contains the fact
(CLYDE IS AN ELEPHANT)and you execute the call
(QUERY '(THE SIZE OF ?WHO IS LARGE)), the application uses
RULE-1to deduce the following fact:
(THE SIZE OF CLYDE IS LARGE)Rules can be linked together like a chain. For example, assume that you have the following additional rule:
RULE-2 (IF (?ANIMAL HAS A BIG TRUNK) THEN (?ANIMAL IS AN ELEPHANT))If the database already contains the fact
(DUMBO HAS A BIG TRUNK), the application can deduce the additional fact
(THE SIZE OF DUMBO IS LARGE). In effect, these rules have been chained together to perform the deduction. Since the rules are linked based on their conclusions and not on their premises, they are invoked in a somewhat backwards direction. Consequently, this procedure is called backward chaining.
You can view backward chaining as follows. Assume that
fact-1 is contained in the database, along with the following rules:
(if fact-1 then fact-2) (if fact-2 then fact-3) (if fact-3 then fact-4)You want to determine whether
fact-4is true. From the rules, you know that
fact-4would be true if
fact-3were true, and
fact-3would be true if
fact-2were true, and
fact-2would be true if
fact-1 is in the database, it must be true. The application determines the truthfulness of
fact-4 as follows:
fact-1is true, so
fact-2is true, so
fact-3is true, so
Generated with Harlequin WebMaker