REPRESENTING KNOWLEDGE

USING RULES

Chandra Prakash Lpu

PROCEDURAL V/S DECLARATIVE KNOWLEDGE

A Declarative representation is one in which knowledge is specified but the use to which that knowledge is to be put in, is not given. A Procedural representation is one in which the control information that is necessary to use the knowledge is considered to be embedded in the knowledge itself.

To use a procedural representation, we need to augment it with an interpreter that follows the instructions given in the knowledge.
The difference between the declarative and the procedural views of knowledge lies in where control information resides.

Consider the example
   

man(Mohit) man (ron) Person(Shyam) Vx : man(x)  person(x)

Now we want to extract from this knowledge base the ans to the question :
 

Ǝy : person (y) Mohit, ron or shyam can be the answers

As there is more than one value that satisfies the predicate, but only one value is needed, the answer depends on the order in which the assertions are examined during the search of a response. If we view the assertions as declarative, then we cannot depict how they will be examined. If we view them as procedural, then they do. Let us view these assertions as a non deterministic program whose output is simply not defined, now this means that there is no difference between Procedural & Declarative Statements. But most of the machines don’t do so, they hold on to what ever method they have, either sequential or in parallel. The focus is on working on the control model.

 Logic programming .

g : PROLOG A PROLOG program is described as a series of logical assertions.  .  Because of uniform representation a simple & effective interpreter can be written. The fact that PROLOG programs are composed only of Horn Clauses and not of arbitrary logical expressions has two important consequences. each of which is a Horn Clause. Logic Programming      Logic programming is a programming language paradigm in which logical assertions are viewed as programs. e. A Horn Clause is a clause that has at most one positive literal. The logic of Horn Clause systems is decidable. Eg p. ¬ p V q etc are also Horn Clauses.

There are some syntactic difference between the logic and the PROLOG representations as mentioned The key difference between the logic & PROLOG representation is that PROLOG interpreter has a fixed control strategy. left to right and search is performed depth-first with backtracking. Logic Programming   Even PROLOG works on backward reasoning. so assertions in the PROLOG program define a particular search path to answer any question. Where as Logical assertions define set of answers that they justify. The program is read top to bottom. there can be more than one answers.    . it can be forward or backward tracking .

Consider paths using a depth-first search strategy and use backtracking. invoke a standard unification procedure. Logic Programming  Control Strategy for PROLOG states that we begin with a problem statement. Propagate to the answer by satisfying the conditions. which is viewed as a goal to be proved.      . To decide whether a fact or a rule can be applied to the current problem. Look for the assertions that can prove the goal. Reason backward from that goal until a path is found that terminates with assertions in the program.

 .WHAT IS PROLOG? Logic programming is a programming language paradigm in which logical assertions are viewed as a program  Prolog is described as a series of logical assertions or it is a logic-based language  With a few simple rules. information can be analyzed.

poodle (x)  Small(x) :.pet(x). small(x)  Pet (x) :.dog (x)  Dog (x) :.poodle (x)  Poodle(abs)  .Representation in logic ∀ x : pet(x) Λ small (x)  apartment(x)  ∀ x : cat(x) ⋁ dog(x)  pet(x)  ∀ x : poodle(x)  dog(x) Λ small(x)  Poodle(abs) Representation in PROLOG  Apartment (x) :.

Argument to predicate child(bob.Y):Indicates a rule male(X). “and” . arity 1 (male/1) male(bob). Terminates a clause male(harry).child(X.harry). son(X.pl files contain lists of clauses  Clauses can be either facts or rules Predicate.Y).SYNTAX  .

child(X.  X is a son of Y if X is male and X is a child of Y .Y).RULES  Rules combine facts to increase knowledge of the system son(X.Y):male(X).

directives are clauses with an empty left-hand side.QUESTIONS  In Prolog the queries are statements called directive  Syntactically. This query is interpreted as : Who is a grandparent of X?  The result of executing a query is either success or failure  Success. means the goals specified in the query does not hold according to the facts and rules of the program . Example : ? .  Failure. W). means the goals specified in the query holds according to the facts and rules of the program.grandparent(X.

yes ?. france).king(bob.Ask the Prolog virtual machine questions  Composed at the ?.prompt  Returns values of bound variables and yes or no  ?.son(bob. no . harry).

QUESTIONS [CONT’D]  Can bind answers to questions to variables  Who is bob the son of? (X=harry) ?.male(X). bob the son of someone? (yes) ?.son(bob. X).  No variables bound in this case! .son(bob.  Who  Is is male? (X=bob. harry) ?. _).

child(X.harry).   Recall the rule: son(X.Y).son(X.Y):male(X).BACKTRACKING How are questions resolved? ?. .

Y) male(X) X=harry Y=harry X=bob Y=harry child(harry.BACKTRACKING [CONT’D]  Y is bound to the atom “harry” by the question.harry)? no child(bob.harry)? yes . child(X.succeeds .

APPLICATIONS Intelligent systems  Complicated knowledge databases  Natural language processing  Logic data analysis  .

CONCLUSIONS Strengths:  Strong ties to formal logic  Many algorithms become trivially simple to implement Weaknesses:  Complicated syntax  Difficult to understand programs at first sight .

ISSUES  What applications can Prolog excel at? Is Prolog suited for large applications? Would binding the Prolog engine to another language be a good idea?   .

1 MODUS PONENS *most common inference strategy *simple .These are Modus Ponens and Modus Tollens.   . The rule states that when A is known to be true and if a rule states " If A then B " it is valid to conclude that B is true.1. There are 2 common rules for deriving new facts from rules and known facts. 7.reaoning based on it is easily understood.FORWARD V/S BACKWARD CHAINING:  Infer means " to derive as a conclusion from facts or premises".

rule If A.  This conclusion seems quite obvious but cannot be reached by most expert systems. New rule : Ahmet car is not dirty.  .  E.g: Rule : IF Ahmet's CAR IS DIRTY THEN Ahmet HAS BEEN DRIVING OUTSIDE ANKARA  Given fact : Ahmet has not been outside Ankara. then B then A is false. Because they use modus ponens for deriving new facts from rules.1.2 MODUS TOLLENS  When B is false.7.

Inference engine performs 2 major tasks: 1) examines existing facts and rules and adds new facts when possible 2) decides the order in which inferences are made.  .

TWO REFERENCING METHODS: Forward Chaining  Backward chaining  .

There are 2 directions to go and find the answer   Forward Backward   8-square problem Reason forward from the initial states : Begin building a tree of move sequences that might be solution by starting with the initial configuration(s) at the root of the tree. Continue. .FORWARD V/S BACKWARD REASONING   The objective of any search is to find a path through a problem space from the initial to the final one. Generate the next level of tree by finding all the rules whose left sides match the root node and use the right sides to create the new configurations. Generate each node by taking each node generated at the previous level and applying to it all of the rules whose left sides match it.

to reason forward.FORWARD V/S BACKWARD REASONING  Reason backward from the goal states : Reason backward from the goal states : Begin building a tree of move sequences that might be solution by starting with the goal configuration(s) at the root of the tree.   . Continue. To reason backwards. the left sides(pre conditions) are matched against the current state and the right sides(the results) are used to generate new nodes until the goal is reached. To summarize. This is also called Goal-Directed Reasoning. Generate the next level of tree by finding all the rules whose right sides match the root node and use the left sides to create the new configurations. the right sides are matched against the current node and the left sides are used to generate new nodes. Generate each node by taking each node generated at the previous level and applying to it all of the rules whose right sides match it.

 Backward chaining : also called goal driven. It starts with something to find out. and looks for rules that will help in answering it.  .Forward chaining : also called data driven. and sees what rules apply. It starts with the facts.

.

Problem: Does situation Z exists or not ? .

. until no new facts have been produced....Fm? N RULES R1. ......FORWARD CHAINING ALGORITHM Given m facts F1...1 to n do if one or more current facts match the antecedent of Ri then 1 ) add the new fact(s) define by the consequent 2 ) flag the rule that has been fired 3 ) increase m until no new facts have been produced.F2.Rn repeat for i ?.R2.

