0% found this document useful (0 votes)
37 views13 pages

Ai Chapter-4

This document discusses using predicate logic to represent knowledge. It explains some key concepts in predicate logic including predicates, quantifiers, and representing relationships. It provides an example of representing facts about people as logical statements and using those statements to deduce new information through logical proofs.

Uploaded by

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

Ai Chapter-4

This document discusses using predicate logic to represent knowledge. It explains some key concepts in predicate logic including predicates, quantifiers, and representing relationships. It provides an example of representing facts about people as logical statements and using those statements to deduce new information through logical proofs.

Uploaded by

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

4 – Using Predicate Logic

Logic
• The logical formalism of a language is useful because it immediately suggests a powerful
way of deriving new knowledge from old using mathematical deduction.
• In this formalism, we can conclude that a new statement is true by proving that it follows
from the statements that are already known.
Proposition
▪ A proposition is a statement, or a simple declarative sentence.
▪ For example, “the book is expensive” is a proposition.
▪ A proposition can be either true or false.
Propositional logic
▪ Logical constants: true, false
▪ Propositional symbols: P, Q, S,... (atomic sentences)
▪ Propositions are combined by connectives:

 and [conjunction]

 or [disjunction]

 implies [implication]

 not [negation]

∀ For all

∃ There exists

▪ Propositional logic is a simple language useful for showing key ideas and definitions.
▪ User defines a set of propositional symbols, like P and Q.
▪ User defines the semantics of each propositional symbol:
P means “It is hot”
Q means “It is humid”
R means “It is raining”
• A sentence (well-formed formula) is defined as follows:
➢ A symbol is a sentence.
➢ If S is a sentence, then  S is a sentence.
➢ If S is a sentence, then (S) is a sentence.
➢ If S and T are sentences, then (S  T), (S  T), (S → T), and (S ↔ T) are sentences
➢ A sentence results from a finite number of applications of the above rules.
• Real world facts can be represented by well-formed formulas (wffs) in propositional
logic.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 1


4 – Using Predicate Logic

Representation of Simple Facts in Logic


• Propositional logic is useful because it is simple to deal with and a decision procedure for it
exists.
• In order to draw conclusions, facts are represented in a more convenient way as,
1. Marcus is a man.
man(Marcus)
2. Plato is a man.
man(Plato)
3. All men are mortal.
mortal(men)
• But propositional logic fails to capture the relationship between any individual being a man
and that individual being a mortal.
• How can these sentences be represented so that we can infer the third sentence from the
first two?
• Propositional logic commits only to the existence of facts that may or may not be the case in
the world being represented.
• It has a simple syntax and simple semantics. It suffices to illustrate the process of inference.
• Propositional logic quickly becomes impractical, even for very small worlds.

Predicate logic
• First-order Predicate logic (FOPL) models the world in terms of
o Objects, which are things with individual identities
o Properties of objects that distinguish them from other objects
o Relations that hold among sets of objects
o Functions, which are a subset of relations where there is only one “value” for any
given “input”
• First-order Predicate logic (FOPL) provides
o Constants: a, b, dog33. Name a specific object.
o Variables: X, Y. Refer to an object without naming it.
o Functions: Mapping from objects to objects.
o Terms: Refer to objects
o Atomic Sentences: in(dad-of(X), food6) Can be true or false, Correspond to
propositional symbols P, Q.
o A well-formed formula (wff) is a sentence containing no “free” variables. That is, all
variables are “bound” by universal or existential quantifiers.
(x)P(x, y) has x bound as a universally quantified variable, but y is free.
Quantifiers
• Universal quantification
(x)P(x) means that P holds for all values of x in the domain associated with that
Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 2
4 – Using Predicate Logic
variable
E.g., (x) dolphin(x) → mammal(x)
• Existential quantification
( x)P(x) means that P holds for some value of x in the domain associated with that
variable
E.g., ( x) mammal(x)  lays-eggs(x)

• Consider the following example that shows the use of predicate logic as a way of
representing knowledge.
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Pompeians 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.
• The facts described by these sentences can be represented as a set of well-formed formulas
(wffs) as follows:
1. Marcus was a man.
man(Marcus)
2. Marcus was a Pompeian.
Pompeian(Marcus)
3. All Pompeians were Romans.
x: Pompeian(x) → Roman(x)
4. Caesar was a ruler.
ruler(Caesar)
5. All Pompeians were either loyal to Caesar or hated him.
inclusive-or
x: Roman(x) → loyalto(x, Caesar)  hate(x, Caesar)
exclusive-or
x: Roman(x) → (loyalto(x, Caesar)  hate(x, Caesar)) 
(loyalto(x, Caesar)  hate(x, Caesar))
6. Every-one is loyal to someone.
x: y: loyalto(x, y)
7. People only try to assassinate rulers they are not loyal to.
x: y: person(x)  ruler(y)  tryassassinate(x, y)
→ loyalto(x, y)
8. Marcus tried to assassinate Caesar.
tryassassinate(Marcus, Caesar)

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 3


