Fundamentals of Artificial Intelligence Chapter 07: Logical Agents
Roberto Sebastiani
DISI, Università di Trento, Italy – roberto.sebastiani@unitn.it http://disi.unitn.it/rseba/DIDATTICA/fai_2020/
Teaching assistant: Mauro Dragoni – dragoni@fbk.eu http://www.maurodragoni.com/teaching/fai/
M.S. Course “Artificial Intelligence Systems”, academic year 2020-2021
Last update: Tuesday 8thDecember, 2020, 13:08
Copyright notice: Most examples and images displayed in the slides of this course are taken from [Russell & Norwig, “Artificial Intelligence, a Modern Approach”, Pearson, 3rded.], including explicitly figures from the above-mentioned book, and their copyright is detained by the authors.
A few other material (text, figures, examples) is authored by (in alphabetical order):
Pieter Abbeel,Bonnie J. Dorr,Anca Dragan,Dan Klein,Nikita Kitaev,Tom Lenaerts,Michela Milano,Dana Nau,Maria Simi, who detain its copyright. These slides cannot can be displayed in public without the permission of the author.
1 / 91
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
3 / 91
Propositional Logic (aka Boolean Logic)
Basic Definitions and Notation
Propositional formula (aka Boolean formula or sentence)
>, ⊥ are formulas
a propositional atom A
1, A
2, A
3, ... is a formula;
if ϕ
1and ϕ
2are formulas, then
¬ϕ
1, ϕ
1∧ ϕ
2, ϕ
1∨ ϕ
2, ϕ
1→ ϕ
2, ϕ
1← ϕ
2, ϕ
1↔ ϕ
2, ϕ
1⊕ ϕ
2are formulas.
Atoms(ϕ): the set {A 1 , ..., A N } of atoms occurring in ϕ.
Literal: a propositional atom A i (positive literal) or its negation
¬A i (negative literal)
Notation: if l := ¬A
i, then ¬l := A
iClause: a disjunction of literals W
j l j (e.g., (A 1 ∨ ¬A 2 ∨ A 3 ∨ ...)) Cube: a conjunction of literals V
j l j (e.g., (A 1 ∧ ¬A 2 ∧ A 3 ∧ ...))
5 / 91
Semantics of Boolean operators
Truth Table
α β ¬α α∧β α∨β α → β α ← β α ↔ β α⊕β
⊥ ⊥ > ⊥ ⊥ > > > ⊥
⊥ > > ⊥ > > ⊥ ⊥ >
> ⊥ ⊥ ⊥ > ⊥ > ⊥ >
> > ⊥ > > > > > ⊥ Note
∧, ∨, ↔ and ⊕ are commutative:
(α ∧ β) ⇐⇒ (β ∧ α)
(α ∨ β) ⇐⇒ (β ∨ α)
(α ↔ β) ⇐⇒ (β ↔ α)
Remark: Semantics of Implication “→” (aka “⇒”, “⊃”)
The semantics of Implication “α → β” may be counter-intuitive
α → β: “the antecedent (aka premise) α implies the consequent (aka conclusion) β” (aka “if α holds, then β holds” (but not vice versa))
does not require causation or relevance between α and β ex: “5 is odd implies Tokyo is the capital of Japan” is true in p.l.
(under standard interpretation of “5”, “odd”, “Tokyo”, “Japan”) relation between antecedent & consequent: they are both true is true whenever its antecedent is false
ex: “5 is even implies Sam is smart” is true (regardless the smartness of Sam)
ex: “5 is even implies Tokyo is in Italy” is true (!)
relation between antecedent & consequent: the former is false does not require temporal precedence of α wrt. β
ex: “the grass is wet implies it must have rained” is true (the consequent precedes temporally the antecedent)
7 / 91
Syntactic Properties of Boolean Operators
¬¬α ⇐⇒ α
(α ∨ β) ⇐⇒ ¬(¬α ∧ ¬β)
¬(α ∨ β) ⇐⇒ (¬α ∧ ¬β) (α ∧ β) ⇐⇒ ¬(¬α ∨ ¬β)
¬(α ∧ β) ⇐⇒ (¬α ∨ ¬β) (α → β) ⇐⇒ (¬α ∨ β) (α → β) ⇐⇒ (¬β ∧ ¬α)
¬(α → β) ⇐⇒ (α ∧ ¬β) (α ← β) ⇐⇒ (α ∨ ¬β)
¬(α ← β) ⇐⇒ (¬α ∧ β)
(α ↔ β) ⇐⇒ ((α → β) ∧ (α ← β))
⇐⇒ ((¬α ∨ β) ∧ (α ∨ ¬β))
¬(α ↔ β) ⇐⇒ (¬α ↔ β)
Tree & DAG Representations of Formulas
Formulas can be represented either as trees or as DAGS (Directed Acyclic Graphs)
DAG representation can be up to exponentially smaller in particular, when ↔’s are involved
(A 1 ↔ A 2 ) ↔ (A 3 ↔ A 4 )
⇓
(((A 1 ↔ A 2 ) → (A 3 ↔ A 4 ))∧
((A 3 ↔ A 4 ) → (A 1 ↔ A 2 )))
⇓
(((A 1 → A 2 ) ∧ (A 2 → A 1 )) → ((A 3 → A 4 ) ∧ (A 4 → A 3 ))) ∧ (((A 3 → A 4 ) ∧ (A 4 → A 3 )) → (((A 1 → A 2 ) ∧ (A 2 → A 1 ))))
9 / 91
Tree & DAG Representations of Formulas: Example
(((A 1 → A 2 ) ∧ (A 2 → A 1 )) → ((A 3 → A 4 ) ∧ (A 4 → A 3 ))) ∧ (((A 3 → A 4 ) ∧ (A 4 → A 3 )) → (((A 1 → A 2 ) ∧ (A 2 → A 1 ))))
A1 A2 A2 A1 A3 A4 A4 A3 A3 A4 A4 A3 A1 A2 A2 A1
Tree Representation
Basic Definitions and Notation [cont.]
Total truth assignment µ for ϕ:
µ : Atoms(ϕ) 7−→ {>, ⊥}.
represents a possible world or a possible state of the world Partial Truth assignment µ for ϕ:
µ : A 7−→ {>, ⊥}, A ⊂ Atoms(ϕ).
represents 2
ktotal assignments, k is # unassigned variables Notation: set and formula representations of an assignment
µ can be represented as a set of literals:
EX: {µ(A
1) := >, µ(A
2) := ⊥} =⇒ {A
1, ¬A
2} µ can be represented as a formula (cube):
EX: {µ(A
1) := >, µ(A
2) := ⊥} =⇒ (A
1∧ ¬A
2)
11 / 91
Basic Definitions and Notation [cont.]
A total truth assignment µ satisfies ϕ (µ is a model of ϕ, µ |= ϕ):
µ |= A
i⇐⇒ µ(A
i) = >
µ |= ¬ϕ ⇐⇒ not µ |= ϕ
µ |= α ∧ β ⇐⇒ µ |= α and µ |= β µ |= α ∨ β ⇐⇒ µ |= α or µ |= β µ |= α → β ⇐⇒ if µ |= α, then µ |= β µ |= α ↔ β ⇐⇒ µ |= α iff µ |= β µ |= α ⊕ β ⇐⇒ µ |= α iff not µ |= β
M(ϕ)
def= {µ | µ |= ϕ} (the set of models of ϕ)
A partial truth assignment µ satisfies ϕ iff all its total extensions satisfy ϕ
(Ex: {A
1} |= (A
1∨ A
2)) because {A
1, A
2} |= (A
1∨ A
2) and
{A
1, ¬A
2} |= (A
1∨ A
2))
Properties & Results
Property
ϕ is valid iff ¬ϕ is unsatisfiable
Deduction Theorem
α |= β iff α → β is valid (|= α → β)
Corollary
α |= β iff α ∧ ¬β is unsatisfiable
Validity and entailment checking can be straightforwardly reduced to (un)satisfiability checking!
13 / 91
Complexity
For N variables, there are up to 2 N truth assignments to be checked.
The problem of deciding the satisfiability of a propositional formula is NP-complete
=⇒ The most important logical problems (validity, inference,
entailment, equivalence, ...) can be straightforwardly reduced to (un)satisfiability, and are thus (co)NP-complete.
⇓
No existing worst-case-polynomial algorithm.
Conjunctive Normal Form (CNF)
ϕ is in Conjunctive normal form iff it is a conjunction of disjunctions of literals:
L
^
i=1 K
i_
j
i=1
l j
ithe disjunctions of literals W K
ij
i=1 l j
iare called clauses Easier to handle: list of lists of literals.
=⇒ no reasoning on the recursive structure of the formula
15 / 91
Classic CNF Conversion CNF (ϕ)
Every ϕ can be reduced into CNF by, e.g., (i) expanding implications and equivalences:
α → β =⇒ ¬α ∨ β
α ↔ β =⇒ (¬α ∨ β) ∧ (α ∨ ¬β) (ii) pushing down negations recursively:
¬(α ∧ β) =⇒ ¬α ∨ ¬β
¬(α ∨ β) =⇒ ¬α ∧ ¬β
¬¬α =⇒ α
(iii) applying recursively the DeMorgan’s Rule:
(α ∧ β) ∨ γ =⇒ (α ∨ γ) ∧ (β ∨ γ) Resulting formula worst-case exponential:
ex: ||CNF( W
Ni=1
(l
i1∧ l
i2)|| =
Labeling CNF conversion CNF label (ϕ)
Labeling CNF conversion CNF label (ϕ) (aka Tseitin’s conversion) Every ϕ can be reduced into CNF by, e.g., applying recursively bottom-up the rules:
ϕ =⇒ ϕ[(l i ∨ l j )|B] ∧ CNF (B ↔ (l i ∨ l j )) ϕ =⇒ ϕ[(l i ∧ l j )|B] ∧ CNF (B ↔ (l i ∧ l j )) ϕ =⇒ ϕ[(l i ↔ l j )|B] ∧ CNF (B ↔ (l i ↔ l j )) l i , l j being literals and B being a “new” variable.
Worst-case linear!
Atoms(CNF label (ϕ)) ⊇ Atoms(ϕ) CNF label (ϕ) is equi-satisfiable w.r.t. ϕ:
M(CNF (ϕ)) 6= ∅ iff M(ϕ) 6= ∅
Much more used than classic conversion in practice.
17 / 91
Labeling CNF conversion CNF label (ϕ) (cont.)
CNF (B ↔ (l i ∨ l j )) ⇐⇒ (¬B ∨ l i ∨ l j )∧
(B ∨ ¬l i )∧
(B ∨ ¬l j ) CNF (B ↔ (l i ∧ l j )) ⇐⇒ (¬B ∨ l i )∧
(¬B ∨ l j )∧
(B ∨ ¬l i ¬l j ) CNF (B ↔ (l i ↔ l j )) ⇐⇒ (¬B ∨ ¬l i ∨ l j )∧
(¬B ∨ l i ∨ ¬l j )∧
(B ∨ l i ∨ l j )∧
(B ∨ ¬l i ∨ ¬l j )
Labeling CNF Conversion CNF label – Example
−A3 A1 A5 −A4 −A3 A4 A2 −A6 A1 A4 A3 −A5 −A2 A6 A1 −A4
B1 B2 B3 B4 B5 B6 B7 B8
B9 B10 B11 B12
B13 B14
B15
CNF (B
1↔ (¬A
3∨ A
1))∧
...∧
CNF (B
8↔ (A
1∨ ¬A
4))∧
CNF (B
9↔ (B
1↔ B
2))∧
...∧
CNF (B
12↔ (B
7∧ B
8))∧
CNF (B
13↔ (B
9∨ B
10))∧
CNF (B
14↔ (B
11∨ B
12))∧
CNF (B
15↔ (B
13∧ B
14))∧
B
15=
(¬B
1∨ ¬A
3∨ A
1) ∧ (B
1∨ A
3) ∧ (B
1∨ ¬A
1)∧
...∧
(¬B
8∨ A
1∨ ¬A
4) ∧ (B
8∨ ¬A
1) ∧ (B
8∨ A
4)∧
(¬B
9∨ ¬B
1∨ B
2) ∧ (¬B
9∨ B
1∨ ¬B
2)∧
(B
9∨ B
1∨ B
2) ∧ (B
9∨ ¬B
1∨ ¬B
2)∧
...∧
(B
12∨ ¬B
7∨ ¬B
8) ∧ (¬B
12∨ B
7) ∧ (¬B
12∨ B
8)∧
(¬B
13∨ B
9∨ B
10) ∧ (B
13∨ ¬B
9) ∧ (B
13∨ ¬B
10)∧
(¬B
14∨ B
11∨ B
12) ∧ (B
14∨ ¬B
11) ∧ (B
14∨ ¬B
12)∧
(B
15∨ ¬B
13∨ ¬B
14) ∧ (¬B
15∨ B
13) ∧ (¬B
15∨ B
14)∧
B
1519 / 91
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
Propositional Reasoning: Generalities
Automated Reasoning in Propositional Logic fundamental task AI, formal verification, circuit synthesis, operational research,....
Important in AI: KB |= α: entail fact α from knowledge base KR (aka Model Checking: M(KB) ⊆ M(α))
typically KB >> α
sometimes KB set of variable implications (A
1∧ ... ∧ A
k) → B All propositional reasoning tasks reduced to satisfiability (SAT)
KR |= α =⇒ SAT(KR ∧ ¬α)=false
input formula CNF-ized and fed to a SAT solver Current SAT solvers dramatically efficient:
handle industrial problems with 10
6− 10
7variables & clauses!
used as backend engines in a variety of systems (not only AI)
21 / 91
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
The Resolution Rule
Resolution: deduction of a new clause from a pair of clauses with exactly one incompatible variable (resolvent):
(
common
z }| { l
1∨ ... ∨ l
k∨
resolvent
z}|{ l ∨
C0
z }| {
l
k +10∨ ... ∨ l
m0) (
common
z }| { l
1∨ ... ∨ l
k∨
resolvent
z}|{ ¬l ∨
C00
z }| {
l
k +100∨ ... ∨ l
n00) ( l
1∨ ... ∨ l
k| {z }
common
∨ l
k +10∨ ... ∨ l
m0| {z }
C0
∨ l
k +100∨ ... ∨ l
n00| {z }
C00
)
Ex: ( A ∨ B ∨ C ∨ D ∨ E ) ( A ∨ B ∨ ¬C ∨ F ) ( A ∨ B ∨ D ∨ E ∨ F )
Note: many standard inference rules subcases of resolution:
(recall that α → β ⇐⇒ ¬α ∨ β) A → B B → C
A → C (trans.) A A → B
B (m. ponens) ¬B A → B
¬A (m. tollens)
23 / 91
Basic Propositional Inference: Resolution
Assume input formula in CNF
if not, apply Tseitin CNF-ization first
=⇒ ϕ is represented as a set of clauses
Search for a refutation of ϕ (is ϕ unsatisfiable?) recall: α |= β iff α ∧ ¬β unsatisfiable
Basic idea: apply iteratively the resolution rule to pairs of clauses with a conflicting literal, producing novel clauses, until either
a false clause is generated, or
the resolution rule is no more applicable
Correct: if returns an empty clause, then ϕ unsat (α |= β)
Complete: if ϕ unsat (α |= β), then it returns an empty clause
Very-Basic PL-Resolution Procedure
( c S. Russell & P. Norwig, AIMA)
25 / 91
Improvements: Subsumption & Unit Propagation
Alternative “set” notation (Γ clause set):
Γ, φ 1 , ..φ n Γ, φ 0 1 , ..φ 0 n
0e.g., Γ, C 1 ∨ p, C 2 ∨ ¬p Γ, C 1 ∨ p, C 2 ∨ ¬p, C 1 ∨ C 2 ,
Clause Subsumption (C clause):
Γ ∧ C ∧ (C ∨ W
i l i ) Γ ∧ (C) Unit Resolution:
Γ ∧ (l) ∧ (¬l ∨ W
i l i ) Γ ∧ (l) ∧ ( W
i l i ) Unit Subsumption:
Γ ∧ (l) ∧ (l ∨ W
l i )
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
27 / 91
The Davis-Putnam-Longemann-Loveland Procedure
Tries to build an assignment µ satisfying ϕ
At each step assigns a truth value to (all instances of) one atom Performs deterministic choices (mostly unit-propagation) first The grandfather of the most efficient SAT solvers
Correct and complete
Much more efficient than PL-Resolution
Requires polynomial space
The DPLL Procedure [cont.]
( c S. Russell & P. Norwig, AIMA)
Pure-Symbol Rule out of date, no more used in modern solvers.
29 / 91
DPLL: Example
DPLL search tree
ϕ = (A 1 ∨ A 2 ) ∧ (A 1 ∨ ¬A 2 ) ∧ (¬A 1 ∨ A 2 ) ∧ (¬A 1 ∨ ¬A 2 )
A1 −A1
A2 A2
Modern CDCL SAT Solvers
Non-recursive, stack-based implementations
Based on Conflict-Driven Clause-Learning (CDCL) schema inspired to conflict-driven backjumping and learning in CSPs learns implied clauses as nogoods
Random restarts
abandon the current search tree and restart on top level previously-learned clauses maintained
Smart literal selection heuristics (ex: VSIDS)
“static”: scores updated only at the end of a branch
“local”: privileges variable in recently learned clauses
Smart preprocessing/inprocessing technique to simplify formulas Smart indexing techniques (e.g. 2-watched literals)
efficiently do/undo assignments and reveal unit clauses Allow Incremental Calls (stack-based interface)
allow for reusing previous search on “similar” problems
Can handle industrial problems with 10 6 − 10 7 variables and clauses!
31 / 91
DPLL Chronological Backtracking: Drawbacks
Chronological backtracking always backtracks to the most recent branching point, even though a higher backtrack could be possible
=⇒ lots of useless search!
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
... ¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ...}
(initial assignment)
33 / 91
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8
√ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
...
A
1¬A
11A
12A
13¬A
10¬A
9DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8
√ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
... A A
23A
1¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ..., A 1 , A 2 , A 3 } (unit A 2 , A 3 )
35 / 91
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 √ c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8
√ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
...
A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 √ c 4 : ¬A 4 ∨ A 5 ∨ A 10 √ c 5 : ¬A 4 ∨ A 6 ∨ A 11 √ c 6 : ¬A 5 ∨ ¬A 6 × c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8
√ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
...
A
5A
6A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 1¬A
41 , A 12 , A 13 , ..., A 1 , A 2 , A 3 , A 4 , A 5 , A 6 } (unit A 5 , A 6 )=⇒ conflict
37 / 91
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 ...
A
5A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 ...
¬A
1A
5A
6A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ..., ¬A 1 } (unit ¬A 1 )
39 / 91
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8 √ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 × ...
A
7A
8¬A
1A
5A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 ...
A
7A
8¬A
1A
5A
6A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ...}
=⇒ backtrack to the most recent open branching point
41 / 91
DPLL Chronological Backtracking: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 ...
A
7A
8¬A
1A
5A
4A
2A
3A
1¬A
11A
12A
13¬A
10¬A
9Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
43 / 91
Backjumping and Learning (Original Strategy)
Idea: when a branch µ fails,
(i) conflict analysis: find the conflict set η ⊆ µ by generating the conflict clause C
def= ¬η via resolution from the falsified clause, using the “Decision” criterion;
(ii) learning: add the conflict clause C to the clause set
(iii) backjumping: backtrack to the most recent branching point s.t. the stack does not fully contain η, and then
unit-propagate the unassigned literal on C
The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 √ c 4 : ¬A 4 ∨ A 5 ∨ A 10 √ c 5 : ¬A 4 ∨ A 6 ∨ A 11 √ c 6 : ¬A 5 ∨ ¬A 6 × c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8 √ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13
...
Conflict!
A
5A
6c
4c
6c
6c
5c
4c
5A
5A
6c
3c
3A
4A
4A
2A
3c
2c
2c
1A
2A
3A
1A
1A
12A
13¬A
9¬A
11¬A
10¬A
11A
12A
13¬A
10¬A
9{..., ¬A 9 , ¬A 10 , ¬A 1¬A
41 , A 12 , A 13 , ..., A 1 , A 2 , A 3 , A 4 , A 5 , A 6 } (unit A 5 , A 6 ) =⇒ conflict;
falsified clause: ¬A 5 ∨ ¬A 6
45 / 91
Conflict analysis
Criterium: “decision”
1. C := falsified clause 2. repeat
(i) resolve the current clause C with the antecedent clause of the last unit-propagated literal l in C
antecedent clause for l: causing the unit-propagation of on l until C contains only decision literals (“decision” criterion) Example
¬A
4∨ A
6∨ A
11Falsified cl.
z }| {
¬A
5∨ ¬A
6The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 √ c 4 : ¬A 4 ∨ A 5 ∨ A 10 √ c 5 : ¬A 4 ∨ A 6 ∨ A 11 √ c 6 : ¬A 5 ∨ ¬A 6 × c 7 : A 1 ∨ A 7 ∨ ¬A 12 √ c 8 : A 1 ∨ A 8
√ c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 ...
Conflict!
A
5A
6c
4c
6c
6c
5c
4c
5A
5A
6c
3c
3A
4A
4A
2A
3c
2c
2c
1A
2A
3A
1A
1A
12A
13¬A
9¬A
11¬A
10¬A
11A
12A
13¬A
10¬A
9=⇒ Conflict set: {¬A 9 , ¬A 10 , ¬A 11 , A 1 } ("decision" schema)
=⇒ learn the conflict clause c 10 := A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1
47 / 91
The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1 ...
A
2A
3A
4A
5¬A
9¬A
10A
¬A
11¬A
10¬A
11A
12A
13A
1¬A
9A
13The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1 √ ...
¬A
1c
10c
10c
10¬A
1A
2A
3A
4A
5A
6¬A
9¬A
10A
12¬A
11¬A
10¬A
11A
12A
13A
1¬A
9A
13{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ..., ¬A 1 } (unit ¬A 1 )
49 / 91
The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 √ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6
c 7 : A 1 ∨ A 7 ∨ ¬A 12 √
c 8 : A 1 ∨ A 8 √
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1 √ ...
A
8A
7A
8A
7c
8c
7c
7¬A
1c
10c
10c
10¬A
1A
2A
3A
4A
5¬A
9¬A
10A
¬A
11¬A
10¬A
11A
12A
13A
1¬A
9A
13The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2
√ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12
√
c 8 : A 1 ∨ A 8 √
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 × c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1
√ ...
c
9c
9c
9Conflict!
A
8A
7A
8A
7c
8c
7c
7¬A
1c
10c
10c
10¬A
1A
2A
3A
4A
5A
6¬A
9¬A
10A
12¬A
11¬A
10¬A
11A
12A
13A
1¬A
9A
13{..., ¬A 9 , ¬A 10 , ¬A 11 , A 12 , A 13 , ..., ¬A 1 , A 7 , A 8 } Conflict!
51 / 91
The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2
√ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12
√
c 8 : A 1 ∨ A 8 √
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 × c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1
√ ...
c
9c
9c
9Conflict!
A
8A
7A
8A
7c
8c
7c
7¬A
1c
10c
10c
10¬A
1A
2A
3A
4A
5¬A
9¬A
10A
¬A
11¬A
10¬A
11A
12A
13A
1¬A
9A
13The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1
c 11 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 12 ∨ ¬A 13
...
A
7A
8¬A
1A
2A
3A
4A
5A
6¬A
9¬A
10A
12¬A
11¬A
10¬A
11A
12A
13A
1¬A
9=⇒ backtrack to A 13 =⇒ Lots of search saved!
53 / 91
The Original Backjumping Strategy: Example
c 1 : ¬A 1 ∨ A 2
√ c 2 : ¬A 1 ∨ A 3 ∨ A 9 √ c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4
c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12
c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 √ c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1
√ c 11 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 12 ∨ ¬A 13 √ ...
¬A
1¬A
13c
10c
10¬A
1c
11c
11c
11c
11c
10¬A
13A
7A
8¬A
1A
2A
3A
4A
¬A
10¬A
11A
12A
13A
1¬A
9¬A
9¬A
10¬A
11Learning
Idea: When a conflict set η is revealed, then C = ¬η
defadded to ϕ
=⇒ the solver will no more generate an assignment containing η:
when |η| − 1 literals in η are assigned, the other is set ⊥ by unit-propagation on C
=⇒ Drastic pruning of the search!
55 / 91
Learning – example
c 1 : ¬A 1 ∨ A 2 c 2 : ¬A 1 ∨ A 3 ∨ A 9 c 3 : ¬A 2 ∨ ¬A 3 ∨ A 4 c 4 : ¬A 4 ∨ A 5 ∨ A 10 c 5 : ¬A 4 ∨ A 6 ∨ A 11 c 6 : ¬A 5 ∨ ¬A 6 c 7 : A 1 ∨ A 7 ∨ ¬A 12 c 8 : A 1 ∨ A 8
c 9 : ¬A 7 ∨ ¬A 8 ∨ ¬A 13 √ c 10 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 1 √ c 11 : A 9 ∨ A 10 ∨ A 11 ∨ ¬A 12 ∨ ¬A 13
√ ...
¬A9
¬A11
¬A10
¬A1
¬A13 A12
¬A1
¬A13
c10
c10
¬A1 c11
c11
c11
c11
c10
¬A13 A7
A8
¬A1 A2
A3
A4
A5 A6
¬A10
¬A11
A12
A13
A1
¬A9
¬A9
¬A10
A12
¬A11
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
57 / 91
Horn Formulas
A Horn clause is a clause containing at most one positive literal a definite clause is a clause containing exactly one positive literal a goal clause is a clause containing no positive literal
A Horn formula is a conjunction/set of Horn clauses
Ex:
A
1∨ ¬A
2// definite A
2∨ ¬A
3∨ ¬A
4// definite
¬A
5∨ ¬A
3∨ ¬A
4// goal
A
3// definite
Intuition: implications between positive Boolean variables:
A
2→ A
1(A
3∧ A
4) → A
2(A
5∧ A
3∧ A
4) → ⊥
A
3Tractability of Horn Formulas
Property
Checking the satisfiability of Horn formulas requires polynomial time:
Hint:
1
Eliminate unit clauses by propagating their value;
2
If an empty clause is generated, return unsat
3
Otherwise, every clause contains at least one negative literal
=⇒ Assign all variables to ⊥; return the assignment
Alternatively: run DPLL, selecting always negative literals first
59 / 91
A simple polynomial procedure for Horn-SAT
function Horn_SAT(formula ϕ, assignment & µ) { Unit_Propagate(ϕ, µ);
if (ϕ == ⊥)
then return UNSAT;
else { µ := µ ∪ S
A
i6∈µ {¬A i };
return SAT;
} }
function Unit_Propagate(formula & ϕ, assignment & µ)
while (ϕ 6= > and ϕ 6= ⊥ and {a unit clause (l) occurs in ϕ}) do {
Example
¬A 1 ∨ A 2 ∨¬A 3
A 1 ∨¬A 3 ∨¬A 4
¬A 2 ∨¬A 4 A 3 ∨¬A 4
A 4
61 / 91
Example
¬A 1 ∨ A 2 ∨¬A 3
A 1 ∨¬A 3 ∨¬A 4
¬A 2 ∨¬A 4 A 3 ∨¬A 4
A 4
µ := {A 4 := >}
Example
¬A 1 ∨ A 2 ∨¬A 3
A 1 ∨¬A 3 ∨¬A 4
¬A 2 ∨¬A 4 A 3 ∨¬A 4
A 4 µ := {A 4 := >, A 3 := >}
63 / 91
Example
¬A 1 ∨ A 2 ∨¬A 3
A 1 ∨¬A 3 ∨¬A 4
¬A 2 ∨¬A 4 A 3 ∨¬A 4
A 4
µ := {A 4 := >, A 3 := >, A 2 := ⊥}
Example
¬A 1 ∨ A 2 ∨¬A 3 × A 1 ∨¬A 3 ∨¬A 4
¬A 2 ∨¬A 4 A 3 ∨¬A 4
A 4
µ := {A 4 := >, A 3 := >, A 2 := ⊥, A 1 := >} =⇒ UNSAT
65 / 91
Example 2
A 1 ∨¬A 2
A 2 ∨¬A 5 ∨¬A 4 A 4 ∨¬A 3
A 3
Example 2
A 1 ∨¬A 2
A 2 ∨¬A 5 ∨¬A 4 A 4 ∨¬A 3
A 3 µ := {A 3 := >}
67 / 91
Example 2
A 1 ∨¬A 2
A 2 ∨¬A 5 ∨¬A 4 A 4 ∨¬A 3
A 3
µ := {A 3 := >, A 4 := >}
Example 2
A 1 ∨¬A 2
A 2 ∨¬A 5 ∨¬A 4 A 4 ∨¬A 3
A 3 µ := {A 3 := >, A 4 := >} =⇒ SAT
69 / 91
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
Local Search with SAT
Similar to Local Search for CSPs Input: set of clauses
Use total truth assignments
allow states with unsatisfied clauses
“neighbour states” differ for one variable truth value steps: reassign variable truth values
Cost: # of unsatisfied clauses
Stochastic local search [see Ch. 4] applies to SAT as well random walk, simulated annealing, GAs, taboo search, ...
The WalkSAT stochastic local search
Clause selection: randomly select an unsatisfied clause C Variable selection:
prob. p: flip variable from C at random
prob. 1-p: flip variable from C causing a minimum number of unsat clauses
Note: can detect only satisfiability, not unsatisfiability Many variants
71 / 91
The WalkSAT Procedure
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
73 / 91
A Quote
You can think about deep learning as equivalent to ... our visual cortex or auditory cortex. But, of course, true intelligence is a lot more than just that, you have to recombine it into higher-level thinking and symbolic reasoning, a lot of the things classical AI tried to deal with in the 80s. ... We would like to build up to this symbolic level of reasoning - maths, language, and logic. So that’s a big part of our work.
Demis Hassabis, CEO of Google Deepmind
Knowledge Representation and Reasoning
Knowledge Representation & Reasoning (KR&R): the field of AI dedicated to representing knowledge of the world in a form a computer system can utilize to solve complex tasks
The class of systems/agents that derive from this approach are called knowledge based (KB) systems/agents
A KB agent maintains a knowledge base (KB) of facts collection of domain-specific facts believed by the agent expressed in a formal language (e.g. propositional logic) represent the agent’s representation of the world initially contains the background knowledge
KB queries and updates via logical entailment, performed by an inference engine
Inference engine allows for inferring actions and new knowledge domain-independent algorithms, can answer any question
( c S. Russell & P. Norwig, AIMA) 75 / 91
Reasoning
Reasoning: formal manipulation of the symbols representing a collection of beliefs to produce representations of new ones Logical entailment (KB |= α) is the fundamental operation Ex:
(KB acquired fact): “Patient x is allergic to medication m”
(KB general rule): “Anybody allergic to m is also allergic to m’.”
(KB general rule): “If x is allergic to m’, do not prescribe m’ for x.”
(query): “Prescribe m’ for x?”
(answer) No (because patient x is allergic to medication m’) Other forms of reasoning (last part of this course)
Probablistic reasoning
Other forms of reasoning (not addressed in this course)
Knowledge-Based Agents (aka Logic Agents)
Logic agents: combine domain knowledge with current percepts to infer hidden aspects of current state prior to selecting actions
Crucial in partially observable environments KB Agent must be able to:
represent states and actions incorporate new percepts
update internal representation of the world deduce hidden properties of the world deduce appropriate actions
Agents can be described at different levels
knowledge level (declarative approach): behaviour completely described by the sentences stored in the KB
implementation level (procedural approach): behaviour described as program code
Declarative approach to building an agent (or other system):
Tell the KB what it needs to know (update KB)
Ask what to do (answers should follow logically from KB & query)
77 / 91
Knowledge-Based Agent: General Schema
Given a percept, the agent
Tells the KB of the percept at time step t
ASKs the KB for the best action to do at time step t Tells the KB that it has in fact taken that action
Details hidden in three functions: M AKE -P ERCEPT -S ENTENCE , M AKE -A CTION -Q UERY , M AKE -A CTION -S ENTENCE
construct logic sentences
implement the interface between sensors/actuators and KRR core
Tell and Ask may require complex logical inference
Example: The Wumpus World
Task Environment: PEAS Description Performance measure:
gold: +1000, death: -1000 step: -1, using the arrow: -10 Environment:
squares adjacent to Wumpus are stenchy 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 Actuators:
Left turn, Right turn, Forward, Grab, Release, Shoot
Sensors:
Stench, Breeze, Glitter, Bump, Scream
One possible configuration:
( c S. Russell & P. Norwig, AIMA)
79 / 91
Wumpus World: Characterization
Fully Observable? No: only local perception Deterministic? Yes: outcomes exactly specified
Episodic? No: actions can have long-term consequences Static? Yes: Wumpus and Pits do not move
Discrete? Yes
Single-agent? Yes (Wumpus is essentially a natural feature)
Example: Exploring the Wumpus World
The KB initially contains the rules of the
environment.
Agent is initially in 1,1 Percepts:
no stench, no breeze
=⇒ [1,2] and [2,1] OK
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: Pit; BGS: bag of gold
81 / 91
Example: Exploring the Wumpus World
Agent moves to [2,1]
perceives a breeze
=⇒ Pit in [3,1] or [2,2]
perceives no stench
=⇒ no Wumpus in [3,1], [2,2]
Example: Exploring the Wumpus World
Agent moves to [2,1]
perceives a breeze
=⇒ Pit in [3,1] or [2,2]
perceives no stench
=⇒ no Wumpus in [3,1], [2,2]
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: Pit; BGS: bag of gold
81 / 91
Example: Exploring the Wumpus World
Agent moves to [1,1]-[1,2]
perceives no breeze
=⇒ no Pit in [1,3], [2,2]
=⇒ [2,2] OK
=⇒ pit in [3,1]
perceives a stench
=⇒ Wumpus in [2,2] or [1,3]!
Example: Exploring the Wumpus World
Agent moves to [1,1]-[1,2]
perceives no breeze
=⇒ no Pit in [1,3], [2,2]
=⇒ [2,2] OK
=⇒ pit in [3,1]
perceives a stench
=⇒ Wumpus in [2,2] or [1,3]!
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: Pit; BGS: bag of gold
81 / 91
Example: Exploring the Wumpus World
Agent moves to [2,2]
perceives no breeze
=⇒ no pit in [3,2], [2,3]
perceives no stench
=⇒ no Wumpus in [3,2], [2,3]
=⇒ [3,2] and [2,3] OK
Example: Exploring the Wumpus World
Agent moves to [2,2]
perceives no breeze
=⇒ no pit in [3,2], [2,3]
perceives no stench
=⇒ no Wumpus in [3,2], [2,3]
=⇒ [3,2] and [2,3] OK
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: Pit; BGS: bag of gold
81 / 91
Example: Exploring the Wumpus World
Agent moves to [2,3]
perceives a glitter
=⇒ bag of gold!
Example 2: Exploring the Wumpus World [see Ch 13]
Alternative scenario: apply coercion Feel stench in [1,1]
=⇒ Wumpus [1,2] or [2,1]
=⇒ Cannot move
Apply coercion: shoot ahead Wumpus was there
=⇒ Wumpus dead
=⇒ Safe
Wumpus wasn’t there
=⇒ Safe
82 / 91
Example 3: Exploring the Wumpus World [see Ch 13]
Alternative scenario: probabilistic solution (hints) Feel breeze in [1,2] and [2,1]
=⇒ pit in [1,3] or [2,2] or [3,1]
=⇒ no safe action
Probability analysis [see Ch 13]
(assuming pits uniformly distributed):
P(pit ∈ [2, 2]) = 0.86
P(pit ∈ [1, 3]) = 0.31
P(pit ∈ [3, 1]) = 0.31
Outline
1 Propositional Logic
2 Propositional Reasoning Resolution
DPLL
Modern CDCL SAT Solvers Reasoning with Horn Formulas Local Search
3 Knowledge-Based Agents
4 Agents Based on Propositional Reasoning
84 / 91
Propositional Logic Agents
Kind of Logic agents
Language: propositional logic
represent KB as set of propositional formulas
percepts and actions are (collections of ) propositional atoms in practice: sets of clauses
Perform propositional logic inference model checking, entailment
in practice: incremental calls to a SAT solver
Representation vs. World
Reasoning process (propositional entailment) sound
=⇒ if KB is true in the real world, then any sentence α derived from KB by a sound inference procedure is also true in the real world
sentences are configurations of the agent
reasoning constructs new configurations from old ones
=⇒ the new configurations represent aspects of the world that actually follow from the aspects that the old configurations represent
( c S. Russell & P. Norwig, AIMA) 86 / 91
Reasoning as Entailment
Scenario in Wumpus World
Consider pits (and breezes) only:
initial: ¬P
[1,1]after detecting nothing in [1,1]:
¬B
[1,1]move to [2,1], detect breeze: B
[2,1]Q: are there pits in [1,2], [2,1], [3,1]?
3 variables: P [1,2] ,P [2,1] ,P [3,1] ,
=⇒ 8 possible models
Reasoning as Entailment [cont.]
8 possible models
( c S. Russell & P. Norwig, AIMA)
88 / 91
Reasoning as Entailment [cont.]
KB: Wumpus World rules + observations =⇒ 3 models
Reasoning as Entailment [cont.]
Query α 1 : ¬P [1,2] =⇒ KB |= α 1 (i.e M(KB) ⊆ M(α 1 ))
( c S. Russell & P. Norwig, AIMA)
88 / 91
Reasoning as Entailment [cont.]
Query α 2 : ¬P [2,2] =⇒ KB 6|= α 2 (i.e M(KB) 6⊆ M(α 2 ))
Reasoning as Entailment [cont.]
In practice: DPLL(CNF (KB ∧ ¬α 2 )) = sat
( c S. Russell & P. Norwig, AIMA)
88 / 91
Example: Exploring the Wumpus World
KB initially contains (the CNFized versions of) the following formulas:
breeze iff pit in neighbours, ∀i, j ∈ [1..4]
B [i,j] ↔ (P [i,j−1] ∨P [i+1,j] ∨ P [i,j+1] ∨ P [i−1,j] ) stench iff Wumpus in neighbours,
∀i, j ∈ [1..4]
S [i,j] ↔ (W [i,j−1] ∨W [i+1,j] ∨W [i,j+1] ∨W [i−1,j] ) safe iff no Wumpus and no pit there
OK [i,j] ↔ (¬W [i,j] ∧ ¬P [j,i] ) glitter iff pile of gold there G [i,j] ↔ BGS [i,j]
in [1, 1] no Wumpus and no pit =⇒ safe
¬P [1,1] , ¬W [1,1] , OK [1,1]
Example: Exploring the Wumpus World
KB initially contains:
¬P [1,1] , ¬W [1,1] , OK [1,1]
B [1,1] ↔ (P [1,2] ∨ P [2,1] ) S [1,1] ↔ (W [1,2] ∨ W [2,1] ) OK [1,2] ↔ (¬W [1,2] ∧ ¬P [2,1] ) OK [2,1] ↔ (¬W [2,1] ∧ ¬P [1,2] ) ...
Agent is initially in 1,1
Percepts (no stench, no breeze):
¬S [1,1] , ¬B [1,1]
=⇒ ¬W [1,2] , ¬W [2,1] , ¬P [1,2] , ¬P [2,1]
=⇒ OK [1,2] , OK [2,1] ([1,2]&[2,1] OK) Add all them to KB
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: pit; BGS: glitter, bag of gold
90 / 91
Example: Exploring the Wumpus World
KB initially contains:
¬P [1,1] , ¬W [1,1] , OK [1,1]
B [2,1] ↔ (P [1,1] ∨P [2,2] ∨ P [3,1] ) S [2,1] ↔ (W [1,1] ∨W [2,2] ∨ W [3,1] ) Agent moves to [2,1]
perceives a breeze: B [2,1]
=⇒ (P [3,1] ∨ P [2,2] ) (pit in [3,1] or [2,2]) perceives no stench ¬S [2,1]
=⇒ ¬W [3,1] , ¬W [2,2]
(no Wumpus in [3,1], [2,2])
Add all them to KB
Example: Exploring the Wumpus World
KB initially contains:
¬P [1,1] , ¬W [1,1] , OK [1,1]
B [2,1] ↔ (P [1,1] ∨P [2,2] ∨ P [3,1] ) S [2,1] ↔ (W [1,1] ∨W [2,2] ∨ W [3,1] ) Agent moves to [2,1]
perceives a breeze: B [2,1]
=⇒ (P [3,1] ∨ P [2,2] ) (pit in [3,1] or [2,2]) perceives no stench ¬S [2,1]
=⇒ ¬W [3,1] , ¬W [2,2]
(no Wumpus in [3,1], [2,2]) Add all them to KB
A: Agent; B: Breeze; G: Glitter; S: Stench
OK: safe square; W: Wumpus; P: pit; BGS: glitter, bag of gold
90 / 91