84
Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Embed Size (px)

Citation preview

Page 1: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Computer Science CPSC 502

Lecture 6

Finish Planning

Start Logic (Ch 5)

Page 2: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Lecture Overview

• Finish Planning• Logics

• Propositional, Definite Clause Logic: Syntax and Semantics Two different proof Procedures

• Reasoning with individuals and relations

2

Page 3: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Where Are We?Environment

Problem Type

Query

Planning

Deterministic Stochastic

Constraint Satisfaction Search

Arc Consistency

Search

Search

Logics

STRIPS

Vars + Constraints

Value Iteration

Variable

Elimination

Belief Nets

Decision Nets

Markov Processes

Static

Sequential

Representation

ReasoningTechnique

Variable

Elimination

First Part of the Course

Page 4: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Where Are We?Environment

Problem Type

Query

Planning

Deterministic Stochastic

Constraint Satisfaction Search

Arc Consistency

Search

Search

Logics

STRIPS

Vars + Constraints

Value Iteration

Variable

Elimination

Belief Nets

Decision Nets

Markov Processes

Static

Sequential

Representation

ReasoningTechnique

Variable

EliminationBack to static

problems, but with richer

representation

Page 5: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

5

Logics in AI: Similar slide to the one for planning

Propositional Logics

First-Order Logics

Propositional Definite Clause

Logics

Semantics and Proof Theory

Satisfiability Testing (SAT)

Description Logics

Cognitive Architectures

Video Games

Ontologies

Semantic Web

Information Extraction

Summarization

Production Systems

Tutoring Systems

Hardware Verification

Product Configuration

Software Verification

Applications

Page 6: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

6

Logics in AI: Similar slide to the one for planning

Propositional Logics

First-Order Logics

Propositional Definite Clause

Logics

Semantics and Proof Theory

Description Logics

Cognitive Architectures

Video Games

Hardware Verification

Product ConfigurationOntologies

Semantic Web

Information Extraction

Summarization

Production Systems

Tutoring Systems

Software Verification

You will know

You will know a little

Applications

Satisfiability Testing (SAT)

Page 7: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

7

What you already know about logic...• From programming: Some logical operators

• If ((amount > 0) && (amount < 1000)) || !(age < 30) • ...

Logic is the language of Mathematics. To define formal structures (e.g., sets, graphs) and to prove statements about those

You know what they mean in a “procedural” way

We use logic as a Representation and Reasoning Systemthat can be used to formalize a domain and to reason about it

Page 8: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Logic: a framework for representation & reasoning

• When we represent a domain about which we have only partial (but certain) information, we need to represent….• Objects, properties, sets, groups, actions, events, time, space, …

• All these can be represented as • Objects• Relationships between objects

• Logic is the language to express knowledge about the world this way• http://en.wikipedia.org/wiki/John_McCarthy (1927 - 2011)

Logic and AI “The Advice Taker”

Coined “Artificial Intelligence”. Dartmouth W’shop (1956)

8

Page 9: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

9

Why Logics?• “Natural” to express knowledge about the world• (more natural than a “flat” set of variables &

constraints)

• e.g. “Every 101 student will pass the course” Course (c1) Name-of (c1, 101)

• It is easy to incrementally add knowledge • It is easy to check and debug knowledge• Provides language for asking complex queries• Well understood formal properties

Page 10: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Logic: A general framework for reasoning

General problem: Query answering• tell the computer how the world works• tell the computer some facts about the world• ask a yes/no question about whether other facts must be true

Solving it with Logic1. Begin with a task domain.

2. Distinguish those things you want to talk about (the ontology)

3. Choose symbols in the computer to denote elements of your ontology

4. Tell the system knowledge about the domain

5. Ask the system whether new statements about the domain are true or false

live_w4? lit_l2?

Page 11: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

/ up

/down

Sintax: are these sentences that a reasoning procedure can process?

Sematic: what do these statements say about the world I need to represent?

Page 12: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

To Define a Logic We Need

• Syntax: specifies the symbols used, and how they can be combined to form legal sentences • Knowledge base is a set of sentences in the language

• Semantics: specifies the meaning of symbols and sentences