4 – Using Predicate Logic
• Now suppose if we want to use these statements to answer the question
Was Marcus loyal to Caesar?
• Now let's try to produce a formal proof, reasoning backward from the desired goal:
¬ Ioyalto(Marcus, Caesar)
• In order to prove the goal, we need to use the rules of inference to transform it into another
goal (or possibly a set of goals) that can in turn be transformed, and so on, until there are no
unsatisfied goals remaining.

Figure 4.1 An attempt to prove ¬loyalto(Marcus, Caesar).

• The problem is that, although we know that Marcus was a man, we do not have any way
to conclude from that that Marcus was a person. We need to add the representation of
another fact to our system, namely:
∀ : man(x) → person(x)
• Now we can satisfy the last goal and produce a proof that Marcus was not loyal to
Caesar.
• From this simple example, we see that three important issues must be addressed in the
process of converting English sentences into logical statements and then using those
statements to deduce new ones:
1. Many English sentences are ambiguous (for example, 5, 6, and 7 above).
Choosing the correct interpretation may be difficult.
2. There is often a choice of how to represent the knowledge. Simple
representations are desirable, but they may exclude certain kinds of reasoning.
3. Even in very simple situations, a set of sentences is unlikely to contain all the
information necessary to reason about the topic at hand. In order to be able to
use a set of statements effectively, it is usually necessary to have access to
another set of statements that represent facts that people consider too obvious
to mention.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 4


4 – Using Predicate Logic

Representing INSTANCE and ISA Relationships


• Specific attributes instance and isa play important role particularly in a useful form of
reasoning called property inheritance.
• The predicates instance and isa explicitly captured the relationships they are used to
express, namely class membership and class inclusion.
• Fig. 4.2 shows the first five sentences of the last section represented in logic in three
different ways.
• The first part of the figure contains the representations we have already discussed. In these
representations, class membership is represented with unary predicates (such as Roman),
each of which corresponds to a class.
• Asserting that P(x) is true is equivalent to asserting that x is an instance (or element) of P.
• The second part of the figure contains representations that use the instance predicate
explicitly.

Figure 4.2 Three ways of representing class membership

• The predicate instance is a binary one, whose first argument is an object and whose second
argument is a class to which the object belongs.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 5


4 – Using Predicate Logic
• But these representations do not use an explicit isa predicate.
• Instead, subclass relationships, such as that between Pompeians and Romans, are described
as shown in sentence 3.
• The implication rule states that if an object is an instance of the subclass Pompeian then it is
an instance of the superclass Roman.
• Note that this rule is equivalent to the standard set-theoretic definition of the subclass-
superclass relationship.
• The third part contains representations that use both the instance and isa predicates
explicitly.
• The use of the isa predicate simplifies the representation of sentence 3, but it requires that
one additional axiom (shown here as number 6) be provided.

Computable Functions and Predicates


• To express simple facts, such as the following greater-than and less-than relationships:
gt(1,O) It(0,1)
gt(2,1) It(1,2)
gt(3,2) It( 2,3)
• It is often also useful to have computable functions as well as computable predicates. Thus
we might want to be able to evaluate the truth of
gt(2 + 3,1)
• To do so requires that we first compute the value of the plus function given the arguments 2
and 3, and then send the arguments 5 and 1 to gt.
• Consider the following set of facts, again involving Marcus:
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)
4. All men are mortal.
∀x: man(x) → mortal(x)
5. All Pompeians died when the volcano erupted in 79 A.D.
erupted(volcano, 79) ∧ ∀ x : [Pompeian(x) → died(x, 79)]
6. No mortal lives longer than 150 years.
∀x: ∀t1: At2: mortal(x) ∧ born(x, t1) ∧ gt(t2 - t1,150) → died(x, t2)
7. It is now 1991.
now = 1991
• Above example shows how these ideas of computable functions and predicates can be
useful.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 6


