+ All Categories
Home > Documents > Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic...

Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic...

Date post: 13-Sep-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
102
Logical Agents CE417: Introduction to Artificial Intelligence Sharif University of Technology Spring 2016 β€œArtificial Intelligence: A Modern Approach”, 3 rd Edition, Chapter 7 Soleymani
Transcript
Page 1: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Logical AgentsCE417: Introduction to Artificial IntelligenceSharif University of TechnologySpring 2016

β€œArtificial Intelligence: A Modern Approach”, 3rd Edition, Chapter 7

Soleymani

Page 2: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Knowledge-based agents

2

Knowledge-based agents

Reasoning operates on internal representation of

knowledge

Logic as a general class of representation

Propositional logic

First-order logic

Page 3: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

A generic knowledge-based agent

3

function KB_AGENT(π‘π‘’π‘Ÿπ‘π‘’π‘π‘‘) returns an π‘Žπ‘π‘‘π‘–π‘œπ‘›

persistent:𝐾𝐡, a knowledge base

𝑑, π‘Ž counter for time, initially 0

TELL(𝐾𝐡,MAKE_PERCEPT_SENTENCE(π‘π‘’π‘Ÿπ‘π‘’π‘π‘‘, 𝑑))

π‘Žπ‘π‘‘π‘–π‘œπ‘› ← ASK(𝐾𝐡,MAKE_ACTION_QUERY(𝑑))

TELL(𝐾𝐡,MAKE_ACTION_SENTENCE(π‘Žπ‘π‘‘π‘–π‘œπ‘›, 𝑑))

𝑑 ← 𝑑 + 1

return π‘Žπ‘π‘‘π‘–π‘œπ‘›

The agent must be able to: Represent states, actions, percepts,….

Incorporate new percepts

Update internal representations of the world

Deduce hidden properties of the world

Deduce appropriate actions

β€’ Makes a sentence asserting that the agent

perceived the given percept at the given time.

β€’ Makes a sentence that asks what action

should be done at the current time.

β€’ Makes a sentence asserting that the chosen

action was executed.

Page 4: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Knowledge Base (KB)

4

KB = a set of sentences expressed in a knowledge

representation language

TELL: adds new sentences to the knowledge base

ASK: asks a question of KB

the answer follows from previously TELLed sentences to the KB

Inference: derives new sentences from old ones

Basis of TELL and ASK operations

Page 5: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world

5

Wumpus

Wumpus

Pitts

Gold

Agent

Page 6: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world PEAS description

Performance measure

+1000 for garbing gold

-1000 for death

-1 for each action

-10 for using up the arrow

Game ends when the agent dies or climbs out of the cave

Environment

4Γ—4 grid

Agent starts in [1,1] while facing to the right

Gold and wumpus are located randomly in the squares except to [1,1]

Each square other than [1,1] can be a pit with probability 0.2

6

Page 7: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world PEAS description

7

Sensors: Stench, Breeze, Glitter, Bump, Scream

In the squares adjacent to wumpus, agent perceives a Stench

It the squares adjacent to a pit, agent perceives a Breeze

In the gold square, agent perceives a Glitter

When walking into a wall, agent perceives a Bump

When Wumpus is killed, agent perceives a Scream

Actuators: Forward, TurnLeft, TurnRight, Shoot, Grab, Climb

Forward,TurnLeft,TurnRight: moving and rotating face actions.

Moving to a square containing a pit or a live wumpus causes death.

If an agent tries to move forward and bumps into a wall then it does not move.

Shoot: to fire an arrow in a straight line in the facing direction of the agent

Shooting kills wumpus if the agent is facing it (o.w. the arrow hits a wall)

The first shoot action has any effect (the agent has only one arrow)

Grab: to pick up the gold if it is in the same square as the agent.

Climb: climb out of the cave but only from [1,1]

Page 8: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world characterization

Fully Observable? No – many aspects are not directly

perceivable

Episodic? No – sequential at the level of actions

Static? Yes

Discrete?Yes

Single-agent?Yes

8

Page 9: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

9

Page 10: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

A: agent

OK: safe square

B: Breeze

10

Page 11: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

11

Page 12: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

S: Stench

12

Page 13: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

S: Stench

13

Page 14: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

S: Stench

14

Page 15: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

S: Stench

15

Page 16: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example

A: agent

OK: safe square

B: Breeze

P: Pit

S: Stench

16

Page 17: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Logic & Language

Logic includes formal languages for representing informationsuch that conclusions can be drawn

Syntax defines the well-formed sentences in a language

Semantics define the "meaning" of sentences i.e., define truth of a sentence with respect to each possible world

We will introduce Propositional Logic in this lecture It talks about facts

Propositions can be true, false, or unknown

17

Page 18: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Propositional logic: Syntax

Propositional logic is the simplest logic

To illustrate basic ideas about logic & reasoning

The proposition symbols 𝑃,𝑄,… are sentences.

If 𝑃 is a sentence,𝑃 is a sentence (negation)

If 𝑃 and 𝑄 are sentences,𝑃𝑄 is a sentence (conjunction)

If 𝑃 and 𝑄 are sentences,𝑃𝑄 is a sentence (disjunction)

If 𝑃 and 𝑄 are sentences,𝑃 𝑄 is a sentence (implication)

If 𝑃 and 𝑄 are sentences,𝑃 𝑄 is a sentence (biconditional)

18

Page 19: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Propositional logic (Grammar)

19

𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 β†’ π΄π‘‘π‘œπ‘šπ‘–π‘π‘†π‘’π‘›π‘‘π‘’π‘›π‘π‘’ | πΆπ‘œπ‘šπ‘π‘™π‘’π‘₯π‘†π‘’π‘›π‘‘π‘’π‘›π‘π‘’π΄π‘‘π‘œπ‘šπ‘–π‘π‘†π‘’π‘›π‘‘π‘’π‘›π‘π‘’ β†’ π‘‡π‘Ÿπ‘’π‘’ πΉπ‘Žπ‘™π‘ π‘’ 𝑃 𝑄 𝑅 | β€¦πΆπ‘œπ‘šπ‘π‘™π‘’π‘₯𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 β†’ (𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒)

| ¬𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒| 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 ∧ 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒| 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 ∨ 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒| 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 ⟹ 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒| 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 ⇔ 𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒

π‘ƒπ‘Ÿπ‘’π‘π‘’π‘‘π‘’π‘›π‘π‘’: Β¬, ∧, ∨, ⟹, ⇔

Page 20: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Truth tables for connectives

20

Page 21: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Propositional logic: Semantics

21

Each model specifies true/false of each proposition symbol

e.g., Propistion symbols:𝑃1,2, 𝑃2,2, 𝑃3,1

8 possible models