• Reasoning theory or proof procedure: a specification of how an answer can be produced.• Sound: only generates correct answers with respect to

the semantics

• Complete: Guaranteed to find an answer if it exists

Page 13: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite ClausesWe will start with a simple logic

• Primitive elements are propositions: Boolean variables that can be {true, false}

Two kinds of statements:• that a proposition is true• that a proposition is true if one or more other propositions are true

Why only propositions?• We can exploit the Boolean nature for efficient reasoning• Starting point for more complex logics

We need to specify: syntax, semantics, proof procedure

Page 14: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite Clauses: Syntax

Definition (atom)

An atom is a symbol starting with a lower case letter

Definition (body)

A body is an atom or is of the form b1 ∧ b2 where b1 and b2 are bodies.

Definition (definite clause)

A definite clause is

- an atom or

- a rule of the form h ← b where h is an

atom (“head”) and b is a body. (Read this as “h if b”.)

Definition (KB)

A knowledge base (KB) is a set of definite clauses

Examples: p1; live_l1

Examples: p1 ∧ p2; ok_w1 ∧ live_w0

Examples: p1 ← p2; live_w0 ← live_w1 ∧ up_s2

Page 15: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

atoms

rules

definiteclauses, KB

Do any of these statements mean anything? Syntax doesn't answer this question!

Page 16: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

PDC Syntax: more examples

a) ai_is_fun

b) ai_is_fun ∨ ai_is_boring

c) ai_is_fun ← learn_useful_techniques

d) ai_is_fun ← learn_useful_techniques ∧ notTooMuch_work

e) ai_is_fun ← learn_useful_techniques ∧ TooMuch_work

f) ai_is_fun ← f(time_spent, material_learned)

g) srtsyj ← errt gffdgdgd∧

Which of the following are legal PDC clause?

Definition (definite clause)

A definite clause is - an atom or - a rule of the form h ← b where h is an atom (‘head’) and b is a body.

(Read this as ‘h if b.’)

Page 17: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

PDC Syntax: more examples

a) ai_is_fun YES

b) ai_is_fun ∨ ai_is_boring NO

c) ai_is_fun ← learn_useful_techniques YES

d) ai_is_fun ← learn_useful_techniques ∧ notTooMuch_work YES

e) ai_is_fun ← learn_useful_techniques ∧ TooMuch_work NO

f) ai_is_fun ← f(time_spent, material_learned) NO

g) srtsyj ← errt gffdgdgd NO∧

Which of the following are legal PDC clause?

Definition (definite clause)

A definite clause is - an atom or - a rule of the form h ← b where h is an atom (‘head’) and b is a body.

(Read this as ‘h if b.’)

Page 18: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite Clauses: Semantics

• Semantics allows you to relate the symbols in the logic to the domain you're trying to model.

• If our domain has 5 atoms, how many interpretations are there?• ……. values for each atom, so ……. combinations• Similar to possible worlds in CSPs

Definition (interpretation)

An interpretation I assigns a truth value to each atom.

Page 19: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite Clauses: Semantics

Semantics allows you to relate the symbols in the logic to the domain you're trying to model.

We can use the interpretation to determine the truth value of clauses

Definition (interpretation)

An interpretation I assigns a truth value to each atom.

Definition (truth values of statements)• A body b1 ∧ b2 is true in I if and only if b1 is true in

I and b2 is true in I.• A rule h ← b is false in I if and only if b is true in I

and h is false in I.

Page 20: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

h b h ← b

I1 F F T

I2 F T F

I3 T F T

I4 T T T

PDC Semantics: Example

a1 a2 a1 ∧ a2

I1 F F F

I2 F T F

I3 T F F

I4 T T T

Truth values under different interpretations

F=false, T=true

Page 21: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

h b h ← b

I1 F F T

I2 F T F

I3 T F T

I4 T T T

PDC Semantics: Example

22

Truth values under different interpretations

F=false, T=true

h ← b is only false if b is true and h is false

h a1 a2 h ← a1 ∧ a2

I1 F F F

I2 F F T

I3 F T F

I4 F T T

I5 T F F

I6 T F T

I7 T T F

I8 T T T

Page 22: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

h b h ← b

I1 F F T

I2 F T F

I3 T F T

