51
Knowledge-Based Agents Knowledge-based agents are best understood as agents that know about their world and reason about their courses of action. Basic concepts: The knowledge-base (KB): a set of representations of facts about the world. The knowledge representation language: a language whose sentences represent facts about the world.

Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Knowledge-Based Agents

Knowledge-based agents are best understood as agents thatknow about their world and reason about their courses of action.

Basic concepts:

• The knowledge-base (KB): a set of representations of factsabout the world.

• The knowledge representation language: a languagewhose sentences represent facts about the world.

Page 2: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Knowledge-Based Agents (cont’d)

• TELL and ASK interface: operations for adding newsentences to the KB and querying what is known. This issimilar to updating and querying in databases.

• The inference mechanism: a mechanism for determiningwhat follows from what has been TELLed to the knowledgebase. The ASK operation utilizes this inference mechanism.

Page 3: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

A Generic Knowledge-based Agent

function KB-Agent(percept) returns an action

static KB, a knowledge-baset, a counter, initially 0, indicating time

Tell(KB,Make-Percept-Sentence(percept, t))action ← Ask(KB,Make-Action-Query(t))Tell(KB,Make-Action-Sentence(action, t))t ← t + 1return action

Page 4: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Knowledge-based Agents (cont’d)

We can describe a knowledge-based agent at three levels:

• The knowledge level: In this level the agent is specified bysaying what it knows about the world and what its goals are.

• The logical level: This is the level at which the knowledge isencoded into sentences of some logical language.

• The implementation level: This is the level where sentencesare implemented. This level runs on the agent architecture.

Note: Declarative vs. procedural way of system building

Page 5: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Knowledge-based Agents (cont’d)

Example:

• Knowledge level or epistemological level:

The automated taxi driver knows that Golden Gate Bridgelinks San Francisco and Marin County.

• Logical level:

The automated taxi driver has the FOL sentenceLinks(GGBridge, SF,Marin) in its KB.

• Implementation level:

The sentence Links(GGBridge, SF,Marin) is implemented bya C structure (or a Prolog fact).

Page 6: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Knowledge-Based Agents (cont’d)

We can build a knowledge-based agent by TELLing it what itneeds to know before it starts perceiving the world.

We can also design learning mechanisms that output generalknowledge about the environment given a series of percepts.

Autonomous agent=Knowledge-based agent + Learning mechanism

Page 7: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

The Wumpus World (WW)

Breeze Breeze

Breeze

BreezeBreeze

Stench

Stench

BreezePIT

PIT

PIT

1 2 3 4

1

2

3

4

START

Gold

Stench

Page 8: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

The WW (cont’d)

• Environment: 4x4 grid of rooms with agent, wumpus, goldand pits.

• Actuators: The agent can move forward, turn left or turnright. The agent dies if it enters a room with a pit or a livewumpus.

The agent has action Grab and Shoot (one arrow only) at itsdisposal.

• Sensors: The percept is a list of 5 symbols:

(Stench, Breeze, Glitter, Bump, Scream)

Any of the above values can be None.

Page 9: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Reasoning and Acting in the WW

ABG

PS

W

= Agent = Breeze = Glitter, Gold

= Pit = Stench

= Wumpus

OK = Safe square

V = Visited

A

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

OKOKB

P?

P?A

OK OK

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

V

(a) (b)

Page 10: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Reasoning and Acting in the WW (cont’d)

BB P!

A

OK OK

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

V

OK

W!

VP!

A

OK OK

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

V

S

OK

W!

V

V V

BS G

P?

P?

(b)(a)

S

ABG

PS

W

= Agent = Breeze = Glitter, Gold

= Pit = Stench

= Wumpus

OK = Safe square

V = Visited

Page 11: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Reasoning and Acting in the WW (cont’d)

What do we need?

• A way to learn facts about the world.

• A way to represent facts and rules about the world.

• A way to reason with the existing facts in order to deducenew ones.

Examples of facts:

• The wumpus is in square [1,3].

• There is no pit in square [2,2].

• There is a pit in square [2,2] or square [3,1].

Page 12: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

KR languages: Syntax and Semantics

A KR language is defined by specifying its syntax and semantics.

The syntax of a KR language specifies the well-formed formulasand sentences.

The semantics of a KR language defines a correspondencebetween formulas/sentences of the language and facts in the worldto which these formulas/sentences refer.

A sentence of a KR language does not mean anything by itself.The semantics or meaning of a sentence must be provided by itswriter by means of an interpretation.

Page 13: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Truth and Entailment

Truth. A sentence will be called true under a particularinterpretation if the state of affairs it represents is the case.

