sat-solving introduction: logic in ai sat-solving techniques: unit-propagationlocal-search

Post on 12-Jan-2016

222 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

SAT-solvingSAT-solving

Introduction: logic in AIIntroduction: logic in AI

SAT-solving techniques:SAT-solving techniques:

Unit-propagationUnit-propagation

Local-searchLocal-search

Introduction:Introduction:

Motivating exampleMotivating example

Automated reasoningAutomated reasoning

Logic:Logic:

SyntaxSyntax

Model semanticsModel semantics

Logical entailment Logical entailment

3

The AI dream in the 60’s:The AI dream in the 60’s:

Logic allows to express almost everything Logic allows to express almost everything ‘formally’.‘formally’.

Logic also allows to prove “theorems” based on the information given.Logic also allows to prove “theorems” based on the information given.

Can we exploit this to build automated reasoning Can we exploit this to build automated reasoning systems ??systems ??

4

Underlying premises:Underlying premises: Logic is the ‘assembly language’ of Logic is the ‘assembly language’ of knowledge knowledge and is closely related to natural and is closely related to natural language.language.

Since computers are supposed to process Since computers are supposed to process the the knowledge, it should be expressed knowledge, it should be expressed

formally and unambiguously.formally and unambiguously.

Logical inferenceLogical inference allows us to derive allows us to derive systematicallysystematically new new knowledge from the knowledge from the existing one.existing one.

In logic almost all kinds of knowledge can be In logic almost all kinds of knowledge can be represented represented formallyformally and and unambiguouslyunambiguously..

Automating deduction?Automating deduction?More recently: SAT-solvingMore recently: SAT-solving

5

Example:Example: The following knowledge is given :The following knowledge is given :

1.1. Marcus was a man. Marcus was a man.

2.2. Marcus was a Pompeian. Marcus was a Pompeian.

3.3. All Pompeians were Romans. All Pompeians were Romans.

4.4. Caesar was a ruler. Caesar was a ruler.

5.5. All Romans were either loyal to Caesar or hated him. All Romans were either loyal to Caesar or hated him.

6.6. Everyone is loyal to someone. Everyone is loyal to someone.

7.7. People only try to assassinate rulers to whom they are People only try to assassinate rulers to whom they are not loyal.not loyal.

8.8. Marcus tried to assassinate Caesar. Marcus tried to assassinate Caesar.

Can we automatically answer the following questions?Can we automatically answer the following questions?

Was Marcus loyal to Caesar?Was Marcus loyal to Caesar? Did Marcus hate Caesar?Did Marcus hate Caesar?

6

Conversion to Conversion to the First Order Logic:the First Order Logic:

Representation of facts:Representation of facts:

1.1. Marcus was a man. Marcus was a man.

man(Marcus)man(Marcus)

2.2. Marcus was a Pompeian. Marcus was a Pompeian.

Pompeian(Marcus)Pompeian(Marcus)

4.4. Caesar was a ruler. Caesar was a ruler.

ruler(Caesar)ruler(Caesar)

8.8. Marcus tried to assassinate Caesar. Marcus tried to assassinate Caesar.

try_assassinate(Marcus, Caesar)try_assassinate(Marcus, Caesar)

7

5.5. All Romans were either loyal to Caesar or hated him. All Romans were either loyal to Caesar or hated him.

Conversion toConversion tothe First Order Logic (2):the First Order Logic (2):

General representation (representation of rules):General representation (representation of rules):

3.3. All Pompeians were Romans. All Pompeians were Romans.x Pompeian(x)x Pompeian(x) Roman(x) Roman(x)

6.6. Everyone is loyal to someone. Everyone is loyal to someone.xx yy loyal_to(x,y)loyal_to(x,y)

7.7. People only try to assassinate rulers to whom they People only try to assassinate rulers to whom they are not loyal.are not loyal.xxy person(x)y person(x) ruler(y)ruler(y) try_assassinate(x,y)try_assassinate(x,y)

~loyal_to(x,y)~loyal_to(x,y)

( ( ))

~(~(loyal_to(x,Caesar) loyal_to(x,Caesar) hates(x,Caesar)hates(x,Caesar)) ) XORXOR

x Roman(x) x Roman(x) loyal_to(x,Caesar) loyal_to(x,Caesar) hates(x,Caesar)hates(x,Caesar)

8

Prove that he did:Prove that he did:

The “theorem” ?The “theorem” ?

Was Marcus loyal to Caesar?Was Marcus loyal to Caesar?

Did Marcus hate Caesar?Did Marcus hate Caesar?

hates(Marcus,Caesar)hates(Marcus,Caesar)

Try, for example, to prove that he was not :Try, for example, to prove that he was not :

~loyal_to(Marcus,Caesar)~loyal_to(Marcus,Caesar)

9

A proof using backward-A proof using backward-reasoning problem-reduction:reasoning problem-reduction:

~loyal_to(Marcus,Caesar)~loyal_to(Marcus,Caesar)

xxy person(x)y person(x) ruler(y)ruler(y) try_assassinate(x,y)try_assassinate(x,y) ~loyal_to(x,y)~loyal_to(x,y)

++ substitution: x/Marcus substitution: x/Marcus y/Caesary/Caesar

person(Marcus)person(Marcus) ruler(Caesar)ruler(Caesar) try_assassi-try_assassi-nate(Marcus,Caesar)nate(Marcus,Caesar) ~loyal_to(Marcus,Caesar)~loyal_to(Marcus,Caesar)

++ Modus ponens Modus ponensperson(Marcus)person(Marcus)

ruler(Cesar)ruler(Cesar)

ANDAND

try_assassinate(Marcus, Caesar)try_assassinate(Marcus, Caesar)

Done!Done!4.4.

Done!Done!

8.8.

Extra rule:Extra rule:x man(x) x man(x) person(x)person(x)

man(Marcus)man(Marcus) Done!Done!1.1.

10

Problems:Problems:1) Knowledge representation:1) Knowledge representation:

Natural language is imprecise / ambiguousNatural language is imprecise / ambiguous see “People only try …”see “People only try …”

Obvious information is easily forgotten.Obvious information is easily forgotten. see man <-> personsee man <-> person

Some information is more difficult to represent Some information is more difficult to represent in in logic.logic. Vb.: “perhaps …”, “possibly…”, “probably…”,Vb.: “perhaps …”, “possibly…”, “probably…”,

“the chance of … is 45%”, “the chance of … is 45%”,

Logic is inconvenient from a software Logic is inconvenient from a software engineering perspective.engineering perspective.

too ‘fine-grained’ (like an assembly language)too ‘fine-grained’ (like an assembly language)

11

Problems:Problems:2) Deductive problem solving:2) Deductive problem solving:

All trade-offs that we had with search methods All trade-offs that we had with search methods based on states space representation:based on states space representation: backward/forward, tree/graph, OR-tree/AND-OR,backward/forward, tree/graph, OR-tree/AND-OR,

control aspects, ...control aspects, ...

What deduction rules are needed in general?What deduction rules are needed in general? Example: prove “ Example: prove “ hates(Marcus,Caesar) hates(Marcus,Caesar) ““

x Roman(x) x Roman(x) loyal_to(x,Caesar) loyal_to(x,Caesar) hates(x,Caesar)hates(x,Caesar)

The only applicable rule is:The only applicable rule is:

Modus ponens???Modus ponens???

How do we handle How do we handle x x andand y y ??

12

Problems:Problems:2) Deductive problem solving:2) Deductive problem solving:

How to compute substitutions in the general caseHow to compute substitutions in the general case ??

xxy person(x)y person(x) ruler(y)ruler(y) try_assassinate(x,y)try_assassinate(x,y) ~loyal_to(x,y)~loyal_to(x,y)

++ substitution: x/Marcus substitution: x/Marcus y/Caesary/Caesar

In general:In general:more complexmore complex

Which theorem do we try to prove?Which theorem do we try to prove? Ex.: Ex.: loyal_to(Marcus,Caesar)loyal_to(Marcus,Caesar) or or ~loyal_to(Marcus,Caesar)~loyal_to(Marcus,Caesar)

How to handle equality of objects?How to handle equality of objects? Problem: combinatorial explosion of the derived Problem: combinatorial explosion of the derived

equalities (reflexivity, symmetry, transitivity, …) equalities (reflexivity, symmetry, transitivity, …)

How to guarantee correctness/completeness?How to guarantee correctness/completeness?

The formal model semantics of The formal model semantics of LogicLogic

The meaning of “Logical entailment” The meaning of “Logical entailment”

Propositional logicPropositional logic

15

The alphabet:The alphabet:

Basic concepts:Basic concepts: In propositional logic:In propositional logic:

weather_is_rainyweather_is_rainy

joe_has_an_umbrellajoe_has_an_umbrella

Atomic propositionsAtomic propositions

~~

connectorsconnectors

(( ))

punctuationpunctuation

Well-formed formulas:Well-formed formulas:

joe_has_an_umbrellajoe_has_an_umbrella weather_is_rainyweather_is_rainy

~~ weather_is_rainyweather_is_rainy

Notation: p, q, r : atomic propositions.Notation: p, q, r : atomic propositions.

16

Semantics (meaning)Semantics (meaning) In general (for all knowledge representation formalisms):In general (for all knowledge representation formalisms):

2 approaches to define semantics:2 approaches to define semantics:

1. Intuitive (natural) semantics:1. Intuitive (natural) semantics: Describe the meaning by means of a natural Describe the meaning by means of a natural

languagelanguage Exs. (propositional logic):Exs. (propositional logic):

: “implies”: “implies” ~~ : “not true that” : “not true that” : “or”: “or” p p q : “p if and only if q” q : “p if and only if q” ~~ p p r : “not p and r” r : “not p and r”

every symbol and every well-formed formula gets every symbol and every well-formed formula gets meaning through the associated natural languagemeaning through the associated natural language

17

Semantics (2)Semantics (2)2. Transformational semantics:2. Transformational semantics:

Describe the meaning by converting to an Describe the meaning by converting to an associated “mathematical” objectassociated “mathematical” object

In propositional logic :In propositional logic : the set of all propositional symbols that are the set of all propositional symbols that are

logically entailed by the given formulas:logically entailed by the given formulas:

qqpp rr

ppqq

pprr qq rr

pp qqrr

Logically entailedLogically entailed

p p ~ q ~ q

ppq q r r

18

But how to define But how to define “logical entailment” ?“logical entailment” ?

NOT as:NOT as: Everything that we can derive from the formulasEverything that we can derive from the formulas

SINCE:SINCE: At this moment we do not know yet: At this moment we do not know yet:

“ “what is a complete set of the derivation rules”what is a complete set of the derivation rules” This is exactly what Automated Reasoning aims to This is exactly what Automated Reasoning aims to

find out!find out!

BUT by:BUT by: InterpretationsInterpretations ModelsModels

19

Interpretation:Interpretation:

= a function that assigns a truth value to each = a function that assigns a truth value to each “atomic” formula“atomic” formula

Also provides (indirectly) truth values for Also provides (indirectly) truth values for each well-formed formulaeach well-formed formula

pp qq ~p~p p p q q p p q q p p q q p p q qTT TTTT FFFF TTFF FF

FF TT TT TT TTFF FF TT FF FFTT FF TT TT FFTT FF FF TT TT

Truth tableTruth table

20

ModelModel Given a set of formulas Given a set of formulas SS::

a a modelmodel is an interpretation that makes is an interpretation that makes all all formulas in formulas in SS true true

p p ~ q ~ q

ppq q r r

SSExample:Example:

p p ~q ~q q q r rTT TT TT

pppp qq rrTT FF TT

Model:Model:

21

Logical entailment:Logical entailment: Given a set of formulas Given a set of formulas S S and a formulaand a formula F F::

FF is is logically entailedlogically entailed by by SS ( ( SS |=|= FF )), if, ifall models of all models of SS also make also make FF true. true.

p p ~ q ~ q

ppq q r r

SSExample:Example:

F:F:

r r p p

pp qq rrTT FF TT

(the only) Model:(the only) Model:

r r p pTT

Satisfiability and consistencySatisfiability and consistency Given a set of formulas Given a set of formulas SS::

SS is is satisfiablesatisfiable or or consistentconsistent if if SS has a model. has a model.

Example of an unsatisfiable set:Example of an unsatisfiable set: SS = { p, ~p} = { p, ~p}

Relation between satisfiability and logical consequence:Relation between satisfiability and logical consequence:

Given a set of formulas Given a set of formulas S S and a formula and a formula FF::

SS |=|= FF if and only if if and only if SS U {F} is unsatisfiable/inconsistent. U {F} is unsatisfiable/inconsistent.

Automated reasoning and SAT-checking can solve Automated reasoning and SAT-checking can solve the same problems.the same problems.

Predicate logicPredicate logic

24

The alphabet:The alphabet: variablesvariablesxx

yy zz