I4 T T T

PDC Semantics: Example for truth values

Truth values under different interpretations

F=false, T=true

h ← a1 ∧ a2

Body of the clause: a1 ∧ a2

Body is only true if both a1 and a2 are true in I

h a1 a2 h ← a1 ∧ a2

I1 F F F T

I2 F F T T

I3 F T F T

I4 F T T F

I5 T F F T

I6 T F T T

I7 T T F T

I8 T T T T

Page 23: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite Clauses: Semantics

Semantics allows you to relate the symbols in the logic to the domain you're trying to model.

We can use the interpretation to determine the truth value of clauses

Definition (interpretation)

An interpretation I assigns a truth value to each atom.

Definition (truth values of statements)• A body b1 ∧ b2 is true in I if and only if b1 is true in

I and b2 is true in I.• A rule h ← b is false in I if and only if b is true in I

and h is false in I.

• A knowledge base KB is true in I if and only if every clause in KB is true in I.

Page 24: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Propositional Definite Clauses: Semantics

Definition (model)A model of a knowledge base KB is an interpretation in

which KB is true.

Similar to CSPs: a model of a set of clauses is an interpretation that makes all of the clauses true

Definition (interpretation)

An interpretation I assigns a truth value to each atom.

Definition (truth values of statements)• A body b1 ∧ b2 is true in I if and only if b1 is true in

I and b2 is true in I.• A rule h ← b is false in I if and only if b is true in I

and h is false in I.• A knowledge base KB is true in I if and only if

every clause in KB is true in I.

Page 25: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

PDC Semantics: Knowledge Base (KB)

p q r s

I1 true true false false

prs ← q p∧

pqs ← q

pq ← r s∧

KB1 KB2KB3

Which of the three KB above are True in I1

• A knowledge base KB is true in I if and only if every clause in KB is true in I.

Page 26: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

PDC Semantics: Example for models

p ← q

KB = q

r ← s

Definition (model)A model of a knowledge base KB is an interpretation in

which every clause in KB is true.

p q r s

I1 T T T T

I2 F F F F

I3 T T F F

I4 T T T F

I5 F T F T

Which of the interpretations below are models of KB?

Page 27: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Slide 31

OK but….• …. Who cares? Where are we going with this?

• Remember what we want to do with Logic

1) Tell the system knowledge about a task domain.• This is your KB• which expresses true statements about the world

2) Ask the system whether new statements about the domain are true or false.• We want the system responses to be

– Sound: only generates correct answers with respect to the semantics– Complete: Guaranteed to find an answer if it exists

Page 28: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Slide 32

For Instance…

1) Tell the system knowledge about a task domain.

2) Ask the system whether new statements about the domain are true or false

p? r? s?

.

.

.

sr

q

qp

KB

Page 29: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Or, More Interestingly

1) Tell the system knowledge about a task domain.

2) Ask the system whether new statements about the domain are true or false

• live_w4? lit_l2?

Page 30: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Slide 34

To Obtain This We Need One More Definition

Definition (logical consequence)If KB is a set of clauses and G is a conjunction of atoms, G is a logical consequence of KB, written KB ⊧ G, if G is true in every model of KB.

• we also say that G logically follows from KB, or that KB entails G.• In other words, KB ⊧ G if there is no interpretation in which KB is true and G is false.

• when KB is TRUE, then G must be TRUE

• We want a reasoning procedure that can find all and only the logical consequences of a knowledge base

Page 31: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Example: Logical Consequences

.

.

.

sr

q

qp

KB

p q r s

I1 true true true true

I2 true true true false

I3 true true false false

I4 true true false true

I5 false true true true

I6 false true true false

I7 false true false false

I8 false true false true

I9 true false true true

I10 true false true false

I11 true false false false

I12 true false false false

….. …… ….. …… …….

Which of the following is true?

• KB ⊧ q,

• KB ⊧ p,

• KB ⊧ s,

• KB ⊧ r

Page 32: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Proof Procedure

• We want a reasoning procedure (proof procedure) that can find all and only the logical consequences of a knowledge base

• Why?

Page 33: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

User’s View of Semantics

1. Choose a task domain: intended interpretation.

2. Associate an atom with each proposition you want to represent.

