AI Lecture 05 FOL
AI Lecture 05 FOL
Semester 3, 2024
Artificial Intelligence
First-Order Logic
(Predicate Calculus)
Road Map for Today
Revision of propositional logic
Model checking
Validity
KB ╞ α if and only if (KB ⇒ α) is valid (Deduction Theorem)
Satisfiability
KB ╞ α if and only if (KB ∧¬α) is unsatisfiable (proof by contradiction)
Inferences Rules
α ⇒ β ,α
Modus Ponens:
β
α ∧β
And-Elimination:
α
Logical equivalence
Resolution:
li ∨… ∨ lk, m1 ∨ … ∨ mn
li ∨ … ∨ li-1 ∨ li+1 ∨ … ∨ lk ∨ m1 ∨ … ∨ mj-1 ∨ mj+1 ∨... ∨ mn
Inferences Algorithms
Model checking
AND-OR graph
In the wumpus world, we have to represent “Squares adjacent to pits are breezy” for each square:
B1,1 ⇔ (P1,2 ∨ P2,1 ) Pits cause breezes in adjacent squares.
B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) Pits cause breezes in adjacent squares.
B1,2 …
B2,2 …
Another essential part of a model is the link between these elements and the
vocabulary of the logical sentences (syntax).
First-Order Logic: An Example Model
Five objects:
Richard the Lioheart (King of England
from 1189 to 1199)
His younger brother (the evil King
John, who ruled from 1199 to 1215)
The left legs of Richard and John
Crown
Relations:
Binary: “brother”, “on head”
One possible interpretation with respect to the previous example model (intended
interpretation):
-- Richard: Richard the Lionheart; John: the evil King John
-- Brother: “brother” relation; OnHead: “on head” relation; Person, King, and Crown:
the set of objects that are persons, kings and crowns.
-- Leftleg: “left leg” function Model checking is not feasible in FOL!
First-Order Logic: Syntax (cont’d)
Other syntactic elements of FOL:
• Variables x, y, a, b,...
• Connectives ¬, ⇒, ∧, ∨, ⇔
• Equality =
• Quantifiers ∀, ∃
An atomic sentence is formed from a predicate symbol followed by a parenthesized list of terms,
e.g., Brother(Richard, John) , stating that under the intended interpretation Richard the Lionheart is
the brother of King John.
[Semantics]: An atomic sentence is true in a given model if the relation referred to by the predicate
symbol holds among the objects referred to by the augments.
Complex sentences are made from atomic sentences using connectives, e.g.,
Brother(Richard, John) ⇒ Sibling(John, Richard) ; ¬ Brother(Father(Richard), John);
Brother(Richard, John) ∧ Brother(John, Richard)
First-Order Logic: Quantifiers
FOL allows objects. To express properties of entire sets of objects, quantifiers can be used instead
of enumerating the objects by name.
Two standard quantifiers in FOL: Universal Quantifier (∀) and Existential Quantifier (∃)
It means the sentence is true for every possible value of the variable (i.e., every object), e.g.,
∀x P(x) - for all x, P is true.
∀x Red(x) - all objects are red.
∀x Likes(x, AI) - everyone likes AI.
It means the sentence is true for some possible value of the variable (i.e., some object), e.g.,
∃ x P(x)
It means that there exists an x such that P(x) is true or for some x P(x) is true.
[Semantics]: ∃ x P is true in a given model if P is true in at least one extended interpretation that
assigns x to a domain element.
Common mistakes:
using ∧ as the connective with ∀, using ⇒ as the connective with ∃
Consecutive quantifiers of the same type can be written as one quantifier with several variables.
∀x ∃y Loves(x, y)
- means “Everybody has someone he/she loves”
∃y ∀x Loves(x, y)
- means “There is someone who is loved by everyone”
2. ∀x P ≡ ¬∃x ¬P
E.g., ∀x Likes(x, IceCream) is same as ¬∃x ¬Likes(x, IceCream)
(Everyone likes ice cream or no one dislikes ice cream)
3. ¬∀x P ≡ ∃x ¬P
E.g., ¬∀x Likes(x, Curry) is same as ∃x ¬Likes(x, Curry)
(Not everyone likes curry or someone dislikes curry)
4. ¬∀x ¬P ≡ ∃x P
E.g., ¬∀x ¬Likes(x, Garlic) is same as ∃x Likes(x, Garlic)
(Not everyone dislikes garlic or someone likes garlic)
Equality
FOL includes one more way to make atomic sentences, i.e., using equality
symbols to signify that two terms refer to the same object.
Equality symbols can be used to state facts about a given function, e.g., Father(John) =
Henry. It can also be used with negation to insist that two terms are not the same object.
A set of constants, predicates and functions needs to be determined to fit the domain. (We assume they
have been determined for the early and later examples of predicates/functions)
The use of constants, predicates and functions must be consistent within a domain, e.g. don’t use
Adjacent sometime but NextTo or Adjac next time.
There is currently no general set of predicates and functions that can be used in any domain. Whether
we can find such a set remains a major research topic.
Kinship Domain
Express some knowledge in the domain of family relationships, or kinship.
Objects in this domain are people; two unary predicates; many binary predicates representing
various kinship relations; two functions
∀x Male(x) ⇔ ¬Female(x) Male and female are disjoint.
∀x, y Parent(x, y) ⇔ Child(y, x) Parent and child are inverse relations.
∀x, y Mother(x, y) ⇔ Female(x) ∧ Parent(x, y) One’s mother is one’s female parent.
∀x, y Husband(x, y) ⇔ Male(x) ∧ Spouse(x, y) One’s husband is one’s male spouse.
∀x, y GrandParent(x, y) ⇔ ∃z Parent(x, z) ∧ Parent(z, y)
A grandparent is a parent of one’s parent.
∀x, y Sibling(x, y) ⇔ ¬(x = y) ∧ ∃z Parent(z, x) ∧ Parent(z, y)
A sibling is another child of one’s parent.
∀x, y Sibling(x,y) ⇔ ¬(x=y) ∧ ∃m, f ¬(m=f) ∧ Parent(m, x) ∧ Parent(m, y) ∧ Parent(f, x) ∧ Parent(f, y)
Definition of full sibling (same father and mother)!!
The above sentences are axioms of the kinship domain, and also definitions based on primitive
predicates.
Theorems are entailed from axioms, essential to reduce computational costs of deriving sentences.
Kinship Domain (cont’d)
Axioms are not always definitions, sometimes just providing more information
about certain predicates, e.g., ∀x Person(x) ⇔ ?
Mission Impossible
¬∃x, y Mission(x) ∧ Solution(x, y)
Inference in FOL
Can we prove “Socrates is mortal” based on the following knowledge base?
1. ∀x Man(x) ⇒ Mortal (x), 2. Man(Socrates)
Man(x) ⇒ Mortal (x) is true for all x, so is true for any instance of x such as Socrates, John,
Richard ……
[Universal Instantiation]: we can infer any sentence obtained by substituting a ground
term for the variable. Here, Substitution is {x/Scorates}.
α ⇒ β ,α
We apply Modus Ponens on sentences 3 & 2, then we get
β
4. Mortal(Socrates)
So, we prove “Socrates is mortal”.
Universal Instantiation
Every instantiation of a universally quantified sentence is entailed by it:
∀v α
SUBST({v/g}, α)
for any variable v and ground term g
There are n+1 premises to this rule: the n atomic sentences p'i and the one implication.
A unification algorithm takes two sentences and returns a unifier (substitution) for them if one exists.
Examples:
Sentence 1 Sentence 2 θ
1 p(John) p(x) {x/John}
2 p(John) p(Richard) Failure
3 p(John, x) p(y, Mary) {y/John, x/Mary}
4 p(x, x) p(John,y) {x/John, y/John}
5 p(x, x) p(John, Richard) Failure
6 p(x) p(y) {x/y}
Unification (cont’d)
As the result of a unification:
-- Some variables are replaced with constant symbols (e.g., 1, 3 of previous examples)
-- Some (two or more) variables are made identical (e.g., 4, 6 of previous examples)
When a variable would need to be bound to two distinct values, unification returns failure (e.g.,
example 5)
Once a variable is given a value via unification, that value cannot be replaced.
There could be more than one substitution being returned. E.g., θ for p(x) and p(y) is {x/y} .
However {x/John, y/John}, {x/Mary, y/Mary} … can also make p(x) = p(y).
Unification should only return the most general one, which makes the least commitment to
constants. It is called most general unifier (MGU).
3. Missile(M1)
Nono … has some missiles,
4. ∀x Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono)
… all of its missiles were sold to it by Colonel West
5. ∀x Missile(x) ⇒ Weapon(x)
Missiles are weapons
6. ∀x Enemy(x, America) ⇒ Hostile(x)
An enemy of America counts as “hostile”
7. American(West)
West, who is American …
8. Enemy(Nono, America)
The country Nono, an enemy of America …
Proof by Forward Chaining
AND-OR Graph
The backward chaining process can be represented as a proof tree. The tree should
constructed depth-first, left to right (recursively).
The arc across branches mean that each branch must be proved.
Now each of the following (one branch in the proof tree) must be established:
- American(West)
- Weapon(y)
- Sells(West, y, z)
- Hostile(z)
Some of these are in the knowledge base, e.g., American(West), and others requires
further backward chaining, e.g., Weapon(y) .
Next we will establish Sells(West, M1, z). Note y in Sells(West, y, z) is already M1.
Logic does not deal well with uncertainty and default rules.
Tomorrow maybe a sunny day.
Birds fly.
Logic does not provide enough “structure” to the knowledge base creation
process.
Conclusion
Revision of propositional logic
First-order logic
Models
Syntax and semantics
Knowledge representation in a simple domain