Title: Propositional Logic
1Propositional Logic
- Russell and Norvig
- Chapter 7
2Knowledge-Based Agent
3A simple knowledge-based agent
- The agent must be able to
- Represent states, actions, etc.
- Incorporate new percepts
- Update internal representations of the world
- Deduce hidden properties of the world
- Deduce appropriate actions
4Types of Knowledge
- Procedural, e.g. functions Such knowledge can
only be used in one way -- by executing it - Declarative, e.g. constraints It can be used
to perform many different sorts of inferences
5Logic
- Logic is a declarative language to
- Assert sentences representing facts that hold in
a world W (these sentences are given the value
true) - Deduce the true/false values to sentences
representing other aspects of W
6Wumpus World PEAS description
- Performance measure
- gold 1000, death -1000
- -1 per step, -10 for using the arrow
- Environment
- Squares adjacent to wumpus are smelly
- Squares adjacent to pit are breezy
- Glitter iff gold is in the same square
- Shooting kills wumpus if you are facing it
- Shooting uses up the only arrow
- Grabbing picks up gold if in same square
- Releasing drops the gold in same square
- Sensors Stench, Breeze, Glitter, Bump, Scream
- Actuators Left turn, Right turn, Forward, Grab,
Release, Shoot
7Wumpus world characterization
- Fully Observable No only local perception
- Deterministic Yes outcomes exactly specified
- Episodic No sequential at the level of actions
- Static Yes Wumpus and Pits do not move
- Discrete Yes
- Single-agent? Yes Wumpus is essentially a
natural feature
8Exploring a wumpus world
9Exploring a wumpus world
10Exploring a wumpus world
11Exploring a wumpus world
12Exploring a wumpus world
13Exploring a wumpus world
14Exploring a wumpus world
15Exploring a wumpus world
16Logic in general
- Logics are formal languages for representing
information such 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
17Connection World-Representation
18Examples of Logics
- Propositional calculus A ? B ? C
- First-order predicate calculus ( x)( y)
Mother(y,x) - Logic of Belief B(John,Father(Zeus,Cronus))
19Model
- A model of a sentence is an assignment of a truth
value true or false to every atomic sentence
such that the sentence evaluates to true.
20Model of a KB
- Let KB be a set of sentences
- A model m is a model of KB iff it is a model
of all sentences in KB, that is, all sentences
in KB are true in m.
21Satisfiability of a KB
A KB is satisfiable iff it admits at least one
model otherwise it is unsatisfiable
KB1 P, ?Q?R is satisfiableKB2 ?P?P is
satisfiable KB3 P, ?P is unsatisfiable
22Logical Entailment
- KB set of sentences
- ? arbitrary sentence
- KB entails ? written KB ? iff every model
of KB is also a model of ? - Alternatively, KB ? iff
- KB,?? is unsatisfiable
- KB ? ? is valid
23Inference Rule
- An inference rule ?, ? ? consists of 2
sentence patterns ? and ? called the conditions
and one sentence pattern ? called the conclusion - If ? and ? match two sentences of KB then the
corresponding ? can be inferred according to the
rule
?
24Inference
- I Set of inference rules
- KB Set of sentences
- Inference is the process of applying successive
inference rules from I to KB, each rule adding
its conclusion to KB
25Example Modus Ponens
- From
- Battery-OK ? Bulbs-OK ? Headlights-Work
- Battery-OK ? Bulbs-OK
- Infer
- Headlights-Work
26? Connective symbol (implication) Logical
entailment Inference
?
27Soundness
- An inference rule is sound if it generates only
entailed sentences - All inference rules previously given are sound,
e.g.modus ponens ? ? ? , ? ? - The following rule ? ? ? , ? ? is
unsound, which does not mean it is useless (an
inference rule for abduction, outside scope of
this course)
?
?
28- Is each of the following a sound inference rule?
- ? ? ? , ?? ??
- ? ? ? , ?? ??
?
?
29Completeness
- A set of inference rules is complete if every
entailed sentences can be obtained by applying
some finite succession of these rules - Modus ponens alone is not complete, e.g.from A
? B and ?B, we cannot get ?A
30Proof
The proof of a sentence ? from a set of
sentences KB is the derivation of ? by applying
a series of sound inference rules
31Proof
The proof of a sentence ? from a set of
sentences KB is the derivation of ? by applying
a series of sound inference rules
- Battery-OK ? Bulbs-OK ? Headlights-Work
- Battery-OK ? Starter-OK ? ?Empty-Gas-Tank ?
Engine-Starts - Engine-Starts ? ?Flat-Tire ? Car-OK
- Headlights-Work
- Battery-OK
- Starter-OK
- ?Empty-Gas-Tank
- ?Car-OK
- Battery-OK ? Starter-OK
by 5,6 - Battery-OK ? Starter-OK ? ?Empty-Gas-Tank
by 9,7 - Engine-Starts
by 2,10 - Engine-Starts ? Flat-Tire
by 3,8 - Flat-Tire
by 11,12
32Inference Problem
- Given
- KB a set of sentence
- ? a sentence
- Answer
- KB ? ?
33Deduction vs. Satisfiability Test
KB ? iff KB,?? is unsatisfiable
- Hence
- Deciding whether a set of sentences entails
another sentence, or not - Testing whether a set of sentences is
satisfiable, or not - are closely related problems
34Complementary Literals
- A literal is a either an atomic sentence or the
negated atomic sentence, e.g.
P, ?P - Two literals are complementary if one is the
negation of the other, e.g.
P and ?P
35Unit Resolution Rule
- Given two sentences L1 ? ? Lp and
M where Li,, Lp and M are all literals,
and M and Li are complementary literals - Infer L1 ? ? Li-1 ? Li1 ? ? Lp
36Examples
- From?Engine-Starts ? Car-OK
- Engine-Starts
- InferCar-OK
Modus ponens
- From?Engine-Starts ? Car-OK
- ?Car-OK
- Infer ?Engine-Starts
Modus tollens
37Shortcoming of Unit Resolution
- From
- ?Engine-Starts ? Flat-Tire ? Car-OK
- Engine-Starts ? Empty-Gas-Tank
- we can infer nothing!
38Full Resolution Rule
- Given two clauses L1 ? ? Lp and
M1 ? ? Mq where Li and Mj are
complementrary - Infer the clause L1? ? Li-1?Li1??Lk?M1? ?
Mj-1?Mj1??Mk
39Example
- From
- ?Engine-Starts ? Flat-Tire ? Car-OK
- Engine-Starts ? Empty-Gas-Tank
- Infer
- Empty-Gas-Tank ? Flat-Tire ? Car-OK
40Example
- From
- ?P ? Q (? P ? Q)
- ?Q ? R (? Q ? R)
- Infer
- ?P ? R (? P ? R)
41Not All Inferences are Useful!
- From
- ?Engine-Starts ? Flat-Tire ? Car-OK
- Engine-Starts ? ?Flat-Tire
- Infer
- ?Flat-Tire ? Flat-Tire ? Car-OK
42Not All Inferences are Useful!
- From
- ?Engine-Starts ? Flat-Tire ? Car-OK
- Engine-Starts ? ?Flat-Tire
- Infer
- ?Flat-Tire ? Flat-Tire ? Car-OK
tautology
43Not All Inferences are Useful!
- From
- ?Engine-Starts ? Flat-Tire ? Car-OK
- Engine-Starts ? ?Flat-Tire
- Infer
- ?Flat-Tire ? Flat-Tire ? Car-OK ? True
tautology
44Example
- ?Battery-OK ? ?Bulbs-OK ? Headlights-Work
- ?Battery-OK ? ?Starter-OK ? Empty-Gas-Tank ?
Engine-Starts - ?Engine-Starts ? Flat-Tire ? Car-OK
- Headlights-Work
- Battery-OK
- Starter-OK
- ?Empty-Gas-Tank
- ?Car-OK
- ?Flat-Tire
- We want to show Flat-Tire, given clauses 1-8.
Using resolution, we can show - that clauses 1-8 along with clause 9 deduce an
empty clause. - Can you trace the resolution steps?
45Sentence ? Clause Form
Example (A ? ?B) ? (C ? D) 1. Eliminate ?
?(A ? ?B) ? (C ? D)2. Reduce scope of ? (?A ?
B) ? (C ? D)3. Distribute ? over ? (?A ? (C ?
D)) ? (B ? (C ? D)) (?A ? C) ? (?A ? D) ? (B ?
C) ? (B ? D) Set of clauses ?A ? C , ?A ? D ,
B ? C , B ? D
46Resolution Refutation Algorithm
- RESOLUTION-REFUTATION(KB,a)
- clauses ? set of clauses obtained from KB and ?a
- new ?
- Repeat
- For each C, C in clauses do res ?
RESOLVE(C,C) If res contains the empty clause
then return yes - new ? new U resIf new ? clauses then return no
- clauses ? clauses U new
47Efficient Propositional Inference
- Two families of efficient algorithms for
propositional inference
- Complete backtracking search algorithms
- DPLL algorithm (Davis, Putnam, Logemann,
Loveland)
- Incomplete local search algorithms
- WalkSAT algorithm
48The DPLL algorithm
- Determine if an input propositional logic
sentence (in CNF) is satisfiable.
- Improvements over truth table enumeration
- Early termination
- A clause is true if any literal is true.
- A sentence is false if any clause is false.
- Pure symbol heuristic
- Pure symbol always appears with the same "sign"
in all clauses. - e.g., In the three clauses (A ? ?B), (?B ? ?C),
(C ? A), A and B are pure, C is impure. - Make a pure symbol literal true.
- Unit clause heuristic
- Unit clause only one literal in the clause
- The only literal in a unit clause must be true.
49Horn Clauses
- Horn Clause
- A clause with at most one positive
literal. -
- KB A Horn clause with one positive literal
which can be written as - a1 ? ? an ? ß
- Query A Horn clause without positive literal
- ?a1 ? ? ?an
- I.e.
- ?( a1 ? ? an )
- Horn clause logic is the basis for Logic
Programming -
-
-
50Forward chaining for Horn Clauses
- Idea fire any rule whose premises are satisfied
in the KB, - add its conclusion to the KB, until query is
found
51Backward chaining for Horn Clasues
- Idea work backwards from the query q
- to prove q by BC,
- check if q is known already, or
- prove by BC all premises of some rule concluding
q
- Avoid loops check if new subgoal is already on
the goal stack
- Avoid repeated work check if new subgoal
- has already been proved true, or
- has already failed
52Summary
- Propositional Logic
- Model of a KB
- Logical entailment
- Inference rules
- Resolution rule
- Clause form of a set of sentences
- Resolution refutation algorithm
- DPLL algorithm
- Horn clauses