Professional Documents
Culture Documents
• Using FOL
• Find Wumpus
– Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y) (stench next to Wumpus) 16 rules
– Relations: red, round, prime, brother of, bigger than, part of, comes between,
…
• Epistemological Commitment:
– What an agent believes about facts — BELIEF
Syntax of FOL: Basic elements
• Constant Symbols:
– Stand for objects
– e.g., KingJohn, 2, UCI,...
• Predicate Symbols
– Stand for relations
– E.g., Brother(Richard, John), greater_than(3,2)...
• Function Symbols
– Stand for functions
– E.g., Sqrt(3), LeftLegOf(John),...
Syntax of FOL: Basic elements
• Constants KingJohn, 2, UCI,...
• Variables x, y, a, b,...
• Connectives , , , ,
• Equality =
• Quantifiers ,
Relations
• Some relations are properties: they state
some fact about a single object: Round(ball), Prime(7).
Registration
RA
s-id c.id Grade Satisfaction
s-id p-id Salary Capability Jack 101 A 1
Jack Oliver High 3 Jack 102 B 2
Kim Oliver Low 1 Kim 102 A 1
Paul Jim Med 2 Paul 101 B 1
21
Terms
• Term = logical expression that refers to an object.
• Examples:
LargerThan(2,3) is false.
Brother_of(Mary,Pete) is false.
Married(Father(Richard), Mother(John)) could be true or false
• Brother_of(Pete,Brother(Pete)) is True.
Consider the statement: "x is an integer.", it consists of two parts, the first
part x is the subject of the statement and second part "is an integer," is known
as a predicate.
Quantifiers in First-order logic:
• These are the symbols that permit to determine or identify the range
and scope of the variable in the logical expression. There are two
types of quantifier:
• Universal Quantifier, (for all, everyone, everything)
• Existential quantifier, (for some, at least one).
binary function
relation
objects
connectives
More Examples
• Brother(Richard, John) Brother(John, Richard)
• King(Richard) King(John)
• Allows us to make statements about all objects that have certain properties
Note that
" x King(x) Person(x) is not correct!
This would imply that all objects x are Kings and are People
• Examples:
x King(x)
x Lives_in(John, Castle(x))
i Integer(i) GreaterThan(i,0)
$ y x Loves(x,y)
- there is someone (“y”) who is loved by everyone
In effect:
- is a conjunction over the universe of objects
- is a disjunction over the universe of objects
Thus, DeMorgan’s rules can be applied
De Morgan’s Law for Quantifiers
https://
www.youtube.com/watch?v=xR2Y zdGzf9k
https://www.youtubecomwatch
. / ?v=ADeffD2lxXk
First-Order Logic: Better choice
for Wumpus World
• Propositional logic represents facts
• First-order logic gives us
– Objects
– Relations: how objects relate to each other
– Properties: features of an object
– Functions: output an object, given others
First-Order Logic in Wumpus
World
• Suppose an agent perceives a stench, breeze, no glitter at
time t = 5:
– Percept([Stench,Breeze,None],5)
– [Stench,Breeze,None] is a list
• Then want to query for an appropriate action. Find an a (ask
the KB):
a Action (a,5) ?
WW
• Performance measure
Agent Description
– gold +1000, death -1000
– -1 per step, -10 for using arrow
• Environment
– Squares adjacent to wumpus are smelly
– Squares adjacent to pit are breezy
– Glitter iff gold is in same square
– Shooting kills wumpus if agent facing it
– Shooting uses up only arrow
– Grabbing picks up gold if in same square
– Releasing drops gold in same square
• Actuators
– Left turn, right turn, forward, grab,
release, shoot
• Sensors
– Breeze, glitter, smell, bump, scream
Simplifying the percept and
deciding actions
b, g , t Percept ([ Stench , b, g ], t ) Stench (t )
s, g , t Percept ([ s, Breeze, g ], t ) Breeze(t )
s, b, t Percept ([ s, b, Glitter ], t ) AtGold (t )
• Simple Reflex Agent
73
Basic Inference rules:
Inference rules are the templates for generating valid arguments. Inference rules are
applied to derive proofs in artificial intelligence, and the proof is a sequence of the
conclusion that leads to the desired goal.
In inference rules, the implication among all the connectives plays an important role.
Following are some terminologies related to inference rules:
77
78
79
80
81
82
83
84
Inference Rules for FOL
• Inference rules for PL apply to FOL as well (Modus
Ponens, And-Introduction, And-Elimination, etc.)
• New (sound) inference rules for use with quantifiers:
– Universal Elimination
– Existential Introduction
– Existential Elimination
– Generalized Modus Ponens (GMP)
• Resolution
– Clause form (CNF in FOL)
– Unification (consistent variable substitution)
– Refutation resolution (proof by contradiction)
85
Universal Elimination (x) P(x) |-- P(c).
• If (x) P(x) is true, then P(c) is true for any constant c in the
domain of x, i.e.,, (x) P(x) |= P(c).
• Replace all occurrences of x in the scope of x by the same ground
term (a constant or a ground function).
• Example: (x) eats(Ali, x) |-- eats(Ali, IceCream)
Existential Introduction P(c) |-- (x) P(x)
• If P(c) is true, so is (x) P(x), i.e., P(c) |= (x) P(x)
• Replace all instances of the given constant symbol by the same new
variable symbol.
• Example eats(Ali, IceCream) |-- (x) eats(Ali, x)
Existential Elimination (x)P(x) |-- P(c)
• where c is a new constant symbol standing for object that makes P true,
– All we know is there must be some constant that makes this true, so
we can introduce a brand new one to stand in for that constant,
even though we don’t know exactly what that constant refer to.
– Example: (x) eats(Ali, x) |= eats(Ali, Stuff)
86
• Things become more complicated when there are universal quantifiers
(x)(y) eats(x, y) |-- (x)eats(x, Stuff) ???
(x)(y) eats(x, y) |-- eats(Ali, Stuff) ???
– Introduce a new function food_sk(x) to stand for y because that y
depends on x
(x)(y) eats(x, y) |-- (x)eats(x, food_sk(x))
(x)(y) eats(x, y) |-- eats(Ali, food_sk(Ali))
– What exactly the function food_sk(.) does is unknown, except that it
takes x as its argument
• The process of existential elimination is called Skolemization (after
Skolem, a Norwegian mathematician).
• The new, unique constants (e.g., Stuff) and functions (e.g., food_sk(.))
are called skolem constants and skolem functions
87
Resolution in FOL
• Resolution is a theorem proving technique that proceeds
by building refutation proofs, i.e., proofs by
contradictions.
• Resolution is used, if there are various statements are
given, and we need to prove a conclusion of those
statements.
• Unification is a key concept in proofs by resolutions.
88
Resolution for FOL
• Resolution rule operates on two clauses
– Clause: Disjunction of literals (an atomic sentence) is called a clause. It is
also known as a unit clause.
– Variables are universally quantified
– Relationship between clauses in KB is conjunction
89
We need answers to the following questions
90
Converting FOL sentences to clause form
• Basic ideas
– How to handle quantifiers
• Careful on quantifiers with preceding negations (explicit or
implicit)
~x P(x) is really x ~P(x)
(x P(x)) => (y Q(y)) ~(x P(x)) v (y Q(y))
x ~P(x) v y Q(y)
• Eliminate true existential quantifier by Skolemization
• For true universally quantified variables, treat them as such
without quantifiers
– similar to PL but need to work with quantifiers
91
Conversion procedure
step 1: remove all “=>” and “<=>” operators
(using P => Q ~P v Q and P <=> Q P => Q ^ Q => P)
step 2: move all negation signs to individual predicates
(using de Morgan’s law)
step 3: remove all existential quantifiers y
case 1: y is not in the scope of any universally quantified variable,
then replace all occurrences of y by a skolem constant
case 2: if y is in scope of universally quantified variables x1, ... xi,
then replace all occurrences of y by a skolem function that
takes x1, ... xi as its arguments
step 4: remove all universal quantifiers x (with the understanding that
all remaining variables are universally quantified)
step 5: convert sentences using different distribution laws
step 6: use parenthesis to separate all disjunctions, then drop all v’s and
^’s
92
Conversion examples
x (P(x) ^ Q(x) => R(x)) y rose(y) ^ yellow(y)
x ~(P(x) ^ Q(x)) v R(x) (by step 1) rose(c) ^ yellow(c)
x ~P(x) v ~Q(x) v R(x) (by step 2) (where c is a skolem constant)
~P(x) v ~Q(x) v R(x) (by step 4) (rose(c)), (yellow(c))
(~P(x), ~Q(x), R(x)) (by step 6)
93
Unification of two clauses
• Basic idea: x P(x) => Q(x), P(a) |-- Q(a)
(~P(x), Q(x)), (P(a))
94
– Cannot bind variable x to y if x appears anywhere in y
• Try to unify x and f(x). If we bind x to f(x) and apply the binding
to both x and f(x), we get f(x) and f(f(x)) which are still not the
same (and will never be made the same no matter how many times
the binding is applied)
– Otherwise, bind variable x to y, written as x/y (this
guarantees to find the most general unifier, or mgu)
• Suppose both x and y are variables, then they can be made the
same by binding both of them to any constant c or any function
f(.). Such bindings are less general and impose unnecessary
restriction on x and y.
– To unify two terms of the same function symbol, unify
their argument lists (unification is recursive)
Ex: to unify f(x) and f(g(b)), we need to unify x and g(b)
95
– When the argument lists contain multiple terms, unify each
corresponding pair of terms
Ex. To unify (x, f(x), ...) (a, y, ...)
1. unify x and a (q = {x/a})
2. apply q to the remaining terms in both lists, resulting
(f(a), ...) and (y, ...)
3. unify f(a) and y with binding y/f(a)
4. apply the new binding y/f(a) to q
5. add y/f(a) to new q
96
Unification Examples
• parents(x, father(x), mother(Bill)) and parents(Bill, father(Bill), y)
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(Bill): q = {x/Bill}
– unify mother(Bill) and y: q = {x/Bill}, y/mother(Bill)}
• parents(x, father(x), mother(Bill)) and parents(Bill, father(y), z)
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(y): q = {x/Bill, y/Bill}
– unify mother(Bill) and z: q = {x/Bill, y/Bill, z/mother(Bill)}
• parents(x, father(x), mother(Jane)) and parents(Bill, father(y), mother(y))
– unify x and Bill: q = {x/Bill}
– unify father(Bill) and father(y): q = {x/Bill, y/Bill}
– unify mother(Jane) and mother(Bill): Failure because Jane and Bill are
different constants
97
More Unification Examples
• P(x, g(x), h(b)) and P(f(u, a), v, u))
– unify x and f(u, a): q = {x/ f(u, a)};
remaining lists: (g(f(u, a)), h(b)) and (v, u)
– unify g(f(u, a)) and v: q = {x/f(u, a), v/g(f(u, a))};
remaining lists: (h(b)) and (u)
– unify h(b) and u: q = {x/f(h(b), a), v/g(f(h(b), a)), u/h(b)};
• P(f(x, a), g(x, b)) and P(y, g(y, b))
– unify f(x, a) and y: q = {y/f(x, a)}
remaining lists: (g(x, b)) and (g(f(x, a), b))
– unify x and f(x, a): failure because x is in f(x, a)
98
Unification Algorithm
procedure unify(p, q, q) /* p and q are two lists of terms and |p| = |q| */
if p = empty then return q; /* success */
let r = first(p) and s = first(q);
if r = s then return unify(rest(p), rest(q), q);
if r is a variable then temp = unify-var(r, s);
else if s is a variable then temp = unify-var(s, r);
else if both r and s are functions of the same function name then
temp = unify(arglist(r), arglist(s), empty);
else return “failure”;
if temp = “failure” then return “failure”; /* p and q are not unifiable */
else q = subst(q, temp)U temp; /* apply tmp to old q then insert it into q
*/
return unify(subst(rest(p), tmp), subst(rest(q), tmp), q);
end{unify}
procedure unify-var(x, y)
if x appears anywhere in y then return “failure”;
else return (x/y)
end{unify-var}
99
Excellent links
• https://www.youtube.com/watch?v=73AUBVOW-sM
• https://www.youtube.com/watch?v=I0QAdG68K0o
• https://www.youtube.com/watch?v=EZJs6w2YFRM
100