50 likes | 148 Views
Chapter1 - continued. 1.3 Recursive rules. How to express predecessor relation in terms of parent relation? It is expressed with two rules: Direct (immediate) predecessors. predecessor (X, Z):- parent (X, Z),
E N D
1.3 Recursive rules • How to express predecessor relation in terms of parent relation? • It is expressed with two rules: • Direct (immediate) predecessors. predecessor (X, Z):- parent (X, Z), • Indirect predecessors ( X is an indirect predecessor of some Z if there is a parentship chain of people between X and Z) For all X and Z, X is a predecessor of Z if there is Y such that (1) X is a parent of Y (2) Y is a parent of Z predecessor (X, Z):- parent (X, Y), predecessor(Y, Z). X X Parent (a) Predecessor Parent (b) Predecessor Parent Z Parent • (Recursion) Z
1.4 How Prolog answers questions • A question is a sequence of one or more goals. To answer questions, Prolog tries to satisfy all the goals • To demonstrate that the goals are true, assuming that the relations in the program are true • To demonstrate that the goal is logically follows from the facts and rules in the program. • If the question contains variables • Prolog also has to find what are the particular objects for which the goals are satisfied. • If Prolog cannot find some instantiation of variables that the goals logically follow from the program, Prolog answer will be ‘no’
Homework Read section 1.4 and 1.5 in your textbook and ask me please if there is any ambiguity.