constantsconstantsYvonneYvonne

YvetteYvette

function symbolsfunction symbolsggff

hhpredicate symbolspredicate symbols

qqpp

~~

connectorsconnectors

(( ))punctuationpunctuation

,, quantifiersquantifiers

Terms:Terms:YvonneYvonneyy f(x, g(Yvette))f(x, g(Yvette))

Well-formed formulas:Well-formed formulas:

p(Yvonne)p(Yvonne)p(x) p(x) ~q(x) ~q(x)z p(z)z p(z)x x y p(x) y p(x) q(y) q(y) p(f(Yvonne, Yvette) p(f(Yvonne, Yvette)

25

Formally:Formally: An An alphabetalphabet consists of variables, constants, function consists of variables, constants, function

symbols, predicate symbols (all user-defined) and of symbols, predicate symbols (all user-defined) and of connectors, punctuations en quantifiers.connectors, punctuations en quantifiers.

TermsTerms are either: are either: variables,variables, constants,constants, function symbols provided with as many terms as function symbols provided with as many terms as

arguments, as the function symbol expects.arguments, as the function symbol expects.

Well-formed formulasWell-formed formulas are constructed from predicate are constructed from predicate symbols, provided with terms as arguments, and from symbols, provided with terms as arguments, and from connectors, quantifiers and punctuation – according to connectors, quantifiers and punctuation – according to the rules of the connectors.the rules of the connectors.

26

Example:Example: Alphabet:Alphabet:

{ {{ {00}, {}, {xx,,yy}, {}, {ss}, {}, {oddodd,,eveneven}, }, ConCon, , PunPun, , QuanQuan}}

Terms:Terms:

{ { 00, , ss((00)), , ss((ss((00)))), , ss((ss((ss((00)))))), …, … xx, , ss((xx)), , ss((ss((xx)))), , ss((ss((ss((xx)))))), …, … yy, , ss((yy)), , ss((ss((yy))), ), ss((ss((ss((yy)))))), … }, … }

Well-formed formulas:Well-formed formulas:

oddodd((00)),, even even((ss((00)))), …, …oddodd((xx)), odd, odd((ss((yy)))), …, …oddodd((xx)) even even((ss((ss((xx)))))), …, …x x (( odd odd((xx)) even even((ss((xx)) ))) ), …, …oddodd((yy)) x x ((eveneven(( s s((xx)))))), ..., ...

27

Interpretation:Interpretation:= a set D (the domain), and= a set D (the domain), and

AA00

ssxx yy

oddodd

Example:Example:

D = ND = N00

11 22

33

a a functionfunction that maps constants to D, and that maps constants to D, and a a functionfunction that maps function symbols to that maps function symbols to functions: D -> Dfunctions: D -> D, and, and

a a functionfunction that maps predicate symbols to that maps predicate symbols to predicates: Dpredicates: D -> Booleans-> Booleans..

BooleansBooleans

truetrue

falsefalse

““even”even”

28

Assigning truth values:Assigning truth values:

1. To ground atomic formulas:1. To ground atomic formulas: form:form: p(p(f(f(aa)),, g( g(aa,,bb))))

Example:Example: I( odd( s ( s( 0 ) ) ) ) ) = ?I( odd( s ( s( 0 ) ) ) ) ) = ?

= = I (I (oddodd) () ( I(I(ss) ( I() ( I(ss) () ( I(I(00)) ) )) ) ))

= = “even”“even” (( succ ( succ (succ ( succ ( 00 ) )) ) ))

= = “even” (“even” ( succ (succ ( 1 1 ) ) ))

= = “even” (“even” ( 22 ))

= = truetrue

29

Assigning truth values (2):Assigning truth values (2):

2. For closed well-formed formulas: 2. For closed well-formed formulas:

(= no non-quantified variables)(= no non-quantified variables) x F(x) x F(x) is true if:is true if:

for all for all d d DD: I( : I( F(F(dd)) ) = ) = truetrue x F(x)x F(x) is true if: is true if:

there exists there exists d d DD such that: I( such that: I( F(F(dd)) ) = ) = truetrue further:further: use the truth tables. use the truth tables.

Example:Example: I(I(x odd( s ( x ) ) x odd( s ( x ) ) odd(x) odd(x) )) = ?= ?

= = truetrue if for all if for all d d in in NN::

I (I (odd( s (odd( s (dd) )) ) odd( odd(dd)) ) = ) = truetrue

