0% found this document useful (0 votes)
49 views37 pages

4 Predicate Logic

Uploaded by

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

4 Predicate Logic

Uploaded by

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

Artificial Intelligence

Predicate Logic
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:
•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”
Propositional logic
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.
• 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.
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
•Objects, which are things with individual identities
•Properties of objects that distinguish them from other objects
•Relations that hold among sets of objects
•Functions, which are a subset of relations where there is only one value” for any
given “input”
• First-order Predicate logic (FOPL) provides:
• Constants: a, b, dog33. Name a specific object.
• Variables: X, Y. Refer to an object without naming it.
• Functions: Mapping from objects to objects.
• Terms: Refer to objects
• Atomic Sentences: in(dad-of(X), food6) Can be true or false, Correspond to
propositional symbols P, Q.
• 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 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)
Example
• 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.
Example (contd..)
• 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))
Example (contd..)
•The facts described by these sentences can be represented as a
set of well-formed formulas (wffs) as follows:
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)
Example (contd..)
•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.
Example (contd..)
• 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.
Example (contd..)
• 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.
Representing INSTANCE and ISA Relationships
Representing INSTANCE and ISA Relationships
• 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.
• 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) lt(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.
Computable Functions and Predicates
• 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&6. All Pompeians died when the volcano erupted in 79 A.D.
5. ∀ x : [Pompeian(x) → died(x, 79)]
6. erupted(volcano, 79)
7. No mortal lives longer than 150 years.
∀x: ∀t1: At2: mortal(x) ∧ born(x, t1) ∧ gt(t2 - t1,150) → dead(x, t2)
8. It is now 1991.
now = 1991
Computable Functions and Predicates
• Above example shows how these ideas of computable functions and predicates
can be useful.
• 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:
9. Alive means not dead.
∀x: ∀t: [alive(x, t) → ¬ dead(x, t)] ∧ [¬ dead(x, t) → alive(x, t)]
10. If someone dies, then he is dead at all later times.
∀x: ∀t1: At2: died(x, t1) ∧ gt(t2, t1) → dead(x, t2)
Computable Functions and Predicates
•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.
•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
Resolution (Contd..)
•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.
•Suppose we know that all Romans who know Marcus either
hate Ceaser or think that anyone who hates anyone is crazy. We
would represent that in the following wff:
∀x: [Roman(x) ∧ know(x, Marcus)] →[hate(x, Caesar) V ( ∀y : ∃z :
hate(y, z) → thinkcrazy(x, y))]
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))]
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)
Algorithm: Convert to Clause Form (Contd..)
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: ∃z: [¬ Roman(x) V ¬ know(x, Marcus)] V [hate(x,
Caesar) V (¬ hate(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.
Algorithm: Convert to Clause Form (Contd..)
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)
Algorithm: Convert to Clause Form (Contd..)
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 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.
Algorithm: Propositional Resolution
Let’s look at a simple example.
Suppose we are given the axioms shown in the first column of the
figure and we want to prove R.
First we convert the axioms into clause form, as shown in the second
column of the figure.
Then we negate R, producing ¬R, which is already in the clause form.
Then we begin selecting any pairs of clauses to resolve together.
The unification algorithm
Consider the following predicates:
Man(Jhon) and ¬man(Jhon)  Complementary predicates
Man(Jhon) and ¬man(Spot)  Not complementary predicates

Matching the literals involves:


•Checking their initial predicate symbols.
•Checking the number of arguments they have.
•Checking the actual arguments for a match, one pair at a time.
•This is what unification algorithm is going to help us to do.

The arguments of a predicate are generally either variable or constants.


Consider the following predicates:
love(x, y) and love(Jhon, Spot).
We write the list of substitutions made to unify these two predicates as
(Jhon/x, Spot/y).
Unifying the predicates
The unification algorithm does the following:
If the literals match, the algorithm identifies and returns the
substitutions necessary to match two literals.
If two literals do not match, the algorithm fails.
If the two literals match without any substitution, the returned list of
substitutions made to match the literals, is empty.

Consider the following predicates:


Tryassassinate(Marcus, Ceaser)
Tryassassinate(x,y)

Substitution is (Marcus/x, Ceaser/y)


Unifying the predicates
Consider the following predicates: like(x, x) and like(y, z)
First substitution: y/x, second substitution z/x
Incorrect result: This substitution is not consistent. We cannot substitute both y as
well as z in the place of same variable x.
First substitution: y/x.
Then find the variable x and make that substitution throughout the literal, across
all arguments , consistently.
So, after finding this consistent substitution y/x, the result is: like(y, y) and like(y, z)
Now compare the second argument.
Second substitution: z/y
The result is: like(y, z) and like(y, z)
The final list of substitution is (y/x) first for the entire literal and then (z/y)
In the function composition notation, this is written as:
(z/y)(y/x)
Where the rightmost substitution is applied first and the result is considered for
the next left substitution.
Algorithm: Unify(L1, L2)
1.If L1 or L2 are both variables or constants, then:
1.If L1 and L2 are identical, then return NIL.
2.Else if L1 is a variable, then if L1 occurs in L2 then return {FAIL}, else return
(L2/L1).
3.Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else return
(L1/L2).
4.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 :
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.

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 of the Example ( in predicate logic)
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)
Solution

You might also like