logic programming automated reasoning in practice

27
Logic Programming Logic Programming Automated Reasoning in practice Automated Reasoning in practice

Upload: alex-carlton

Post on 14-Dec-2015

250 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Logic Programming Automated Reasoning in practice

Logic ProgrammingLogic Programming

Automated Reasoning in practiceAutomated Reasoning in practice

Page 2: Logic Programming Automated Reasoning in practice

2

ButBut: people seldom reason monotonically !: people seldom reason monotonically !

First order logic is First order logic is monotonemonotone::

GG

T ’T ’

Motivation: monotonicityMotivation: monotonicity

TT |=|=

F1F1F2F2

F3F3

++Fred is a Fred is a penguinpenguin

Birds flyBirds fly

++Fred is a birdFred is a bird

Fred fliesFred flies

Page 3: Logic Programming Automated Reasoning in practice

3

Default reasoning:Default reasoning: Is a form of reasoning that we’d like to use Is a form of reasoning that we’d like to use

permanentlypermanently otherwise the rules are far too complex!otherwise the rules are far too complex!

Is usually supported by hierarchy, inheritance Is usually supported by hierarchy, inheritance and exceptions in OOPand exceptions in OOP also an early AI-formalismalso an early AI-formalism

CANNOTCANNOT be expressed in FOL be expressed in FOL independent on the knowledge representation !!independent on the knowledge representation !!

CANCAN be expressed in some FOL extensions be expressed in some FOL extensions non-monotone logicsnon-monotone logics the simplest one of those is … … the simplest one of those is … …

Page 4: Logic Programming Automated Reasoning in practice

4

Logic ProgrammingLogic Programming

Resolution-based automated reasoning:Resolution-based automated reasoning: restricted to restricted to Horn clausesHorn clauses restricted to restricted to backwards linear resolutionbackwards linear resolution

BUTBUT: with 3 important new extensions:: with 3 important new extensions:

return return Answer SubstitutionsAnswer Substitutions

Least-model semanticsLeast-model semantics instead ofinstead ofstandard FOL model semanticsstandard FOL model semantics

Extending Horn clause logic with Extending Horn clause logic with Negation Negation as Finite Failureas Finite Failure

Page 5: Logic Programming Automated Reasoning in practice

Answer substitutionsAnswer substitutions

The link to programmingThe link to programming

Page 6: Logic Programming Automated Reasoning in practice

6

Answer substitutionsAnswer substitutionsanc(x,y) parent(x,y) (1)anc(x,y) parent(x,z) anc(z,y) (2)parent(A,B) (3) parent(B,C) (4)false anc(u,v)

false anc(u,v)

false parent(x1,z1) anc(z1,y1)

(2) {u/x1,v/y1}

false anc(B,y1)(3) {x1/A,z1/B}

false parent(B,y1)(1) {x2/B, y2/y1}

false (4) {y1/C}

Answer:Answer:Yes, Yes, u u v anc(u,v) v anc(u,v)

That is:That is:u = A and v = C u = A and v = C

(composition of all mgu’s (composition of all mgu’s applied to the goal variables)applied to the goal variables)

Page 7: Logic Programming Automated Reasoning in practice

7

The third answer:The third answer:u = B and v = C u = B and v = C Another answer:Another answer:

u = A and v = B u = A and v = B

And computes ALL answersAnd computes ALL answers

false anc(u,v)

false parent(x1,y1)(1) {u/x1,v/y1}

false (3) {x1/A,y1/B}

false

(4) {x1/B,y1/C}

anc(x,y) parent(x,y) (1)anc(x,y) parent(x,z) anc(z,y) (2)parent(A,B) (3) parent(B,C) (4)false anc(u,v)

Page 8: Logic Programming Automated Reasoning in practice

8

Logic PROGRAMMINGLogic PROGRAMMING

By computing By computing answer substitutionsanswer substitutions Logic Logic Programming serves as a de basis for a number Programming serves as a de basis for a number of “general purpose” programming languages.of “general purpose” programming languages.

Prolog, Mercury, XSB, …Prolog, Mercury, XSB, …

with an efficiency with an efficiency comparable with Ccomparable with C ! !

and even faster for some programs.and even faster for some programs.

Page 9: Logic Programming Automated Reasoning in practice

9

Practical programming?Practical programming? Example Example arithmeticarithmetic::

double_plus_1(x,y) double_plus_1(x,y) y is 2*x + 1 y is 2*x + 1

Example Example listslists::

append([], list, list) append([], list, list) append([x|list1], list2, [x|list3]) append([x|list1], list2, [x|list3])

append(list1, list2, list3)append(list1, list2, list3)

false false double_plus_1(3,z) double_plus_1(3,z) Yes: z=7Yes: z=7

false false double_plus_1(2,5) double_plus_1(2,5) YesYes

false false append([1,2], [3,4,5], z) append([1,2], [3,4,5], z) Yes: z= [1,2,3,4,5]Yes: z= [1,2,3,4,5]

false false append([1,2], y, [1,2,3]) append([1,2], y, [1,2,3]) Yes: y= [3]Yes: y= [3]

false false append(x, y, [1,2]) append(x, y, [1,2]) Yes: x = [], y = [1,2]Yes: x = [], y = [1,2] x = [1], y = [2]x = [1], y = [2] … …

Page 10: Logic Programming Automated Reasoning in practice

Least model semanticsLeast model semantics

Specify in a more compact waySpecify in a more compact way

Page 11: Logic Programming Automated Reasoning in practice

11

Least model semanticsLeast model semantics ExampleExample: a database:: a database:

celebrity(Crabé)celebrity(Crabé)celebrity(Jambers)celebrity(Jambers)celebrity(Peeters)celebrity(Peeters)

celebrity(Lisa)celebrity(Lisa)celebrity(Tieleman)celebrity(Tieleman)celebrity(Samson)celebrity(Samson)

Is DeSchreye a celebrity ??Is DeSchreye a celebrity ??

false false celebrity(DeSchreye) celebrity(DeSchreye)

We get no proof of inconsistency !We get no proof of inconsistency !FOL semantics says:FOL semantics says: celebrity(DeSchreye)celebrity(DeSchreye) is not is not

logically entailed, logically entailed, thusthus: we do not know if it is true : we do not know if it is true or not!or not!

Least model semantics says:Least model semantics says: ~ celebrity(DeSchreye)~ celebrity(DeSchreye)

Page 12: Logic Programming Automated Reasoning in practice

12

What are the atomic consequences of theory What are the atomic consequences of theory TT??

TT

In FOL:In FOL:

Formally: the ideaFormally: the idea

Consequences are in the intersection: p en ~r. Consequences are in the intersection: p en ~r. We do not know anything about the truth of q We do not know anything about the truth of q and s.and s.

model 3model 3

qq

~s~s

model 2model 2

pp ~r~r

~q~q

ss model 1model 1

In LP:In LP:Consequences are in the intersection: p en ~r. Consequences are in the intersection: p en ~r. Other predicates are NOT true: ~q and ~s. Other predicates are NOT true: ~q and ~s.

Page 13: Logic Programming Automated Reasoning in practice

13

Relation with FOLRelation with FOL

celebrity(Crabé)celebrity(Crabé)celebrity(Jambers)celebrity(Jambers)celebrity(Peeters)celebrity(Peeters)

celebrity(Lisa)celebrity(Lisa)celebrity(Tieleman)celebrity(Tieleman)celebrity(Samson)celebrity(Samson)

The logic program:The logic program:

celebrity(Crabé)celebrity(Crabé)celebrity(Jambers)celebrity(Jambers)celebrity(Peeters)celebrity(Peeters)~celebrity(DeSchreye)~celebrity(DeSchreye)~celebrity(Janssens)~celebrity(Janssens)… …

