0% found this document useful (0 votes)
36 views31 pages

Firstorderlogic JSN

This document provides an introduction to first-order logic (FOL). It discusses the syntax and semantics of FOL, including constants, predicates, functions, variables, connectives, equality, and quantifiers. It explains how FOL adds relations, variables, and quantifiers to propositional logic, making it more expressive. Examples are provided to illustrate how FOL can be used to represent generalizations, patterns, and relations between individuals. The truth of sentences in FOL depends on a model and interpretation. Various concepts are defined, such as atomic and complex sentences, models, interpretations, and the use of assertions and queries in a knowledge base.

Uploaded by

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

Firstorderlogic JSN

This document provides an introduction to first-order logic (FOL). It discusses the syntax and semantics of FOL, including constants, predicates, functions, variables, connectives, equality, and quantifiers. It explains how FOL adds relations, variables, and quantifiers to propositional logic, making it more expressive. Examples are provided to illustrate how FOL can be used to represent generalizations, patterns, and relations between individuals. The truth of sentences in FOL depends on a model and interpretation. Various concepts are defined, such as atomic and complex sentences, models, interpretations, and the use of assertions and queries in a knowledge base.

Uploaded by

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

First-Order Logic

Chapter 8
Outline
• Why FOL?
• Syntax and semantics of FOL
• Using FOL
• Wumpus world in FOL
• Knowledge engineering in FOL
Pros and cons of propositional
logic
 Propositional logic is declarative
 Propositional logic allows partial/disjunctive/negated
information
– (unlike most data structures and databases)
 Propositional logic is compositional:
– meaning of B1,1  P1,2 is derived from meaning of B1,1 and of P1,2
 Meaning in propositional logic is context-independent
(unlike natural language, where meaning depends on context)
 Propositional logic has very limited expressive power
(unlike natural language)
– E.g., cannot say "pits cause breezes in adjacent squares“
• except by writing one sentence for each square
Propositional logic is a weak language

• Hard to identify “individuals” (e.g., Mary,


3)
• Can’t directly talk about properties of
individuals or relations between
individuals (e.g., “Bill is tall”)
• Generalizations, patterns, regularities
can’t easily be represented (e.g., “all
triangles have 3 sides”)
• First-Order Logic (abbreviated FOL or
FOPC) is expressive enough to concisely
represent this kind of information
FOL adds relations, variables, and quantifiers,
e.g.,
•“Every elephant is gray”:  x (elephant(x) → gray(x))
•“There is a white alligator”:  x (alligator(X) ^ white(X))
First-order logic
Propositional logic assumes the world
contains facts.
First-order logic (like natural language)
assumes the world contains
– Objects: people, houses, numbers, colors,
baseball games, wars, …
– Relations: red, round, prime, brother of,
bigger than, part of, comes between, …
– Functions: father of, best friend, one more
than, plus, …
Syntax of FOL: Basic elements
• Constants KingJohn, 2, NUS,...
• Predicates Brother, >,...
• Functions Sqrt, LeftLegOf,...
• Variables x, y, a, b,...
• Connectives , , , , 
• Equality =
• Quantifiers , 
Atomic sentences
Atomic sentence = predicate (term1,...,termn)
or term1 = term2

Term = function (term1,...,termn)


or constant or variable

• E.g., Brother(KingJohn,RichardTheLionheart) >


(Length(LeftLegOf(Richard)),
Length(LeftLegOf(KingJohn)))
Complex sentences
• Complex sentences are made from atomic
sentences using connectives

S, S1  S2, S1  S2, S1  S2, S1  S2,

E.g.
Sibling(KingJohn,Richard) Sibling(Richard,KingJohn)
>(1,2)  ≤ (1,2)
>(1,2)   >(1,2)
Backus–Naur form for FOL
• Sentence → AtomicSentence | ComplexSentence
• AtomicSentence → Predicate | Predicate(Term,...) | Term = Term
• ComplexSentence → ( Sentence ) | [ Sentence ] | ¬ Sentence | Sentence ∧
Sentence | Sentence ∨ Sentence | Sentence ⇒ Sentence | Sentence ⇔
Sentence | Quantifier Variable,... Sentence
• Term → Function(Term,...) | Constant | Variable
• Quantifier → ∀| ∃
• Constant → A | X1 | John | ···
• Variable → a | x | s | ···
• Predicate → True | False | After | Loves | Raining | ···
• Function → Mother | LeftLeg | ···
• OPERATOR PRECEDENCE : ¬, =, ∧, ∨, ⇒, ⇔
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(term 1,...,term n) is true


iff the objects referred to by term 1,...,term n
are in the relation referred to by predicate
Models for FOL: Example
Translating English to FOL
Every gardener likes the sun.
x gardener(x)  likes(x,Sun)
You can fool some of the people all of the time.
x t person(x) time(t)  can-fool(x,t)
You can fool all of the people some of the time.
x t (person(x)  time(t) can-fool(x,t))
x (person(x)  t (time(t) can-fool(x,t)))
Equivalent
All purple mushrooms are poisonous.
x (mushroom(x)  purple(x))  poisonous(x)
No purple mushroom is poisonous.
x purple(x)  mushroom(x)  poisonous(x)
x (mushroom(x)  purple(x))  poisonous(x) Equivalent
There are exactly two purple mushrooms.
x y mushroom(x)  purple(x)  mushroom(y)  purple(y) ^ (x=y)  z
(mushroom(z)  purple(z))  ((x=z)  (y=z))
Clinton is not tall.
tall(Clinton)
X is above Y iff X is on directly on top of Y or there is a pile of one or
more other objects directly on top of one another starting with X and
ending with Y.
x y above(x,y) ↔ (on(x,y)  z (on(x,z)  above(z,y)))
Universal quantification
• <variables> <sentence>
Everyone at NUS is smart:
x At(x,NUS)  Smart(x)

• x P is true in a model m iff P is true with x being each


possible object in the model

• Roughly speaking, equivalent to the conjunction of


instantiations of P

At(KingJohn,NUS)  Smart(KingJohn)
 At(Richard,NUS)  Smart(Richard)
 At(NUS,NUS)  Smart(NUS)
 ...
A common mistake to avoid
• Typically,  is the main connective with 
• Common mistake: using  as the main
connective with :
x At(x,NUS)  Smart(x) means “Everyone is at NUS
and everyone is smart”
Existential quantification
• <variables> <sentence>

• Someone at NUS is smart:


• x At(x,NUS)  Smart(x)

• x P is true in a model m iff P is true with x being some
possible object in the model

• Roughly speaking, equivalent to the disjunction of
instantiations of P

At(KingJohn,NUS)  Smart(KingJohn)
 At(Richard,NUS)  Smart(Richard)
 At(NUS,NUS)  Smart(NUS)
Another common mistake to
avoid
• Typically,  is the main connective with 

• Common mistake: using  as the main


connective with :

x At(x,NUS)  Smart(x)

is true if there is anyone who is not at NUS!


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,Broccoli) x Likes(x,Broccoli)


Equality
• term1 = term2 is true under a given interpretation
if and only if term1 and term2 refer to the same
object

• E.g., definition of Sibling in terms of Parent:



x,y Sibling(x,y)  [(x = y)  m,f  (m = f) 
Parent(m,x)  Parent(f,x)  Parent(m,y)  Parent(f,y)]
The kinship domain
• One’s mother is one’s female parent:
∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c) .
• One’s husband is one’s male spouse:
∀ w, h Husband(h, w) ⇔ Male(h) ∧ Spouse(h, w) .
• Male and female are disjoint categories:
∀ x Male(x) ⇔ ¬Female(x) .
• Parent and child are inverse relations:
∀ p, c Parent(p, c) ⇔ Child(c, p) .
• A grandparent is a parent of one’s parent:
∀ g, c Grandparent(g, c) ⇔ ∃ p Parent(g, p) ∧ Parent(p, c) .
A sibling is another child of one’s parents:
∀ x, y Sibling(x, y) ⇔ x = y ∧ ∃ p Parent(p, x) ∧ Parent(p, y)
.
Sets
1. The only sets are the empty set and those made by
adjoining something to a set:
∀ s Set(s) ⇔ (s = { }) ∨ (∃ x, s2 Set(s2) ∧ s = {x|s2}) .
2. The empty set has no elements adjoined into it. In other
words, there is no way to decompose { } into a smaller set
and an element:
¬∃ x, s {x|s} = { } .
3. Adjoining an element already in the set has no effect:
∀ x, s x∈ s ⇔ s = {x|s} .
4. The only members of a set are the elements that were
adjoined into it. We express this recursively, saying that x is
a member of s if and only if s is equal to some set s2
adjoined with some element y, where either y is the same
as x or x is a member of s2:
∀ x, s x∈ s ⇔ ∃ y, s2 (s = {y|s2} ∧ (x = y ∨ x∈ s2)) .
5. A set is a subset of another set if and only
if all of the first set’s members are members
of the second set:
∀ s1, s2 s1 ⊆ s2 ⇔ (∀ x x∈ s1 ⇒ x∈ s2) .
6. Two sets are equal if and only if each is a
subset of the other:
∀ s1, s2 (s1 = s2) ⇔ (s1 ⊆ s2 ∧ s2 ⊆ s1) .
Assertions and queries in first-
order logic
• Sentences are added to a knowledge base
using TELL, exactly as in propositional
logic. Such sentences are called
ASSERTIONS.
• TELL(KB, King(John)) .
• TELL(KB, Person(Richard)) .
• TELL(KB, ∀ x King(x) ⇒ Person(x)) .
• Questions asked with ASK are called
queries or goals
• ASK(KB, Person(John))
• ASK(KB, ∃ x Person(x)) .-returns true not
useful
• ASKVARS(KB,Person(x))- :
returns{x/John} and {x/Richard}.
• . Such an answer is called a substitution or
binding list
Wumpus World-FOL
• Sensed value at t=5
Percept([Stench, Breeze, Glitter , None,
None], 5) .
Actions Possible:
• Turn(Right), Turn(Left), Forward, Shoot,
Grab, Climb .
Query
ASKVARS(∃ a BestAction(a, 5)) ,
returns {a/Grab}
• ∀ t, s, g, m, c Percept([s, Breeze, g, m, c],
t) ⇒ Breeze(t) ,
• ∀ t, s, b, m, c Percept([s, b, Glitter , m, c],
t) ⇒ Glitter(t) ,
• ∀ t Glitter (t) ⇒ BestAction(Grab, t) .
• ∀ x, y, a, b Adjacent([x, y], [a, b]) ⇔ (x = a
∧ (y = b − 1 ∨ y = b + 1)) ∨ (y = b ∧ (x = a
− 1 ∨ x = a + 1)) .
• At(Agent, s, t) to mean that the agent is at
square s at time t.
• ∀t At(Wumpus, [2, 2], t).
• ∀ x, s1, s2, t At(x, s1, t) ∧ At(x, s2, t) ⇒
s1 = s2 .
∀ s, t At(Agent, s, t) ∧ Breeze(t) ⇒ Breezy(s)
∀ s Breezy(s) ⇔ ∃ r Adjacent(r, s) ∧ Pit(r) .
∀ t HaveArrow(t + 1) ⇔ (HaveArrow(t) ∧
¬Action(Shoot, t)) .
Interacting with FOL KBs
• Suppose a wumpus-world agent is using an FOL KB and perceives a smell
and a breeze (but no glitter) at t=5:

Tell(KB,Percept([Smell,Breeze,None],5))
Ask(KB,a BestAction(a,5))

• I.e., does the KB entail some best action at t=5?

• Answer: Yes, {a/Shoot} ← substitution (binding list)

• Given a sentence S and a substitution σ,


• Sσ denotes the result of plugging σ into S; e.g.,
S = Smarter(x,y)
σ = {x/Hillary,y/Bill}
Sσ = Smarter(Hillary,Bill)

• Ask(KB,S) returns some/all σ such that KB╞ σ


Knowledge base for the
wumpus world
• Perception
– t,s,b Percept([s,b,Glitter],t)  Glitter(t)

• Reflex
– t Glitter(t)  BestAction(Grab,t)
Deducing hidden properties
• x,y,a,b Adjacent([x,y],[a,b]) 
[a,b]  {[x+1,y], [x-1,y],[x,y+1],[x,y-1]}

Properties of squares:
• s,t At(Agent,s,t)  Breeze(t)  Breezy(s)
Squares are breezy near a pit:
Diagnostic rule---infer cause from effect
s Breezy(s)  ∃{r} Adjacent(r,s)  Pit(r)

– Causal rule---infer effect from cause


r Pit(r)  [s Adjacent(r,s)  Breezy(s)
• Reference: Artificial Intelligence A Modern
Approach,Third Edition by Stuart Russell
and Peter Norvig

You might also like