Entailment. We will write KB |= α to denote that whenever thesentences of KB are true, then the sentence α is also true. In thiscase we will say that the sentences of KB entail the sentence α.

Given a knowledge-base KB and a sentence α, how do we designan algorithm that verifies whether KB |= α?

Page 14: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Entailment (cont’d)

Follows

Sentences

Facts

Sentence

Fact

Entails

Se

ma

ntic

s

Se

ma

ntic

s

Representation

World

Page 15: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Inference, proof and proof-theory

Inference is the process of mechanically deriving sentencesentailed by a knowledge-base. If sentence α is derived from KB

using inference mechanism i then we will write KB `i α.

An inference mechanism is called sound if it derives only sentencesthat are entailed.

An inference mechanism is called complete if it derives all thesentences that are entailed.

The steps used to derive a sentence α from a set of sentences KB iscalled a proof.

A proof theory is a set of rules for deriving the entailments of aset of sentences.

Page 16: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Logic

The KR languages we will consider will be based on propositionallogic and first-order logic.

Thus, the knowledge-based agents we will design can also be calledlogical agents.

In general, a logic is a formal system consisting of:

• Syntax

• Semantics

• Proof theory

Question: Why do we use logical languages for KR? Why don’twe use natural language or programming languages?

Page 17: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Propositional Logic (PL): Syntax

The symbols of PL are:

• A countably infinite set of proposition symbols P1, P2, . . ..This set will be denoted by P.

• The logical connectives ¬,∧,∨,⇒ and ⇔.

• Parentheses: (, ).

Note: Logicians usually introduce only the connectives ¬ and ∨and define the rest in terms of them.

Page 18: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Syntax (cont’d)

The following context-free grammar defines the well-formedsentences of propositional logic.

Sentence → AtomicSentence | ComplexSentence

AtomicSentence → True | False | Symbol

Symbol → P1 | P2 | · · ·ComplexSentence → (Sentence) | ¬Sentence

| Sentence BinaryConnective Sentence

BinaryConnective → ∧| ∨ | ⇒ | ⇔Precedence: ¬,∧,∨,⇒ and ⇔.

Page 19: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Semantics

A proposition symbol can mean anything we want. Itsinterpretation can be any arbitrary fact. This fact will be eithertrue or false in the world. This is not the same in other logics (e.g.,fuzzy logic!).

This is formalized by introducing the notion of interpretation.

Definition. Let P be the set of proposition symbols. Aninterpretation for P is a mapping

I : P → {true, false}.

Page 20: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Semantics (cont’d)

The notion of interpretation can be extended to arbitrarywell-formed sentences of PL using the following recursivedefinitions:

• I(True) = true.

• I(False) = false.

• I(¬φ) = true if I(φ) = false; otherwise it is false.

• I(φ1 ∧ φ2) = true if I(φ1) = true and I(φ2) = true; otherwiseit is false.

• I(φ1 ∨ φ2) = true if I(φ1) = true or I(φ2) = true; otherwise itis false.

Page 21: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Semantics (cont’d)

• I(φ1 ⇒ φ2) = true if I(φ1) = false or I(φ2) = true; otherwiseit is false.

Explanation: If φ1 and φ2 are both true then most peoplewould agree that φ1 ⇒ φ2 (φ1 implies φ2) should be true.

Example: For all integers, if x is even then x + 2 is even. If wetake x to be 6 then this says: “If 6 is even then 6+2 is even”.

But what about cases where the truth value of φ1 is false?

Example: If we take x to be 7 then the above formula says:“If 7 is even then 7+2 is even”. Is this sentence true or false?This is an instance of a “false implies false” implication.

Page 22: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Semantics (cont’d)

We will take the above sentence to be true although some of usmight find it disconcerting. It would be wrong to take it to be falsegiven that the more general sentence of which it is an instance istrue.

We have similar difficulties for “false implying true”.

Example: If 1+1=3 then Athens is the capital of Greece.

The case “true implying false” is easier: most people wouldaccept such an implication to be false.

Thus we have taken “implication” to have the semantics ofmaterial implication.

Page 23: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL: Semantics (cont’d)

• I(φ1 ⇔ φ2) = true if I(φ1) = I(φ2); otherwise it is false.

Page 24: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Compositionality of PL

A language is called compositional when the meaning of asentence is a function of the meaning of the parts.

Compositionality is a desirable property in formal languages.

Page 25: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

The Ontological Commitments of PL

Ontological commitments have to do with the nature of reality.

PL assumes that the world consists of facts that either holdor not hold.

Other logics, for example FOL, make more elaborate and detailedontological commitments.

Page 26: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Satisfaction and Models

Definition. Let φ be a PL sentence. If I is an interpretation suchthat I(φ) = true then we say that I satisfies φ or I is a model ofφ.

Page 27: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Satisfiability

Definition. A sentence φ of PL is satisfiable if there is aninterpretation I such that I(φ) = true.

Examples: P, P ∨Q, (P ∧R) ∨Q

Definition. A sentence φ of PL is unsatisfiable if there is nointerpretation I such that I(φ) = true.

Example: P ∧ ¬P

Page 28: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Validity

Definition. A sentence φ of PL is valid if for all interpretationsI, I(φ) = true.

Examples: P ∨ ¬P , ((P ∨H) ∧ ¬H) ⇒ P

Valid statements in PL are also called tautologies.

Theorem. Let φ be a sentence of PL. If φ is unsatisfiable then itsnegation ¬φ is valid. Proof?

Page 29: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Entailment

Definition. Let φ and ψ be sentences of PL. We will say that φ

entails ψ or φ logically implies ψ (denoted by φ |= ψ) if for allinterpretations I such that I(φ) = true then I(ψ) = true.

Example: P ∧Q |= P

The deduction theorem. Let φ and ψ be sentences of PL.Then φ |= ψ iff φ ⇒ ψ is valid. Proof?

Example: (P ∧Q) ⇒ P is a valid sentence.

Page 30: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Entailment and Unsatisfiability

Theorem. Let φ and ψ be sentences of PL. Then φ |= ψ iffφ ∧ ¬ψ is unsatisfiable. Proof?

Example: P ∧Q |= P

The above theorem is the essence of proofs by contradiction orrefutation.

Page 31: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Equivalence

Definition. Let φ and ψ be sentences of PL. We will say that φ

is equivalent to ψ (denoted by φ ≡ ψ) if φ |= ψ and ψ |= φ.

Example: ¬(P ∧ ¬Q) ≡ ¬P ∨Q

Page 32: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Some Useful Equivalences

• (α ∧ β) ≡ (β ∧ α) commutativity of ∧• (α ∨ β) ≡ (β ∨ α) commutativity of ∨• ((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧• ((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ)) associativity of ∨• ¬(¬α) ≡ α double-negation elimination

• (α ⇒ β) ≡ (¬β ⇒ ¬α) contraposition

Page 33: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Some Useful Equivalences (cont’d)

• (α ⇒ β) ≡ (¬α ∨ β) implication elimination

• (α ⇔ β) ≡ ((α ⇒ β) ∧ (β ⇒ α)) biconditional elimination

• ¬(α ∧ β) ≡ (¬α ∨ ¬β) de Morgan law

• ¬(α ∨ β) ≡ (¬α ∧ ¬β) de Morgan law

• (α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distribution of ∧ over ∨• (α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distribution of ∨ over ∧

Page 34: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Truth Tables

Truth tables are tools that allow us to find the truth value of aPL formula if we know the truth value of its constituent parts.

A ¬A

true false

false true

A B A ∧B A ∨B A ⇒ B A ⇔ B

false false false false true true

false true false true true false

true false false true false false

true true true true true true

Page 35: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Truth Tables

Why are truth tables useful?

Truth tables can be used for showing the truth or falsity of anyPL sentence in a given interpretation.

Similarly, truth tables can be used for showing the satisfiabilityor validity of any PL sentence.

Page 36: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Truth tables (cont’d)

Example: A truth table for showing the validity of sentence((P ∨H) ∧ ¬H) ⇒ P .

P H P ∨H (P ∨H) ∧ ¬H ((P ∨H) ∧ ¬H)

⇒ P

false false false false true

false true true false true

true false true true true

true true true false true

Page 37: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

PL Satisfiability as a CSP

The satisfiability problem for PL is fundamental. The entailmentand validity problems can be rephrased as satisfiability problems.

Notice that the satisfiability problem for PL can be phrased as aCSP. What are the variables, values and constraints?

Page 38: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Complexity of PL Satisfiability and Validity

Theorem. The problem of determining whether a sentence of PLis satisfiable is NP-complete (Cook, 1971).

Corollary. The problem of determining whether a sentence of PLis valid is co-NP-complete.

The above results mean that it is highly unlikely that we will everfind a polynomial time algorithm for these problems.

Page 39: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Horn Sentences

Definition. A PL sentence will be called Horn if it is in one of thefollowing forms:

Q

P1 ∧ P2 ∧ . . . ∧ Pn ⇒ Q or equivalently ¬P1 ∨ ¬P2 ∨ . . . ∨ ¬Pn ∨Q

¬P1 ∨ ¬P2 ∨ . . . ∨ ¬Pn

Theorem. If φ is a conjunction of Horn sentences then the satisfiability ofφ can be decided in polynomial time.

Page 40: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Inference

Let KB be a set of PL sentences and φ a PL sentence. How can wedecide whether KB |= φ?

Use truth tables! (either explicitly or by writing an appropriatealgorithm)

Computational complexity: O(2n) where n is the number ofpropositional symbols in KB and φ.

Page 41: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Example

A truth table showing that { P ∨H, ¬H } |= P .

P H P ∨H ¬H P

false false false true false

false true true false false

true false true true true

true true true false true

Method: Go through all the lines of the truth table that makeeach sentence of KB true, and check whether they make φ true too.

Page 42: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Proof Theory: Inference Rules for PL

An inference rule is a rule of the formα1, α2, . . . , αn

β

where α1, α2, . . . , αn are sentences called conditions and β is asentence called conclusion.

Whenever we have a set of sentences that match the conditions ofan inference rule then we can conclude the sentence in theconclusion.

Page 43: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Inference Rules for PL (cont’d)

• Modus Ponens: α⇒β, αβ

• And-Elimination: α1∧α2∧...∧αn

αi

• And-Introduction: α1,α2,...,αn

α1∧α2∧...∧αn

• Or-Introduction: αi

α1∨α2∨...∨αn

• Double-Negation Elimination: ¬¬αα

• Unit Resolution: α∨β, ¬βα

• Resolution: α∨β, ¬β∨γα∨γ

Page 44: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Why Is Inference Important?

Wo

rld

input sentences

conclusions

User

?

Page 45: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Formalizing the WW in PL

ABG

PS

W

= Agent = Breeze = Glitter, Gold

= Pit = Stench

= Wumpus

OK = Safe square

V = Visited

A

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

OKOKB

P?

P?A

OK OK

OK

1,1 2,1 3,1 4,1

1,2 2,2 3,2 4,2

1,3 2,3 3,3 4,3

1,4 2,4 3,4 4,4

V

(a) (b)

Page 46: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Formalizing the WW in PL (cont’d)

The WW knowledge base for Figure (a):

• There is no pit in [1, 1] (agent percept):

R1 : ¬P11

• A square is breezy if and only if there is a pit in a neighboringsquare. (Rule of the WW). We state this for the square B11 only:

R2 : B11 ⇔ P12 ∨ P21

• There is no breeze in square [1, 1]. (agent percept)

R3 : ¬B11

Page 47: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Inference in the WW

The agent can now use the PL inference rules and logicalequivalences to prove the following: “There is no pit in squares[1, 2] or [1, 2] ”

• Apply biconditional elimination to R2:

R4 : (B11 ⇒ (P12 ∨ P21)) ∧ ((P12 ∨ P21) ⇒ B11)

• Apply And-elimination to R4:

R5 : (P12 ∨ P21) ⇒ B11

• Apply logical equivalence for contrapositives to R5:

R6 : ¬B11 ⇒ ¬(P12 ∨ P21)

Page 48: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Inference in the WW (cont’d)

• Apply modus ponens to R6 and R3:

R7 : ¬(P12 ∨ P21)

• Apply de Morgan’s rule to R7:

R8 : ¬P12 ∧ ¬P21

Page 49: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Formalizing the WW in PL (cont’d)

Consider now the following WW rule:

If a square has no smell, then neither the square nor any ofits adjacent squares can house a Wumpus.

How can we formalize this rule in PL?

We have to write one rule for every relevant square! Forexample:

¬S11 ⇒ ¬W11 ∧ ¬W12 ∧W21

This is a very disappointing feature of PL. There is no way inPL to make a statement referring to all objects of somekind (e.g., to all squares).

Not to worry: this can be done in first order logic!

Page 50: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

A knowledge-based agent using PL

function Propositional-KB-Agent(percept) returns an action

static KB, a knowledge-baset, a counter, initially 0, indicating time

Tell(KB,Make-Percept-Sentence(percept, t))for each action in the list of possible actions do

if Ask(KB,Make-Action-Query(t, action)) thenTell(KB,Make-Action-Sentence(action, t))t ← t + 1return action

end

Page 51: Knowledge-Based Agentscgi.di.uoa.gr/~ys02/siteAI2008/propositional1spp.pdf · 2007-11-27 · Knowledge-based Agents (cont’d) We can describe a knowledge-based agent at three levels:

Teqnht  NohmosÔnh M. Koumpar�khc'

&

$

%

Readings

Chapter 7 of AIMA: Logical Agents (Sections 7.1 to 7.5 and 7.7)

We did not cover all the material in Section 7.5 in great detail (e.g.,resolution) because these techniques will be revisited in the moregeneral framework of FOL in the forthcoming lectures.