π‘š1 = {𝑃1,2 = π‘“π‘Žπ‘™π‘ π‘’, 𝑃2,2 = π‘“π‘Žπ‘™π‘ π‘’, 𝑃3,1 = π‘‘π‘Ÿπ‘’π‘’}

Semantics of a complex sentence in any model m:

𝑃 is true iff 𝑃 is false in π‘š.

𝑃𝑄 is true iff 𝑃 is true and 𝑄 is true in π‘š.

𝑃 ∨ 𝑄 is true iff 𝑃 is true or 𝑄 is true in π‘š.

𝑃 ⟹ 𝑄 is true unless 𝑃 is true and 𝑄 is false in π‘š.

𝑃 ⟺ 𝑄 is true iff 𝑃 and 𝑄 are both true or both false in π‘š.

Page 22: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world sentences

𝑃𝑖,𝑗 is true if there is a pit in [𝑖, 𝑗].

π‘Šπ‘–,𝑗 is true if there is a wumpus in [𝑖, 𝑗], dead or alive.

𝐡𝑖,𝑗 is true if the agent perceives a breeze in [𝑖, 𝑗].

𝑆𝑖,𝑗 is true if the agent perceives a stench in [𝑖, 𝑗].

General rules (only related ones to the current agent position) 𝑅1: 𝑃1,1 (no pit in [1,1])

𝑅2: 𝐡1,1 ⇔ 𝑃1,2 ∨ 𝑃2,1 (Pits cause breezes in adjacent squares)

𝑅3: 𝐡2,1 ⇔ 𝑃1,1 ∨ 𝑃2,2 ∨ 𝑃3,1 (Pits cause breezes in adjacent squares)

Perception

𝑅4: 𝐡1,1 𝑅5: 𝐡2,1

22

Page 23: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Models

Models are mathematical abstraction of possible worlds Each model fixes the truth or falsehood of every relevant sentence.

We can consider a set for each logical sentence that specifies

all possible worlds in which 𝛼 is true

𝑀(𝛼): set of all models of the sentence 𝛼 (all satisfying 𝛼) π‘š ∈ 𝑀(𝛼) if 𝛼 is true in model π‘š E.g., For 𝛼: π‘₯ + 𝑦 = 4, all possible assignments of values to π‘₯, 𝑦 are

models.𝑀(𝛼) contains a subset of models satisfying π‘₯ + 𝑦 = 4.

23

Page 24: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

24

Agents starts at [1,1] with no active sensor,

then moves to [2,1] and senses Breeze in it

Possible models for pits in [1,2], [2,2], [3,1]:

Page 25: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Logical reasoning: entailment

25

𝛼 ⊨ 𝛽 (entailment):𝛼 entails 𝛽 𝛼 β‡’ 𝛽 is a tautology or valid

A sentence is valid or tautology if it is Tπ‘Ÿπ‘’π‘’ in all models (e.g., 𝑃𝑃,

(𝑃(𝑃𝑄))𝑄)

𝛽 logically follows from 𝛼 or 𝛼 is stronger than 𝛽

𝛼 ⊨ 𝛽 iff 𝑀 𝛼 𝑀 𝛽 𝛼 entails 𝛽 iff 𝛽 is true in all worlds where 𝛼 is true

Page 26: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Entailment

𝐾𝐡 ⊨ 𝛼 iff 𝑀(𝐾𝐡) βŠ† 𝑀(𝛼)

Example: KB=β€œA is red” & β€œB is blue”

Ξ± = β€œA is red”

26

Page 27: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Entailment in the wumpus world

𝐾𝐡 (before perception): rules of the

wumpus world

Perception: After detecting nothing in

[1,1], moving right, a breeze in [1,2]

27

Page 28: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

28

Possible models for pits in [1,2], [2,2], [3,1]

Consider possible models for only

pits in neighboring squares 23 = 8possible models

Page 29: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

𝐾𝐡 = wumpus-world rules + perceptions

29

Page 30: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

𝐾𝐡 = wumpus-world rules + perceptions

𝛼1 = "[1,2] is safe"

𝑀(𝐾𝐡) βŠ† 𝑀(𝛼1) β‡’ 𝐾𝐡 ⊨ 𝛼1

30

Page 31: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

KB = wumpus-world rules + perceptions

31

Page 32: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus models

𝐾𝐡 = wumpus-world rules + perceptions

𝛼2 = "[2,2] is safe",𝐾𝐡 ⊭ 𝛼2

32

Page 33: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Inference

πΎπ΅β”œπ‘–π›Ό:𝛼 can be derived from 𝐾𝐡 by an inference algorithm 𝑖

An inference algorithm 𝑖 is: sound if whenever πΎπ΅β”œπ‘–π›Ό, it is also true that 𝐾𝐡 ⊨ 𝛼

all provable statements by this algorithm are true

complete if whenever 𝐾𝐡 ⊨ 𝛼, it is also true that πΎπ΅β”œπ‘–π›Ό all true statements are provable by this algorithm

33

Page 34: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Inference methods

Inference methods can be categorized into: Model checking (enumerating models)

truth table enumeration (always exponential in 𝑛)

improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL)

heuristic search in model space (sound but incomplete)

e.g., min-conflicts-like hill-climbing algorithms

Theorem proving (searching proofs by applying inference rules)

Applying a sequence of inference rules on KB to find the desired sentence

Legitimate (sound) generation of new sentences from old ones.

34

Page 35: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Truth tables for inference

35

𝐾𝐡 ⊨ 𝛼?

Enumerate the models

β€œIs 𝛼 true in every model in which KB is true?”

𝑅1: 𝑃1,1𝑅2: 𝐡1,1 ⇔ 𝑃1,2 ∨ 𝑃2,1𝑅3: 𝐡2,1 ⇔ 𝑃1,1 ∨ 𝑃2,2 ∨ 𝑃3,1𝑅4: 𝐡1,1𝑅5: 𝐡2,1

KB

Page 36: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Entailment by enumeration (model checking)

36

function 𝑇𝑇_𝐸𝑁𝑇𝐴𝐼𝐿𝑆? (𝐾𝐡, 𝛼) returns π‘‘π‘Ÿπ‘’π‘’ or π‘“π‘Žπ‘™π‘ π‘’

inputs: 𝐾𝐡, the knowledge base, a sentence in propositional logic

𝛼, the query, a sentence in propositional logic

π‘ π‘¦π‘šπ‘π‘œπ‘™π‘  ← a list of the proposition symbols in 𝐾𝐡 and 𝛼

return 𝑇𝑇_𝐢𝐻𝐸𝐢𝐾_𝐴𝐿𝐿(𝐾𝐡, 𝛼 , π‘ π‘¦π‘šπ‘π‘œπ‘™π‘ , {})

function 𝑇𝑇_𝐢𝐻𝐸𝐢𝐾_𝐴𝐿𝐿(𝐾𝐡, 𝛼, π‘ π‘¦π‘šπ‘π‘œπ‘™π‘ , π‘šπ‘œπ‘‘π‘’π‘™) returns π‘‘π‘Ÿπ‘’π‘’ or π‘“π‘Žπ‘™π‘ π‘’

if πΈπ‘€π‘ƒπ‘‡π‘Œ? ( π‘ π‘¦π‘šπ‘π‘œπ‘™π‘ ) then

if 𝑃𝐿_π‘‡π‘…π‘ˆπΈ? (𝐾𝐡,π‘šπ‘œπ‘‘π‘’π‘™) then return 𝑃𝐿_π‘‡π‘…π‘ˆπΈ? (𝛼,π‘šπ‘œπ‘‘π‘’π‘™)

else return π‘‘π‘Ÿπ‘’π‘’

else

𝑃 ← 𝐹𝐼𝑅𝑆𝑇(π‘ π‘¦π‘šπ‘π‘œπ‘™π‘ )

π‘Ÿπ‘’π‘ π‘‘ ← 𝑅𝐸𝑆𝑇(π‘ π‘¦π‘šπ‘π‘œπ‘™π‘ )

return 𝑇𝑇_𝐢𝐻𝐸𝐢𝐾_𝐴𝐿𝐿(𝐾𝐡, 𝛼, π‘Ÿπ‘’π‘ π‘‘,π‘šπ‘œπ‘‘π‘’π‘™β‹ƒ{𝑃 = π‘‘π‘Ÿπ‘’π‘’}) and

𝑇𝑇_𝐢𝐻𝐸𝐢𝐾_𝐴𝐿𝐿(𝐾𝐡, 𝛼, π‘Ÿπ‘’π‘ π‘‘,π‘šπ‘œπ‘‘π‘’π‘™β‹ƒ{𝑃 = π‘“π‘Žπ‘™π‘ π‘’})

Page 37: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Entailment by enumeration: properties

37

Depth-first enumeration of all models is sound and complete

(when finite models).

For 𝑛 symbols, time complexity is 𝑂(2𝑛), space complexity is

𝑂(𝑛).

Page 38: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Satisfiability

38

A sentence is satisfiable if it is true in some models

e.g.,𝑃𝑄

Determining the satisfiability of sentences in propositional

logic (SAT problem) is NP-complete

Satisfiability and validity are connected.

𝛼 is valid or tautology iff ¬𝛼 is unsatisfiable.

𝛼 is satisfiable iff ¬𝛼 is not valid.

𝛼 ⊨ 𝛽 iff (𝛼 ∧ ¬𝛽) is unsatisfiable

Proof by contradiction

Page 39: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

The DPLL (Davis, Putnam, Logemann,

Loveland) algorithm

39

Improvements over truth table enumeration (simple DFS): 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 (𝐴𝐡) ∧ (¬𝐡 𝐢) ∧ (𝐢𝐴),𝐴 and 𝐡 are pure,𝐢 is impure.

Make a pure symbol literal true.

In determining purity, we can ignore clauses already known to be true

Unit clause heuristic

Unit clause: all literals except to one already assigned false by model.

The only literal in a unit clause will be assigned true.

Many tricks can be used to enable SAT solvers to scale up.

Page 40: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

The DPLL algorithm

40

Determining satisfiability of an input propositional logic sentence (in CNF)

Page 41: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Entailment by using inference rule

41

Propositional theorem proving

Searching proofs can be more efficient than model

checking.

Can ignore irrelevant propositions.

When the number of models is large but the length of proof is

short, entailment by theorem proving is useful.

Page 42: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Inference rules

42

Some samples:

Modus Ponens:Ξ±β‡’Ξ², Ξ±

Ξ²

And elimination:π›Όβˆ§π›½

𝛽

Biconditional elimination:𝛼⇔𝛽

(𝛼⇒𝛽)∧(𝛽⇒𝛼)

Page 43: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Valid implication

43

Deduction theorem: 𝛼 ⊨ 𝛽 iff 𝛼 β‡’ 𝛽 is valid.

Every valid implication describes a legitimate inference.

Modus Ponens:Ξ±β‡’Ξ², Ξ±

Ξ²is equivalent to valid implication

Ξ± β‡’ Ξ² ∧ Ξ± β‡’ Ξ² is valid

All logical entailments can be used as inference rules.

Page 44: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Logical equivalence

Using logical equivalence we can find many inference rules

Two sentences are logically equivalent iff they are true in the

same models

𝛼 ≑ 𝛽 iff 𝛼 ⊨ 𝛽 and 𝛽 ⊨ 𝛼

44

Page 45: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Example of inference

45

𝑅1: 𝑃1,1

𝑅2: 𝐡1,1 ⇔ 𝑃1,2 ∨ 𝑃2,1

𝑅3: 𝐡2,1 ⇔ 𝑃1,1 ∨ 𝑃2,2 ∨ 𝑃3,1 𝑅4: 𝐡1,1 𝑅5: 𝐡2,1

Can we infer from 𝑅1 through 𝑅5 to prove 𝑃1,2?

𝑅6: 𝐡1,1 β‡’ 𝑃1,2 ∨ 𝑃2,1 ∧ 𝑃1,2 ∨ 𝑃2,1 β‡’ 𝐡1,1 [biconditional elim. to 𝑅2]

𝑅7: 𝑃1,2 ∨ 𝑃2,1 β‡’ 𝐡1,1 [and elim. to 𝑅6]

𝑅8: ¬𝐡1,1 β‡’ Β¬ 𝑃1,2 ∨ 𝑃2,1 [(𝑃 β‡’ 𝑄) ≑ (¬𝑄 β‡’ ¬𝑃)]

𝑅9: Β¬ 𝑃1,2 ∨ 𝑃2,1 [Modus Ponens with 𝑅8 and 𝑅4]

𝑅10: ¬𝑃1,2 ∧ ¬𝑃2,1 [De Morgan’ rule]

Page 46: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Finding a proof as a search problem

46

𝐼𝑁𝐼𝑇𝐼𝐴𝐿_𝑆𝑇𝐴𝑇𝐸: the initial knowledge base

𝐴𝐢𝑇𝐼𝑂𝑁𝑆: all inference rules applied to all the sentences

that match their top line

π‘…πΈπ‘†π‘ˆπΏπ‘‡: add the sentence in the bottom line of the used

inference rule to the current ones

𝐺𝑂𝐴𝐿: a state containing the sentence we are trying to

prove.

Page 47: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Monotonicity property

47

The set of entailed sentences can only grow as

information is added to 𝐾𝐡.

Inference rules can be applied where premises are found in KB

(regardless of what else is in KB)

If 𝐾𝐡 ⊨ 𝛼 then 𝐾𝐡 ∧ 𝛽 ⊨ 𝛼 (for any 𝛼 and 𝛽)

The assertion 𝛽 can not invalidate any conclusion 𝛼 already

inferred.

Page 48: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Resolution

48

Inference rules are sound.

Is a set of rules complete?

Are the available inference rules adequate?

Resolution: a single inference rule that yields a complete

inference algorithm (when couples with any complete

search algorithm).

Page 49: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Resolution

49

Unit resolution: 𝑙𝑖 and π‘š are complementary literals

𝑙1 ∨ 𝑙2 ∨ β‹―βˆ¨ π‘™π‘˜ , π‘š

𝑙1 ∨ β€¦βˆ¨ π‘™π‘–βˆ’1 ∨ 𝑙𝑖+1 ∨ β‹―βˆ¨ π‘™π‘˜

Full resolution rule: 𝑙𝑖 and π‘šπ‘— are complementary literals

𝑙1 ∨ 𝑙2 ∨ β‹―βˆ¨ π‘™π‘˜ , π‘š1βˆ¨π‘š2 ∨ β‹―βˆ¨π‘šπ‘›

𝑙1 ∨ β€¦βˆ¨ π‘™π‘–βˆ’1 ∨ 𝑙𝑖+1 ∨ β‹―βˆ¨ π‘™π‘˜ ∨ π‘š1 ∨ β€¦βˆ¨π‘šπ‘—βˆ’1 ∨ π‘šπ‘—+1 ∨ β‹―βˆ¨π‘šπ‘›

It resolution rule sound.Why?

A resolution-based theorem prover can (for any sentences 𝛼 and 𝛽 in

propositional logic) decide whether 𝛼 ⊨ 𝛽 Is 𝛼 ∧ ¬𝛽 unsatisfiable?

CNF (Conjunctive Normal Form)

Page 50: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

CNF Grammar

50

𝐢𝑁𝐹𝑆𝑒𝑛𝑑𝑒𝑛𝑐𝑒 β†’ πΆπ‘™π‘Žπ‘’π‘ π‘’1 ∧ β‹―βˆ§ πΆπ‘™π‘Žπ‘’π‘ π‘’π‘›

πΆπ‘™π‘Žπ‘’π‘ π‘’ β†’ πΏπ‘–π‘‘π‘’π‘Ÿπ‘Žπ‘™1 ∨ β‹―βˆ¨ πΏπ‘–π‘‘π‘’π‘Ÿπ‘Žπ‘™π‘š

πΏπ‘–π‘‘π‘’π‘Ÿπ‘Žπ‘™ β†’ π‘†π‘¦π‘šπ‘π‘œπ‘™ | Β¬π‘†π‘¦π‘šπ‘π‘œπ‘™

π‘†π‘¦π‘šπ‘π‘œπ‘™ β†’ 𝑃 𝑄 𝑅 | …

Page 51: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Example of resolution

51

𝑃1,1 ∨ 𝑃3,1, ¬𝑃1,1∨ ¬𝑃2,2𝑃3,1 ∨ ¬𝑃2,2

Page 52: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Resolution algorithm

To show 𝐾𝐡 ⊨ 𝛼, we show 𝐾𝐡 ∧ ¬𝛼 is unsatisfiable

52

function PL-RESOLUTION(KB,Ξ±) returns π‘‘π‘Ÿπ‘’π‘’ or π‘“π‘Žπ‘™π‘ π‘’input: 𝐾𝐡, the knowledge base (a sentence in propositional logic)

𝛼, the query (a sentence in propositional logic)

π‘π‘™π‘Žπ‘’π‘ π‘’π‘  ← the set of clauses in the CNF representation of 𝐾𝐡¬𝛼𝑛𝑒𝑀 ← {}

loop do

for each pair of clauses 𝐢𝑖 , 𝐢𝑗 in π‘π‘™π‘Žπ‘’π‘ π‘’π‘  do

π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘  ← 𝑃𝐿_𝑅𝐸𝑆𝑂𝐿𝑉𝐸 (𝐢𝑖, 𝐢𝑗)

if π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘  contains the empty clause then return π‘‘π‘Ÿπ‘’π‘’

𝑛𝑒𝑀 ← 𝑛𝑒𝑀 βˆͺ π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘ 

if 𝑛𝑒𝑀 βŠ† πΆπ‘™π‘Žπ‘’π‘ π‘’π‘  then return π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘’π‘ π‘’π‘  ← π‘π‘™π‘Žπ‘’π‘ π‘’π‘  βˆͺ 𝑛𝑒𝑀

Page 53: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Resolution algorithm

To show 𝐾𝐡 ⊨ 𝛼, we show 𝐾𝐡 ∧ ¬𝛼 is unsatisfiable

53

function PL-RESOLUTION(KB,Ξ±) returns π‘‘π‘Ÿπ‘’π‘’ or π‘“π‘Žπ‘™π‘ π‘’input: 𝐾𝐡, the knowledge base (a sentence in propositional logic)

𝛼, the query (a sentence in propositional logic)

π‘π‘™π‘Žπ‘’π‘ π‘’π‘  ← the set of clauses in the CNF representation of 𝐾𝐡¬𝛼𝑛𝑒𝑀 ← {}

loop do

for each pair of clauses 𝐢𝑖 , 𝐢𝑗 in π‘π‘™π‘Žπ‘’π‘ π‘’π‘  do

π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘  ← 𝑃𝐿_𝑅𝐸𝑆𝑂𝐿𝑉𝐸 (𝐢𝑖, 𝐢𝑗)

if π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘  contains the empty clause then return π‘‘π‘Ÿπ‘’π‘’

𝑛𝑒𝑀 ← 𝑛𝑒𝑀 βˆͺ π‘Ÿπ‘’π‘ π‘œπ‘™π‘£π‘’π‘›π‘‘π‘ 

if 𝑛𝑒𝑀 βŠ† πΆπ‘™π‘Žπ‘’π‘ π‘’π‘  then return π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘’π‘ π‘’π‘  ← π‘π‘™π‘Žπ‘’π‘ π‘’π‘  βˆͺ 𝑛𝑒𝑀

Each pair containing complementary literals is resolved and the

resulted clause is added to the set if it is not already present.

The process continues until one of these happens:

- No new clauses (𝐾𝐡 ⊭ 𝛼)

- Two clauses resolve to yield the empty clause (𝐾𝐡 ⊨ 𝛼)

Sound and complete inference algorithm

Page 54: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Resolution example

𝐾𝐡 = 𝐡1,1 𝑃1,2 𝑃2,1 𝐡1,1

𝛼 = ¬𝑃1,2

Convert 𝐾𝐡 ∧ ¬𝛼 into CNF(𝐡1,1 𝑃1,2 𝑃2,1) (𝑃1,2 𝐡1,1) (𝑃2,1 𝐡1,1)(𝐡1,1)𝑃1,2

54

Contradiction

OK?

Page 55: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Completeness of resolution

55

Resolution closure 𝑅𝐢(𝑆) : a set of clauses derivable by

repeated application of resolution rule to clauses in 𝑆 or their

derivatives.

𝑅𝐢(𝑆) is finite. Thus 𝑃𝐿_onstructed out of 𝑃1, 𝑃2, … , π‘ƒπ‘˜ that appear in

𝑆. π‘…πΈπ‘†π‘‚πΏπ‘ˆπ‘‡πΌπ‘‚π‘ terminates.

Finite distinct clauses can be c

Ground resolution theorem: If a set of clauses 𝑆 is unsatisfiable

then 𝑅𝐢(𝑆) contains the empty clause.

If 𝑅𝐢(𝑆) does not contain the empty clause, we can find an assignment of

values to the symbols that satisfies 𝑅𝐢(𝑆) and thus 𝑆

Page 56: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Horn clauses & definite clauses

56

Some real-world KBs satisfy restrictions on the form of

sentences

We can use more restricted and efficient inference algorithms

Definite clause: a disjunction of literals of which exactly one is

positive literal.

¬𝑃1 ∨ ¬𝑃2 βˆ¨β€¦βˆ¨ Β¬π‘ƒπ‘˜ ∨ π‘ƒπ‘˜+1 ⇔ (𝑃1 ∧ 𝑃2 βˆ§β€¦ ∧ π‘ƒπ‘˜) β‡’ π‘ƒπ‘˜+1

Horn clause: a disjunction of literals of which at most one is

positive literal.

Closed under resolution

Page 57: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Grammar

57

π‘†π‘¦π‘šπ‘π‘œπ‘™ β†’ 𝑃 𝑄 𝑅 | …

π»π‘œπ‘Ÿπ‘›πΆπ‘™π‘Žπ‘’π‘ π‘’ β†’ π·π‘’π‘“π‘–π‘›π‘–π‘‘π‘’πΆπ‘™π‘Žπ‘’π‘ π‘’ | πΊπ‘œπ‘Žπ‘™πΆπ‘™π‘Žπ‘’π‘ π‘’

π·π‘’π‘“π‘–π‘›π‘–π‘‘π‘’πΆπ‘™π‘Žπ‘’π‘ π‘’ β†’ π‘†π‘¦π‘šπ‘π‘œπ‘™1 ∧ β‹―βˆ§ π‘†π‘¦π‘šπ‘π‘œπ‘™π‘™ β‡’ π‘†π‘¦π‘šπ‘π‘œπ‘™

πΊπ‘œπ‘Žπ‘™πΆπ‘™π‘Žπ‘’π‘ π‘’ β†’ (π‘†π‘¦π‘šπ‘π‘œπ‘™1 βˆ§β‹―βˆ§ π‘†π‘¦π‘šπ‘π‘œπ‘™π‘™) β‡’ πΉπ‘Žπ‘™π‘ π‘’

Page 58: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward and backward chaining

Inference with Horn clauses can be done through forward

chaining or backward chaining.

These algorithms are very natural and run in time that is linear

in the size of KB.

They are bases of logic programming Prolog: backward chaining

58

Page 59: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining

Repeated application of Modus Ponens until reaching goal

Fire any rule whose premises are satisfied in the KB

add its conclusion to the KB, until query is found

59

Arcs show

conjunctions

Page 60: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining algorithm

60

function 𝑃𝐿_𝐹𝐢_𝐸𝑁𝑇𝐴𝐼𝐿𝑆? (𝐾𝐡, π‘ž) returns π‘‘π‘Ÿπ‘’π‘’ or π‘“π‘Žπ‘™π‘ π‘’

inputs:𝐾𝐡, the knowledge base (a set of propositional definite clauses)

π‘ž, the query (a propositional symbol)

π‘π‘œπ‘’π‘›π‘‘ ← a table where π‘π‘œπ‘’π‘›π‘‘[𝑐] is the number of symbols in 𝑐’s premise

π‘–π‘›π‘“π‘’π‘Ÿπ‘Ÿπ‘’π‘‘ ← a table, where π‘–π‘›π‘“π‘’π‘Ÿπ‘Ÿπ‘’π‘‘[𝑠] is initially false for all symbols

π‘Žπ‘”π‘’π‘›π‘‘π‘Ž ← a queue of symbols, initially symbols known to be true in 𝐾𝐡

while π‘Žπ‘”π‘’π‘›π‘‘π‘Ž β‰  {} do𝑝 ← 𝑃𝑂𝑃(π‘Žπ‘”π‘’π‘›π‘‘π‘Ž)

if 𝑝 = π‘ž then return π‘‘π‘Ÿπ‘’π‘’

if π‘–π‘›π‘“π‘’π‘Ÿπ‘Ÿπ‘’π‘‘[𝑝] = π‘“π‘Žπ‘™π‘ π‘’ thenπ‘–π‘›π‘“π‘’π‘Ÿπ‘Ÿπ‘’π‘‘[𝑝] ← π‘‘π‘Ÿπ‘’π‘’

for each clause 𝑐 in 𝐾𝐡 where 𝑝 is in 𝑐. 𝑃𝑅𝐸𝑀𝐼𝑆𝐸 do

π‘π‘œπ‘’π‘›π‘‘[𝑐]= π‘π‘œπ‘’π‘›π‘‘[𝑐]-1

if π‘π‘œπ‘’π‘›π‘‘[𝑐] = 0 then add 𝑐. πΆπ‘‚π‘πΆπΏπ‘ˆπ‘†πΌπ‘‚π‘ to π‘Žπ‘”π‘’π‘›π‘‘π‘Ž

return false

Begin with known

facts (positive

literals) in KB

The process continues

until q is added or no

further inference

Page 61: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

61

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 62: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

62

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 63: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

63

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 64: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

64

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 65: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

65

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 66: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

66

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 67: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

67

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 68: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining: example

68

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 69: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward chaining

69

Assumption: KB of definite clauses

Sound?

Every inference is an application of Modus Ponens.

Complete?

Every entailed atomic sentence will be derived?

Humans keep forward chaining under careful control (to

avoid irrelevant consequences)

Page 70: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Proof of completeness

1. Consider the final state of the inferred table (fixed point

where no new atomic sentences are derived)

2. Consider the final state as a model π‘š, assigning π‘‘π‘Ÿπ‘’π‘’ to

inferred symbols and π‘“π‘Žπ‘™π‘ π‘’ to others

3. Every definite clause in the original KB is true in π‘šIf β€œπ‘Ž1 ∧ β‹―βˆ§ π‘Žπ‘› β‡’ 𝑏” is false then π‘Ž1 ∧ β‹―βˆ§ π‘Žπ‘› is true and 𝑏 is false. But it

contradicts with reaching a fixed point.

4. Thus,π‘š is a model of KB

5. If 𝐾𝐡 ⊨ π‘ž, atomic sentence π‘ž is true in every model of KB,

including π‘š

70

Page 71: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining

71

Idea: work backwards from the query π‘ž:

To prove π‘ž:if π‘ž is known to be true then

no work is needed

else

Find those rule concluding π‘ž

If all premises of one of them can be proved (by backward chaining)then π‘ž is true

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 failed

Page 72: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

72

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 73: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

73

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 74: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

74

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 75: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

75

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 76: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

76

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 77: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

77

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 78: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

78

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 79: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

79

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 80: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

80

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 81: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Backward chaining example

81

𝑃 β‡’ 𝑄

𝐿 ∧ 𝑀 β‡’ 𝑃

𝐡 ∧ 𝐿 β‡’ 𝑀

𝐴 ∧ 𝑃 β‡’ 𝐿

𝐴 ∧ 𝐡 β‡’ 𝐿

𝐴

𝐡

Page 82: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Forward vs. backward chaining

Forward chaining is data-driven, automatic, unconsciousprocessing

May do lots of work that is irrelevant to the goal

Backward chaining is goal-driven, appropriate for problem-solving

Only relevant facts are considered.

Complexity of BC can be much less than linear in size of KB

82

Page 83: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Efficient propositional inference

Efficient algorithms for general propositional inference:

We introduced DPLL algorithm as a systematic search method

Backtracking search algorithms

Now, we will introduceWalkSAT algorithm as a local search algorithm

83

Page 84: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

WalkSAT

It tests entailment 𝐾𝐡 ⊨ 𝛼 by testing unsatisfiability of 𝐾𝐡∧ ¬𝛼.

Local search algorithms (hill climbing, SA,…)

state space: complete assignments

evaluation function: number of unsatisfied clauses

WalkSat

Simple & effective

Balance between greediness and randomness

To escape from local minima

84

Page 85: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

WalkSAT

85

If max _𝑓𝑙𝑖𝑝𝑠 = ∞ and 𝑝 > 0, WalkSAT will find a model (if any exists)

If max _𝑓𝑙𝑖𝑝𝑠 = ∞, it never terminates for unsatisfiable sentences.

Page 86: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

WalkSAT

86

Failure may mean:

1) The sentence is unsatisfiable.

2) The algorithm needs more time.

It can not detect unsatisfiability.

Cannot be reliably used for deciding entailment.

Page 87: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Random SAT problems

Under-constrained problems: relatively few clauses

A large portion of possible assignments are solutions

e.g., (𝐷𝐡𝐢) ∧ (𝐡𝐴𝐢) ∧ (¬𝐢𝐡𝐸) ∧ (𝐸𝐷𝐡) ∧ (𝐡𝐸𝐢)

Over-constrained problems: many clauses relative to the

number of variables

Likely to have no solution

87

Page 88: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Hard satisfiability problems

88

π‘š = number of clauses

𝑛 = number of symbols

m/n = 4.3 (critical point)

3 βˆ’ 𝐢𝑁𝐹𝑛 = 50

Hard problems around

critical point

Page 89: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example:

propositional symbols

89

Atemporal variables that may be needed

𝑃𝑖,𝑗 is true if there is a pit in [𝑖, 𝑗].

π‘Šπ‘–,𝑗 is true if there is a wumpus in [𝑖, 𝑗], dead or alive.

𝐡𝑖,𝑗 is true if the agent perceives a breeze in [𝑖, 𝑗].

𝑆𝑖,𝑗 is true if the agent perceives a stench in [𝑖, 𝑗].

Some of the temporal variables that may be needed Variables for percepts and actions

𝐿𝑖,𝑗𝑑 , πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘π‘‘ , πΉπ‘Žπ‘π‘–π‘›π‘”π‘Šπ‘’π‘ π‘‘π‘‘ , πΉπ‘Žπ‘π‘–π‘›π‘”π‘π‘œπ‘Ÿπ‘‘β„Žπ‘‘ , πΉπ‘Žπ‘π‘–π‘›π‘”π‘†π‘œπ‘’π‘‘β„Žπ‘‘

π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€π‘‘

π‘Šπ‘’π‘šπ‘π‘’π‘ π΄π‘™π‘–π‘£π‘’π‘‘

Page 90: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example:

axioms on atemporal aspect of the world

90

Axioms: general knowledge about how the world works

General rules on atemporal variables

𝑃1,1

π‘Š1,1

𝐡π‘₯,𝑦 (𝑃π‘₯,𝑦+1 𝑃π‘₯,π‘¦βˆ’1 𝑃π‘₯+1,𝑦 𝑃π‘₯βˆ’1,𝑦)

𝑆π‘₯,𝑦 (π‘Šπ‘₯,𝑦+1 π‘Šπ‘₯,π‘¦βˆ’1 π‘Šπ‘₯+1,𝑦 π‘Šπ‘₯βˆ’1,𝑦)

π‘Š1,1 π‘Š1,2 … π‘Š4,4

π‘Š1,1 π‘Š1,2

π‘Š1,1 π‘Š1,3

…

A distinct rule is needed

for each square

Page 91: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example:

perceptions & actions

91

Perceptions are converted to facts and are Telled to KB

𝑀𝐴𝐾𝐸_𝑃𝐸𝑅𝐢𝐸𝑃𝑇_𝑆𝐸𝑁𝑇𝐸𝑁𝐢𝐸 π΅π‘Ÿπ‘’π‘’π‘§π‘’, π‘†π‘‘π‘’π‘›π‘β„Ž, π‘π‘œπ‘›π‘’, π‘π‘œπ‘›π‘’, π‘π‘œπ‘›π‘’ , 𝑑

π΅π‘Ÿπ‘’π‘’π‘§π‘’π‘‘, π‘†π‘‘π‘’π‘›π‘β„Žπ‘‘ are added to KB

Selected action is converted to a fact and is Telled to KB

𝑀𝐴𝐾𝐸_𝐴𝐢𝑇𝐼𝑂𝑁_𝑆𝐸𝑁𝑇𝐸𝑁𝐢𝐸 πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘, 𝑑

πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘π‘‘ is added to KB

Page 92: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example: transition model

92

Changing aspect of world (Temporal variables)

They are also called as fluents or state variables

Initial KB includes the initial status of some of the temporal variables:

𝐿1,10 , πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘0, π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€0,π‘Šπ‘’π‘šπ‘π‘’π‘ π΄π‘™π‘–π‘£π‘’0

Percepts are connected to fluents describing the properties of

squares

𝐿π‘₯,𝑦𝑑 β‡’ (π΅π‘Ÿπ‘’π‘’π‘§π‘’π‘‘ ⇔ 𝐡π‘₯,𝑦)

𝐿π‘₯,𝑦𝑑 β‡’ π‘†π‘‘π‘’π‘›π‘β„Žπ‘‘ ⇔ 𝑆π‘₯,𝑦

…

Transition model: fluents can change as the results of agent’s actions

Page 93: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world example: transition model

Frame problem

93

Transition model:

𝐿1,10 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘0 ∧ πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘0 β‡’ (𝐿2,1

1 ∧ ¬𝐿1,11 )

𝐿1,10 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘0 ∧ π‘‡π‘’π‘Ÿπ‘›πΏπ‘’π‘“π‘‘0 β‡’ (𝐿1,1

1 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”π‘π‘œπ‘Ÿπ‘‘β„Ž1 ∧ Β¬πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘1)

…

After doing πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘ action at time 0:

𝐴𝑆𝐾 𝐾𝐡,π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€1 = π‘“π‘Žπ‘™π‘ π‘’

Why?

Frame problem: representing the effects of actions without having to

represent explicitly a large number of intuitively obvious non-effects

Page 94: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world exampleSolution to frame problem: successor-state axioms

94

A Solution to frame problem: Successor-state axioms

Instead of writing axioms about actions, we write axioms

about fluents

𝐹𝑑+1 ⇔ π΄π‘π‘‘π‘–π‘œπ‘›πΆπ‘Žπ‘’π‘ π‘’π‘ πΉπ‘‘ ∨ (𝐹𝑑 ∧ Β¬π΄π‘π‘‘π‘–π‘œπ‘›πΆπ‘Žπ‘’π‘ π‘’π‘ π‘π‘œπ‘‘πΉπ‘‘)

π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€π‘‘+1 ⇔ π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€π‘‘ ∧ Β¬π‘†β„Žπ‘œπ‘œπ‘‘π‘‘

𝐿1,1𝑑+1 ⇔ (𝐿1,1

𝑑 ∧ (Β¬πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘π‘‘ ∨ π΅π‘’π‘šπ‘π‘‘+1))

∨ (𝐿1,2𝑑 ∧ (πΉπ‘Žπ‘π‘–π‘›π‘”π‘†π‘œπ‘’π‘‘β„Žπ‘‘ ∧ πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘π‘‘))

∨ (𝐿2,1𝑑 ∧ (πΉπ‘Žπ‘π‘–π‘›π‘”π‘Šπ‘’π‘ π‘‘π‘‘ ∧ πΉπ‘œπ‘Ÿπ‘€π‘Žπ‘Ÿπ‘‘π‘‘))

Page 95: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

A hybrid agent for the wumpus world

95

Basic concepts:

Safeness of [π‘₯, 𝑦] square:

𝑂𝐾π‘₯,𝑦𝑑 ⇔ ¬𝑃π‘₯,𝑦 ∧ Β¬(π‘Šπ‘₯,𝑦 ∧ π‘Šπ‘’π‘šπ‘π‘’π‘ π΄π‘™π‘–π‘£π‘’π‘‘)

Set of safe squares:

π‘ π‘Žπ‘“π‘’ ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡, 𝑂𝐾π‘₯,𝑦𝑑 = π‘‘π‘Ÿπ‘’π‘’

Set of unvisited squares:

𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡, 𝐿π‘₯,𝑦𝑑′ = π‘“π‘Žπ‘™π‘ π‘’ π‘“π‘œπ‘Ÿ π‘Žπ‘™π‘™ 𝑑′ ≀ 𝑑

Page 96: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

96

function π»π‘Œπ΅π‘…πΌπ·_π‘Šπ‘ˆπ‘€π‘ƒπ‘ˆπ‘†_𝐴𝐺𝐸𝑁𝑇(π‘π‘’π‘Ÿπ‘π‘’π‘π‘‘) returns an action sequence

inputs: π‘π‘’π‘Ÿπ‘π‘’π‘π‘‘, a list, π‘π‘Ÿπ‘’π‘’π‘§π‘’, π‘ π‘‘π‘’π‘›π‘β„Ž, π‘”π‘™π‘–π‘‘π‘‘π‘’π‘Ÿ, π‘π‘’π‘šπ‘, π‘ π‘π‘Ÿπ‘’π‘Žπ‘š

persistent: 𝐾𝐡, initially the atemporal β€œwumpus physics”

𝑑, a time counter, initially 0

π‘π‘™π‘Žπ‘›, an action sequence, initially empty

TELL(𝐾𝐡,𝑀𝐴𝐾𝐸_𝑃𝐸𝑅𝐢𝐸𝑃𝑇_𝑆𝐸𝑁𝑇𝐸𝑁𝐢𝐸 π‘π‘’π‘Ÿπ‘π‘’π‘π‘‘, 𝑑 )

TELL the 𝐾𝐡 the temporal β€œphysics” sentences for time 𝑑

π‘ π‘Žπ‘“π‘’ ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡,𝑂𝐾π‘₯,𝑦𝑑 = π‘‘π‘Ÿπ‘’π‘’

if 𝐴𝑆𝐾(𝐾𝐡, πΊπ‘™π‘–π‘‘π‘‘π‘’π‘Ÿπ‘‘) = π‘‘π‘Ÿπ‘’π‘’ then

π‘π‘™π‘Žπ‘› ← πΊπ‘Ÿπ‘Žπ‘ + 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 1,1 , π‘ π‘Žπ‘“π‘’ + [πΆπ‘™π‘–π‘šπ‘]

if π‘π‘™π‘Žπ‘› = {} then

𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡, 𝐿π‘₯,𝑦𝑑′ = π‘“π‘Žπ‘™π‘ π‘’ π‘“π‘œπ‘Ÿ π‘Žπ‘™π‘™ 𝑑′ ≀ 𝑑

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ∩ π‘ π‘Žπ‘“π‘’, π‘ π‘Žπ‘“π‘’)

if π‘π‘™π‘Žπ‘› = {} and 𝐴𝑆𝐾 𝐾𝐡,π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€π‘‘ = π‘‘π‘Ÿπ‘’π‘’ then

π‘π‘œπ‘ π‘ π‘–π‘π‘™π‘’_π‘€π‘’π‘šπ‘π‘’π‘  ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡,Β¬π‘Šπ‘₯,𝑦 = π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_𝑆𝐻𝑂𝑇(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, π‘π‘œπ‘ π‘ π‘–π‘π‘™π‘’_π‘€π‘’π‘šπ‘π‘’π‘ , π‘ π‘Žπ‘“π‘’)

if π‘π‘™π‘Žπ‘› = {} then

π‘›π‘œπ‘‘_π‘’π‘›π‘ π‘Žπ‘“π‘’ ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡,¬𝑂𝐾π‘₯,𝑦𝑑 = π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ∩ π‘›π‘œπ‘‘_π‘’π‘›π‘ π‘Žπ‘“π‘’, π‘ π‘Žπ‘“π‘’)

if π‘π‘™π‘Žπ‘› = {} then

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 1,1 , π‘ π‘Žπ‘“π‘’ + [πΆπ‘™π‘–π‘šπ‘]

action ← 𝑃𝑂𝑃(π‘π‘™π‘Žπ‘›)

𝑇𝐸𝐿𝐿(𝐾𝐡,𝑀𝐴𝐾𝐸_𝐴𝐢𝑇𝐼𝑂𝑁_𝑆𝐸𝑁𝑇𝐸𝑁𝐢𝐸(π‘Žπ‘π‘‘π‘–π‘œπ‘›, 𝑑))

𝑑 ← 𝑑 + 1

return π‘Žπ‘π‘‘π‘–π‘œπ‘›

Page 97: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Hybrid agent (phases listed based on priority)

97

Simple-reflex (condition-action rule):

if 𝐴𝑆𝐾(𝐾𝐡, πΊπ‘™π‘–π‘‘π‘‘π‘’π‘Ÿπ‘‘) = π‘‘π‘Ÿπ‘’π‘’ then

π‘π‘™π‘Žπ‘› ← [πΊπ‘Ÿπ‘Žπ‘] + 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 1,1 , π‘ π‘Žπ‘“π‘’ + [πΆπ‘™π‘–π‘šπ‘]

Goal-based & reasoning:

if π‘π‘™π‘Žπ‘› = {} then

𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡, 𝐿π‘₯,𝑦𝑑′ = π‘“π‘Žπ‘™π‘ π‘’ π‘“π‘œπ‘Ÿ π‘Žπ‘™π‘™ 𝑑′ ≀ 𝑑

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ∩ π‘ π‘Žπ‘“π‘’, π‘ π‘Žπ‘“π‘’)

if π‘π‘™π‘Žπ‘› = {} and 𝐴𝑆𝐾 𝐾𝐡,π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€π‘‘ = π‘‘π‘Ÿπ‘’π‘’ then

π‘π‘œπ‘ π‘ π‘–π‘π‘™π‘’_π‘€π‘’π‘šπ‘π‘’π‘  ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡,Β¬π‘Šπ‘₯,𝑦 = π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_𝑆𝐻𝑂𝑇(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, π‘π‘œπ‘ π‘ π‘–π‘π‘™π‘’_π‘€π‘’π‘šπ‘π‘’π‘ , π‘ π‘Žπ‘“π‘’)

Page 98: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Hybrid agent (phases listed based on priority)

98

Exploration & reasoning

if π‘π‘™π‘Žπ‘› = {} then

π‘›π‘œπ‘‘_π‘’π‘›π‘ π‘Žπ‘“π‘’ ← π‘₯, 𝑦 : 𝐴𝑆𝐾 𝐾𝐡,¬𝑂𝐾π‘₯,𝑦𝑑 = π‘“π‘Žπ‘™π‘ π‘’

π‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 𝑒𝑛𝑣𝑖𝑠𝑖𝑑𝑒𝑑 ∩ π‘›π‘œπ‘‘_π‘’π‘›π‘ π‘Žπ‘“π‘’, π‘ π‘Žπ‘“π‘’)

Goal-based:

if π‘π‘™π‘Žπ‘› = {} thenπ‘π‘™π‘Žπ‘› ← 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, 1,1 , π‘ π‘Žπ‘“π‘’ + [πΆπ‘™π‘–π‘šπ‘]

Page 99: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Hybrid agent: Using A* to make a plan

99

function 𝑃𝐿𝐴𝑁_π‘…π‘‚π‘ˆπ‘‡πΈ(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, π‘”π‘œπ‘Žπ‘™, π‘Žπ‘™π‘™π‘œπ‘€π‘’π‘‘) returns an action sequence

inputs: π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, the agent’s current position

π‘”π‘œπ‘Žπ‘™π‘ , a set of squares; try to plan a route to one of them

π‘Žπ‘™π‘™π‘œπ‘€π‘’π‘‘, a set of squares that can form part of the route

π‘π‘Ÿπ‘œπ‘π‘™π‘’π‘š ← π‘…π‘‚π‘ˆπ‘‡πΈ_𝑃𝑅𝑂𝐡𝐿𝐸𝑀(π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘, π‘”π‘œπ‘Žπ‘™π‘ , π‘Žπ‘™π‘™π‘œπ‘€π‘’π‘‘)return π΄βˆ—_𝐺𝑅𝐴𝑃𝐻_𝑆𝐸𝐴𝑅𝐢𝐻(π‘π‘Ÿπ‘œπ‘π‘™π‘’π‘š)

Page 100: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Logical state estimation

100

Problem: Computational time of ASK grows by the length ofthe agent’s life We must save the results of inference to use them in the next time steps

Solution: Belief state instead of the whole past history ofpercepts and actions

Belief state: the agent’s knowledge about the state of the world

(the set of all possible current states of the world)

𝐡1,2 ∧ (𝑃1,3 ∨ 𝑃2,2)

∧ 𝐿1,21 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”π‘π‘œπ‘Ÿπ‘‘β„Ž1 ∧ π»π‘Žπ‘£π‘’π΄π‘Ÿπ‘Ÿπ‘œπ‘€1 βˆ§π‘Šπ‘’π‘šπ‘π‘’π‘ π΄π‘™π‘–π‘£π‘’1

State estimation: process of updating the belief state when doingactions and receiving new percepts

Page 101: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Approximate state estimation

101

Problem: The exact belief state estimation may require logical

formulas whose size is exponential in the number of symbols.

𝑛 fluent symbols, 2𝑛 possible physical states, 22𝑛

possible belief states

Solution: approximation

e.g., 1-CNF belief state: given the belief state at 𝑑 βˆ’ 1, agent tries to

prove 𝑋𝑑 or ¬𝑋𝑑 for each 𝑋𝑑)

Approximate belief state estimation?

compact representation (open area for research)

Relation to model-based agents

Page 102: Informed search algorithmsce.sharif.edu/courses/94-95/2/ce417-1/resources/root...Propositional logic First-order logic A generic knowledge-based agent 3 function KB_AGENT ... Inference

Wumpus world

Distinct rules β€œfor each square [x,y]” and β€œfor each time t”

𝐿π‘₯,𝑦𝑑 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘π‘‘ ∧ π‘‡π‘’π‘Ÿπ‘›πΏπ‘’π‘“π‘‘π‘‘ β‡’ (𝐿π‘₯,𝑦

𝑑+1 ∧ πΉπ‘Žπ‘π‘–π‘›π‘”π‘ˆπ‘π‘‘+1 ∧ Β¬πΉπ‘Žπ‘π‘–π‘›π‘”πΈπ‘Žπ‘ π‘‘π‘‘+1)

Many rules are needed to describe the world axioms

Rather impractical for bigger world

We can not express general knowledge about β€œphysics” of the worlddirectly in propositional language

More expressive language is needed.

Qualification problem: specifying all the exceptions

Probability theory allows us to summarize all the exceptions (withoutexplicitly naming them)

Limitations of propositional logic

102


Recommended