Ch.8 First-Order Logic: Firstorderlogic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

Ch.

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 描述 的 能⼒ 被 限制

– E.g., cannot say “pits cause breezes in adjacent squares”


– except by writing one sentence for each square
First-Order Logic
• Whereas propositional logic assumes world contains facts,
first-order logic (like natural language) assumes the world contains
– Objects (nouns and noun phrases)
• people, houses, numbers, theories, Ronald McDonald, colors,
baseball games, wars, centuries, …
– Relations (verbs and verb phrases)
• red, round, bogus, prime, multistoried, … brother of, bigger than, inside, part of, has
color, occurred after, owns, comes between, …
– Functions (special kind of relations)
• father of, best friend, third inning of, one more than, end of, …
Figure 8.1 Logics in General
(p.290)
Figure 8.1
8.2 Syntax and Semantics of First-
Order Logic
Syntax of FOL (basic elements)
• Constants
– KingJohn, 2, UCB, …
• Predicates
nnnn 描述 Relation
– Brother, >, …
• Functions
– Sqrt, LeftLegOf, …
• Variables
– x, y, a, b, …
• Connectives
– ∧∨⇒⇔¬
• Equality
– =
Typically

– 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)

2. Assemble the relevant knowledge


– Behavior of gates
• AND, OR, XOR, NOT
– Input, output, connectors
– Wire?
Example: Electronic Circuits
3. Decide on a vocabulary of predicates, functions, and constants
– Circuits, terminals, signals, gates
– Functions, predicates, constants
– Gate(X), Type(X) = XOR, Circuit(C)
– Terminal(x), In(1, X1), Connected(Out(1, X1), In(1,X2)), Arity(c, i, j)
– On(t), Signal(t)
4. Encode general knowledge about the domain
– If two terminals are connected, then they have the same signal
• ∀ t1, t2 Terminal(t1) ∧ Terminal(t2) ∧ Connected(t1, t2) ⇒ Signal(t1) = Signal(t2)
– The signal at every terminal is either 1 or 0
• ∀ t Terminal(t) ⇒ Signal(t) = 1 ∨ Signal(t) = 0
– Connected is commutative
• ∀ t1, t2 Connected(t1, t2) ⇔ Connected(t2, t1)
– There are four types of gates
• ∀ g Gate(g) ∧ k = Type(g) ⇒ k = AND ∨ k = OR ∨ k = XOR ∨ k = NOT
• An AND gate’s output is 0 if and only if any of its inputs is 0
– ∀ g Gate(g) ∧ Type(g) = AND ⇒ Signal(Out(1, g)) = 0 ⇔ ∃ n Signal(In(n, g)) = 0
• An OR gate’s output is 1 if and only if any of its inputs is 1
– ∀ g Gate(g) ∧ Type(g) = OR ⇒ Signal(Out(1, g)) = 1 ⇔ ∃ n Signal(In(n, g)) = 1
• An XOR gate’s output is 1 if and only if its inputs are different
– ∀ g Gate(g) ∧ Type(g) = XOR ⇒ Signal(Out(1, g)) = 1 ⇔ Signal(In(1, g)) = Signal(In(2, g))
• A NOT gate’s output is different from its input
– ∀ g Gate(g) ∧ (Type(g) = NOT) ⇒ Signal(Out(1, g)) = Signal(In(1, g))
• The gates (except for NOT) have two inputs and one output.
– ∀ g Gate(g) ∧ Type(g) = NOT ⇒ Arity(g, 1, 1)
– ∀ g Gate(g) ∧ k = Type(g) ∧ (k = AND ∨ k = OR ∨ k = XOR) ⇒ Arity(g, 2, 1)
• A circuit has terminals, up to its input and output arity, and nothing beyond its arity
– ∀ c, i, j Circuit(c) ∧ Arity(c, i, j) ⇒
∀ n (n ≤ i ⇒ Terminal(In(c, n))) ∧ (n > i ⇒ In(c, n) = Nothing) ∧
∀ n (n ≤ j ⇒ Terminal(Out(c, n))) ∧ (n > j ⇒ Out(c, n) = Nothing)
• Gates, terminals, signals, gate types, and Nothing are all distinct.
– ∀ g, t Gate(g) ∧ Terminal(t) ⇒ g = t = 1 = 0 = OR = AND = XOR = NOT = Nothing
• Gates are circuits.
– ∀ g Gate(g) ⇒ Circuit(g)
Example: Electronic Circuits
5. Encode a description of the specific problem instance
– Gates
• Circuit(C1) ∧ Arity(C1, 3, 2)
• Gate(X1) ∧ Type(X1) = XOR
• Gate(X2) ∧ Type(X2) = XOR
• Gate(A1) ∧ Type(A1) = AND
• Gate(A2) ∧ Type(A2) = AND
• Gate(O1) ∧ Type(O1) = OR
– Connections
• Connected(Out(1, X1), In(1, X2)) Connected(In(1, C1), In(1, X1))
• Connected(Out(1, X1), In(2, A2)) Connected(In(1, C1), In(1, A1))
• Connected(Out(1, A2), In(1, O1)) Connected(In(2, C1), In(2, X1))
• Connected(Out(1, A1), In(2, O1)) Connected(In(2, C1), In(2, A1))
• Connected(Out(1, X2), Out(1, C1)) Connected(In(3, C1), In(2, X2))
• Connected(Out(1, O1), Out(2, C1)) Connected(In(3, C1), In(1, A2))
6. Pose queries to the inference procedure and get answers
7. Debug the knowledge base
Example: Electronic Circuits
6. Pose queries to the inference procedure and get answers
– What combinations of inputs would cause the first output of C1 (the sum
bit) to be 0 and the second output of C1 (the carry bit) to be 1?
• ∃ i1, i2, i3 Signal(In(1, C1)) = i1 ∧ Signal(In(2, C1)) = i2 ∧ Signal(In(3, C1)) = i3
∧ Signal(Out(1, C1)) = 0 ∧ Signal(Out(2, C1)) = 1
• Answers: {i1/1, i2/1, i3/0} {i1/1, i2/0, i3/1} {i1/0, i2/1, i3/1}
– What are the possible sets of values of all the terminals for the adder
circuit?
• ∃ i1, i2, i3, o1, o2 Signal(In(1, C1)) = i1 ∧ Signal(In(2, C1)) = i2
∧ Signal(In(3, C1)) = i3 ∧ Signal(Out(1, C1)) = o1 ∧ Signal(Out(2, C1)) = o2
7. Debug the knowledge base
– Test case generation
– Check, observe, pinpoint, fix
Summary
• First-order logic
– objects and relations are semantic primitives
– syntax: constants, functions, predicates, equality, quantifiers
• Increased expressive power
– sufficient to define wumpus world
• Situation calculus
– conventions for describing actions and change in FOL
– can formulate planning as inference on a situation calculus KB
Cha
Discussion

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy