Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
Logical agents & First-order logic
Tutorial 2
Tutorial 2 1
Outline
♦ Knowledge-based agents
♦ Wumpus world
♦ Logic in general—models and entailment
♦ Propositional (Boolean) logic
♦ Equivalence, validity, satisfiability
♦ Inference rules and theorem proving– forward chaining– backward chaining– resolution
♦ Syntax and semantics of FOL
Tutorial 2 2
Knowledge bases
Inference engine
Knowledge base domain−specific content
domain−independent algorithms
Knowledge base = set of sentences in a formal language
Declarative approach to building an agent (or other system):Tell it what it needs to know
Then it can Ask itself what to do—answers should follow from the KB
Agents can be viewed at the knowledge leveli.e., what they know, regardless of how implemented
Or at the implementation leveli.e., data structures in KB and algorithms that manipulate them
Tutorial 2 3
Logic in general
Logics are formal languages for representing informationsuch that conclusions can be drawn
Syntax defines the sentences in the language
Semantics define the “meaning” of sentences;i.e., define truth of a sentence in a world
E.g., the language of arithmetic
x + 2 ≥ y is a sentence; x2 + y > is not a sentence
x + 2 ≥ y is true iff the number x + 2 is no less than the number y
x + 2 ≥ y is true in a world where x = 7, y = 1x + 2 ≥ y is false in a world where x = 0, y = 6
Tutorial 2 4
Entailment
Entailment means that one thing follows from another:
KB |= α
Knowledge base KB entails sentence αif and only if
α is true in all worlds where KB is true
E.g., the KB containing “the Giants won” and “the Reds won”entails “Either the Giants won or the Reds won”
E.g., x + y = 4 entails 4 = x + y
Entailment is a relationship between sentences (i.e., syntax)that is based on semantics
Note: brains process syntax (of some sort)
Tutorial 2 5
Models
Logicians typically think in terms of models, which are formallystructured worlds with respect to which truth can be evaluated
We say m is a model of a sentence α if α is true in m
M(α) is the set of all models of α
Then KB |= α if and only if M(KB) ⊆ M(α)
E.g. KB = Giants won and Reds wonα = Giants won M( )
M(KB)
x
x
x
x
x
x
x x
x
x
xx
xx
xx
xx
x
xxxx
x x
xx
xx x
x
xx
x x x
x
xx
x
x
x
x
x
x
x
x
Tutorial 2 6
Propositional logic: Syntax
Propositional logic is the simplest logic—illustrates basic ideas
The proposition symbols P1, P2 etc are sentences
If S is a sentence, ¬S is a sentence (negation)
If S1 and S2 are sentences, S1 ∧ S2 is a sentence (conjunction)
If S1 and S2 are sentences, S1 ∨ S2 is a sentence (disjunction)
If S1 and S2 are sentences, S1 ⇒ S2 is a sentence (implication)
If S1 and S2 are sentences, S1 ⇔ S2 is a sentence (biconditional)
Tutorial 2 7
Propositional logic: Semantics
Each model specifies true/false for each proposition symbol
E.g. P1,2 P2,2 P3,1
true true false
(With these symbols, 8 possible models, can be enumerated automatically.)
Rules for evaluating truth with respect to a model m:
¬S is true iff S is falseS1 ∧ S2 is true iff S1 is true and S2 is trueS1 ∨ S2 is true iff S1 is true or S2 is true
S1 ⇒ S2 is true iff S1 is false or S2 is truei.e., is false iff S1 is true and S2 is false
S1 ⇔ S2 is true iff S1 ⇒ S2 is true and S2 ⇒ S1 is true
Simple recursive process evaluates an arbitrary sentence, e.g.,¬P1,2 ∧ (P2,2 ∨ P3,1) = true ∧ (false ∨ true) = true ∧ true = true
Tutorial 2 8
Logical equivalence
Two sentences are logically equivalent iff true in same models:α ≡ β if and only if α |= β and β |= α
(α ∧ β) ≡ (β ∧ α) commutativity of ∧(α ∨ β) ≡ (β ∨ α) commutativity of ∨
((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ)) associativity of ∨
¬(¬α) ≡ α double-negation elimination(α ⇒ β) ≡ (¬β ⇒ ¬α) contraposition(α ⇒ β) ≡ (¬α ∨ β) implication elimination(α ⇔ β) ≡ ((α ⇒ β) ∧ (β ⇒ α)) biconditional elimination¬(α ∧ β) ≡ (¬α ∨ ¬β) De Morgan¬(α ∨ β) ≡ (¬α ∧ ¬β) De Morgan
(α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distributivity of ∧ over ∨(α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distributivity of ∨ over ∧
Tutorial 2 9
Validity and satisfiability
A sentence is valid if it is true in all models,e.g., True, A ∨ ¬A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B
Validity is connected to inference via the Deduction Theorem:KB |= α if and only if (KB ⇒ α) is valid
A sentence is satisfiable if it is true in some modele.g., A ∨B, C
A sentence is unsatisfiable if it is true in no modelse.g., A ∧ ¬A
Satisfiability is connected to inference via the following:KB |= α if and only if (KB ∧ ¬α) is unsatisfiable
i.e., prove α by reductio ad absurdum
Tutorial 2 10
Forward and backward chaining
Horn Form (restricted)KB = conjunction of Horn clauses
Horn clause =♦ proposition symbol; or♦ (conjunction of symbols) ⇒ symbol
E.g., C ∧ (B ⇒ A) ∧ (C ∧D ⇒ B)
Modus Ponens (for Horn Form): complete for Horn KBs
α1, . . . , αn, α1 ∧ · · · ∧ αn ⇒ β
β
Can be used with forward chaining or backward chaining.These algorithms are very natural and run in linear time
Tutorial 2 11
Forward vs. backward chaining
FC is data-driven, cf. automatic, unconscious processing,e.g., object recognition, routine decisions
May do lots of work that is irrelevant to the goal
BC is goal-driven, appropriate for problem-solving,e.g., Where are my keys? How do I get into a PhD program?
Complexity of BC can be much less than linear in size of KB
Tutorial 2 12
Resolution
Conjunctive Normal Form (CNF—universal)conjunction of disjunctions of literals︸ ︷︷ ︸
clausesE.g., (A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)
Resolution inference rule (for CNF): complete for propositional logic
`1 ∨ · · · ∨ `k, m1 ∨ · · · ∨mn
`1 ∨ · · · ∨ `i−1 ∨ `i+1 ∨ · · · ∨ `k ∨m1 ∨ · · · ∨mj−1 ∨mj+1 ∨ · · · ∨mn
where `i and mj are complementary literals. E.g.,
OK
OK OK
A
A
B
P?
P?
A
S
OK
P
W
A
P1,3 ∨ P2,2, ¬P2,2
P1,3
Resolution is sound and complete for propositional logic
Tutorial 2 13
First-order logic
Whereas propositional logic assumes world contains facts,first-order logic (like natural language) assumes the world contains
• Objects: people, houses, numbers, theories, Ronald McDonald, colors,baseball games, wars, centuries . . .
• Relations: red, round, bogus, prime, multistoried . . .,brother of, bigger than, inside, part of, has color, occurred after, owns,comes between, . . .
• Functions: father of, best friend, third inning of, one more than, end of. . .
Tutorial 2 14
Logics in general
Language Ontological EpistemologicalCommitment Commitment
Propositional logic facts true/false/unknownFirst-order logic facts, objects, relations true/false/unknownTemporal logic facts, objects, relations, times true/false/unknownProbability theory facts degree of beliefFuzzy logic facts + degree of truth known interval value
Tutorial 2 15
Syntax of FOL: Basic elements
Constants KingJohn, 2, UCB, . . .Predicates Brother, >, . . .Functions Sqrt, LeftLegOf, . . .Variables x, y, a, b, . . .Connectives ∧ ∨ ¬ ⇒ ⇔Equality =Quantifiers ∀ ∃
Tutorial 2 16
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)))
Tutorial 2 17
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)
Tutorial 2 18
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 beingeach 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))∧ . . .
Tutorial 2 19
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 beingsome 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))∨ . . .
Tutorial 2 20
Properties of quantifiers
∀x ∀ y is the same as ∀ y ∀x (why??)
∃x ∃ y is the same as ∃ y ∃x (why??)
∃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)
Tutorial 2 21
Equality
term1 = term2 is true under a given interpretationif and only if term1 and term2 refer to the same object
E.g., 1 = 2 and ∀x ×(Sqrt(x), Sqrt(x)) = x are satisfiable2 = 2 is valid
E.g., 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)]
Tutorial 2 22
Summary
Logical agents apply inference to a knowledge baseto derive new information and make decisions
Basic concepts of logic:– syntax: formal structure of sentences– semantics: truth of sentences wrt models– entailment: necessary truth of one sentence given another– inference: deriving sentences from other sentences– soundess: derivations produce only entailed sentences– completeness: derivations can produce all entailed sentences
Wumpus world requires the ability to represent partial and negated informa-tion, reason by cases, etc.
Forward, backward chaining are linear-time, complete for Horn clausesResolution is complete for propositional logic
Propositional logic lacks expressive power
Tutorial 2 23
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
Tutorial 2 24
Exercises
♦ Decide whether each of the following sentences is valid, unsatisfiable, orneither. Verify your decisions using truth tables or the equivalence rules ofFigure 7.11.
a. Smoke ⇒ Smoke
b. (Smoke ⇒ Fire) ⇒ (¬Smoke ⇒ ¬Fire)
♦ Represent the following sentences in first-order logic, using a consistentvocabulary (which you must define):
a. Only one student took Greek in spring 2001
b. The best score in Greek is always higher than the best score in French
Tutorial 2 25
Answers
1.
a. V alid
b. Satisfiable
2.
Let the basic vocabulary be as follows:
Takes(x, c, s): student x takes course c in semester s;
Score(x, c, s): the score obtained by student x in course c in semester s;
x > y: x is greater than y;
F and G: specific French and Greek courses (one could also interpret thesesentences as referring to any such course.
a. ∃x, Student(x)∧Takes(x,G, Spring2001)∧∀y, y 6= x ⇒ ¬Takes(y, G, Spring2001)
Tutorial 2 26
b. ∀s, ∃x, ∀y, Score(x,G, s) > Score(y, F, s)
Tutorial 2 27