Intelligent Systems

48
www.sti-innsbruck.at © Copyright 2008 STI INNSBRUCK www.sti- innsbruck.at Intelligent Systems Intelligent Systems Propositional Logic – Lecture 2 Prof. Dieter Fensel (& James Scicluna)

description

Intelligent Systems. Propositional Logic – Lecture 2 Prof. Dieter Fensel (& James Scicluna ). Agenda. Motivation Propositional Logic Inference by Enumeration Validity and Satisfiability Logical Equivalence Proof Methods – Resolution Soundness and Completeness Horn Clauses - PowerPoint PPT Presentation

Transcript of Intelligent Systems

Page 1: Intelligent Systems

www.sti-innsbruck.at © Copyright 2008 STI INNSBRUCK www.sti-innsbruck.at

Intelligent SystemsIntelligent Systems

Propositional Logic – Lecture 2

Prof. Dieter Fensel (& James Scicluna)

Page 2: Intelligent Systems

www.sti-innsbruck.at

Agenda

• Motivation• Propositional Logic

– Inference by Enumeration– Validity and Satisfiability– Logical Equivalence– Proof Methods – Resolution– Soundness and Completeness

• Horn Clauses– Forward Chaining– Backward Chaining

• Efficient Propositional Inference – The DPLL Algorithm• Limitations of Propositional Logic• Summary

2

Page 3: Intelligent Systems

www.sti-innsbruck.at

Motivation – Why Logics?

• Origins of Logic– Ancient Greece– Philosophers argued about themes, but who was right in the end?– When Socrates claimed that one statement followed from another, was it actually true?

• Logics today– Verification (e.g. Circuits)– Proofs– Robotics– ...others

• Logics are formal languages for representing information such that conclusions can be drawn.

– Syntax defines the sentences in the language.– Semantics define the "meaning" of sentences, i.e., defines the truth of each sentence

w.r.t. each possible world (model)

3

Page 4: Intelligent Systems

www.sti-innsbruck.at

Motivation – Basic Ideas

• Entailment means that one thing follows from anotherKB╞ α

• Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true

– E.g., the KB containing “Innsbruck is in Tirol” and “Tirol is in Austria” entails “Innsbruck is in Austria”

– E.g., the KB containing x+y = 4 entails 4 = x+y

• Entailment is a relationship between sentences (i.e., syntax) that is based on semantics

4

Page 5: Intelligent Systems

www.sti-innsbruck.at

Motivation – Models/Interpretations

• Possible worlds – environments in which the agent might or might not be in

• Models – mathematical abstractions, formally structured worlds with respect to which truth of sentences can be evaluated

• m is a model of a sentence α if α is true in m

• M(α) is the set of all models of α

• KB ╞ α iff M(KB) M(α)

• Knowledge base KB entails sentence α if and only if all models of the KB are models of α

5

Page 6: Intelligent Systems

www.sti-innsbruck.at

Motivation – Inference

• KB ├i α : sentence α can be derived from KB by procedure i, i proves α

• Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α

• Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α

• A sound and complete procedure answers any question whose answer follows from what is known by the KB correctly.

6

Page 7: Intelligent Systems

www.sti-innsbruck.at

Solution – Propositional Logic

Syntax

• Propositional logic is the simplest logic and illustrates basic ideas of logic

• The proposition symbols P1, P2,…are sentences (formulae)– If S is a sentence, S is a sentence (negation)– If S1 and S2 are sentences, S1 S2 is a sentence (conjunction)– If S1 and S2 are sentences, S1 S2 is a sentence (disjunction)– If S1 and S2 are sentences, S1 S2 is a sentence (implication)– If S1 and S2 are sentences, S1 S2 is a sentence (biconditional)

7

Page 8: Intelligent Systems

www.sti-innsbruck.at

Solution – Propositional Logic

Semantics

• Each model specifies true/false values for each proposition symbol (8 possible models)– E.g. P1,2 P2,2 P3,1

false true false

• Rules for evaluating truth with respect to an interpretation m:

S is true iff S is false S1 S2 is true iff S1 is true and S2 is trueS1 S2 is true iff S1 is true or S2 is trueS1 S2 is true iff S1 is false or S2 is trueS1 S2 is false iff S1 is true and S2 is falseS1 S2 is true iff S1S2 is true and S2S1 is true