celebrity(Lisa)celebrity(Lisa)celebrity(Tieleman)celebrity(Tieleman)celebrity(Samson)celebrity(Samson)~celebrity(Cobain)~celebrity(Cobain)~celebrity(Dali)~celebrity(Dali)… …

is equivalent to the infinite FOL theory:is equivalent to the infinite FOL theory:

x celebrity(x) x celebrity(x) (x = Crabé) (x = Crabé) (x = Jambers) (x = Jambers) (x = Peeters) (x = Peeters) (x = Lisa) (x = Lisa) ( x = Tieleman) ( x = Tieleman) (x = Samson) (x = Samson)

or also to:or also to:

Page 14: Logic Programming Automated Reasoning in practice

14

The “closed” assumptionThe “closed” assumption Logic programming provides a compact way to Logic programming provides a compact way to

express express ‘complete knowledge’‘complete knowledge’ on some subject. on some subject.

If you If you do not saydo not say that something is true, than it that something is true, than it is false.is false.

In other wordsIn other words: Logic Programming supports : Logic Programming supports formulating formulating definitionsdefinitions of the concepts.of the concepts.

Not just state Not just state what is truewhat is true about these concepts about these concepts (=FOL) !(=FOL) !

The Closed World Assumption !The Closed World Assumption ! (= everything not entailed by the theory is false)(= everything not entailed by the theory is false)

Page 15: Logic Programming Automated Reasoning in practice

15

How relevant is the change of How relevant is the change of semantics?semantics?

In FOL:In FOL:{smart(Kelly)}{smart(Kelly)} implies neitherimplies neither strong(Kelly)strong(Kelly) nornor ~strong(Kelly)~strong(Kelly)

In LP:In LP:{smart(Kelly)}{smart(Kelly)} impliesimplies ~strong(Kelly)~strong(Kelly)

In particular: LP is a In particular: LP is a non-monotone logicnon-monotone logic !! !! In In {smart(Kelly), strong(Kelly)}{smart(Kelly), strong(Kelly)} ,, ~strong(Kelly)~strong(Kelly)

is is no longer entailed.no longer entailed.

Knowledge is Knowledge is differentlydifferently represented in these 2 represented in these 2 formalisms.formalisms.

AlsoAlso: some concepts can be completely : some concepts can be completely axiomatizedaxiomatized in LP but not in FOL. in LP but not in FOL. Ex.:Ex.: the natural numbers ! the natural numbers !

Page 16: Logic Programming Automated Reasoning in practice

Negation as finite failureNegation as finite failure

Page 17: Logic Programming Automated Reasoning in practice

17

Negation as finite failureNegation as finite failure The basic idea:The basic idea:

extending the representation power of Logic extending the representation power of Logic Programming beyond the Horn Clauses logic Programming beyond the Horn Clauses logic

How?How? equivalentequivalent::

allow disjunctions in the headsallow disjunctions in the heads allow negation before the body atomsallow negation before the body atoms

– both give complete predicate logic !both give complete predicate logic !– (but: with the least model semantics we will get (but: with the least model semantics we will get

something different from FOL!)something different from FOL!)

Here: Introduce negations in bodies !Here: Introduce negations in bodies !

Page 18: Logic Programming Automated Reasoning in practice

18

NotNot the meaning of the meaning of standard negationstandard negation

Meaning of Meaning of negation as finite failurenegation as finite failure

If all attempts to prove If all attempts to prove BB using linear LP-resolutionusing linear LP-resolution, , fail in a finite time, conclude than fail in a finite time, conclude than not(B)not(B)

not(B)not(B) means: means:

This is meaningful only with the least model This is meaningful only with the least model semantics semantics (where everything that is not proven (where everything that is not proven to be ‘true’, is considered to be ‘false’)to be ‘true’, is considered to be ‘false’)

Page 19: Logic Programming Automated Reasoning in practice

19

Try to prove that “anc(John,B)” holds!Try to prove that “anc(John,B)” holds!

false anc(John,B)

The ancestor exampleThe ancestor exampleanc(x,y) parent(x,y) (1)anc(x,y) parent(x,z) anc(z,y) (2)parent(A,B) (3) parent(B,C) (4)false anc(u,v)

Conclusion:Conclusion: not anc(John,B) not anc(John,B)

false parent(John,B)(1) {x/John,y/B}

failsfails

false parent(John,z) anc(z,B)

(2) {x/John,y/B}

failsfails

Page 20: Logic Programming Automated Reasoning in practice

20

even(0)even(0)even(s(s(x))) even(s(s(x))) even(x) even(x)odd(y) odd(y) not even(y) not even(y)false false odd(s(s(s(0)))) odd(s(s(s(0))))

false false odd(s(s(s(0)))) odd(s(s(s(0))))

false false even(s(s(s(0)))) even(s(s(s(0))))

Another exampleAnother example

false false not even(s(s(s(0)))) not even(s(s(s(0))))

false false even(s(0)) even(s(0)){x/s(0)}{x/s(0)}

failsfailsProof forProof for even(s(s(s(0)))) fails: even(s(s(s(0)))) fails: conclusion not even(s(s(s(0))))conclusion not even(s(s(s(0))))

false false

Page 21: Logic Programming Automated Reasoning in practice

21

q q q qp p not q not qfalse false p p

false false p p

false false q q

And another exampleAnd another example

But But ~q~q is true according to the least model semantics! is true according to the least model semantics!

false false not q not q

false false q q

……

Proof forProof for q goes into infinite q goes into infinite derivation: no conclusion for qderivation: no conclusion for q

no answerno answer

Page 22: Logic Programming Automated Reasoning in practice

22

{x/Fly}false <- locomotion(Fred,x)false <- locomotion(Fred,x)

false <- abnormal1(Fred)false <- abnormal1(Fred)

Default reasoning in LP (1):Default reasoning in LP (1):

locomotion(x,Fly) locomotion(x,Fly) isa(x,Bird), not abnormal1(x) isa(x,Bird), not abnormal1(x)locomotion(x,Walk) locomotion(x,Walk) isa(x,Ostrich), not abnormal2(x) isa(x,Ostrich), not abnormal2(x)isa(x,Bird) isa(x,Bird) isa(x,Ostrich) isa(x,Ostrich)abnormal1(x) abnormal1(x) isa(x,Ostrich) isa(x,Ostrich)

Also known:Also known: isa(Fred,Bird), isa(Fred,Bird), Prove that:Prove that: x locomotion(Fred,x)x locomotion(Fred,x)

false <- isa(Fred,Bird), not abnormal1(Fred)false <- isa(Fred,Bird), not abnormal1(Fred)false <- not abnormal1(Fred)false <- not abnormal1(Fred)

false <- false <- failsfails

false <- isa(Fred,Ostrich)false <- isa(Fred,Ostrich)

Page 23: Logic Programming Automated Reasoning in practice

23

Default reasoning in LP (2):Default reasoning in LP (2):

Also known:Also known: isa(Fred,Ostrich), isa(Fred,Ostrich), Prove that:Prove that: x locomotion(Fred,x)x locomotion(Fred,x)

locomotion(x,Fly) locomotion(x,Fly) isa(x,Bird), not abnormal1(x) isa(x,Bird), not abnormal1(x)locomotion(x,Walk) locomotion(x,Walk) isa(x,Ostrich), not abnormal2(x) isa(x,Ostrich), not abnormal2(x)isa(x,Bird) isa(x,Bird) isa(x,Ostrich) isa(x,Ostrich)abnormal1(x) abnormal1(x) isa(x,Ostrich) isa(x,Ostrich) isa(Fred,Bird) isa(Fred,Bird)