4 – Using Predicate Logic
• It also makes use of the notion of equality and allows equal objects to be substituted for
each other whenever it appears helpful to do so during a proof.
• Now suppose we want to answer the question "Is Marcus alive?”
• The statements suggested here, there may be two ways of deducing an answer.
• Either we can show that Marcus is dead because he was killed by the volcano or we can
show that he must be dead because he would otherwise be more than 150 years old, which
we know is not possible.
• As soon as we attempt to follow either of those paths rigorously, however, we discover, just
as we did in the last example, that we need some additional knowledge. For example, our
statements talk about dying, but they say nothing that relates to being alive, which is what
the question is asking.
• So we add the following facts:
8. Alive means not dead.
∀x: ∀t: [alive(x, t) → ¬ dead(x, t)] ∧ [¬ dead(x, t) → alive(x, t)]
9. If someone dies, then he is dead at all later times.
∀x: ∀t1: At2: died(x, t1) ∧ gt(t2, t1) → dead(x, t2)
• Now let's attempt to answer the question "Is Marcus alive?" by proving:
¬ alive(Marcus, now)

Resolution
• Resolution is a procedure, which gains its efficiency from the fact that it operates on
statements that have been converted to a very convenient standard form.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 7


4 – Using Predicate Logic
• Resolution produces proofs by refutation.
• In other words, to prove a statement (i.e., to show that it is valid), resolution attempts to
show that the negation of the statement produces a contradiction with the known
statements (i.e., that it is unsatisfiable).
• The resolution procedure is a simple iterative process: at each step, two clauses, called the
parent clauses, are compared (resolved), resulting into 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 V summer
¬ winter V cold
• Now we observe that precisely 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.
• Thus we see that from these two clauses we can deduce
summer V cold
• This is the deduction that the resolution procedure will make.
• Resolution operates by taking two clauses that each contains 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
¬ winter
will produce the empty clause.

Conversion to Clause form


• To apply resolution, 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
A.
• 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.
Algorithm: Convert to Clause Form
1. Eliminate →, using the fact that a → b is equivalent to ¬ a V b. Performing this
transformation on the wff given above becomes
∀x: ¬ [Roman(x) ∧ know(x, Marcus)] V
[hate(x, Caesar) V (∀y : ¬(∃z : hate(y, z)) V thinkcrazy(x, y))]
Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 8
4 – Using Predicate Logic
2. Reduce the scope of each ¬ to a single term, using the fact that ¬ (¬ p) = p, Performing
this transformation on the wff from step 1 becomes
∀x: [¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V (∀y: ∀z: ¬ hate(y, z) V thinkcrazy(x, y))]
3. Standardize variables so that each quantifier binds a unique variable. Since variables are
just dummy names, this process cannot affect the truth value of the wff.
For example, the formula ∀x: P(x) V ∀x: Q(x)
would be converted to ∀x: P(x) V ∀y: Q(y)
4. Move all 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
the formula of step 2, we get
∀x: ∀y: Az: [¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V (¬ hale(y, z) V thinkcrazy(x, y))]
5. Eliminate existential quantifiers. So, for example, the formula
∃y : President(y)
can be transformed into the formula
President(S1)
For example, in the formula
∀x: ∃y: father-of(y, x)
would be transformed into
∀x: father-of(S2(x), x)
These generated functions are called Skolem functions. Sometimes ones with no
arguments are called Skolem constants.
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. Now the formula produced in step 4 appears as
[¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V (¬ hate(y, z) V thinkcrazy(x, y))]
7. Convert the matrix into a conjunction of disjuncts. In the case or our example, since
there are no and’s, it is only necessary to exploit the associative property of or [ i.e., (a ∧
b) V c = (a V c) ∧ (b ∧ c)] and simply remove the parentheses, giving
¬ Roman(x) V ¬ know(x, Marcus) V
hate(x, Caesar) V ¬ hate(y, z) V 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.
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)
Thus since each clause is a separate conjunct and since all the variables are universally

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 9


4 – Using Predicate Logic
quantified, there need be no relationship between the variables of two clauses, even if they
were generated from the same wff.

Algorithm: Propositional Resolution


1. Convert all the propositions of F to clause form.
2. Negate P and convert the result to clause form. Add it to the set of clauses obtained in
step 1.
3. Repeat until either a contradiction is found or no progress can be made:
a. Select two clauses. Call these the parent clauses.
b. Resolve them together. The resulting clause, called the resolvent, will be the
disjunction of all of the literals of both of the parent clauses with the following
exception: If there are any pairs of literals L and ¬ L such that one of the parent
clauses contains L and the other contains ¬L, then select one such pair and
eliminate both L and ¬ L from the resolvent.
c. If the resolvent is the empty clause, then a contradiction has been found. If it is
not, then add it to the set of clauses available to the procedure.

The Unification Algorithm