3. Tell the system clauses that are true in the intended interpretation: axiomatizing the domain.

4. Ask questions about the intended interpretation.• If KB ⊧ g,

then g must be true in all models, so it is true in the intended interpretation (which is a model).

• The user can interpret the answer using their intended interpretation of the symbols.

Page 34: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Computer’s view of semantics

• The computer doesn’t have access to the intended interpretation.• All it knows is the knowledge base.

• The computer can determine if a formula is a logical consequence of KB.• If KB ⊧ g then g must be true in the intended interpretation.• Otherwise, there is a model of KB in which g is false.

This could be the intended interpretation.

The computer wouldn't know!

Page 35: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Proof Procedures• A proof procedure is a mechanically derivable demonstration that

a formula logically follows from a knowledge base.• Given a proof procedure P, KB ⊦ P g means g can be derived

from knowledge base KB with the proof procedure.

• If I tell you I have a proof procedure for PDCL• What do I need to show you in order for you to trust my

procedure?

That is sound and complete

Page 36: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Soundness and Completeness

• Completeness of proof procedure P: need to prove that

If g is true in all models of KB (KB g)⊧ then g is derived by the procedure (KB ⊦P g)

Definition (completeness)

A proof procedure P is complete if KB g implies KB ⊧ ⊦P g.

complete: every atom that logically follows from KB is derived by P

• Soundness of proof procedure P: need to prove that

Definition (soundness)

A proof procedure P is sound if KB ⊦P g implies KB g.⊧

If g can be derived by the procedure (KB ⊦P g) then g is true in all models of KB (KB g)⊧

sound: every atom derived by P follows logically from KB (i.e. is true in every model)

Page 37: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Simple Proof Procedure

problem with this approach?

• If there are n propositions in the KB, must check all the interpretations!

Goal of proof theory • find sound and complete proof procedures that allow us to

prove that a logical formula follows from a KB avoiding to do the above

Simple proof procedure S• Enumerate all interpretations• For each interpretation I, check whether it is a model of KB

i.e., check whether all clauses in KB are true in I

• KB ⊦S g if g holds in all such models

Page 38: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Lecture Overview

• Finish Planning• Logics

• Propositional, Definite Clause Logic: Syntax and Semantics Two different proof Procedures

• Reasoning with individuals and relations

43

Page 39: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Bottom-up proof procedure

• One rule of derivation, a generalized form of modus ponens:

• If “h ← b1 … bm" is a clause in the knowledge base, and each bi has been derived, then h can be derived.

• This rule also covers the case when m = 0.

Page 40: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Bottom-up proof procedure

C :={};repeat

select clause “h ← b1 ∧ … ∧ bm” in KB such that bi ∈ C for all i, and h ∉ C;

C := C ∪ { h }until no more clauses can be selected.

KB ⊦ G if G ⊆ C at the end of this procedure

Page 41: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

C := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Bottom-up proof procedure: example

a ← b c

a ← e f

b ← f k

c ← e

d ← k

e.

f ← j e

f ← c

j ← c

{}

Page 42: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

C := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Bottom-up proof procedure: example

a ← b c

a ← e f

b ← f k

c ← e

d ← k

e.

f ← j e

f ← c

j ← c

{}

{e}

{c,e}

{c,e,f}

{c,e,f,j}

{a,c,e,f,j}

Done.

Page 43: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Lecture Overview

• Recap Lecture 24

• Bottom-Up Proof Procedure

• Soundness

• Completeness

• Top-Down Proof Procedure (time permitting)

Page 44: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Soundness of bottom-up proof procedure BU

What do we need to prove to show that BU is sound ?

sound: every atom g that P derives follows logically from KB

Definition (soundness)

A proof procedure P is sound if KB ⊦P g implies KB g⊧ .

C := {};Repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C; C := C {h}until no more clauses can be selected.

Page 45: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Soundness of bottom-up proof procedure BU

What do we need to prove to show that BU is sound ?

If g C at the end of BU procedure, then g is true in all models of KB (KB g)⊧

sound: every atom g that P derives follows logically from KB

Definition (soundness)

A proof procedure P is sound if KB ⊦P g implies KB g⊧ .