• Simple recursive process evaluates an arbitrary sentence w.r.t. an interpretation, e.g.,

P1,2 (P2,2 P3,1) : true (true false) = true true = true

8

Page 9: Intelligent Systems

www.sti-innsbruck.at

Solution – Propositional Logic

Truth Tables

9

Page 10: Intelligent Systems

www.sti-innsbruck.at

Solution – Propositional Logic

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

10

Page 11: Intelligent Systems

www.sti-innsbruck.at

Procedure - Inference by Enumeration

• Depth-first enumeration of all models is sound and complete

– PL-TRUE evaluates a sentence recursively wrt. to an interpretation– EXTEND(s,v,m) extends the partial model m by assigning value v to symbol s.

• For n symbols, time complexity is O(2n), space complexity is O(n)

11

Page 12: Intelligent Systems

www.sti-innsbruck.at

Definition - Validity and Satisfiability

A sentence is valid if it is true in all models,e.g., True, A A, A A, (A (A B)) B

Validity is connected to inference via the Deduction Theorem:KB ╞ α if and only if (KB α) is valid

A sentence is satisfiable if it is true in some modele.g., A B, C

A sentence is unsatisfiable if it is true in no modelse.g., A A

Satisfibility is connected to inference via the following

KB ╞ α if and only if (KB α) is unsatisfiable

12

Page 13: Intelligent Systems

www.sti-innsbruck.at

Definition - Logical equivalence

• Two sentences are logically equivalent iff they are true in same models: α ≡ ß iff α╞ β and β╞ α

13

Page 14: Intelligent Systems

www.sti-innsbruck.at

Procedure - Proof Methods

• Proof methods divide into (roughly) two kinds

– Application of inference rules• Legitimate (sound) generation of new sentences from old ones• Proof = a sequence of inference rule applications• Can use inference rules as operators in a standard search algorithm• Typically requires transformation of sentences into a normal form

– Model checking• Truth table enumeration (always exponential in n)• 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

14

Page 15: Intelligent Systems

www.sti-innsbruck.at

Procedure - Resolution

Conjunctive Normal Form (CNF) conjunction of disjunctions of literals often called clauses

E.g., (A B) (B C D)

• Resolution inference rule (for CNF):li … lk, m1 … mn

li … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn

where li and mj are complementary literals.

E.g., P1,3 P2,2, P2,2

P1,3

• Resolution is sound and complete for propositional logic

15

Page 16: Intelligent Systems

www.sti-innsbruck.at

Procedure - Conversion to CNF

B1,1 (P1,2 P2,1)

1. Eliminate , replacing α β with (α β) (β α).(B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1)

2. Eliminate , replacing α β with α β.(B1,1 P1,2 P2,1) ((P1,2 P2,1) B1,1)

3. Move inwards using de Morgan's rules:(B1,1 P1,2 P2,1) ((P1,2 P2,1) B1,1)

4. Apply distributivity law ( over ) and flatten:(B1,1 P1,2 P2,1) (P1,2 B1,1) (P2,1 B1,1)

16

Page 17: Intelligent Systems

www.sti-innsbruck.at

Definition - Soundness

Whenever KB ├r α, it is also true that KB╞ α

li … lk, m1 … mn

li … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn

li and mj are complementary literals.

(li … li-1 li+1 … lk) li mj (m1 … mj-1 mj+1 ... mn)

(li … li-1 li+1 … lk) (m1 … mj-1 mj+1 ... mn)

using the rule (a b) (b a) which can be written also as (a b) ( a b).

17

Page 18: Intelligent Systems

www.sti-innsbruck.at

Definition - Completeness

• Whenever KB╞ α, it is also true that KB ├r α

• KB ╞ α if and only if (KB α) is unsatisfiable

• Ground resolution theorem– If a set of clauses is unsatisfiable, then the resolution closure of those

clauses contains the empty clause.

• Proof by contradiction– Assume KB ╞ α and that the closure does not contain the empty clause.

18

Page 19: Intelligent Systems

www.sti-innsbruck.at

Procedure - Forward and backward chaining

• Horn clauses: disjunction of literals of which at most one is positive– Important because Horn clauses can be written as an implication whose

premise is a conjuction of positive literals and whose conclusion is a single positive literal

• Definite clauses: exactly one positive literal– Positive literal forms the head– Negative literals form the body