= = “even”“even” (( succ(succ(dd)) ) ) “even”“even” ((dd))

Assume: Assume: dd = = 00, then:, then:

= = falsefalse truetrue

Truth tables: Truth tables: falsefalse ! !

30

Semantics / Logical entailment:Semantics / Logical entailment: Exactly as in propositional logic !Exactly as in propositional logic !

Given a set of formulas Given a set of formulas SS::a a modelmodel is an interpretation that makes all is an interpretation that makes all

formulas in formulas in SS true. true.

Given a set of formulas Given a set of formulas S S and a formulaand a formula F F::FF is is logically entailedlogically entailed by by SS ( ( SS |=|= FF )), ,

if if all models of all models of SS also make also make FF true. true.

Given a set of formulas Given a set of formulas SS::SS is is inconsistentinconsistent or unsatisfiable if or unsatisfiable if SS has no models. has no models.

Example:Example: SS = { p(a), ~p(a)} = { p(a), ~p(a)}

31

Marcus example:Marcus example:

xx yyVV

MarcusMarcusCaesarCaesar

CCAA

F = F =

manmanpersopersonn

rulerruler

RomanRoman PompeianPompeianhateshates loyal_toloyal_to

try_assassinatetry_assassinatePP

D = world of ~40 VC.D = world of ~40 VC.

““Marcus”Marcus”

““Caesar”Caesar”

““Intended” interpretation:Intended” interpretation:

Is a model IF ALL FORMULAS ARE CORRECTIs a model IF ALL FORMULAS ARE CORRECT

BooleanBoolean

truetrue

falsefalse

““was_ruler”was_ruler”

““was_pompeian”was_pompeian”BooleanBoolean

truetrue

falsefalse

32

Marcus example:Marcus example:

xx yyVV

MarcusMarcusCaesarCaesar

CCAA

F = F =

manman personpersonrulerruler

RomanRoman PompeianPompeianhateshates loyal_toloyal_to

try_assassinatetry_assassinatePP

NN

44

33

I(man) = I(person)= I(Roman)I(man) = I(person)= I(Roman)== “natural number”“natural number”

I(Pompeian) =I(Pompeian) = “even number”“even number”

I(ruler) =I(ruler) = “prime number”“prime number”

I(try_assassinate) =I(try_assassinate) = “ “ >> ” ”

I(loyal_to) =I(loyal_to) = “divides”“divides”

I(hates) =I(hates) = “doesn’t divide”“doesn’t divide”

33

Model ??Model ??1.1. Marcus was a man. Marcus was a man.

4 is a natural number4 is a natural number

2.2. Marcus was Pompeian. Marcus was Pompeian.

4 is an even number4 is an even number

4.4. Caesar was a ruler. Caesar was a ruler.

3 is a prime number3 is a prime number8.8. Marcus tried to Marcus tried to

assassinate Caesar. assassinate Caesar. 4 4 >> 3 3

3.3. All Pompeians were Romans. All Pompeians were Romans.Even numbers are naturals.Even numbers are naturals.

5.5. All Romans were either loyal to Caesar or hated him. All Romans were either loyal to Caesar or hated him.A number either divides 3 or doesn’t divide 3.A number either divides 3 or doesn’t divide 3.

6.6. Everybody is loyal to somebody. Everybody is loyal to somebody.

Each number is a divisor of some number.Each number is a divisor of some number.

7.7. People try to assassinate only those rulers to whom People try to assassinate only those rulers to whom they are not loyal. they are not loyal. A natural number that is greater than a A natural number that is greater than a prime number doesn’t divide the prime number. prime number doesn’t divide the prime number.

YES !YES !

34

““Logic is all form, no content”Logic is all form, no content”person(x) person(x) mortal(x) mortal(x)person(Socrates)person(Socrates) mortal(Socrates)mortal(Socrates)

January(x) January(x) cold(x) cold(x)January(21/1/01)January(21/1/01) cold(21/1/01)cold(21/1/01)

P(x) P(x) Q(x) Q(x)P(A)P(A) Q(A)Q(A)

Only the underlying structure of a set of logical formulas is Only the underlying structure of a set of logical formulas is important for the conclusions! (up to the names isomorphism)important for the conclusions! (up to the names isomorphism)

But from the knowledge representation perspective But from the knowledge representation perspective also the ‘contents’ is important.also the ‘contents’ is important.

top related