C := {};repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C; C := C {h}until no more clauses can be selected.

Page 46: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Soundness of bottom-up proof procedure BU

By contradiction: Suppose there is a g such that

KB g but not KB g.⊦ ⊧

If g C at the end of BU procedure, then g is true in all models of KB (KB g)⊧

What do we need to prove to show that BU is sound ?

• Let h be the first atom added to C that is not true in every model of KB. • In particular, suppose I is a model of KB in which h isn’t true

• There must be a clause in KB of form

h b1 ... bn

where each bi is true in I.

• Because h is false in I, this clause is false in I.

• Therefore I is not a model of KB => Contradiction

Page 47: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

We define a specific model of our KB, in which• every atom in C at the end of BU is true • every other atom is false

This is called minimal model

Using this model, we’ll then show that, if KB ⊧ G, then G must be in C, that is

Completeness of BU: general idea

If g is true in all models of KB (KB ⊧ g) then g C at the end of BU procedure (KB ⊦BU g)

Page 48: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Minimal Model

The C at the end of BU procedure is a fixed point:• Further applications of our rule of derivation will not

change C!

Definition (minimal model)The minimal model MM is the interpretation in which – - every element of BU’s fixed point C is true - every other atom is false.

C := {};repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C; C := C {h}until no more clauses can be selected.

Page 49: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Minimal model MM is a model of KB

Proof by contradiction.

Assume that MM is not a model of KB. • Then there must exist some clause in KB which is false in

MMLike every clause in KB, it is of the form h ← b1 … bm

(with m 0).

• h ← b1 … bm can only be false in MM if each bi is true in MM and h is false in MM.Since each bi is true in MM, each bi must be in C as well.

BU would add h to C, so h would be true in MMContradiction! Thus, MM is a model of KB

Definition (minimal model)The minimal model MM is the interpretation in which- every element of BU’s fixed point C is true - every other atom is false.

Page 50: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Completeness of bottom-up procedure

Direct proof based on minimal model:• Suppose KB ⊧ g. Then g is true in all models of KB.• Thus g is true in the minimal model.• Thus g C at the end of BU procedure.

• Thus KB ⊦BU g. Done. KB g implies KB ⊧ ⊦BU g

If g is true in all models of KB (KB ⊧ g) then g C at the end of BU procedure (KB ⊦BU g)

Page 51: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Summary for bottom-up proof procedure BU

• BU is sound: it derives only atoms that logically follow from KB

• BU is complete:it derives all atoms that logically follow from KB

• Together: it derives exactly the atoms that logically follow from KB

• And, it is efficient!• Linear in the number of clauses in KB

Each clause is used maximally once by BU

Page 52: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Bottom-up vs. Top-down

KB

g is proved if g C

When does BU look at the query? g

Bottom-up

C

Page 53: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Bottom-up vs. Top-down

• Key Idea of top-down: search backward from a query g to determine if it can be derived from KB.

KB C

g is proven if g C

When does BU look at the query g?• Never• It derives the same C

regardless of the query

Bottom-up Top-down

TD performs a backward search starting at g

KB answer

Query G

Page 54: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

• Idea: search backward from a query to determine if it is a logical consequence of KB.

• An answer clause is of the form

yes a1 ... ai-1 ai ai+1 … am

• We express a query q1 q∧ 2 … q∧ m as an answer clause

yes ← q1 … qk

• Basic operation: SLD Resolution of an answer clause

yes a1 ... ai-1 ai ai+1 … am

on atom ai with the clause:

ai b1 ... bp

yields the clause

yes a1 ... ai-1 b1 ... bp ai+1 ... am

Top-down Proof Procedure for PDCL

Page 55: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

• Rule of derivation: the SLD Resolution of clause

yes a1 ... ai-1 ai ai+1 … am on atom ai with the clause:

ai b1 ... bp

is the answer clause

yes a1 ... ai-1 b1 ... bp ai+1 ... am

Example

yes ← b c. ∧b ← k f.∧

yes←

yes ← e f.∧e.

yes ←SLD resolution

Page 56: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Rules of derivation in top-down and bottom-up

Top-down:

SLD Resolution

yes ← c1 ci … cm ci ← b1 … bp

