Download presentation

Presentation is loading. Please wait.

Published byQuintin Watler Modified about 1 year ago

1
Declarative Programming Autumn 2014 Introduction

2
Lecture times Regular lectures on Wednesdays 16:30-18:05, room lectures The lectures at the following dates will be rescheduled (dates/times to be agreed, but likely to some time in November/December): Some other changes are possible (but hopefully, not too many).

3
Web page(s) Is expected to contain: short summaries of lectures power point presentations (when present) problems for programming assignments/project your grades other relevant information (exam dates, changes in lecture times etc) Course material also available as e-course: https://estudijas.lu.lv/login/index.php

4
Contact information Juris Vīksna Room 421, Rainis boulevard 29 phone: Consultations: "official" consultation times: Thursdays (???) 16:30-18:00, Rainis bouleverd 29, room 421; by individual arrangements. In "official" times I will be usually (but probably not always) available without an appointment, so just in case I recommend to check in advance.

5
Programming languages ImperativeFunctionalLogical C++LispProlog PascalML JavaHaskell... Imperative Declarative

6
Declarative vs imperative languages [Adapted from U.Nilsson]

7
Declarative vs imperative languages [Adapted from U.Nilsson]

8
Imperative languages Program is a list of explicit steps of computation list procedure cat(list a, list b) { list t = list u = copylist(a); while (t.tail != nil) t = t.tail; t.tail = b; return u; }

9
Functional languages Program is a composition of functions cat(a,b) if b = nil then a else cons(head(a), cat(tail(a),b))

10
Logical languages Program is a list of facts that are known to be true and a query, which has to be proved or disproved cat([], Z, Z). cat([H|T], L, [H|Z]) :- cat(T, L, Z). u (S(u) z (R(z) P(u,z))) y (S(y) & w (Q(w) P(y,w))) y (Q(y) R(y)) Can this really be done (at least efficiently)? Depends...

11
Propositional logic (propositional calculus) Infinite set of variables:A,B,C,D,... Finite set of operators: , , , , Finite set of auxiliary symbols:(,) Set of rules that defines syntactically correct formulas, e.g.: ( A B) (A B) Interpretation of formulas: We assign truth values 0 and 1 to each of variables in a formula. The truth value of formula is computed using rules such as: A = 1 A = 0 A B = 1 A = 1 and B = 1

12
Propositional logic (propositional calculus)

13

14
Predicate logic (first-order) Infinite set of constants:c 1,c 2,... Infinite set of variables:x 1,x 2,... Infinite set of function symbols:f 1,f 2,... Infinite set of relation symbols:r 1,r 2,... Finite set of operators: , , , , , , Finite set of auxiliary symbols:(,),”,”, Set of rules that defines syntactically correct formulas, e.g.: ( x)(r(x) c) ( y)q(c,y) ( x)( y)r(x,y,c) r(x,y,c) “might” mean e.g.: “for given c and for any x there exists y such that x+y=c”

15
Predicate logic (first-order) How to assign truth values to predicate logic formulas? Again we use notion of interpretation, however now it gets more complicated. interpretation domain D c3c3 c1c1 c2c2 f(c 3 ) = c 2 r(c 2,c 2 ) = 1 or 0 (true or false) Thus, interpretation defines: - domain D - “semantics” of functional and relational symbols. Given interpretation we can assign truth values to formulas!

16
Predicate logic (first-order)

17

18

19
Motivation logic programming is quite important and useful concept in computer science kind of fun! there are problems for which PROLOG may be a natural choice of programming language

20
Requirements 4-6 short programming assignments0 – 50% (half of them must be submitted before the exam session, in order to be allowed to proceed, others are optional) 1 programming project (optional)0 – 30% Exam (open book, optional)–20 – 20% (?)

21
Academic honesty You are expected to submit only your own work! Sanctions: Receiving a zero on the assignment (in no circumstances a resubmission will be allowed) No admission to the exam and no grade for the course

22
Textbooks Ivan Bratko PROLOG programming for artificial intelligence Pearson Range Extension Paul 2011 (4 th ed)

23
Textbooks Leon Sterling, Ehud Shapiro The art of Prolog MIT Press 1994 (2 nd ed)

24
Textbooks Richard A. O’Keefe The craft of Prolog MIT Press 1990 (reprint 2009)

25
Textbooks W.F. Clocksin, C.S.Mellish Programming in Prolog Springer Verlag 2003 (4 th /5 th ed) (5 th ed looks like just a reprint of 4 th ed from 2003)

26
Textbooks This one can be downloaded from the internet: Ulf Nilsson and Jan Maluszynski Logic, Programming and Prolog (2ed) Previously published by John Wiley & Sons Ltd.

27
Textbooks Also available from the internet: Attila Csenki Applications of Prolog Prolog Techniques

28
Textbooks L.C.Paulson ML for working programmer Cambridge University Press, 1996

29
Prolog compilers/interpreters SWI Prologhttp://www.swi-prolog.org/

30
Prolog compilers/interpreters SWI Prolog Editor /swiprolog/indexe.html An integrated environment that allows editing and running of Prolog programs + provides some debugging functionality. Http link also from SWI Prolog site.

31
Prolog compilers/interpreters SICSTUS Prolog

32
Prolog compilers/interpreters [Adapted from wikipedia.org]

33
Workplan PROLOG syntax4 formal (its quite simple...) special keywords and their semantics (also there is not that much...) Computational model of PROLOG programs1 PROLOG interpreters - how to use them1 Program examples7 PROLOGish (often AI related) general (for training - to try to write thing that are hard in PROLOG) Functional programming 2

34
Prolog – short history 1961Resolution method for predicate calculus (John Robinson) 1965ABSYS (Aberdeen System), ABSET (Aberdeen Set Language) (Michael Foster, Ted Ellock) 1971SYSTEMQ (Colmerauer, Kowalski), eventually it become Prolog st FORTRAN compiler for Prolog (David Warren) Was generally considered to be a very promising language up to early 1990s

35
Prolog is a ‘declarative’ language Clauses are statements about what is true about a problem, instead of instructions how to accomplish the solution. The PROLOG system uses the clauses to work out how to accomplish the solution by searching through the space of possible solutions. Not all problems have pure declarative specifications. Sometimes extralogical statements are needed.

36
What a program looks like % At the Zoo % elephant(george). elephant(mary). panda(chi_chi). panda(ming_ming). dangerous(X) :- big_teeth(X). dangerous(X) :- venomous(X). guess(X, tiger) :- stripey(X), big_teeth(X), isaCat(X). guess(X, koala) :- arboreal(X), sleepy(X). guess(X, zebra) :- stripey(X), isaHorse(X).

37
Example: Concatenate lists a and b list procedure cat(list a, list b) { list t = list u = copylist(a); while (t.tail != nil) t = t.tail; t.tail = b; return u; } In an imperative language: In a declarative language In a functional language: cat(a,b) if b = nil then a else cons(head(a),cat(tail(a),b)) cat([], Z, Z). cat([H|T], L, [H|Z]) :- cat(T, L, Z).

38
Prolog “pseudocodes” “Hand computation” Prolog program “Pseudocode” [Adapted from A.Csenki]

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google