0% found this document useful (0 votes)
36 views56 pages

BCS Lecture3 2015

artificial intelligence notes part 4

Uploaded by

ISAAC SICHALWE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views56 pages

BCS Lecture3 2015

artificial intelligence notes part 4

Uploaded by

ISAAC SICHALWE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 56

BCS/BIT:ARTIFICIAL

INTELLIGENCE

Lecture PowerPoints

1
Knowledge Representation

2
Topics Covered
• Introduction
• First-Order Predicate Calculus
• Introduction to PROLOG

3
Introduction
• In order to solve the complex problems encountered in
artificial intelligence, one needs
– a large amount of knowledge
– and some mechanisms for manipulating that knowledge to create
solutions to new problems
• A variety of ways of representing knowledge (facts) have
been exploited in AI programs.
• In knowledge representation, we are dealing with two
different kinds of entities:
– Facts: truths in some relevant world. These are the things we want
to represent.
– Representations of facts in some chosen formalism. These are the
things we will actually be able to manipulate.
4
First order predicate calculus

5
First order predicate calculus (1)
• First order predicate calculus (or first-order predicate logic) is
one formalism of representing facts
• The logical formalism is appealing because it immediately
suggests a powerful way of deriving new knowledge from the
old
– mathematical deduction
• We can conclude that a new statement is true by proving that it
follows from statements that are already known
• The following standard logic symbols are used: “” (material
implication), “” (not), “” (or), “” (and), “” (for all), “”
(equivalence), and “” (there exists)
• The variable quantifiers  and  constrain the meaning of a
sentence containing a variable.

6
First order predicate calculus (2)
• A quantifier is followed by a variable and a sentence,
such as
 Y friends(Y, peter)
 X likes(X, ice_cream)
• First order predicate calculus allows quantified variables
to refer to objects in the domain of discourse and not to
predicates or functions.
– Example of predicates are likes, equals, on, near , part_of

7
Representing simple facts in logic (1)
• Propositional logic can be used to representing the sort of
world knowledge that an AI system might need.
• A proposition is a statement that is either true or false but not
both.
• An example proposition is the statement “it is raining”.
– This can be represented by a symbol RAINING which can either be
true or false.
• Real-world facts can be represented as logical propositions
written as well-formed formulas (wff’s) in propositional logic as
shown in Figure 1.
• An expression is a sentence or well-formed formula of
propositional logic if and only if it can be formed of legal
symbols through some sequence of rules.

8
It is raining.
RAINING

It is sunny.
SUNNY

It is windy.
WINDY

If it is raining, then it is not sunny.


RAINING SUNNY

Figure 1: Some simple facts in propositional logic


9
Representing simple facts in logic (2)
• We appear to be forced to move to first-order predicate logic (first
order predicate calculus)
– to represent knowledge since it permits representations of things that cannot
reasonably be represented in propositional logic.
• In predicate logic, we can represent real-world facts as statements
written as wff’s.
• A major motivation for choosing to use logic is that
– if we use logical statements to representing knowledge, then we have
available a good way of reasoning with that knowledge
• Predicate logic provides a way of deducing new statements from
old ones
• Let’s explore the use of predicate logic as a way of representing
knowledge
• Consider the following set of sentences:

10
Representing simple facts in logic (3)

1. Marcus was a man.


2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers they are not loyal
to.
8. Marcus tried to assassinate Caesar.

11
Representing simple facts in logic (4)
1. Marcus was a man.
man(Marcus)
– This representation captures a fact of Marcus being a man.
– It fails to capture of the information in the English sentence, namely
the notion of past tense.
– Whether this omission is acceptable or not depends on use to which
we intend to put the knowledge. For this example it is ok
2. Marcus was a Pompeian.
Pompeian(Marcus)
3. All Pompeians were Romans.
x:Pompeian(x) Roman(x)
4. Caesar was a ruler.
ruler(Caesar)