BACKWARD CHAINING:  With this inference method the system starts with what it wants to prove. . Figure following shows how bacward chaining would work using the rules from the forward chaining example. and only executes rules that are relavent to establishing it.that situation Z exists. e.g..

.

.

.

 Otherwise. it is proven. . and try to prove each of that rule's conditions. find a rule which can be used to conclude G.BACKWARD CHAINING ALGORITHM: ‡ Prove goal G :  If G is in the initial facts .

In which direction is the branching factor (the average number of nodes that can be reached directly from a single node) greater? We would like to proceed in the direction with the lower branching factor.Factors that influence whether to choose forward or backward reasoning :  Are there more possible start states or goal states? We would like to go from smaller set of states to larger set of states. use backward reasoning. . Will the program be asked to justify its reasoning process to the user? It so. it is important to proceed in the direction that corresponds more closely with the way user will think. forward reasoning should be used. If it a query to which response is desired.    What kind of event is going to trigger a problem-solving episode? If it is the arrival of a new fact .

 . Backward Rules : which encode knowledge about how to achieve particular goals. MYCIN Bidirectional Search ( The two searches must pass each other) Forward Rules : which encode knowledge about how to respond to certain input configurations. Forward v/s Backward Reasoning     Home to unknown place example.

Matching is more complex for forward chaining systems. We work on the incoming data here. The left sides of rules are matched with against the state description. Forward v/s Backward Reasoning  Backward-Chaining Rule Systems    PROLOG is an example of this.  Forward –Chaining Rule Systems      . The rules that match the state dump their right side assertions into the state. Hence Prolog & MYCIN are examples of the same. These are good for goal-directed problem solving. OPS5 is the examples of the same.

 Combining Forward v/s Backward Reasoning   Patients example of diagnosis.this is only possible in reversible rules. In some systems . .

y) P(x. f(x))  Backward chaining with depth-first search: incomplete P(x. y)  Q(x.QUESTION ANSWERING PROLOG:   Only Horn sentences are acceptable The occur-check is omitted from the unification: unsound test  P(x. y)  Q(y. x) 40 . x) P(x. x) Q(x.

C  !. C 41 A . C B  D. E. E D  B.QUESTION ANSWERING PROLOG:  Unsafe cut: incomplete A  B. !. C  D. E. !.

C B  D. C A  Negation as failure: P if fails to prove P 42 . C  D. !.QUESTION ANSWERING PROLOG:  Unsafe cut: incomplete A  B. E. E D  B. C  !. !. E.

Chandra Prakash Then we need to match a particular situation and the preconditions of a given situation. Backward Chaining Systems usually use depth-first backtracking to select individual rules. In many rules based systems. One efficient many to many match algorithm is RETE 43 . but forward chaining systems use Conflict Resolution Strategies.Matching with Variables KNOWLEDGE REPRESENTATION The problem of selecting applicable rules is made more difficult when preconditions are not stated as exact descriptions of particular situations but rather describe properties that the situations must have. we need to compute the whole set of rules that match the current state description.

Example ELIZA Chandra Prakash 44 . Once that is done.Complex & Approximate Matching KNOWLEDGE REPRESENTATION A more complex matching process is required when the preconditions of a rule specify required properties that are not stated explicitly in the description of the current state. so few rules apply that the remaining search is trivial. Example of listening to a recording of a telephonic conversation. almost all the action is in the matching of the rules to the problem state. a separate set of rules must be used to describe how some properties can be inferred from others. In this case. For some problems. An even more complex matching process is required if rules should be applied if their preconditions approximately match the current situation.

Assign a preference based on the action that the matched rule would 45 perform. There are three basic approaches to the problem of conflict resolution in the production system Assign a preference based on the rule that matched. It is the job of the search method to decide on the order in which the rules will be applied. . Chandra Prakash Assign a preference based on the objects that matched.KNOWLEDGE REPRESENTATION Conflict Resolution The result of the matching process is a list of rules whose antecedents have matched the current state description along with whatever variable binding were generated by the matching process. But sometimes it is useful to incorporate some of the decision making into the matching process. This phase is called conflict resolution.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.