• Inference with Horn clauses can be done by forward or backward chaining in a time that is linear in the size of the KB.

19

Page 20: Intelligent Systems

www.sti-innsbruck.at

Procedure - Forward chaining

• Fire any rule whose premises are satisfied in the KB• Add its conclusion to the KB, until query is found

20

Page 21: Intelligent Systems

www.sti-innsbruck.at

Procedure - Forward chaining algorithm

• agenda: true symbols not yet processed• count: how many premises are unknown

– for each new symbol processed, count is reduced by one for each implication in whose premise this symbol appears

• Count = 0 conclusion can be added to the agenda• Forward chaining is sound and complete for Horn KB

21

Page 22: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

22

Page 23: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

23

Page 24: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

24

Page 25: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

25

Page 26: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

26

Page 27: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

27

Page 28: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

28

Page 29: Intelligent Systems

www.sti-innsbruck.at

Example - Forward Chaining

29

Page 30: Intelligent Systems

www.sti-innsbruck.at

Procedure - Backward chaining

• Work backwards from the query q

• To prove q by BC, check if q is known already, or prove by BC all premises of some rule concluding q

• Avoid loops: check if new sub-goal is already on the goal stack

• Avoid repeated work: check if new sub-goal has already been proved true, or has already failed

31

Page 31: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

32

Page 32: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

33

Page 33: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

34

Page 34: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

35

Page 35: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

36

Page 36: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

37

Page 37: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

38

Page 38: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

39

Page 39: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

40

Page 40: Intelligent Systems

www.sti-innsbruck.at

Example – Backward Chaining

41

Page 41: Intelligent Systems

www.sti-innsbruck.at

Explanation: Forward vs. Backward chaining

• FC is data-driven, automatic, unconscious processing,– e.g., object recognition, routine decisions

• May do lots of work that is irrelevant to the goal !!!

• BC is goal-driven, appropriate for problem-solving,– e.g., Where are my keys? How do I get into a PhD program?

• Complexity of BC can be much less than linear in size of KB (only relevant facts are considered)

42

Page 42: Intelligent Systems

www.sti-innsbruck.at

Procedure: Efficient propositional inference

• Two families of efficient algorithms for propositional inference

– Complete backtracking search algorithms• DPLL algorithm (Davis, Putnam, Logemann, Loveland)

– Incomplete local search algorithms

• WalkSAT algorithm (Incomplete, local search algorithm)

43

Page 43: Intelligent Systems

www.sti-innsbruck.at

Procedure: The DPLL algorithm

Determine if an input propositional logic sentence (in CNF) is satisfiable.

Improvements over truth table enumeration1. Early termination

• A clause is true if any literal is true (disjunction of literals)• A sentence is false if any clause is false (conjunction of clauses)

2. Pure symbol heuristic• Pure symbol: always appears with the same "sign" in all clauses. • e.g., In the three clauses (A B), (B C), (C A), A and B are pure, C is

impure. • If a sentence has a model then it has a model with the pure symbols assigned so as

to make their literals true.

3. Unit clause heuristic• Unit clause: only one literal in the clause• The only literal in a unit clause must be true.

44

Page 44: Intelligent Systems

www.sti-innsbruck.at

Procedure: The DPLL algorithm

45

Page 45: Intelligent Systems

www.sti-innsbruck.at

Procedure: The DPLL algorithm

46

Page 46: Intelligent Systems

www.sti-innsbruck.at

• KB contains “physics” sentences for every single square

• For every time t and every location [x,y],

• Rapid proliferation of clauses

Limitation of propositional logic

1,1,

tyx

tttyx LForwardtFacingRighL

47

Page 47: Intelligent Systems

www.sti-innsbruck.at

Summary

• Logical agents apply inference to a knowledge base to derive new information and make decisions

• Basic concepts of logic:– syntax: formal structure of sentences– semantics: truth of sentences w.r.t. models– entailment: necessary truth of one sentence given another– inference: deriving sentences from other sentences– soundness: derivations produce only entailed sentences– completeness: derivations can produce all entailed sentences

• Resolution is complete for propositional logic• Forward, backward chaining are linear-time, complete for Horn clauses• Propositional logic lacks expressive power

48

Page 48: Intelligent Systems

www.sti-innsbruck.at

References

• S. Russell, P. Norvig: Artificial Intelligence – A Modern Approach

49