12
Representing simple facts in logic (5)
– Here we ignore the fact that proper names are often not references to
unique individuals, since many people share the same name.
5. All Romans were either loyal to Caesar or hated him.
x:Roman(x) loyalto(x,Caesar) hated(x,Caesar)
– Here we have used inclusive interpretation of or.
6. Everyone is loyal to someone.
x:  y: loyalto(x,y)
– The major problem that arises when trying to convert English sentences
into logical statements is the scope of quantifiers.
– Does this sentence say that for each person there exist someone to
whom he or she is loyal, possibly a different someone for everyone?
– Or does it say that there exist someone to whom everyone is loyal (which
would be written as y:x:loyalto(x,y)?
– Often only one of the two interpretations seems likely.

13
Representing simple facts in logic (6)

7. People only try to assassinate rulers they are not loyal to.
x:y: person(x)ruler(y)tryassasinate(x,y)loyalto(x,y)
– This sentence, too, is ambiguous.
– Does it mean that the only rulers that people try to assassinate
are those to whom they are not loyal (interpretation used here)?
– Or does it mean that the only thing people try to do is to
assassinate rulers to whom they are not loyal?
8. Marcus tried to assassinate Caesar.
tryassasinate(Marcus,Caesar)
• From this brief attempt to convert English sentences into
logical statements, it should be clear how difficult the task
is.

14
Representing simple facts in logic (7)
• Now suppose that we want to use these statements to
answer the question
Was Marcus loyal to Caesar?
• It seems that using 7 and 8, we should be able to prove
that Marcus was not loyal to Caesar.
• Now let’s try to produce a formal proof, reasoning
backward from the desired goal
loyalto(Marcus,Caesar)
• To prove the goal, we need to use the rules of inference
to transform it to another goal (or a set of goals)
– that can in turn be transformed, and so on, until there are no
unsatisfied goals remaining.
15
Representing simple facts in logic (8)
• Figure 2 shows an attempt to produce a proof of the goal
– by reducing the set of necessary but as yet unattained goals to the
empty set.
• The attempt fails, since there is no way to satisfy the goal
person(Marcus) with the statements available.
• Although we know that Marcus was a man, we have no way to
conclude from this that Marcus was a person.
• We need to add the representation of another fact to our
system, namely:
9. All men are people.
x:man(x)person(x)
• Now we can satisfy the last goal and produce a proof that
Marcus was not loyal to Caesar.

16
loyalto(Marcus, Caesar)
(7, substitution)
person(Marcus) 
ruler(Caesar) 
tryassasinate (Marcus, Caesar)
(4)
person(Marcus) 
tryassasinate (Marcus, Caesar)
(8)
person(Marcus)
Figure 2: An attempt to prove  loyalto(Marcus,Caesar) 17
Representing simple facts in logic (9)
• An additional problem arises in situations where we do not
know in advance which statements to deduce.
• In the previous example, the object was to answer the
question “Was Marcus loyal to Caesar?”
• How would a program decide whether it should try
loyalto(Marcus,Caesar)
loyalto(Marcus,Caesar)
• There are several things it could do:
• Reason forward from axioms to proposed truth and see which
answer it gets to.
– The problem is that, in general, the branching factor going forward from
the axioms is so great
– It probably won’t get to the answer in reasonable amount of time

18
Representing simple facts in logic (10)
• A second thing is use some sort of heuristic rules for
deciding which answer is more likely and then try to
prove that one first.
– If it fails to find a proof after some reasonable amount of time, it
can try the other answer.
• Another thing it could do is simply try to prove both
answers simultaneously and stop when one effort is
successful.
• A fourth strategy is to try both to prove one answer and
to disprove it and to use information gained in one of the
process to guide the other.

19
Connections between  and  (1)
• The two quantifiers are actually intimately connected with each
other, through negation.
• Asserting that everyone dislikes snakes is the same as
asserting there does not exist someone who likes them, and
vice versa:
x: likes(x,snakes) is equivalent to x: likes(x,snakes)
• “Everyone likes ice cream” means that there is no one who
does not like ice cream:
x: likes(x,ice_cream) is equivalent to x: likes(x,ice_cream)
• Since  is a conjunction over the universe of objects and  is a
disjunction, they obey De Morgan’s rules.
• The De Morgan’s rules for quantified and unquantified
sentences are as follows:

20
Connections between  and  (2)

x: P(x)   x:P(x) (PQ)  PQ


 x: P(x)   x:P(x) (PQ)  PQ
x: P(x)    x:P(x) (PQ) 
(PQ)
x: P(x)   x:P(x) PQ  (PQ)

Thus, we do not need both  and  just as we do not need


both  and .

21
Computable functions and predicates
(1)
• Suppose we want to express simple facts, such as the following
greater than and less than relationships:
gt(1, 0) lt(0,1)
gt(2,1) lt(1,2)
gt(3,2) lt(2,3)
 
• There are infinitely many representations of the facts above and
thus not feasible to write them individually.
• Even if they were finite, it would be inefficient to store a large set
of statements.
• It is better if we compute each value as we need it.
• It thus becomes useful to augment our representation by these
computable predicates.
22
Computable functions and predicates
(2)
• Whenever such a predicate is encountered, we can
simply invoke a procedure that will evaluate it and return
true or false.
• It is also useful to have computable functions as well.
• Thus we might want to evaluate the truth of gt(2+3,1)
– Here we first compute the value of the plus function given in the
arguments 2 and 3, and then send the arguments 5 and 1 to gt.
• The next example shows how these ideas of computable
functions and predicates can be useful.
• Consider the following set of facts, again involving
Marcus:

23
Computable functions and predicates
(3)
1. Marcus was a man.
Man(Marcus)
2. Marcus was a Pompeian.
Pompeian(Marcus)
3. Marcus was born in 40 A.D.
born(Marcus,40)
For simplicity, A.D. is not represented explicitly.
4. All men are mortal
x: man(x)mortal(x)
5. All Pompeians died in 79 A.D.
x: Pompeian(x)died(x,79)
6. The volcano erupted in 79 A.D.
erupted(volcano,79)
24
Computable functions and predicates
(4)
7. No mortal lives longer than 150 years
x: t1 : t2 mortal(x) born(x,t1)  gt(t2-t1, 150) dead(x,t2)
The sentence could also be expressed by introducing a function
and assert that its value is never greater than 150.
8. It is now 2012
now = 2012
Here we exploit the idea of equal quantities that can be
substituted for each other.
• Suppose we ask the question “Is Marcus alive?”
• There may be two ways of deducing an answer.

25
Computable functions and predicates
(5)
• Either we can show Marcus is dead because he was killed by
the volcano
– or show that he must be dead because he would otherwise be more
than 150 years.
• As we attempt to follow either of those paths rigorously, we
discover that additional knowledge is needed.
• Our statements talk about dying but say nothing that relates to
being alive.
• So we add the two facts:
Alive means not dead
9. x: t : [ alive(x,t)  dead(x,t)] [ alive(x,t)  dead(x,t)]
If someone dies, then he is dead at all later times
10. x: t1 : t2 died(x,t1) gt(t2,t1) dead(x,t2)

26
Computable functions and predicates
(6)
– This says one is dead in all years after the one which one died.
• All Pompeians died when the volcano erupted in 79 A.D.
erupted (volcano, 79) x: [Pompeian(x)died(x,79)]
– This asserts the two facts represented above. It may also assert
that the eruption of volcano caused the death of the Pompeians.
• Now let’s attempt to answer the question “Is Marcus
alive?” by proving
 alive(Marcus, now)

27
Computable functions and predicates
(7)
• One proof is shown in Figure 3.
• The term nil at the end of the proof indicates that the list
of conditions remaining to be proved is empty and so the
proof has succeeded.
• Notice that whenever a statement of the form a  b  c
was used, a and b were set up as independent subgoals.
• From the proof just shown, two things should be clear:
– Even very simple conclusions can require many steps to prove.
– A variety of processes, such as matching, substitutions are
involved in the production of a proof.

28
Figure 3: One way of proving that Marcus is dead 29
Computable functions and predicates
(8)
• The first observation suggests that to do non-trivial
reasoning, some statements that require bigger steps
along the way may be needed.
– These should represent the facts that people gradually acquire
as they become experts.
• The second observation suggests that building a
program to do what people do in producing proofs such
as these may not be easy.
• A proof procedure called resolution reduces some of the
complexity because it operates on statements that have
first been converted to a single canonical form.

30
Resolution (1)
• It would be useful from a computational point of view if we had a
proof procedure that carried out in a single operation the variety
of processes involved in reasoning with statements in predicate
logic
• Resolution is such a procedure,
– It gains its efficiency from the fact that it operates on statements that
have been converted to a very convenient standard form
• Resolution produces proofs by refutation.
– In other words, to prove a statement (i.e., show that it is valid), resolution
attempts to show that the negation of the statement produces a
contradiction with the known statements.
• This approach contrasts with the technique to generate proofs
by chaining backward from the theorem to be proved to the
axioms.
31
Conversion to clause form (1)
• Suppose we know that all Romans who know Marcus either
hate Caesar or think that anyone who hates anyone is crazy.
• We could represent that in the following wff:
 x:[Roman(x) know(x, Marcus)]
[hate(x,Caesar) ( y: z: hate(y,z)thinkcrazy(x,y))]
• To use this formula in a proof requires complex matching
process.
• Having matched one piece to it, such as, thinkcrazy(x,y), it is
necessary to do the right thing with the rest of the formula.
• If the formula were in a simpler form, this process would be
much easier.

32
Conversion to clause form (2)
• The formula would be easier to work with if
– It were flatter, i.e., there was less embedding of components
– The quantifiers were separate from the rest of the formula so that they
did not need to be considered
• Conjunctive normal form has both of these properties.
• For example the formula given above would be represented
in conjunctive normal form as
 Roman(x)  know(x, Marcus)]
