1 problem solving cs 331 dr m m awais representational methods formal methods propositional logic...

36
CS 331 Dr M M Awais 1 roblem Solving Representational Methods Formal Methods • Propositional Logic • Predicate Logic

Post on 19-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 1

Problem Solving

Representational Methods

Formal Methods

• Propositional Logic

• Predicate Logic

Page 2: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 2

Problem Solving

Propositional Logic

• Represent FACTS only• Is declarative in nature• Can infer the truth value of fact only• Context free• Compositional: Can combine facts

Page 3: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 3

Problem Solving

Propositional Logic

• Symbols P,Q,R,S ……..• Truth Symbols True (T), False (F)• Connectives

^ (and), v (or), (Implication), (Equality, equivalence) (not)

Statements (Propositions) could be true/falseFACTS are also called Atomic Proposition

Page 4: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 4

Problem Solving

Truth TableP Q P Q P v Q P Q

T T F F T T

T F F T F F

F T T F T T

F F T T T T

Are same

Page 5: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 5

Problem Solving

Possible Sentences (Well Formed Formulas-WFF)

• P ^ Q Conjuncts

• P v Q Disjuncts

• P Q P=Premise/Antecedent

Q=conclusion/Consequent P

• (P v Q) = ( P Q) Inter conversion

Page 6: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 6

Problem Solving

Propositional logic: Syntax

• Propositional logic is the simplest logic – illustrates basic ideas

• The proposition symbols P1, P2 etc are sentences

– 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)

Page 7: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 7

Problem Solving

Propositional logic: SemanticsEach model specifies true/false for each proposition symbol

E.g. P1,2 P2,2 P3,1

false true false

With these symbols, 8 possible models, can be enumerated automatically.Rules for evaluating truth with respect to a model m:

S is true iff S is false S1 S2 is true iff S1 is true and S2 is trueS1 S2 is true iff S1is true or S2 is trueS1 S2 is true iff S1 is false or S2 is true i.e., 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, e.g.,

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

Page 8: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 8

Problem Solving

Laws of Propositional Expressions

• Demorgan’s Law (P v Q)=( P ^ Q)

• Distributive Law P v (Q ^ R) = (P v Q) ^ (P v R)

• Commutative Law P ^ Q= Q ^ P

• Associative Law (P ^ Q) ^ R=P ^ (Q ^ R)

• Contrapositive Law P Q= Q P

Page 9: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 9

Problem Solving

Inferencing

• If simple facts are known to be true one can find the truth value for the expressions

• Thus INTERPRETATIONS can be done.

• Interpretation is the assignment of truth values to the sentences

Symbols T/F

Mapping

Page 10: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 10

Problem Solving

Expressions for KR

• Fact 1: Ali likes cars P

• Fact 2: Ali drives cars Q

• P v Q : Ali likes cars or drives cars

• P ^ Q : Ali likes cars and drives cars Q : Ali does not like cars

• P Q: If Ali likes cars then he drives cars

• P Q: ?????– Above and vice versa

Page 11: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 11

Problem Solving

Implicative Statements

• P Q: If Ali likes cars then he drives cars

• If P is FALSE and Q is TRUE, it means:

• ALI DOESNOT LIKE CARS BUT STILL HE DRIVES THEM

• Truth Table:

P Q P Q

T T T

F F T (of our interest)

T F F

F T T (bizarre)

Page 12: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 12

Problem Solving

Model

• Model:If a sentence “S” is satisfied under a given interpretation “I” for all possible variables bindings (values) then I is a model of S

• Satisfy: If S maps to T (true) under an interpretation I then I satisfy S (interpretation that makes the sentence true)

Page 13: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 13

Problem Solving

Definitions

• Logically Follows: X logically follows from a set of predicate calculus expressions S if every interpretation that satisfy S also satisfy X (X F S)

• Satisfiable: S is satisfiable iff there exists an interpretation and variable assignments that satisfy it

Page 14: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 14

Problem Solving

S F XS: All birds fly

S: Sparrow is bird

X: Sparrow fliesAll humans are mortal

Shahid is a human

Shahid is mortal

All students at LUMS are hardworking

Farooq is a student at LUMS

Farooq is a hard working student

Page 15: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 15

Problem Solving

Definitions• Inconsistent: If a set of expressions are not satisfiable

• Valid: If any expression has a value T for all possible interpertations

• Sound: If an expression logically follows from another expression then the inferential rule is sound

• Complete: When inferential rule produces every expression that logically follows a particular expression

Page 16: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 16

Problem Solving

Logic in general

• 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., define truth of a sentence in a world

Page 17: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 17

Problem Solving

Validity and satisfiability

VALIDA sentence is valid if it is true in all models,

e.g., True, A A, A A, (A (A B)) B

SATISFIABLEA sentence is satisfiable if it is true in some model

e.g., A B

UNSATISFIABLEA sentence is unsatisfiable if it is true in no models

e.g., A A

Page 18: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 18

Problem Solving

Example: Wumpus World• Performance measure

– gold +1000, death -1000– -1 per step, -10 for using the arrow

• Environment– Squares adjacent to wumpus are smelly– Squares adjacent to pit are breezy– Glitter iff gold is in the same square– Shooting kills wumpus if you are facing it– Shooting uses up the only arrow– Grabbing picks up gold if in same square– Releasing drops the gold in same square

