Logic Programming Gilian Henke Universitt zu Lbeck January 5, 2016 - - PowerPoint PPT Presentation

logic programming
SMART_READER_LITE
LIVE PREVIEW

Logic Programming Gilian Henke Universitt zu Lbeck January 5, 2016 - - PowerPoint PPT Presentation

Logic Programming Gilian Henke Universitt zu Lbeck January 5, 2016 History Example January 5, 2016 Logic Programming Gilian Henke (Universitt zu Lbeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics


slide-1
SLIDE 1

Logic Programming

Gilian Henke

Universität zu Lübeck

January 5, 2016

slide-2
SLIDE 2

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 2

slide-3
SLIDE 3

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 3

slide-4
SLIDE 4

History Basics Logic Control Problems

History

Idea from 1930s Based on automation of theorem proving and AI 1970s Kowalski developed SLD resolutions Colmerauer developed Prolog

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 4

slide-5
SLIDE 5

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 5

slide-6
SLIDE 6

History Basics Logic Control Problems

Basics

Based on First-Order-Predicate-Logic Declarative language Divided into Logic and Control Most common language: Prolog Others: Datalog, Parlog

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 6

slide-7
SLIDE 7

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 7

slide-8
SLIDE 8

History Basics Logic Control Problems

Horn Clause

Definition (Horn Clause)

A clause, i.e. a disjunction of literals, where at most one positive literal exists. Example: A ∨ ¬B ∨ ¬C

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 8

slide-9
SLIDE 9

History Basics Logic Control Problems

Different Horn Clauses

Normal name Normal logic Logic programming Logic programming name Definite clause A ∨ ¬B1 ∨ ¬B2 ∨ ... ∨ ¬Bn A ← B1 ∧ B2 ∧ ... ∧ Bn Rule Unit clause A A ← Fact Goal clause ¬G1 ∨ ¬G2 ∨ ... ∨ ¬Gn ← G1 ∧ G2 ∧ ... ∧ Gn Query

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 9

slide-10
SLIDE 10

History Basics Logic Control Problems

Hello World!

hw( h e l l o w o r l d ) . ?−hw(X) . ?− w r i t e ( ’ Hello world ! ’ ) .

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 10

slide-11
SLIDE 11

History Basics Logic Control Problems

Example in Prolog

parent ( sophie , frank ) . parent ( sophie , gary ) . parent ( steve , ben ) . parent ( steve , sophie ) . parent ( c l a i r e , ben ) . parent ( c l a i r e , sophie ) . parent ( alice , c a r l ) . parent (ben , c a r l ) . parent (tom , frank ) . parent (tom , gary ) . grandparent (X,Z):−parent (X,Y) , parent (Y,Z) . ancestor (X,Y):−parent (X,Y) . ancestor (X,Y):−parent (Z,Y) , ancestor (X,Z) . ?−grandparent (X, gary ) . ?−parent ( sophie , gary ) . ?−ancestor ( steve , c a r l ) . Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 11

slide-12
SLIDE 12

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 12

slide-13
SLIDE 13

History Basics Logic Control Problems

Search-Tree

How to get the solution to a query? Build a Search-Tree with Depth-First Traversal, where

the query is the root nodes are subgoals leaves are success or failure nodes

If a path to a success node exist the query is successful

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 13

slide-14
SLIDE 14

History Basics Logic Control Problems

Example

grandparent(X,carl) parent(X,Y),parent(Y,carl) parent(sophie,Y), parent(Y,carl) parent(sophie,frank), parent(frank,carl) fail Y=frank parent(sophie,gary), parent(gary,carl) fail Y=gary X=sophie parent(steve,Y), parent(Y,carl) parent(steve,ben), parent(ben,carl) true Y=ben X=steve

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 14

slide-15
SLIDE 15

History Basics Logic Control Problems

Substitution

Definition (Substitution)

Let X be variable and t be a term. For a given set of tuples (X,t) the substitution θ denotes that if θ is applied to a term s every Xi is replaced by its corresponding ti. Example: θ = (X, alice) θ(parent(X, Y)) = parent(alice, Y)

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 15

slide-16
SLIDE 16

History Basics Logic Control Problems

Unification

Definition (Unification)

Let s and t be terms. If there exists a Substitution θ so that sθ = tθ, then θ is called the unifier of s and t. This is also called that t and s unify. Example: θ = (X, alice) θ(parent(X, Y)) = parent(alice, Y) θ(parent(alice, Y)) = parent(alice, Y)

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 16

slide-17
SLIDE 17

History Basics Logic Control Problems

Resolution

Definition (Resolution)

If the Rules A ← B and B ← C holds true then also A ← C holds true.

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 17

slide-18
SLIDE 18

History Basics Logic Control Problems

SLD-Resolution

Data: Q=G1, G2...Gn Result: substitution σ and failure Resolvent = Q; σ={}; failure=false; while Resolvent! = {} do select Gi ∈ Resolvent; if Gi=true then delete Gi; continue; end select Rule A ← B1...Bm where A and Gi unify with θ; if A does not exists then failure = true; break; end replace Gi with B1...Bm; apply θ to Resolvent; σ = θσ; end return σ, failure;

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 18

slide-19
SLIDE 19

History Basics Logic Control Problems

Content

1

History

2

Basics

3

Logic Horn Clause Example

4

Control Search-Trees SLD-Resolution

5

Problems

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 19

slide-20
SLIDE 20

History Basics Logic Control Problems

Problems

Negation as failure Determinism Termination Prolog: Non-Uniformity

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 20

slide-21
SLIDE 21

History Basics Logic Control Problems

Conclusion

Declarative programming language based on First Order Predicate Logic Useful in specialised contexts Non-trivial problems exist

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 21

slide-22
SLIDE 22

History Basics Logic Control Problems

Thank you for your attention!

Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 22