yes ← c1 … ci-1 b1 … bp ci+1 … cm

Bottom-up:

Generalized modus ponens

h ← b1 … bm b1 … bm

h

Page 57: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Derivations• An answer is an answer clause with m = 0.

yes .

• A successful derivation from KB of query

? q1 ... qk

is a sequence of answer clauses 0, 1 , .., n such that

0 is the answer clause yes q1 ... qk.

i is obtained by resolving i-1with a clause in KB, and

n is an answer. yes .

• An unsuccessful derivation from KB of query ? q1 ... qk

We get to something like yes b1 ... bk.

There is no clause in KB with any of the bi as its head

Page 58: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

To solve the query ? q1 ... qk :

ac:= yes body, where body is q1 ... qk

repeat

select qi body;

choose clause C KB, C is qi bc;

replace qi in body by bc

until ac is an answer (fail if no clause with qi as head)

select: any choice will work

(“don’t care” non-determinism)

choose: non-deterministic, have to pick the right one

(“don’t know” non-determinism)

Top-down Proof Procedure for PDCL

Page 59: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

4: yes e3: yes c

1: yes e f

5: yes

Example: successful derivation

0: yes a

2: yes e c

1

2

435

a b c. a e f. b f k.

c e. d k e.

f j e. f c. j c.

Query: ?a

Done. The question was “Can we derive a?”

The answer is “Yes, we can”

Page 60: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

a b c. a e f. b f k.

c e. d k e.

f j e. f c. j c.

Query: ?a

Example: failing derivation

4: yes e k c3: yes c k c

1: yes b c

5: yes k c

0: yes a

2: yes f k c

6: yes k e7: yes k

1 2

3

4 5

There is no rule with k as its head, thus … fail

6 7

Page 61: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Sound and Complete?

• When you have derived an answer, you can read a bottom up proof in the opposite direction.

• Every top-down derivation corresponds to a bottom up proof and every bottom up proof has a top-down derivation.

• This equivalence can be used to prove the soundness and completeness of the derivation procedure.

Do it as an exercise!

Page 62: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

SLD resolution as search

• SLD resolution can be seen as a search

• from a query stated as an answer clause

• to an answer

• Through the space of all possible answer clauses

Page 63: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

• Constraint Satisfaction (Problems):• State: assignments of values to a subset of the variables• Successor function: assign values to a “free” variable• Goal test: set of constraints• Solution: possible world that satisfies the constraints• Heuristic function: none (all solutions at the same distance from start)

• Planning : • State: full assignment of values to features• Successor function: states reachable by applying valid actions• Goal test: partial assignment of values to features• Solution: a sequence of actions• Heuristic function: relaxed problem! E.g. “ignore delete lists”

• Query (Top-down/SLD resolution)• State: answer clause of the form yes a1 ... ak

• Successor function: all states resulting from substituting firstatom a1 with b1 … bm if there is a clause a1 ← b1 … bm

• Goal test: is the answer clause empty (i.e. yes ) ?• Solution: the proof, i.e. the sequence of SLD resolutions• Heuristic function: ?????

Inference as Standard Search

Page 64: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Search Graph

Prove: ?← a ∧ d.

a ← b c. ∧ a ← g.a ← h. b ← j.b ← k. d ← m.d ← p. f ← m. f ← p. g ← m.g ← f. k ← m. h ←m. p.

KB

Why is this a dead end in the search space?

Because m cannot be resolved. The successor function is defined as resolving the first atom in the body of the answer clause

Page 65: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Search Graph

Possible Heuristic?

Admissible?

Prove: ?← a ∧ d.

a ← b c. ∧ a ← g.a ← h. b ← j.b ← k. d ← m.d ← p. f ← m. f ← p. g ← m.g ← f. k ← m. h ←m. p.

KB

Page 66: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Lecture Overview

• Finish Planning• Logics

• Propositional, Definite Clause Logic: Syntax and Semantics Two different proof Procedures

• Reasoning with individuals and relations

73

Page 67: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Representation and Reasoning in complex domains

• Expressing knowledge with propositions can be quite limiting

up_s2 up_s3

ok_cb1

ok_cb2

live_w1

connected_w1_w2

