24
CS.462 Artificial Intelligence SOMCHAI THANGSATHITYANGKUL Lecture 04 : Logic

CS.462 Artificial Intelligence

  • Upload
    moriah

  • View
    19

  • Download
    0

Embed Size (px)

DESCRIPTION

CS.462 Artificial Intelligence. SOMCHAI THANGSATHITYANGKUL Lecture 04 : Logic. Logic. When we have too many states, we want a convenient way of dealing with sets of states . The sentence “It’s raining” stands for all the states of the world in which it is raining. - PowerPoint PPT Presentation

Citation preview

Page 1: CS.462 Artificial Intelligence

CS.462Artificial Intelligence

SOMCHAI THANGSATHITYANGKUL

Lecture 04 : Logic

Page 2: CS.462 Artificial Intelligence

2

Logic• When we have too many states, we want a c

onvenient way of dealing with sets of states.• The sentence “It’s raining” stands for all the

states of the world in which it is raining.• Logic provides a way of manipulating big coll

ections of sets by manipulating short descrip tions instead.

• Instead of thinking about all the ways a world could be, we’re going to work in the a langua

ge of expressions that describe those sets.

Page 3: CS.462 Artificial Intelligence

3

What is logic• A formal language

– Syntax – what expressions are legal– Semantics – what legal expressions mean– Proof system – a way of manipulating syntactic

expressions to get other syntactic expressions (which will tell us something new)

• Why proofs? Two kinds of inferences an agent might want to make:– Multiple percepts => conclusions about the world– Current state & operator => properties of next

state

Page 4: CS.462 Artificial Intelligence

4

Propositional Logic Syntax• Syntax: what you’re allowed to write

– for (thing t = fizz; t == fuzz; t++){ … }

– Colorless green ideas sleep furiously.

• Sentences (wffs: well formed formulas)– true and false are sentences– Propositional variables are sentences: P,Q,R,Z– If and are sentences, then so are

• ( ), ~, ∨, ∧, →, ↔– Nothing else is a sentence

• ((~P ∨((True ∧R) ↔Q)) →S) well formed

• (~(P ∨Q) ∧→S) not well formed

Page 5: CS.462 Artificial Intelligence

5

Precedence

• If the order is clear, you can leave o ff parenthesis.

~

highest

lowest

A ∨ B ∧ C A ∨ (B ∧ C)

A ∧ B → C ∨ D (A ∧ B) →(C ∨ D)

A → B ∨ C ↔ D (A → (B ∨ C)) ↔ D

Page 6: CS.462 Artificial Intelligence

6

Try this

Which of these are legal sentences?

Give fully parenthesized expressions for the legal sentences.

Page 7: CS.462 Artificial Intelligence

7

Semantics

• An interpretation is a complete True / Fa lse assignment to propositional symbols

• The semantics (meaning) of a sentence is the set of interpretations in which the

sentence evaluates to True.• Example: the semantics of the sentence

P ∨ Q is the set of three interpretations– P=True, Q=True– P=True, Q=False– P=False, Q=True

Page 8: CS.462 Artificial Intelligence

8

Evaluating a sentence under an interpretation

• Truth Tables

P Q ~P P ∧ QP ∨ Q

P → Q Q → P P ↔ Q

f f t f f t t t

f t t f t t f f

t f f f t f t f

t t f t t t t t

Page 9: CS.462 Artificial Intelligence

9

Logical equivalences

Page 10: CS.462 Artificial Intelligence

10

Terminology

• A sentence is valid iff its truth value is t in all interpretations.

• Valid sentences: true, : false, P ∨ ~ P• A sentence is satisfiable iff its truth value

is t in at least one interpretation– Satisfiable sentences: P, true, ~ P

• A sentence is unsatisfiable iff its truth value is f in all interpretations– Unsatisfiable sentences: P ∧ ~ P, false, ~

true

Page 11: CS.462 Artificial Intelligence

11

Examples

smoke → smoke

smoke Ç :smokevalid

smoke fire satisfiable, not valid

(s ! f) ! (: s ! : f) satisfiable, not valid

smoke = t, fire = f

Interpretation that make sentence’s truth value = fSentence Valid?

s = f, f = t

s ! f = t, : s ! : f = f

(s ! f) ! (: f ! : s) valid

b Ç d Ç (b ! d)valid

b Ç d Ç : b Ç d

Page 12: CS.462 Artificial Intelligence

12

Satisfiability Problems• Many problems can be expressed as a

list of constraints. Answer is assignment to variables that satisfy all the constraints.

• Examples:– Scheduling people to work in shifts at a hospital

• Some people don’t work at night• No one can work more than x hours a week• Some pairs of people can’t be on the same shift• Is there assignment of people to shifts that satisfy all

constraints?

Page 13: CS.462 Artificial Intelligence

13

Conjunctive Normal Form

• Satisfiability problems are written as conjunctive normal form (CNF) formulas:

– is a clause, which is a disjunction of literals

– A, B, and : C are literals, each of which is a variable or the negation of a variable.

– Each clause is a requirement which must be satisfied and it has different ways of being satisfied.

– Every sentence in propositional logic can be written in CNF

(A B C) (B D) (A) (B C)

(A B C)

Page 14: CS.462 Artificial Intelligence

14

Converting to CNF

Page 15: CS.462 Artificial Intelligence

15

CNF Conversion Example

Page 16: CS.462 Artificial Intelligence

16

Try this

• Convert to CNF

Page 17: CS.462 Artificial Intelligence

17

Algorithms for Satisfiability

• Given a sentence in CNF, how can we prove it is satisfiable?

• Consider a search tree where at each level we consider the possible assignments to one variable, say P. On one branch, we assume P is f and on the other that it is t.

• Given an assignment for a variable, we can simplify the sentence and then repeat the process for another variable.

Page 18: CS.462 Artificial Intelligence

18

Assign and Simplify Example

Page 19: CS.462 Artificial Intelligence

19

Search Example

Page 20: CS.462 Artificial Intelligence

20

Search Example

Page 21: CS.462 Artificial Intelligence

21

Search Example

Page 22: CS.462 Artificial Intelligence

22

Search Example

Page 23: CS.462 Artificial Intelligence

23

Search Example

Page 24: CS.462 Artificial Intelligence

24

Try this

• Given a sentence find the satisfiability search tree

(T X) (S T ) (S X)