Automated reasoning and theorem proving

39
Automated reasoning Automated reasoning and theorem proving and theorem proving Introduction: logic in AI Introduction: logic in AI Automated reasoning Automated reasoning : : Resolution Resolution Unification Unification Normalization Normalization

description

Automated reasoning and theorem proving. Introduction: logic in AI. Automated reasoning : Resolution Unification Normalization. Introduction:. Automated reasoning. Motivating example. Logic: Syntax Model semantics Logical entailment. The AI dream in the 60’s:. - PowerPoint PPT Presentation

Transcript of Automated reasoning and theorem proving

Page 1: Automated reasoning  and theorem proving

Automated reasoning Automated reasoning and theorem provingand theorem proving

Introduction: logic in AIIntroduction: logic in AI

Automated reasoningAutomated reasoning::

ResolutionResolution

UnificationUnification

NormalizationNormalization

Page 2: Automated reasoning  and theorem proving

Introduction:Introduction:

Motivating exampleMotivating example

Automated reasoningAutomated reasoning

Logic:Logic:

SyntaxSyntax

Model semanticsModel semantics

Logical entailment Logical entailment

Page 3: Automated reasoning  and theorem proving

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 ??

Page 4: Automated reasoning  and theorem proving

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 deductionLogical deduction 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 ??

Page 5: Automated reasoning  and theorem proving

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?

Page 6: Automated reasoning  and theorem proving

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)

Page 7: Automated reasoning  and theorem proving

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)

Page 8: Automated reasoning  and theorem proving

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)

Page 9: Automated reasoning  and theorem proving

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.

Page 10: Automated reasoning  and theorem proving

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)

Page 11: Automated reasoning  and theorem proving

11

Problems:Problems:2) Problem solving:2) 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 ??

Page 12: Automated reasoning  and theorem proving

12

Problems:Problems:2) Problem solving (2):2) Problem solving (2):

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?

Page 13: Automated reasoning  and theorem proving

The formal model semantics of The formal model semantics of LogicLogic

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

Page 14: Automated reasoning  and theorem proving

Propositional logicPropositional logic

Page 15: Automated reasoning  and theorem proving

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.

Page 16: Automated reasoning  and theorem proving

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

Page 17: Automated reasoning  and theorem proving

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

Page 18: Automated reasoning  and theorem proving

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

Page 19: Automated reasoning  and theorem proving

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

Page 20: Automated reasoning  and theorem proving

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:

Page 21: Automated reasoning  and theorem proving

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

Page 22: Automated reasoning  and theorem proving

Predicate logicPredicate logic

Page 23: Automated reasoning  and theorem proving

23

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)

Page 24: Automated reasoning  and theorem proving

24

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.

Page 25: Automated reasoning  and theorem proving

25

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)))))), ..., ...

Page 26: Automated reasoning  and theorem proving

26

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”

Page 27: Automated reasoning  and theorem proving

27

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

Page 28: Automated reasoning  and theorem proving

28

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 ! !

Page 29: Automated reasoning  and theorem proving

29

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.

Additional: inconsistency:Additional: inconsistency:

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

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

Page 30: Automated reasoning  and theorem proving

30

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

Page 31: Automated reasoning  and theorem proving

31

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”

Page 32: Automated reasoning  and theorem proving

32

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 !

Page 33: Automated reasoning  and theorem proving

33

““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.

Page 34: Automated reasoning  and theorem proving

Relation with respect to Relation with respect to other courses:other courses:

Page 35: Automated reasoning  and theorem proving

35

Logic as a foundation for AILogic as a foundation for AI

A A much deepermuch deeper and and more formalmore formal study of Logic for Knowledge study of Logic for Knowledge Representation and Reasoning !Representation and Reasoning !

Page 36: Automated reasoning  and theorem proving

36

Programming Languages and Programming Languages and Programming MethodologiesProgramming Methodologies

Logic-based programming Logic-based programming languageslanguages

(Prolog/CLP)(Prolog/CLP)

Page 37: Automated reasoning  and theorem proving

37

Selected Topics in Logic Selected Topics in Logic ProgrammingProgramming

Formal studies of semantics and formal Formal studies of semantics and formal methods (analysis, termination) of logic-methods (analysis, termination) of logic-based programming languagesbased programming languages

(also beyond Prolog)(also beyond Prolog)

Page 38: Automated reasoning  and theorem proving

38

Fundamentals of Fundamentals of Artificial Artificial Intelligence Intelligence

First Order predicate First Order predicate LogicLogic

Formal semanticsFormal semanticsand analysisand analysis

Logic-basedLogic-basedprogramming languagesprogramming languages(Prolog/CLP)(Prolog/CLP)

Techniques for Techniques for automated reasoningautomated reasoning

Problem-representationProblem-representationin logicin logicMostly in the exercisesMostly in the exercises

Page 39: Automated reasoning  and theorem proving

39

Methodology for Methodology for knowledge representation?knowledge representation?

Very complicated. Not many simple guidelines.Very complicated. Not many simple guidelines. Basis:Basis:

Choose an alphabetChoose an alphabet that allows us to represent all that allows us to represent all

objects and all relations from the problem domain:objects and all relations from the problem domain: What are the What are the basic objectsbasic objects, , functionsfunctions and and

relationsrelations in your problem domain ? in your problem domain ?

– Ontology:Ontology: represent only the RELEVANT represent only the RELEVANT informationinformation

Choose Choose constantsconstants, , functionfunction and and predicate predicate symbolssymbols to represent them. to represent them.

TranslateTranslate every sentence in a natural language in every sentence in a natural language in one or more corresponding logical formulas.one or more corresponding logical formulas.