Predicate Logic
Predicate Logic
Terms
First-Order Logic (FOL) • First-order logic has terms that represent objects or
individuals. Terms are built using constant, variable,
• Propositional logic has only sentences, which represent and function symbols.
facts. – Constants (designate specific object): A, B, John,
• First-order logic extends propositional logic in two Red, etc.
directions – Variables (designate unspecified object): x, y, z, etc.
– It provides an inner structure for sentences. They are – Functions (designate a specific object related in a
viewed as expressing relations between objects or certain way to another object, or objects):
individuals. FatherOf, ColorOf, etc.
– It provides a means to express, and reason with, • Examples of terms:
generalizations. It makes it possible to say that a
certain property holds of all objects, of some objects, – ColorOf(CarOf(Bill)),
or of no object. CostOf(TextbookOf(CMPSCI383)), etc.
• Ground terms are terms that include no variables.
Predicates
Universal Quantifier
• Predicates have a value of true or false
• A predicate can take arguments, which are terms ∀x P(x) means “for all x, P of x is true”
• A predicate with one argument expresses a property of
Example: ∀x Happy(x)
an object
If the universe of discourse is people, then this
– Student(Bob)
means that everyone is happy.
• A predicate with two or more arguments expresses a
relation between objects Other examples:
– likes(Bob, Mary) ∀x ∀y Knows(x,y) => Knows(y,x)
– likes(Bob, school-of (Bob)) ∀x ∀y Knows(x,y) ^ Knows(y,x)
• A predicate with no arguments is a simple proposition, ∀x ∀y Knows(x,y) => ¬ Likes(y,x)
as in propositional logic
1
Relationship between Universal
Existential Quantifier and Existential Quantifiers
∃x P(x) means “there exists at least one x for ∀x ¬ P(x) <=> ¬∃x P(x)
which P of x is true” ¬∀x P(x) <=> ∃x ¬P(x)
Example: ∃x Happy(x) ∀x P(x) <=> ¬∃x ¬ P(x)
If the universe of discourse is people, then this ∃x P(x) <=> ¬∀x ¬ P(x)
means there is at least one happy person. Examples:
Other examples: ¬∃y Happy(y) <=> ∀y ¬ Happy(y)
∀x ∃y Knows(x,y) ∃y ¬Happy(y) <=> ¬ ∀y Happy(y)
∃x ∃y Knows(x,y) ^ Knows(y,x) ∀x ¬ Likes(x,Jane) <=> ¬∃x Likes(x,Jane)
∀x ∃y Knows(x,y) => ¬ Likes(y,x) ∀x Likes(x,Jane) <=> ¬∃x ¬Likes(x,Jane)
2
Translate from English to FOL The Semantics of FOL
• You can fool some of the people all of the time.
• An interpretation is a set of objects and a
mapping from each constant, functional symbol
• You can’t fool all of the people all of the time. and predicate to an appropriate object, function
and relation in the domain.
• A sentence can be valid, satisfiable, or
• There is one and only one Pope. unsatisfiable, just as in propositional logic.
3
Normal Form Converting to CNF
• It is easier for a computer to perform logical inference 1) Eliminate the ⇔ connective using the equivalence
if we convert all sentences into a “normal form.” Any between P⇔Q and (P Q)∧(Q P)
sentence of first-order logic can be transformed into an 2) Eliminate the connective using the equivalence
between P Q and ¬P ∨ Q
• In conjunctive normal form (CNF), every sentence is 3) Move negation symbols inward, using the following
expressed as a conjunction of clauses (where a clause is equivalences:
a disjunction of literals) • ¬(P∨Q) becomes ¬P∧¬Q
• ¬(P∧Q) becomes ¬P∨¬Q
(P(x)∨R(x,y)) ∧ (¬S(y)∨R(y,z)) ∧ T(y)
• ¬∀xP becomes ∃x¬P
• In implicative normal form, every sentence is
• ¬∃xP becomes ∀x¬P
expressed as an implication with a conjunction of atoms
• ¬ ¬ P becomes P
on the left and a disjunction of atoms on the right
P(x) ∧ Q(x,y) S(y) ∨ T(x,y)
Skolemization
Skolemization: Example
• Method for converting a sentence with existential
quantifiers into a sentence without existential quantifiers
such that the first sentence is satisfiable if and only if the ∀x∃y (Person(x) ∧ Person(y)) Loves(x,y)
second is.
• To eliminate an existential quantifier, replace each is converted to
occurrence of its variable by a Skolem function whose
arguments are the variables of universal quantifiers whose ∀x (Person(x) ∧ Person(f(x)) Loves(x,f(x))
scope includes the scope of the existential quantifier being
eliminated. where f(x) specifies the person that x loves
• If the existential quantifier being eliminated is not within
the scope of any universal quantifiers, the Skolem
function has no arguments, that is, it is a constant.
4
Skolemization: Another Example Skolemization: More examples
• The sentence “Everyone has a brain” is represented as
∀x Person(x) ∃y Brain(y) ∧ Has(x,y) ∃xP(x) becomes P(A)
• If we simply substitute the constant B for the
existentially quantified variable y, we get a sentence
that says “Everyone has the same brain,” not what we ∀x∀y∃zP(x,y,z) becomes ∀x∀yP(x,y,F(x,y))
want to say!
∀x Person(x) Brain(B) ∧ Has(x,B)
∀x∃yPred(x,y) becomes ∀xPred(x,Succ(x))
Unification
• In propositional logic, it is easy to see that two literals
Unification cont.
(such as p and ¬p) contradict each other.
• The unification algorithm takes two atomic
• In FOL, this matching process is more complicated
because arguments of predicates must be considered. sentences (literals), such as Knows(John, x)
For example, man(John) and ¬man(John) is a and Knows(John, Paul), and returns a
contradiction, while man(John) and man(Spot) is not. substitution that makes them look the same,
• To detect contradictions in FOL, we need a matching such as {x/Paul}
procedure that compares two literals and discovers
whether there exists a set of substitutions that makes • If there is no such substitition, the
them identical. This procedure is called unification. unification fails.
• Notation: x/car means car is substituted for x
5
Example
Most General Unifier Rule:
Knows(John, x) => Hates(John, x)
• There may be more than one substitution Knowledge Base:
that unifies two clauses. In fact, there may Knows (John, Jane)
be infinitely many Knows(y,Leonid)
Knows(y, Mother-of(y))
• The unification algorithm returns the “most Knows(x, Elizabeth)
general unifier”, that is, the substitution that
makes the least commitment about the Unify(Knows(John,x), Knows(John,Jane)) =
bindings of variables Unify(Knows(John, x), Knows(y, Leonid)) =
Unify(Knows(John,x), Knows(y, Mother(y))) =
Unify(Knows(John,x), Knows(x,Elizabeth)) =
2. But anyone who studies or is lucky can pass all his 1. ∀x ¬ (Pass(x, History) ∧ Win(x, Lottery)) ∨ Happy(x)
exams.
∀x ∀y Study(x) ∨ Lucky(x) Pass(x,y)
6
Convert to CNF Cont. Convert to CNF Cont.
Move ¬ inward
Distribute ∧ over ∨
1. ∀x ¬ Pass(x, History) ∨ ¬ Win(x, Lottery)) ∨ Happy(x)
2. ∀x ∀y (¬ Study(x) ∧ ¬Lucky(x) )∨ Pass(x,y)
3. ¬ Study(John) ∧ Lucky(John) 1. ¬ Pass(x, History) ∨ ¬ Win(x, Lottery)) ∨ Happy(x)
4. ∀x ¬ Lucky(x) ∨ Win(x, Lottery)
2. (¬ Study(x) ∨ Pass(x,y)) ∧ ( ¬ Lucky(x) ∨ Pass(x,y))
Standardize variables: no action needed
Move quantifiers left: no action needed except drop quantifiers 3. ¬ Study(John) ∧ Lucky(John)
Skolemize: no action needed
4. ¬ Lucky(x) ∨ Win(x, Lottery)
¬Lucky(John) 3b.
to the KB
FALSE
• Resolve clauses together until FALSE is
derived