
Adding Forward Chaining and Truth Maintenance to Prolog Tim Finin Rich Fritzson Dave Matuszek Paoli Research Center Unisys Corporation Paoli, Pennsylvania Contact: Paoli Research Center, Unisys, PO Box 517, Paoli, PA 19301. fininQprc.unisys.com (215-648-7446); fritzsonQprc.unisys.com (215-648-7606); daveQprc.unisys.com (2 15-648- 7489). Topic: Principles, knowledge representation and reasoning tools. Abstract: This paper describes Pjc , a simple package which supplies a for- ward chaining facility in Prolog. Pfc is intended to be used in conjunction with ordinary Prolog programs, allowing the programmer to decide whether to encode a rule as a forward-chaining Pjc rule or a backward chaining Prolog one. Like other logic programming languages, Pfc programs have a declarative interpretation as well as clear and predictable procedural one. A truth maintenance system is built into Pfc system which maintains consis- tency as well as makes derivations available for applications. Finally, Pfcis designed to be practical, being relatively efficient and fairly unobtrusive. Status: Research tool. Domain: This paper describes a domain-independant tool. Language: Prolog. Effort: approximately 1/2 person year. I23 CH2712-8/89/0000/0123$01.00 0 1989 IEEE 1 Introduction tice [15, 231. This section reviews some of the reasons why one might want to apply certain knowledge in the form of forward- Prolog, like most logic programming languages, offers backward chaining rules and looks at some of the issues surrounding the chaining as the only reasoning scheme. It is well known that design of a forward chaining facility. In particular, we will dis- sound and complete reasoning systems can be built using either cuss the importance of a truth maintenance system in a forward exclusive backward chaining or exclusive forward chaining [19]. chaining system. Thus, this is not a theoretical problem. It is also well understood how to “implement” forward reasoning using a backward chain- 2.1 Characterization of Forward Chaining ing system and vice versa. Thus, this need not be a practical problem. In fact, many of the logic-based languages developed The terms forwanl and backwad chaining are used somewhat for AI applications [14,7,20,11] allow one to build systems with loosely within the AI community, covering such disparate things both forward and backward chaining rules. as OPS5-like production systems to resolution-based theorem provers. In general, when one speaks of a forward chaining rule, There are, however, some interesting and important issues which need to be addresses in order to provide the Prolog pro- one has in mind a rule of the form: grammer with a practical, efficient, and well integrated facility PIP~*..P~+QIQ~..*Q~ for forward chaining. This paper describes such a facility, Pjc , which we have implemented in standard Prolog. Informally, the Pj on the left hand side (lhs) of the rule form The Pfc system is a package that provides a forward rea- a set of conditions which, if satisfied, enable the rule for firing. soning capability to be used together with conventional Prolog When fired, the Q; on the rule’s right hand side (rhs) specify a programs. The Pjc inference rules are Prolog terms which are set of actions which are to be carried out. Typically, the condi- asserted as facts into the regular Prolog database. For example, tions correspond to the presence of assertions in a database of Figure 1 shows a file of Pic rules and facts which are appropriate facts. A condition is satisfied if it matches some particular fact for the ubiquitous kinship domain. in this database. There is more variability on the meaning and In the next section of this paper we will review the nature of character of an action in the rhs of a rule. In some systems, such forward chaining, motivations for using it and some of the issues as OPS5 [lo, 171, these can be arbitrary evaluable expressions. one must address in a forward chaining system. We will then give In others, such as MRS [7], the Q; are propositions which are an informal, example-based presentation of the Pjc language in to be added to the fact database. Even in this latter case, sys- the third section. The fourth section will give some more detailed tems differ as to whether the newly derived facts are persistent examples of the use of Pfc . Some of the implementation details and are recorded into the global database [7, 141 or are held in are described in the fifth section. This paper concludes with a a temporary extension to the permanent database (as in a list) final section which summarizes our experiences and plans for the [181. future. Some of the ways in which the meaning of a forward chaining rule can vary are: 2 Forward Chaining Are the constituents of the rule’s rhs actions to be per- formed or propositions to be added to the database? It is well known that one can define sound and complete infer- When the addition of a new fact to the database triggers encing systems which rely solely on either forward or backward some rules, should all of the rules be run or just one? If reasoning. This is discussed in introductory AI texts [19]. It more than one is run, should the order be important? is equally well understood that there are good reasons why one Should retracting database assertions be allowed? might wish to rely on one or the other or a mixed strategy in prac- If retractions are allowed, how should they effect partially triggered rules? If retractions are allowed, should we perform “truth main- <=> spouse(X,Y) spouse(Y,X). tenance”? spouse(X ,Y) ,gender(X ,G> ,IotherGender(G. GZ))=>gender(Y, GZ) . gender(P,male) <=> male(P). Given that we are trying to provide a forward chaining facility for <=> gender(P,female) female(P). Prolog, some of these choices are fairly clear cut. The particulars parent(X,Y),female(X) <=> mother(X,Y). parent(X.Y) ,parent(Y,Z) => grandparent(X,Z). of the package that we have designed are described in the sections grandparent(X,Y),male(X) <=> grandfather(X,Y). to follow. grandparent(X,Y),female(X) <=> grandmtherO(,Y). mother(Ma,Kid),parent(Kid,GKid) => grandmother(Ma,GKid). 2.2 Motivations for Forward Chaining grandparent(X,Y),female(X) <=> grandmother(X,Y). parent(X,Y) .male(X) <=> father(X,Y). There are a number of situations in which a forward chaining mother(Ha,X) ,mother(Ma,Y) ,{X\==Y) => sibling(X,Y). control strategy is preferred over a backward chaining one. We will briefly mention the major ones. We will assume that we are discussing a forward chaining system in which the rhs’s of Figure 1: Examples Pj. Rules which represent common of rules specify necessarily true facts which are to be asserted into kinship relations the global database and remain there until explicitly retracted. 1 24 The usual reasons for choosing a forward reasoning strategy stem drawn (and re-drawn, if necessary) with respect to the current from the particular nature of the problem being solved. These state of the database. include: The second (“internal”) need for a TMS has to do with the particular implementational strategy we have employed. A rule space/time tmdeofls. If a problem involves solving the same with a conjunction on its lhs (i) can be rewritten as shown below goal frequently, it may be more efficient to express the rules (ii): for deducing that goal as forward chaining rules. This re- duces the computation while increasing the need for static (i) P, Q, R => S memory. (ii) F => (9 => (R => SI) the shape of the inferential space. Forward chaining tends That is, as a rule with a atomic lhs (P) which, when triggered, to involve less search than backward chaining when the adds a new rule which monitors for the remaining conjuncts from ratio of premises to conclusions is high. the original rule. In such a scheme, it is important to keep track avoiding long deductive chains. Forward chaining is useful of these derived rules which represent partially instantiated or for avoiding long (or even infinite) deductive chains. triggered rules. If a database assertion supporting a partially dmwing all possible inferences. Many problems require one triggered rule is erased, then the rule need to be killed. This to draw all possible inferences from a set of axioms. For- ensures that a rule will fire only if all of its required conditions ward chaining is an efficient way to do this. are simultaneously true. alerting. A related situation is one in which we want to A truth maintenance system is useful for reasons besides keep- ensure that certain deductions are made as soon as possible, ing the knowledge base consistent. A TMS typically records the e.g. for purposes of alerting or monitoring. proof derivations of all of the facts in the database. This is useful in a variety of ways, such as generating explanations, abductive There are other reasons to consider using a forward chain- reasoning and debugging. ing control structure, one of which we will briefly mention. It is sometimes very convenient to construct a logic program in which a subset of the database acts as the interface between two inde- 3 The Pfclanguage pendent and “concurrent” subsystems. As an example, consider designing a system in which one subsystem maintains a model This section describes Pjc . We will start by introducing the of a set of objects and their locations on a plane and another is language informally through a series of examples drawn from responsible for maintaining a graphical display of these objects.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-