Download presentation

Presentation is loading. Please wait.

Published byAngie Wadhams Modified over 3 years ago

1
1 Logic Programming School of Informatics, University of Edinburgh Logic Programming in 50 Minutes The purpose of this lecture is to explain why logic programming was invented; how it might be useful to you; and what you need to do to start programming.

2
2 Logic Programming School of Informatics, University of Edinburgh The Ideal Every program specification can be written in logic. Specifications are independent of computers. Rules of logic can prove the correctness of a specification even if computers didn’t exist. But proof can also be done by a computer smart enough to find the right proof. So specifications and programs are the same. nearly

3
3 Logic Programming School of Informatics, University of Edinburgh Where Has This Worked? Symbolic reasoning systems (machine learning, planning, constraint solving, etc) Language systems (parsers, generators, etc) Verification systems (theorem provers, model checkers, etc). Multi-agent systems (reactive systems, performative handling, brokering, etc) Web systems (page parsing/generation, semantic webs)

4
4 Logic Programming School of Informatics, University of Edinburgh Axioms, Assumptions, Goals Your parent is your ancestor. Your parent’s ancestors are your ancestors. ancestor(X, Y) parent(X, Y). ancestor(X, Y) parent(X, Z) & ancestor(Z, Y). Given: parent(dave, thomas). parent(dave,helen). parent(helen, margaret), etc. We can prove: A. ancestor(dave, A) B. ancestor(B, margaret) A,B. ancestor(B, A)

5
5 Logic Programming School of Informatics, University of Edinburgh Proof Involves Search ancestor(X, Y) parent(X, Y). ancestor(X, Y) parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret). A. ancestor(dave, A) parent(dave, Y) parent(dave, Z) & ancestor(Z, Y) parent(dave, helen) parent(helen, Y) parent(helen, margaret) A = Y Z = helen Y = margaret 1 1 2 3 3 4 4 5 5 6 6 parent(dave, thomas) 2 Y = thomas

6
6 Logic Programming School of Informatics, University of Edinburgh Practical Problem 1 Not all specifications are executable. X = X 2 is a specification of square root but doesn’t compute square roots. We need to write specifications with an understanding of their future use.

7
7 Logic Programming School of Informatics, University of Edinburgh Practical Problem 2 Proof mechanisms that are unsophisticated can easily be fooled. e.g. Prolog has trouble with this: Given: p(X) p(Y) & q(Y,X). p(1). q(1,2). Prove: p(1). Proof mechanisms that are sophisticated are difficult to operate as programming systems.

8
8 Logic Programming School of Informatics, University of Edinburgh Practical Problem 3 Some computable specifications consume a lot of resource before giving an answer. e.g. Prolog has trouble with this: Given: p is_integer(X) & X > 100000. is_integer(1). is_integer(N) is_integer(N1) & N is N + 1. Logic programming system designers worry about efficiency. So must programmers.

9
9 Logic Programming School of Informatics, University of Edinburgh Practical Problem 4 Programmers like to think about closed worlds so negation often is simplified to “I can’t prove it true in my current circumstances”. e.g. Prolog has trouble with this: Given: p(X) not(q(X)) & r(X). q(2). r(1). Prove: p(X)

10
10 Logic Programming School of Informatics, University of Edinburgh A Logic Program’s Interpretation ancestor(X, Y) parent(X, Y). ancestor(X, Y) parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret). Interpretation contains all ground conclusions: A1,B1. ancestor(A1, B1) A2,B2. parent(A2, B2) ancestor(dave, thomas). ancestor(dave,helen). ancestor(helen, margaret). ancestor(dave,margaret) parent(dave, thomas). parent(dave,helen). parent(helen, margaret).

11
11 Logic Programming School of Informatics, University of Edinburgh Everything is a Structured Term ancestor(X, Y) parent(X, Y). ancestor(X, Y) parent(X, Z) & ancestor(Z, Y). parent(dave, thomas). parent(dave,helen). parent(helen, margaret). parent X Z ancestor Z Y & Z Y parent dave thomas

12
12 Logic Programming School of Informatics, University of Edinburgh Logic Programs Manipulate Terms sum(null, 0). sum(seq(First,Rest), N) sum(Rest, N1) & N is N1 + 1. We can prove: N. sum(null, N) N. sum(seq(5,null), N) N. sum(seq(5,seq(2,null)), N) and so on…. N = 0 N = 5 N = 9

13
13 Logic Programming School of Informatics, University of Edinburgh Logic Programming Learning Curve Time Learning effort Logic programming Imperative programming A crude caricature: Imperative programmers learn lots of little things Logic programmers learn one big thing

14
14 Logic Programming School of Informatics, University of Edinburgh Starting to Program in Prolog sicstus | ?- 1 < 2. yes | ?- not(1 < 2). no | ?- [library(lists)]. | ?- append([a,b], [c], X). X = [a,b,c] Unix command to start SICStus Prolog Goal, using a built-in predicate Goal, using a built-in logical operator which succeeds which fails Loading definitions from a (library) file Goal, using a loaded predicate. Result of variable binding

15
15 Logic Programming School of Informatics, University of Edinburgh Sources l Sterling & Shapiro “The Art of Prolog” l Clocksin & Mellish “Prolog Programming” l John Lloyd “Foundations of Logic Programming” Books: Organisation: Association for Logic Programming Main conference: International Conference on Logic Programming Main journal: Theory and Practice of LP (pre-2001 main journal was Journal of LP )

Similar presentations

OK

1 Logic Programming School of Informatics, University of Edinburgh Mode Inference Given the definition of a predicate p/N infer a calling pattern p(M 1,

1 Logic Programming School of Informatics, University of Edinburgh Mode Inference Given the definition of a predicate p/N infer a calling pattern p(M 1,

© 2018 SlidePlayer.com Inc.

All rights reserved.

By using this website, you agree with our use of **cookies** to functioning of the site. More info in our Privacy Policy and Google Privacy & Terms.

Ads by Google

Ppt on classification of salts Ppt on case study format Ppt on steve jobs leadership Ppt on child labour in hindi Convert free pdf to ppt online conversion Ppt on distance-time graph and velocity time graph Ppt on soil pollution and its control Ppt on media and networking Ppt on human chromosomes pictures Ppt on metabolism of drugs