up( s2 ) up( s3 ) ok( cb1 ) ok( cb2 ) live( w1)connected( w1 , w2 )

• What we need is a more natural way to consider individuals and their properties

E.g. there is no notion that Now there is a notion that

up_s1 and up_s1 are about the same property

w1 is the same in live_w1

and in connected_w1_w2

w1 is the same in live(w1)and in connected(w1, w2)

up is the same in up(s1)and up(s3)

Page 68: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog

• An extension of propositional definite clause (PDC) logic• We now have variables• We now have relationships between variables• We can express knowledge that holds for a set of individuals, writing

more powerful clauses by introducing variables, such as:

• We can ask generic queries, E.g. “which wires are connected to w1?“

live(W) wire(W) ∧ connected_to(W,W1) ∧ wire(W1) ∧ live(W1).

? connected_to(W, w1)

Page 69: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog: a relational rule language

A variable is a symbol starting with an upper case letter

A constant is a symbol starting with lower-case letter or a sequence of digits.

A predicate symbol is a symbol starting with a lower-case letter.

A term is either a variable or a constant.

Datalog expands the syntax of PDCL….

Examples: X, Y

Examples: alan, w1

Examples: live, connected, part-of, in

Examples: X, Y, alan, w1

Page 70: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog Syntax (cont’d)An atom is a symbol of the form p or p(t1 …. tn) where p is a predicate

symbol and ti are terms

A definite clause is either an atom (a fact) or of the form:

h ← b1 … ∧ ∧ bm

where h and the bi are atoms (Read this as ``h if b.'')

A knowledge base is a set of definite clauses

Examples: sunny, in(alan,X)

Example: in(X,Z) ← in(X,Y) part-of(Y,Z) ∧

Page 71: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Summary of Datalog Syntax

Definite Clause

atomic

p p(t1,….tn)

a <- b1 ^…^ bn

where a and b1.. bn are atoms

Datalog Expression

Term Query: ?body

constant variable

Page 72: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

DataLog Sematics• Role of semantics is still to connect symbols and sentences in the

language with the target domain. Main difference:• need to create correspondence both between terms and

individuals, as well as between predicate symbols and relations

We won’t cover the formal definition of Datalog semantics, but if you are interested see 12.3.1 and 12.3.2 in textbook

Page 73: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog: Top Down Proof Procedure

• Extension of Top-Down procedure for PDCL. How do we deal with variables?• Idea:

- Find a clause with head that matches the query- Substitute variables in the clause with their matching constants

• Example:

• We will not cover the formal details of this process, called unification. See textbook Section 12.4.2, p. 511 for the details.

in(alan, r123).

part_of(r123,cs_building).

in(X,Y) part_of(Z,Y) & in(X,Z).

Query: yes in(alan, cs_building).

yes part_of(Z,cs_building), in(alan, Z).

in(X,Y) part_of(Z,Y) & in(X,Z).with Y = cs_building X = alan

Page 74: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Example proof of a Datalog queryin(alan, r123).

part_of(r123,cs_building).

in(X,Y) part_of(Z,Y) & in(X,Z).

Query: yes in(alan, cs_building).

yes part_of(Z,cs_building), in(alan, Z).

yes in(alan, r123).

yes part_of(Z, r123), in(alan, Z).

yes .

Using clause: in(X,Y) part_of(Z,Y) & in(X,Z), with Y = cs_building X = alan

Using clause: part_of(r123,cs_building) with Z = r123

Using clause: in(alan, r123).

Using clause: in(X,Y) part_of(Z,Y) & in(X,Z). With X = alan Y = r123

fail

No clause with matching head: part_of(Z,r123).

Page 75: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Tracing Datalog proofs in AIspace

• You can trace the example from the last slide in the AIspace Deduction Applet at http://aispace.org/deduction/ using file in-part-of available in course schedule

Page 76: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog: queries with variables

What would the answer(s) be?

Query: in(alan, X1).

in(alan, r123).

part_of(r123,cs_building).

in(X,Y) part_of(Z,Y) & in(X,Z).

yes(X1) in(alan, X1).

Page 77: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Datalog: queries with variables

What would the answer(s) be?

yes(r123).

yes(cs_building).

