1. Artificial Intelligence Knowledge & Reasoning
Predicate Logic.
Reading: Sections 8.1, 8.2 & 8.3 of Textbook R&N
The world is blessed with many objects, some of which are
related to other objects.
Objects: people, houses, numbers, colors, baseball games, wars, …
Relations: red, round, brother of, bigger than, part of, comes between, …
How to represent the objects and their relation?
By Bal Krishna Subedi 1
2. Artificial Intelligence Knowledge & Reasoning
Predicate Logic: Basic Elements
Constants: John, 2, TU,...
Predicates Brother, >,...
Functions Sqrt, LeftLegOf,...
Variables x, y, a, b,...
Connectives ¬, ⇒, ∧, ∨, ⇔
Equality =
Quantifiers ∀, ∃
By Bal Krishna Subedi 2
3. Artificial Intelligence Knowledge & Reasoning
Predicate Logic: Syntax
Sentence → AtomicSentence
| (Sentence Connective Sentence)
| Quantifier Variable, ... Sentence
| ¬ Sentence
AtomicSentence → Predicate(Term, …) | Term = Term
Term → Function(Term, …) | Constant | Variable
Connective → ∧ | ∨ | ⇒ | ⇔
Quantifier → ∀ | ∃
Constant → A, B, C, X1 , X2, Jim, Jack
Variable → a, b, c, x1 , x2, counter, position, ...
Predicate → Adjacent-To, Younger-Than, HasColor, ...
Function → Father-Of, Square-Position, Sqrt, Cosine
ambiguities are resolved through precedence or parentheses
By Bal Krishna Subedi 3
4. Artificial Intelligence Knowledge & Reasoning
Sentences
Atomic Sentence:
A atomic sentence is formed from a predicate symbol followed by a parenthesized
list of terms.
E.g., Brother (Bill, Mary),
Father (Jack, John), Mother (Jill, John),
Sister (Jane, John)
Married (Jack, Jill)
BrotherOf (Bill) = Bob
Complex Sentence:
Complex sentences are made from atomic sentences using connectives.
E.g., Sibling (Tom, Bill) ⇒ Sibling (Bill, Tom).
Father (Jack, John) ∧ Mother (Jill, John) ∧ Sister (Jane, John).
¬ Sister (John, Jane).
Older (Father-Of (John), 30) ∨ Older (Mother-Of (John), 20).
By Bal Krishna Subedi 4
5. Artificial Intelligence Knowledge & Reasoning
Truth in first-order logic
Sentences are true with respect to a model and an interpretation
Model contains objects (domain elements) and relations among
them.
Interpretation specifies referents for
constant symbols → objects.
predicate symbols → relations.
function symbols → functional relations.
An atomic sentence predicate(term1,...,termn) is true iff the objects
referred to by term1,...,termn are in the relation referred to by
predicate.
Syntactically correct logical formulas are called well-formed
formulas (wff). Such wff are thus used to represent real-world
facts.
By Bal Krishna Subedi 5
6. Artificial Intelligence Knowledge & Reasoning
Quantifiers
• can be used to express properties of the
collections of objects
– eliminates the need to explicitly enumerate all
objects
• predicate logic uses two quantifiers
– universal quantifier ∀ : We can make a statement for all the
objects in the universe
– existential quantifier ∃ :We can make a statement about some
objects in the universe
By Bal Krishna Subedi 6
7. Artificial Intelligence Knowledge & Reasoning
Universal Quantification
∀<variables> <sentence>
Every CSG student needs a course in AI: ∀x Student (x, CSG) ⇒ Needs (x, AI)
∀x P is equivalent to the conjunction of instantiations of P and is interpreted as
P(x) is true for any possible x from the universe.
E.g., ∀x Student (x, CSG) ⇒ Needs (x, AI) is equivalent to claiming that
Student (John, CSG) ⇒ Needs (John, AI)
∧ Student (Richard, CSG) ⇒ Needs (Richard, AI)
∧ Student (Mike, CSG) ⇒ Needs (Mike, AI) ∧ ...
Typically, ⇒ is the main connective with ∀.
A common mistake to avoid: using ∧ as the main connective with ∀:
∀x Student (x, CSG) ∧ Needs (x, AI)
means “Everyone are CSG student and everyone needs AI” – very strong
statement - does not reflect the semantic.
By Bal Krishna Subedi 7
8. Artificial Intelligence Knowledge & Reasoning
Existential Quantification
∃<variables> <sentence>
Someone at CDCSIT is smart: ∃x At (x, CDCSIT) ∧ Smart (x)
∃x P is equivalent to the disjunction of instantiations of P and is interpreted as P(x)
is true for some object x in the universe.
E. g., ∃x At (x, CDCSIT) ∧ Smart (x) is equivalent to claiming that
At (John, CDCSIT) ∧ Smart (John)
∨ At (Richard, CDCSIT) ∧ Smart (Richard)
∨ At (Mike, CDCSIT) ∧ Smart (Mike) ∨ ...
Typically, ∧ is the main connective with ∃
Common mistake: using ⇒ as the main connective with ∃:
∃x At (x, CDCSIT) ⇒ Smart (x) is true if there is anyone who is not at
CDCSIT – very weak statement - does not reflect the semantic.
By Bal Krishna Subedi 8
9. Artificial Intelligence Knowledge & Reasoning
Multiple Quantifiers
more complex sentences can be formulated by
multiple variables and by nesting quantifiers
– the order of quantification is important
– variables must be introduced by quantifiers, and belong
to the innermost quantifier that mention them
Examples
∀x ∀y Brother (x, y) ⇒ Sibling (x, y)
∀x, y Parent (x, y) ⇒ Child (y, x)
∀x Human (x) ∃ y Mother (y, x)
∀x ∃ y Loves (x, y)
By Bal Krishna Subedi 9
10. Artificial Intelligence Knowledge & Reasoning
Properties of quantifiers
∀x ∀y is the same as ∀y ∀x.
∃x ∃y is the same as ∃y ∃x.
∃x ∀y is not the same as ∀y ∃x.
∃x ∀y Loves (x, y)
“There is a person who loves everyone in the world”.
∀y ∃x Loves (x, y)
“Everyone in the world is loved by at least one person”
Quantifier duality: each can be expressed using the other.
∀x Likes (x, IceCream) ¬∃x ¬Likes (x, IceCream).
∃x Likes (x, Cabbage) ¬∀x ¬Likes (x, Cabbage).
By Bal Krishna Subedi 10
11. Artificial Intelligence Knowledge & Reasoning
Some Examples
Everybody loves Jerry: ∀x Loves (x, Jerry)
Everybody loves somebody: ∀x ∃y Loves (x, y)
Brothers are siblings: ∀x, y Brother (x, y) ⇒ Sibling (x, y)
“Sibling” is reflexive: ∀x, y Sibling (x, y) ⇔ Sibling (y, x)
One's mother is one's female parent:
∀ x, y Mother (x, y) ⇔ (Female (x) ^ Parent (x, y))
A cousin is a child of a parent's sibling:
∀ x, y Cousin (x, y) ⇔ ∃ p, ps Parent (p, x) ^ Sibling
(ps, p) ^Parent (ps, y)
By Bal Krishna Subedi 11
12. Artificial Intelligence Knowledge & Reasoning
Inference With Predicate Logic
Reading: Chapter 9 of Textbook R&N
How to answer the questions if KB represented in
Predicate logic?
By Bal Krishna Subedi 12
13. Artificial Intelligence Knowledge & Reasoning
Inference rules for Quantifiers
Universal Instantiation:
if ∀ x P(x) is true then P(A) is true for any
individual “A”.
E.g., If we know that
∀ x Man (x) ⇒ Mortal (x),
then we can conclude
Man (Socrates) ⇒ Mortal (Socrates)
By Bal Krishna Subedi 13
14. Artificial Intelligence Knowledge & Reasoning
Reduction to Propositional Inference
How to convert quantified sentence to nonquantified?
∀x Student (x, CSG) ⇒ Needs (x, AI) is equivalent to
Student (John, CSG) ⇒ Needs (John, AI)
∧ Student (Richard, CSG) ⇒ Needs (Richard, AI)
∧ Student (Mike, CSG) ⇒ Needs (Mike, AI) ∧ ...
An existential quantifier sentence replaced by one instances where as
universal quantifier replaced by the set all possible instances.
Now we can apply any propositional inference rules.
By Bal Krishna Subedi 14
15. Artificial Intelligence Knowledge & Reasoning
Example
Bob is a buffalo. 1. Buffalo(Bob)
Pat is a pig 2. Pig(Pat)
Buffaloes run faster than pigs 3. ∀x, y Buffalo(x) ^ Pig(y) ⇒ Faster(x, y).
Bob runs faster than Pat ..?
From 1&2 (and-introduction) 4. Buffalo(Bob) ^ Pig(Pat)
∀ Elimination {x/Bob, y/Pat}5. Buffalo(Bob) ^ Pig(Pat) ⇒ Faster(Bob, Pat)
Modus Ponen 4 & 5 6. Faster(Bob, Pat)
Problem: branching factor huge –inefficient approach.
By Bal Krishna Subedi 15
16. Artificial Intelligence Knowledge & Reasoning
Generalized Modus Ponens (GMP)
n atomic sentence (p’i )and one implication, and the conclusion is
the result of applying the substitution (σ) to the consequent (q).
E.g. p’1= Faster(Bob,Pat)
p’2 = Faster(Pat,Steve)
p1 ^ p2 ⇒ q = Faster(x,y) ^ Faster(y, z) ⇒ Faster(x, z)
σ = {x/Bob, y/Pat, z/Steve}
qσ = Faster(Bob, Steve)
GMP used with KB of definite clauses (exactly one positive literal in conclusion):
either a atomic sentence or (conjunction of atomic sentences) ⇒ (atomic sentence)
All variables assumed universally quantified
By Bal Krishna Subedi 16
17. Artificial Intelligence Knowledge & Reasoning
Unification
To apply inference rule (e.g Modus Ponen) an inference system must
be able to find substitutions that make different logical expression
look identical.
Unification is an algorithm for determining the such substitutions
needed to make two predicate expression identical.
E. g., is P(x) and P(y) equivalent? – when y is substituted by x.
By Bal Krishna Subedi 17
18. Artificial Intelligence Knowledge & Reasoning
Unification
A substitution σ unifies atomic sentences p and q if pσ = qσ
p q σ
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y,OJ) {x/John, y/OJ}
Knows(John, x) Knows(y, Mother(y)) {y/John, x/Mother(John)}
Idea: Unify rule premises with known facts, apply unifier to conclusion
E.g., if we know q and Knows(John, x) ⇒ Likes(John, x)
then we conclude Likes(John, Jane)
Likes(John,OJ)
Likes(John, Mother(John))
By Bal Krishna Subedi 18
19. Artificial Intelligence Knowledge & Reasoning
Most General Unifier (MGU)
Let the premises:
Knows(John, x) Knows(y, z)
The unify algorithm can return {y/John, x/z} or {x/John, y/John,
z/John} for the given premises.
The first gives the unification result as Knows(John, z) and second
gives Knows(John, John)
The first is more general then second.
For every unifiable pair of expressions, there is single most general
unifier that is unique up to the remaining of variables.
By Bal Krishna Subedi 19
20. Artificial Intelligence Knowledge & Reasoning
Predicate Definite Clauses
A definite clause is either a atomic sentence or a implication
whose antecedent is a conjunction of positive literals and whose
consequent is a single positive literal.
Buffalo(Bob).
Pig(Pat).
Buffalo(x) ^ Pig(y) ⇒ Faster(x, y).
- Universal quantifier is omitted.
Definite clauses are suitable normal form for use with GMP.
Problem: Not all knowledge bases can be converted into a set
of definite clauses, because of single positive restriction.
By Bal Krishna Subedi 20
21. Artificial Intelligence Knowledge & Reasoning
Forward chaining
When a new fact p is added to the KB
for each rule such that p unifies with a premise
if the other premises are known
then add the conclusion to the KB and continue
chaining
Forward chaining is also called data-driven reasoning
e.g., inferring properties and categories from percepts
By Bal Krishna Subedi 21
22. Artificial Intelligence Knowledge & Reasoning
Forward chaining example
Add facts 1, 2, 3, 4, 5, 6 in turn.
1. Buffalo(x) ^ Pig(y) ⇒ Faster(x, y)
2. Pig(y) ^ Slug(z) ⇒ Faster(y, z)
3. Faster(x, y) ^ Faster(y, z) ⇒ Faster(x, z)
4. Buffalo(Bob)
5. Pig(Pat)
6. Slug(Steve)
On the first iteration: {x/Bob, y/Pat, z/steve}
On the second iteration:
rule 1 is satisfied and Faster(Bob, Pat) is added
rule 2 is satisfied and Faster(Pat, Steve) is added
7. Faster(Bob, Pat)
8. Faster(Pat, Steve)
On the 3rd iteration: rule 3 is satisfied and Faster(Bob, Steve)
9. Faster(Bob, Steve)
By Bal Krishna Subedi 22
23. Artificial Intelligence Knowledge & Reasoning
Backward Chaining
When a query q is asked
if a matching fact q’ is known, return the unifier
for each rule whose consequent q’ matches q
attempt to prove each premise of the rule by backward
chaining
It is a recursive call, when goal unifies with known fact, no new subgoals
are added and the goal is solved.
Some added complications in keeping track of the unifiers.
More complications help to avoid infinite loops.
Two versions: find any solution, find all solutions.
Backward chaining is the basis for logic programming, e.g., Prolog
Back ward chaining also called goal-driven reasoning.
By Bal Krishna Subedi 23
25. Artificial Intelligence Knowledge & Reasoning
Resolution
Resolution inference rule combines two clauses to make a new one
C1 C2
C
Inference continues until an empty clause is derived (contradiction)
Resolution is a refutation procedure.
to prove KB |= α , show that KB ^ ¬ α is unsatisable
Resolution uses KB in CNF (conjunction of clauses)
By Bal Krishna Subedi 25
27. Artificial Intelligence Knowledge & Reasoning
Conjunctive Normal Form
Literal = (possibly negated) atomic sentence. e.g., ¬ Rich(Me)
Clause = disjunction of literals, e.g., ¬ Rich(Me) ∨ Unhappy(Me)
The KB is a conjunction of clauses
Any predicate KB can be converted to CNF as follows:
1. Replace P ⇒ Q by ¬ P ∨ Q.
2. Move ¬ inwards, e.g., ¬∀x P becomes ∃x ¬P.
3. Standardize variables apart, e.g., ∀x P ∨ ∃x Q becomes ∀x P ∨ ∃y Q.
4. Move quantifiers left in order, e.g., ∀x P ∨ ∃y Q becomes ∀x ∃y P ∨ Q.
5. Eliminate ∃ by Skolemization (next slide).
6. Drop universal quantifiers.
7. Distribute ^ over ∨, e.g., (P ^ Q) ∨ R becomes (P ∨ Q) ^ (P ∨ R).
By Bal Krishna Subedi 27
28. Artificial Intelligence Knowledge & Reasoning
Skolemization
Skolemization is the process of removing existential quantifiers by
elimination.
∃x Rich(x) becomes Rich(G1) where G1 is a new “Skolem constant”
More tricky when ∃ is inside ∀
E.g., “Everyone has a heart"
∀x Person(x) ⇒ ∃y Heart(y) ^ Has(x, y)
Incorrect:
∀x Person(x) ⇒ Heart(H1) ^ Has(x, H1)
Correct:
∀x Person(x) ⇒ Heart(H(x)) ^ Has(x, H(x))
where H is a new symbol (“Skolem function")
Skolem function arguments: universally quantified variables
By Bal Krishna Subedi 28
29. Artificial Intelligence Knowledge & Reasoning
Resolution proof
To prove α:
- negate it
- convert to CNF
- add to CNF KB
- infer contradiction
E.g., to prove Rich(me), add ¬Rich(me) to the CNF KB
¬ PhD(x) ∨ HighlyQualified(x)
PhD(x) ∨ EarlyEarnings(x)
¬ HighlyQualified(x) ∨ Rich(x)
¬ EarlyEarnings(x) ∨ Rich(x)
By Bal Krishna Subedi 29
31. Artificial Intelligence Knowledge & Reasoning
Completeness of Resolution
• Resolution is complete (for proof see page 300) and usually
necessary for mathematics.
• Completeness theorem by German mathematician KURT
Gaedel in 1930, J. A. Robinsion published resolution
algorithm in 1965.
• Automated theorem provers are starting to be useful to
mathematicians and have proved several new theorems; it has
been used to verify hardware designs and to generate logically
correct programs.
• Other detailed examples of resolution can be found on pages
298-300.
By Bal Krishna Subedi 31