• Sensors: Stench, Breeze, Glitter, Bump, Scream• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot

•–––––

–•

Page 19: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 19

Problem Solving

Wumpus world characterization

• Fully Observable • Deterministic • Episodic • Static • Discrete • Single-agent?

•••••

Page 20: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 20

Problem Solving

Wumpus world characterization

• Fully Observable No – only local perception• Deterministic Yes – outcomes exactly specified• Episodic No – sequential at the level of actions• Static Yes – Wumpus and Pits do not move• Discrete Yes• Single-agent? Yes – Wumpus is essentially a

natural feature

Page 21: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 21

Problem Solving

Exploring a wumpus world

Page 22: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 22

Problem Solving

Exploring a wumpus world

Page 23: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 23

Problem Solving

Exploring a wumpus world

Page 24: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 24

Problem Solving

Exploring a wumpus world

Page 25: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 25

Problem Solving

Exploring a wumpus world

Page 26: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 26

Problem Solving

Exploring a wumpus world

Page 27: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 27

Problem Solving

Exploring a wumpus world

Page 28: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 28

Problem Solving

Exploring a wumpus world

Page 29: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 29

Problem Solving

Finding wumpus world

W

4

3

2

1

1 2 3 4

If Wumpus is in [1,3],

How can we prove it using Propositional logic

Page 30: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 30

Problem Solving

Finding wumpus world

W

4

3

2

1

1 2 3 4

Knowledge base Contains:~S1,1 ~B1,1~S2,1 B2,1 S1,2 B1,2

Page 31: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 31

Problem Solving

Finding wumpus world

W

4

3

2

1

1 2 3 4

Rules:R1: ~ S1,1 ~W1,1 ^ ~W1,2 ^ ~W2,1

R2: ~ S2,1 ~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1

R3: S1,2 W1,3 V W1,2

V W2,2 V

~W1,1

Assumption: The square with wumpus is also smelly

s

Page 32: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 32

Problem Solving

Inference rules in PL

• Modus Ponens

• And-elimination: from a conjuction any conjunction can be inferred:

• Resolution:

Unit resolution when

l3 is empty

,

Page 33: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 33

Problem Solving

Proof of W presenceW

4

3

2

11 2 3 4

Knowledge base Contains:~ S1,1 ~B1,1~S2,1 B2,1 S1,2 B1,2Rules:R1: ~ S1,1 ~W1,1 ^ ~W1,2 ^ ~W2,1

R2: ~ S2,1 ~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1 R3: S1,2 W1,3

V W1,2 V W2,2

V ~W1,1

Modus Ponen on R1: ~ S1,1 ~W1,1 ^ ~W1,2 ^ ~W2,1 ~W1,1 ^ ~W1,2 ^ ~W2,1

And Elimination:

~W1,1 ~W1,2

~W2,1

Results:

~W1,1 ~W1,2

~W2,1

Page 34: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 34

Problem Solving

Proof of W presenceW

4

3

2

11 2 3 4

Knowledge base Contains:~ S1,1 ~B1,1~S2,1 B2,1 S1,2 B1,2Rules:R1: ~ S1,1 ~W1,1 ^ ~W1,2 ^ ~W2,1

R2: ~ S2,1 ~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1 R3: S1,2 W1,3

V W1,2 V W2,2

V ~W1,1

Modus Ponen on R2: ~ S2,1 ~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1

~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1

And Elimination:~W1,1

~W2,1

~W2,2

~W3,1

Results:

~W1,1 ~W1,2

~W2,1

~W1,1

~W2,1

~W2,2

~W3,1

Page 35: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 35

Problem Solving

Proof of W presenceW

4

3

2

11 2 3 4

Knowledge base Contains:~ S1,1 ~B1,1~S2,1 B2,1 S1,2 B1,2Rules:R1: ~ S1,1 ~W1,1 ^ ~W1,2 ^ ~W2,1

R2: ~ S2,1 ~W1,1 ^ ~W2,1 ^ ~W2,2 ^ ~W3,1 R3: S1,2 W1,3

V W1,2 V W2,2

V W1,1 Modus Ponen on R3: S1,2 W1,3 V W1,2 V W2,2

V W1,1

W1,3 V W1,2 V W2,2 V W1,1

Unit Resolution:Alpha:W1,3 V W1,2 V W2,2 and Beta: W1,1 W1,3 V W1,2 V W2,2

Unit Resolution again with : W1,2 and W2,2

W1,3

Results:

~W1,1 ~W1,2

~W2,1

~W1,1~W2,1~W2,2 ~W3,1

W1,3

Simply drop all facts that can create conflict

Page 36: 1 Problem Solving CS 331 Dr M M Awais Representational Methods Formal Methods Propositional Logic Predicate Logic

CS 331 Dr M M Awais 36

Problem Solving

Pros and cons of propositional logic

Propositional logic is declarative Propositional logic allows partial/disjunctive/negated

information– (unlike most data structures and databases)

Propositional logic is compositional:– meaning of (B P ) is derived from meaning of B and of P

Meaning in propositional logic is context-independent– (unlike natural language, where meaning depends on context)

Propositional logic has very limited expressive power– (unlike natural language)– E.g., cannot say “Music cause disturbance to all neighbors“

• except by writing one sentence for each neighbor