• In propositional logic, it is easy to determine that two literals cannot both be true at the
same time.
• Simply look for L and ¬L in predicate logic, this matching process is more complicated
since the arguments of the predicates must be considered.
• For example, man(John) and ¬man(John) is a contradiction, while man(John) and
¬man(Spot) is not.
• Thus, in order to determine contradictions, we need a matching procedure that
compares two literals and discovers whether there exists a set of substitutions that
makes them identical.
• There is a straightforward recursive procedure, called the unification algorithm, that
does it.
Algorithm: Unify(L1, L2)
1. If L1 or L2 are both variables or constants, then:
a. If L1 and L2 are identical, then return NIL.
b. Else if L1 is a variable, then if L1 occurs in L2 then return {FAIL}, else return (L2/L1).
c. Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else return (L1/L2).
d. Else return {FAIL}.
2. If the initial predicate symbols in L1 and L2 are not identical, then return {FAIL}.
3. If LI and L2 have a different number of arguments, then return {FAIL}.
4. Set SUBST to NIL. (At the end of this procedure, SUBST will contain all the substitutions used
to unify L1 and L2.)
5. For i ← 1 to number of arguments in L1 :

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 10


4 – Using Predicate Logic
a. Call Unify with the ith argument of L1 and the ith argument of L2, putting result in S.
b. If S contains FAIL then return {FAIL}.
c. If S is not equal to NIL then:
i. Apply S to the remainder of both L1 and L2.
ii. SUBST: = APPEND(S, SUBST).
6. Return SUBST.

Resolution in Predicate Logic


• We can now state the resolution algorithm for predicate logic as follows, assuming a set
of given statements F and a statement to be proved P:
Algorithm: Resolution
1. Convert all the statements of F to clause form.
2. Negate P and convert the result to clause form. Add it to the set of clauses obtained in 1.
3. Repeat until a contradiction is found, no progress can be made, or a predetermined
amount of effort has been expended.
a. Select two clauses. Call these the parent clauses.
b. Resolve them together. The resolvent will be the disjunction of all the literals of
both parent clauses with appropriate substitutions performed and with the
following exception: If there is one pair of literals T1 and ¬T2 such that one of the
parent clauses contains T2 and the other contains T1 and if T1 and T2 are
unifiable, then neither T1 nor T2 should appear in the resolvent. We call T1 and
T2 Complementary literals. Use the substitution produced by the unification to
create the resolvent. If there is more than one pair of complementary literals,
only one pair should be omitted from the resolvent.
c. If the resolvent is an empty clause, then a contradiction has been found. If it is
not, then add it to the set of clauses available to the procedure.

Example: Consider the following facts. Translate given sentences into formulas in predicate logic.
Prove by resolution the given fact.

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 11


4 – Using Predicate Logic
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.
Prove: hate (Marcus, Caesar)
Solution:
Predicate logic statements.
1. Marcus was a man.
man(Marcus)
2. Marcus was a Pompeian.
Pompeian(Marcus)
3. All Pompeians were Romans.
x: Pompeian(x) → Roman(x)
4. Caesar was a ruler.
ruler(Caesar)
5. All Pompeians were either loyal to Caesar or hated him.
x: Roman(x) → loyalto(x, Caesar)  hate(x, Caesar)
6. Every-one is loyal to someone.
x: y: loyalto(x, y)
7. People only try to assassinate rulers they are not loyal to.
x: y: person(x)  ruler(y)  tryassassinate(x, y)
→ loyalto(x, y)
8. Marcus tried to assassinate Caesar.
tryassassinate(Marcus, Caesar)
Axioms in clause form –
1. man(Marcus)
2. Pompeian(Marcus)
3. ¬Pompeian(x1) \/ Roman(x1)
4. ruler(Caesar)
5. ¬Roman(x2) \/ loyalto(x2, Caesar) \/ hate(x2, Caesar)
6. loyalto(x3,fl(x3))
7. ¬man(x4) \/ ¬ruler(y1) \/ ¬tryassassinate(x4,y1) \/ loyalto(x4,y1)
8. trayassassinate(Marcus,Caesar)

• To prove hate (Marcus, Caesar) we start with a negation of it as ¬hate (Marcus, Caesar).

Prove: hate (Marcus, Caesar) ¬hate (Marcus, Caesar) 5


Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 12
4 – Using Predicate Logic
Marcus l x2

3 ¬Roman(Marcus) \/ loyalto(Marcus, Caesar)


Marcus l x1

¬Pompeian(Marcus) \/ loyalto(Marcus, Caesar) 2

7 loyalto(Marcus, Caesar)

Marcusl x4, Caesarl y1


1 ¬man(Marcus) \/ ¬ruler(Caesar) \/ ¬tryassassinate(Marcus, Caesar)

¬ruler(Caesar) \/ ¬tryassassinate(Marcus, Caesar) 4

¬tryassassinate(Marcus, Caesar) 8

• Final resolvent is an empty clause means that a contradiction is found in the initial
assumption so, proved hate (Marcus, Caesar).

Gopi Sanghani, CE Department | 2180703 – Artificial Intelligence 13

You might also like