Query: in(alan, X1).

in(alan, r123).

part_of(r123,cs_building).

in(X,Y) part_of(Z,Y) & in(X,Z).

yes(X1) in(alan, X1).

Again, you can trace the SLD derivation for this query in the AIspace Deduction Applet, using file http://cs.ubc.ca/~mack/CS322/in-part-of.pl

Page 78: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Logics: Big picture

• We only covered rather simple logics• There are much more powerful representation and reasoning

systems based on logics e.g. full first order logic (with negation, disjunction and function

symbols)second-order logics (predicates over predicates)non-monotonic logics, modal logics, …

• There are many important applications of logic• For example, software agents roaming the web on our behalf

Based on a more structured representation: the semantic webThis is just one example for how logics are used

Page 79: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Slide 86

Logics: Big Picture

Propositional Logics

First-Order Logics

Propositional Definite Clause

Logics

Semantics and Proof Theory

Satisfiability Testing (SAT)

Description Logics

Cognitive Architectures

Video Games

Hardware Verification

Product ConfigurationOntologies

Semantic Web

Information Extraction

Summarization

Production Systems

Tutoring Systems

Page 80: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Learning Goals For Logic

• PDCL syntax & semantics

- Verify whether a logical statement belongs to the language of propositional definite clauses

- Verify whether an interpretation is a model of a PDCL KB.

- Verify when a conjunction of atoms is a logical consequence of a KB• Bottom-up proof procedure

- Define/read/write/trace/debug the Bottom Up (BU) proof procedure

- Prove that the BU proof procedure is sound and complete • Top-down proof procedure

- Define/read/write/trace/debug the Top-down (SLD) proof procedure

- Define it as a search problem• Datalog

- Represent simple domains in Datalog

- Apply the Top-down proof procedure in Datalog

Page 81: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Semantic Web: Extracting data

• Examples for typical queries• How much is a typical flight to Mexico for a given date?• What’s the cheapest vacation package to some place in the

Caribbean in a given week?Plus, the hotel should have a white sandy beach and scuba diving

• If webpages are based on basic HTML• Humans need to scout for the information and integrate it• Computers are not reliable enough (yet?)

Natural language processing (NLP) can be powerful (see Watson and Siri!)

But some information may be in pictures (beach), or implicit in the text, so existing NLP techniques still don’t get all the info.

Page 82: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

More structured representation: the Semantic Web

• Beyond HTML pages only made for humans• Languages and formalisms based on description logics that allow

websites to include rich, explicit information on • relevant concepts, individual and their relationships \• Goal: software agents that can roam the web and carry out sophisticated tasks

on our behalf, based on these richer representations

• Different than searching content for keywords and popularity. • Infer meaning from content based on metadata and assertions that have

already been made.

• Automatically classify and integrate information

• For further material, P&M text, Chapter 13. Also• the Introduction to the Semantic Web tutorial given at 2011 Semantic

TechnologyConference http://www.w3.org/People/Ivan/CorePresentations/SWTutorial/

89

Page 83: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

Examples of ontologies for the Semantic Web“Ontology”: logic-based representation of the world• eClassOwl: eBusiness ontology

• for products and services• 75,000 classes (types of individuals) and 5,500 properties

• National Cancer Institute’s ontology: 58,000 classes• Open Biomedical Ontologies Foundry: several ontologies

• including the Gene Ontology to describegene and gene product attributes in any organism or protein sequence

• OpenCyc project: a 150,000-concept ontology including• Top-level ontology

describes general concepts such as numbers, time, space, etc• Hierarchical composition: superclasses and subclasses• Many specific concepts such as “OLED display”, “iPhone”

Page 84: Computer Science CPSC 502 Lecture 6 Finish Planning Start Logic (Ch 5)

A different example of applications of logic

Cognitive Tutors (http://pact.cs.cmu.edu/)

• computer tutors for a variety of domains (math, geometry, programming, etc.)• Provide individualized support to problem solving

exercises, as good human tutors do

• Rely on logic-based, detailed computational models of skills and misconceptions underlying a learning domain.

• CanergieLearning (http://www.carnegielearning.com/ ): • a company that commercializes these tutors, sold to

hundreds of thousands of high schools in the USA