Ch.8 First-Order Logic: Firstorderlogic
Ch.8 First-Order Logic: Firstorderlogic
Ch.8 First-Order Logic: Firstorderlogic
8 First-Order Logic
⽤ Firstorderlogic 描述 句⼦
First-Order Logic
8.1. Representation Revisited
8.1.1. The language of thought
8.1.2. Combining the best of formal and natural languages
8.2. Syntax and Semantics of First-Order Logic
8.2.1. Models for first-order logic
8.2.2. Symbols and interpretations
8.2.3. Terms
8.2.4. Atomic sentences
8.2.5. Complex sentences
8.2.6. Quantifiers
Universal quantification (∀)
Existential quantification (∃)
Nested quantifiers
Connections between ∀ and ∃
8.2.7. Equality
8.2.8. An alternative semantics?
First-Order Logic
8.3. Using First-Order Logic
8.3.1. Assertions and queries in first-order logic
8.3.2. The kinship domain
8.3.3. Numbers, sets, and lists
8.3.4. The wumpus world
8.4. Knowledge Engineering in First-Order Logic
8.4.1. The knowledge-engineering process
8.4.2. The electronic circuits domain
Identify the task
Assemble the relevant knowledge
Decide on a vocabulary
Encode general knowledge of the domain
Encode the specific problem instance
Pose queries to the inference procedure
Debug the knowledge base
Pros and Cons of Propositional Logic
• Propositional logic is declarative: pieces of syntax correspond to facts
• 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 描述 的 能⼒ 被 限制
– themaincomectionwithoossexist
t.is
• Quantifiers
,
a n ⼆
∀∃
↳ Forall
Richard the Lionheart vs. King John
Figure 8.2
(p.291)
Model of Figure 8.2
• Five objects
– Richard the Lionheart, King John, Richard’s left leg, John’s left leg,
crown
• Two binary relations
– Brother, on head
• Three unary relations (properties)
– Person, king, crown
• One unary function
– Left leg
Figure 8.3
(p.293)
Atomic Sentences
• Atomic sentence = predicate(term1, …, termn)
– Or term1 = term2
• Term = function(term1, …, termn)
– or constant or variable
• Examples
– Broher(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 ,
• Examples
– Sibling(KingJohn, Richard) ⇒ Sibling(Richard, KingJohn)
– >(1,2) ∧ ≤(1,2)
– >(1,2) ∨ ¬ >(1,2)
Truth in First-Order Logic
• Sentences are true with respect to a model and an interpretation
• Model contains ≥ 1 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
Truth Example
• Consider the interpretation in which
– Richard Richard the Lionheart
– John the evil King John
– Brother the brotherhood relation
• Under this interpretation,
Brother(Richard, John) is true
Models for FOL
需要
• Entailment in propositional logic can be computed by enumerating models
– Considering each instance
• We can enumerate the FOL models for a given KB vocabulary:
• For each number of domain elements n from 1 to ∞
For each k-ary predicate Pk in the vocabulary
For each possible k-ary relation on n objects
For each constant symbol C in the vocabulary
For each choice of referent for C from n objects …
• Computing entailment by enumerating FOL models is not easy!
Figure 8.4
(p.293)
Universal Quantification
• ∀ <variables> <sentence>
• Everyone at Berkeley is smart
– ∀x At(x, Berkeley) ) ⇒ 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, Berkeley) ) ⇒ Smart(KingJohn))
∧ (At(Richard, Berkeley) ) ⇒ Smart(Richard))
∧ (At(Berkeley, Berkeley) ) ⇒ Smart(Berkeley))
∧…
• (∀x)P(x) is equivalent to P(a1) ∧P(a2) ∧P(a3) ∧... P(aN) where ai are
instances.
A Common Mistake to Avoid
• Typically, ⇒ is the main connective with ∀
• Common mistake
– using ∧ as the main connective with ∀
∀x At(x, Berkeley) ∧ Smart(x)
– It means “Everyone is at Berkeley and everyone is smart”
Existential Quantification
• ∃ <variables> <sentence>
• Someone at Stanford is smart
– ∃x At(x, Stanford) ∧ 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, Stanford) ∧ Smart(KingJohn))
∨ (At(Richard, Stanford) ∧ Smart(Richard))
∨ (At(Stanford, Stanford) ∧ Smart(Stanford))
∨ ...
• (∃x)(P(x)) equivalent to P(a1) ∨ P(a2) ∨ P(a3) ∨ ... ∨ P(aN) if at least one is false
Another Common Mistake to Avoid
• Typically, ∧ is the main connective with ∃
• Common mistake
– Using ⇒ as the main connective with ∃
– ∃x At(x, Stanford) ⇒ Smart(x)
– It is true if there is anyone who is not at Stanford!
Properties of Quantifiers
• ∀x ∀y is the same as ∀y ∀x (or ∀x,y)
• ∃x ∃y is the same as ∃y ∃x (or ∃x,y)
• ∃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, IceCream) ¬∀x ¬Likes(x, IceCream)
Fun with Sentences
• Brothers are siblings
– ∀ x,y Brother(x, y) ⇒ Sibling(x, y).
• “Sibling” is symmetric
– ∀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 first cousin is a child of a parent’s sibling
– ∀x,y FirstCousin(x, y) ⇔ ∃ p,ps Parent(p, x) ∧ Sibling(ps, p) ∧
Parent(ps, y)
Equality
• Term1 = term2 is true under a given interpretation
• If and only if term1 and term2 refer to the same object
• Examples
– 1 =2 and ∀x ╳(Sqrt(x), Sqrt(x)) = x are satisfiable
– 2 = 2 is valid
• Definition of (full) 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)]
8.3 Using First-Order Logic
Example: 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)
Example: Numbers
• Natural numbers defined recursively
– NatNum(0)
– ∀n NatNum(n) ⇒ NatNum(S(n))
• Addition
– ∀ m NatNum(m) ⇒ + (0, m) = m
– ∀ m, n NatNum(m) ∧ NatNum(n) ⇒ + (S(m), n) = S(+(m, n))
– Alternatively, ∀ m, n NatNum(m) ∧ NatNum(n) ⇒ (m + 1) + n = (m + n)
+1
•
Example: Sets
• 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})
• The empty set has no elements adjoined into it.
– ¬∃ x, s {x|s} = { }
• Adjoining an element already in the set has no effect
– ∀ x, s x ∈ s ⇔ s = {x|s}
• The only members of a set are the elements that were adjoined
into it.
– ∀ x, s x ∈ s ⇔ ∃ y, s2 (s = {y|s2} ∧ (x = y ∨ x ∈ s2))
Example: Sets (cont.)
• 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)
• Two sets are equal if and only if each is a subset of the other
– ∀ s1, s2 (s1 = s2) ⇔ (s1 ⊆ s2 ∧ s2 ⊆ s1)
• An object is in the intersection of two sets if and only if it is a member of
both sets
– ∀ x, s1, s2 x ∈ (s1 ∩ s2) ⇔ (x ∈ s1 ∧ x ∈ s2)
• An object is in the union of two sets if and only if it is a member of either
set
– ∀ x, s1, s2 x ∈ (s1 ∪ s2) ⇔ (x ∈ s1 ∨ x ∈ s2)
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 Action(a,5))
– I.e., does KB entail any particular actions 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=Billg}
– Sσ = Smarter(Hillary, Bill)
• Ask(KB, S) returns some/all σ such that KB ⊨ Sσ
Knowledge Base for the Wumpus World
Deducing Hidden Properties
Keeping Track of Change
• Facts hold in situations, rather than eternally
– E.g., Holding(Gold; Now) rather than just Holding(Gold)
• Situation calculus is one way to represent change in FOL:
– Adds a situation argument to each non-eternal predicate
– E.g., Now in Holding(Gold; Now) denotes a situation
– Situations are connected by the Result function
– Result(a, s) is the situation that results from doing a in s
Describing Actions
• “Effect” axiom
– describe changes due to action
– ∀s AtGold(s) ⇒ Holding(Gold, Result(Grab, s))
• “Frame” axiom
– describe non-changes due to action
– ∀s HaveArrow(s) ⇒ HaveArrow(Result(Grab, s))
• Frame problem
– find an elegant way to handle non-change
– (a) representation--avoid frame axioms
– (b) inference--avoid repeated “copy-overs” to keep track of state
• Qualification problem
– true descriptions of real actions require endless caveats
– what if gold is slippery or nailed down or …
• Ramification problem
– real actions have many secondary consequences
– what about the dust on the gold, wear and tear on gloves, ….
Describing Actions (cont.)
Making Plans
• Initial condition in KB
– At(Agent, [1, 1]; S0)
– At(Gold, [1, 2]; S0)
• Query: Ask(KB, ∃s Holding(Gold, s))
– i.e., in what situation will I be holding the gold?
• Answer: {s/Result(Grab, Result(Forward; S0))}
– i.e., go forward and then grab the gold
• This assumes that the agent is interested in plans starting at S0 and
that S0 is the only situation described in the KB
Making Plans: a Better Way
8.4 Knowledge Engineering in First-
Order Logic
Knowledge Engineer
• Someone who
– investigates a particular domain,
– learns what concepts are important in that domain, and
– creates a formal representation of the objects and relations in the
domain.
Knowledge Engineering Process
1. Identify the task
2. Assemble the relevant knowledge
3. Decide on a vocabulary of predicates, functions, and
constants
4. Encode general knowledge about the domain
5. Encode a description of the specific problem instance
6. Pose queries to the inference procedure and get answers
7. Debug the knowledge base
Example: Electronic Circuits
1. Identify the task
2. Assemble the relevant knowledge
3. Decide on a vocabulary of predicates, functions, and
constants
4. Encode general knowledge about the domain
5. Encode a description of the specific problem instance
6. Pose queries to the inference procedure and get answers
7. Debug the knowledge base
Example: Electronic Circuits
1. Identify the task
– Circuit’s functionality
– Figure 8.6 Figure 8.6
(p.309)