hate(x,Caesar)  hate(y,z) thinkcrazy(x,y)
• For resolution to work, we need to reduce a set of wff’s to
a set of clauses,
– where a clause is defined to be a wff in conjunctive normal form but
with no instances of the connector  .

33
Conversion to clause form (3)
• We can do this by first converting each wff into
conjunctive normal form and then breaking apart each
such expression into clauses, one for each conjunct.
• All the conjuncts will be considered to be conjoined
together as the proof procedure operates.
• To convert a wff into clause form, perform the following
sequence of steps.

34
Algorithm: Convert to clause form (1)
1. Eliminate , using the fact that a  b is equivalent to  a  b.
Performing this transformation on the wff given above yields
 x:  [Roman(x) know(x, Marcus)] 
[hate(x,Caesar)  ( y: ( z: hate(y,z) thinkcrazy(x,y))]
2. Reduce the scope of each  to a single term, using the fact
that
(p) = p,
deMorgan’s laws [ (a  b) = a   b and (a  b) =  a   b ],
and the standard correspondences between quantifiers [ x: P(x) = x:
P(x) and x: P(x) = x: P(x) ].
Performing this transformation on the wff from step 1 yields
 x: [ Roman(x)   know(x, Marcus)] 
[hate(x,Caesar)  ( y:  z:  hate(y,z) thinkcrazy(x,y))]

35
Algorithm: Convert to clause form (2)
3. Standardize variables so that each quantifier binds a unique
variable.
– Since the variables are just dummy names, this process cannot affect truth
value of the wff
– For example, the formula  x: P(x)   x:Q(x) would be converted to  x:
P(x)   y:Q(y). This step is in preparation for the next.
4. Move all the quantifiers to the left of the formula without changing
their relative order.
– This is possible since there is no conflict among variable names.
Performing this operation on formula of step 2, we get
 x:  y:  z:[ Roman(x)   know(x, Marcus)] 
[hate(x,Caesar)  (  hate(y,z) thinkcrazy(x,y))]
– The formula is now in what is known as prenex normal form.
– It contains a prefix of quantifiers followed by a matrix, which is quantifier-
free.

36
Algorithm: Convert to clause form (3)
5. Eliminate existential quantifiers.
– A formula that contains an existentially quantified variable asserts
that there is a value that can be substituted for a variable that
makes the formula true.
– We can do so by substituting for the variable a reference to a
function that produces the desired value.
– For example  y:President(y) can be transformed into President
(SI) where SI is a function with no arguments but produces a
value that satisfies President.
6. Drop the prefix.
– At this point all remaining variables are universally quantified
– so the prefix can just be dropped and any proof procedure we use
can simply assume that any variable it sees is universally
quantified.
37
Algorithm: Convert to clause form (4)
– Now the formula produced in step 4 appears as
[ Roman(x)   know(x, Marcus)] 
[hate(x,Caesar)  (  hate(y,z) thinkcrazy(x,y))]
7. Convert the matrix into a conjunction of disjuncts.
– In the case of our example, since there are no and’s it is necessary to
exploit the associative property of or [i.e., a  (b  c) = (a  b)  c] and
simply remove the parentheses, giving
 Roman(x)   know(x, Marcus) 
hate(x,Caesar)   hate(y,z) thinkcrazy(x,y)
8. Create a separate clause corresponding to each conjunct.
– In order for a wff to be true, all the clauses that are generated from it must
be true.
– If we are going to be working with several wff’s, all the clauses generated
by each of them can now be combined to represent the same set of facts
as were represented by the original wff’s.

38
Algorithm: Convert to clause form (5)

9. Standardize apart the variables in the set of clauses


generated in step 8.
– By this we mean rename the variables so that no two clauses
make reference to the same variable.
– In making this transformation, we rely on the fact that ( x: P(x)
 Q(x)) =  x: P(x)   x: Q(x)
– Performing this final step of standardization is important
because during the resolution procedure it is sometimes
necessary to instantiate a universally quantified variable.
– After applying this entire procedure to a set of wff’s, we will
have a set of clauses, each of which is a disjunction of literals.
– These clauses can now be exploited by the resolution
procedure to generate proofs.

39
Horn Clause (1)
• A horn clause is a disjunction of literals of which at most
one is positive. An example of a horn clause is
 p  q t  u
– Such a formula can also be written equivalently in the form of an
implication:
(p  q  t ) u
• In other words, if p, q, t etc. are all true then u must be true.
• Horn clauses are relevant to theorem proving by resolution,
in that the resolution of two Horn clauses is itself a Horn
clause.
• Moreover, the resolution of a goal clause and a definite
clause is again a goal clause.

40
Horn Clause (2)
• A Horn clause with exactly one positive literal is a
definite clause.
• In automated theorem proving, this can lead to greater
efficiencies in proving a theorem represented as a goal
clause.

41
The basis of resolution (1)
• The resolution procedure is a simple iterative process:
– at each step, two clauses, called the parent clauses, are compared
(resolved), yielding a new clause that has been inferred from them.
• The new clause represents ways that the two parent clauses
interact with each other.
• Suppose that there are two clauses in the system:
winter  summer
 winter  cold
both clauses must be true.
• One of winter and  winter will be true at any point.
– If winter is true, then cold must be true to guarantee the truth of the second
clause.
– If  winter is true, then summer must be true to guarantee the truth of the
first clause.

42
The basis of resolution (2)
• Thus we can see that from these two clauses we can deduce
summer  cold
• This is a deduction that a resolution procedure will make
• Resolution operates by taking two clauses that each contain
the same literal, in this example, winter.
• The literal must occur in positive form in one clause and in
negative form in the other.
• The resolvent is obtained by combining all of the literals of the
two parent clauses except the ones that cancel
• If the clause that is produced is the empty clause, then a
contradiction has been found.
– For example, the two clauses winter and  winter will produce an
empty clause.

43
Logic Programming (PROLOG)

44
Introduction to PROLOG (1)
• Logic programming is a programming language paradigm in
which logical assertions are viewed as programs.
• There are several logic programming systems today,
– the most popular is PROLOG (PROgramming in LOGic).
• A PROLOG program is described as a series of logical
assertions, each of which is a Horn clause.
• A Horn clause is a clause that has at most one positive literal.
– To be precise, a horn clause is a disjunction of literals of which at
most one is positive. An example
P Q…TU
– Can also be written equivalently in the form of an implication:
( P  Q  …T )  U

45
Introduction to PROLOG (2)
– If P, Q, T, etc. are all true then U must be true.
• Thus P,  P  Q, and P  Q are all Horn clauses.
– P  Q is equivalent to  P Q
• Horn clauses in PROLOG programs
– have an implication with at most one literal on the right
• The fact that PROLOG programs are composed only of Horn
clauses has two important consequences:
– A simple and efficient interpreter can be written
– The logic of Horn clause systems is decidable
• The input to a program is a goal to be proved.
– Backward reasoning is applied to try to prove the goal given the assertions
in the program.
– The program is read top to bottom, left to right and search is performed
depth-first with backtracking.

46
Introduction to PROLOG (3)
• Figure 1 shows an example of a simple knowledge base
represented in standard logical notation and PROLOG.
X ( pet ( X )  small ( X )  apartmentp et ( X ))
X (cat ( X )  dog ( X )  pet ( X ))
X ( poodle ( X )  dog ( X )  small ( X ))
poodle ( fluffy )
A representation in Logic

apartmentpet(X) :- pet(X), small(X).


pet(X) :- cat(X).
pet(X) :- dog(X).
dog(X) :- poodle(X).
small(X):- poodle(X).
poodle(fluffy).
A representation in PROLOG
47
Figure 1: A declarative and procedural representation
Introduction to PROLOG (4)
• Both representations contain two types of statements
– Facts, which contain only constants (i.e., no variables). Facts represent
statements about specific objects
– Rules, which contain variables. Rules represent statements about classes
of objects
• Syntactic differences between the logical and PROLOG
representations
– In logic, variables are explicitly quantified. In PROLOG, quantification is
provided implicitly by the way the variables are interpreted.
– In PROLOG, all variables begin with upper case letters and all constants
begin with lower case letters or numbers
– In logic, there are explicit symbols for and (  ) and or ( ). In PROLOG,
there is an explicit symbol for and (,), but none for or.
 In PROLOG, disjunction is represented as a list of alternative statements, any
one of which may provide a basis for a conclusion.

48
Introduction to PROLOG (5)
– In logic, implications of the form “P imply Q” are written PQ. In
PROLOG, the implication is written “backward”, as Q :- P.
 This form is natural in PROLOG since the interpreter works backwards
from a goal
 The first component (Q) is called the head of the rule.
• The first two of these differences arise from the fact that
PROLOG programs are sets of Horn clauses that have been
transformed as follows:
– If the Horn clause contains no negative literals, leave it as it is.
– Otherwise, rewrite the Horn clause as an implication,
 combining all of the negative literals into the antecedent of the implication
and leaving the single positive literal as the consequent
• This procedure causes a clause to be transformed into a
single implication whose LHS is a conjunction of literals.

49
Introduction to PROLOG (6)
• In a clause, all variables are implicitly universally
quantified.
• But when we apply transformation, any variables that
occurred in negative literals now occur in the antecedent
become existentially quantified,
– while the variables in the consequent (the head) are still
universally quantified.
• For example, the PROLOG clause
P(X) :- Q(X, Y)
is equivalent to the logical expression
 X (  Y Q(X,Y) P(X))

50
Introduction to PROLOG (7)
• A key difference between logic and the PROLOG:
– The PROLOG interpreter has a fixed control strategy,
 and so assertions in the PROLOG program define a particular search path to an answer
to any question.
– In contrast, the logical assertions define only the set of answers that they justify;
 they themselves say nothing about how to choose among those answers if there are
more than one.
• The PROLOG control strategy outlined above is simple.
– Begin with a problem statement, viewed as a goal to be proved.
– Look for assertions that can prove the goal.
– Consider facts, which prove the goal directly, and also consider any rule whose
head matches the goal.
– To decide whether a fact or a rule can be applied to the current problem, invoke a
standard unification procedure.
– Reason backward from that goal until a path is found that terminates with
assertions in the program.

51
Introduction to PROLOG (8)
– Consider paths using a depth-first search strategy and using backtracking.
– At each choice point, consider options in the order in which they appear in
the program.
– If a goal has more than one conjunctive part, prove the pairs in the order in
which they appear, propagating variable bindings as they are determined
during unification.
• We can illustrate this strategy with a simple example.
• Suppose the problem is to find a value of X that satisfies the
predicate apartmentpet(X).
• We state this goal to PROLOG as
?- apartmentpet(X).
• Think of this as the input to the program.
– The PROLOG interpreter begins looking for a fact with the predicate
apartmentpet or a rule with that predicate as its head.

52
Introduction to PROLOG (9)
• PROLOG programs are usually written with facts containing a
given predicate coming before the rules for that predicate
• In this example, there are no facts with this predicate so the
one rule there must be used
• Since the rule will succeed if both clauses on its RHS can be
satisfied,
– the next thing the interpreter does is to try to prove each of them.
• They will be tried in the order in which they appear.
– There are no facts with the predicate pet but again there are rules with
it on the RHS. But this time there are two such rules, rather than one.
• All that is necessary for proof is that one of them succeed.
– They will be tried in the order in which they occur.

53
Introduction to PROLOG (10)
• The first will fail because there are no assertions about the
predicate cat in the program.
• The second will eventually lead to success,
– using the rule about dogs and poodles and using the fact poodle(fluffy).
• This results in the variable X being bound to fluffy.
• Now the second clause small(X) of the initial rule must be
checked.
• Since X is now bound to fluffy, the more specific goal,
small(fluffy), must be proved.
• This too can be done by reasoning backward to the assertion
poodle(fluffy).
• The program halts with the result apartmentpet(fluffy).

54
Introduction to PROLOG (11)
• Logical negation () cannot be represented explicitly in pure
PROLOG.
• E.g., it’s not possible to encode directly the logical assertion
X(dog(X)  cat(X))
• Negation is represented implicitly by lack of an assertion.
• This leads to the problem-solving strategy called negation as
failure.
• If the PROLOG program of Figure 1 were given the goal
?- cat(fluffy).
• It would return FALSE because it is unable to prove that
fluffy is a cat

55
Introduction to PROLOG (12)
• Negation by failure requires that we make the closed world assumption,
– all relevant, true assertions are contained in our knowledge base or are derivable
from assertions that are so contained.
• Any assertion that is absent can be assumed to be false.
• A great advantage to logic programming
– is that the programmer need only specify rules and facts since a search engine is
built directly into the language
• The disadvantage is that the search control is fixed.
– It is difficult to write PROLOG code that uses search strategies other than depth-
first with backtracking.
– It is more difficult to apply domain knowledge to constrain a search.
• The fact that PROLOG programs must be composed of a restricted set
of logical operators
– can be viewed as a limitation of the expressiveness of the language.

56

You might also like