{x/Fly}false <- locomotion(Fred,x)false <- locomotion(Fred,x)

false <- abnormal1(Fred)false <- abnormal1(Fred)

false <- isa(Fred,Bird), not abnormal1(Fred)false <- isa(Fred,Bird), not abnormal1(Fred)false <- not abnormal1(Fred)false <- not abnormal1(Fred)

false <- isa(Fred,Ostrich)false <- isa(Fred,Ostrich)false <-false <-

fails (for this branch)fails (for this branch)backtracking: the 2nd branchbacktracking: the 2nd branch

Page 24: Logic Programming Automated Reasoning in practice

24

Default reasoning (3):Default reasoning (3):

Also known:Also known: isa(Fred,Ostrich), isa(Fred,Ostrich), Prove that:Prove that: x locomotion(Fred,x)x locomotion(Fred,x)

locomotion(x,Fly) locomotion(x,Fly) isa(x,Bird), not abnormal1(x) isa(x,Bird), not abnormal1(x)locomotion(x,Walk) locomotion(x,Walk) isa(x,Ostrich), not abnormal2(x) isa(x,Ostrich), not abnormal2(x)isa(x,Bird) isa(x,Bird) isa(x,Ostrich) isa(x,Ostrich)abnormal1(x) abnormal1(x) isa(x,Ostrich) isa(x,Ostrich) isa(Fred,Bird) isa(Fred,Bird)

{x/Walk}false <- locomotion(Fred,x)false <- locomotion(Fred,x)

false <- abnormal2(Fred)false <- abnormal2(Fred)

false <- isa(Fred,Ostrich), not abnormal2(Fred)false <- isa(Fred,Ostrich), not abnormal2(Fred)false <- not abnormal2(Fred)false <- not abnormal2(Fred)

false <- false <- failsfails

Page 25: Logic Programming Automated Reasoning in practice

25

A specific programming language based on LP. A specific programming language based on LP.

PrologProlog

Uses a depth-first strategy to search linear Uses a depth-first strategy to search linear resolution proofs.resolution proofs.incomplete incomplete

can get stuck in infinite branches can get stuck in infinite branches Has a bunch of built-in predicates (sometimes Has a bunch of built-in predicates (sometimes

without logical meaning) for:without logical meaning) for:Numerical computations, input-output, changing Numerical computations, input-output, changing

the search strategy, meta-programming, etc.the search strategy, meta-programming, etc. More recent LP languages: Goedel, Mercury, Hal, ..More recent LP languages: Goedel, Mercury, Hal, ..

Page 26: Logic Programming Automated Reasoning in practice

26

Beyond FOL and Logic Beyond FOL and Logic ProgrammingProgramming

Logic ProgrammingLogic Programming is very useful if you have a is very useful if you have a COMPLETECOMPLETE knowledge over your predicates knowledge over your predicates

FOLFOL is very useful if your knowledge is is very useful if your knowledge is INCOMPLETEINCOMPLETE

Combine !Combine ! Open Logic ProgrammingOpen Logic Programming

LP-definitions for the part for which you have LP-definitions for the part for which you have a complete knowledge,a complete knowledge,

FOL formulae for the rest.FOL formulae for the rest.

Page 27: Logic Programming Automated Reasoning in practice

27

Constraint Logic Programming Constraint Logic Programming

Integrate Integrate constraint processing techniquesconstraint processing techniques (consistency, forward checking, looking ahead, (consistency, forward checking, looking ahead, …) with …) with Logic ProgrammingLogic Programming..

Advantages of Advantages of LogicLogic for for knowledge representationknowledge representation

Advantages of Advantages of Constraint solvingConstraint solving for for efficient efficient problem solvingproblem solving

A number of languagesA number of languages: CHIP, Eclipse, Sicsus, etc.: CHIP, Eclipse, Sicsus, etc.