IN112 Mathematical Logic
|
|
- Eric Griffin
- 5 years ago
- Views:
Transcription
1 Institut Supérieur de l Aéronautique et de l Espace IN112 Mathematical Logic Lab session on Prolog Christophe Garion DMIA ISAE Christophe Garion IN112 IN112 Mathematical Logic 1/ 31
2 License CC BY-NC-SA 3.0 This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license (CC BY-NC-SA 3.0) You are free to Share (copy, distribute and transmite) and to Remix (adapt) this work under the following conditions: Attribution You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Noncommercial You may not use this work for commercial purposes. Share Alike If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. See Christophe Garion IN112 IN112 Mathematical Logic 2/ 31
3 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 3/ 31
4 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 4/ 31
5 Prolog interpreter Prolog is an interpreted language: no executable is created (even if it is possible) a Prolog program is loaded into the interpreter queries are executed on this program through the interpreter Christophe Garion IN112 IN112 Mathematical Logic 5/ 31
6 Prolog interpreter Prolog is an interpreted language: no executable is created (even if it is possible) a Prolog program is loaded into the interpreter queries are executed on this program through the interpreter We will use the GNU Prolog interpreter. Diaz, D. (2013a). GNU Prolog. (2013b). GNU Prolog Manual. Christophe Garion IN112 IN112 Mathematical Logic 5/ 31
7 Starting GNU Prolog and queries Starting the interpreter: shell gprolog GNU Prolog By Daniel Diaz Copyright (C) Daniel Diaz?- The?- prompt waits for a query. Christophe Garion IN112 IN112 Mathematical Logic 6/ 31
8 Starting GNU Prolog and queries Starting the interpreter: shell gprolog GNU Prolog By Daniel Diaz Copyright (C) Daniel Diaz?- The?- prompt waits for a query. To escape from the interpretor, the halt predicate is used:?- halt. Christophe Garion IN112 IN112 Mathematical Logic 6/ 31
9 Prolog syntax: a (concise) overview Syntax (case) Case is important in Prolog: identifiers beginning by an uppercase letter are variables names. Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
10 Prolog syntax: a (concise) overview Syntax (case) Case is important in Prolog: identifiers beginning by an uppercase letter are variables names. Examples: in p(x,f(y),a) p is a predicate name X and Y are variable names f is a function name a is a constant name Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
11 Prolog syntax: a (concise) overview Syntax (case) Case is important in Prolog: identifiers beginning by an uppercase letter are variables names. Examples: in p(x,f(y),a) p is a predicate name X and Y are variable names f is a function name a is a constant name... but P ( My_Constant ) is also valid! Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
12 Prolog syntax: a (concise) overview Syntax (case) Case is important in Prolog: identifiers beginning by an uppercase letter are variables names. Examples: in p(x,f(y),a) p is a predicate name X and Y are variable names f is a function name a is a constant name... but P ( My_Constant ) is also valid! N.B. When speaking of a predicate, its arity is given (ancestor/2 for instance). Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
13 Prolog syntax: a (concise) overview Syntax (clauses) A clause is written like this: A :- B1,...,Bn. where A is the head of the clause and B1,...,Bn its body. When a clause is written A :- true., it simply noted A. Such a clause is called a fact. Do not forget the. at the end! Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
14 Prolog syntax: a (concise) overview Syntax (clauses) A clause is written like this: A :- B1,...,Bn. where A is the head of the clause and B1,...,Bn its body. When a clause is written A :- true., it simply noted A. Such a clause is called a fact. Do not forget the. at the end! Examples: jack is a parent of mary parent(jack, mary). for all X and Y, if there exists a Z such that X is an ancestor of Z and Z is a parent of Y, then X is an ancestor of Z ancestor(x, Y) :- ancestor(x, Z), parent(z, Y). Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
15 Prolog syntax: a (concise) overview Syntax (comments) Comments are written like this: /* Comments */ Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
16 Prolog syntax: a (concise) overview Syntax (comments) Comments are written like this: /* Comments */ N.B. Types cannot be declared explicitely. Christophe Garion IN112 IN112 Mathematical Logic 7/ 31
17 A Prolog program for ancestors... We will consider the following program: ancestors.pl /**************************/ /* Definition of parent/2 */ /**************************/ parent(jack, mary). parent(louise, jack). parent(franck, john). /***************************/ /* Definition of ancestor/2 */ /***************************/ ancestor(x, Y) :- parent(x, Y). ancestor(x, Y) :- ancestor(x, Z), parent(z, Y). Christophe Garion IN112 IN112 Mathematical Logic 8/ 31
18 Emacs mode for Prolog There is a major mode for Prolog in Emacs. Astrom, A., M. Zamazal, and S. Bruda. EMACS major mode for Prolog. Christophe Garion IN112 IN112 Mathematical Logic 9/ 31
19 Emacs mode for Prolog There is a major mode for Prolog in Emacs. Astrom, A., M. Zamazal, and S. Bruda. EMACS major mode for Prolog. Add the following lines into your.emacs:.emacs (add-to-list load-path "/chemin/vers/repertoire/contenant/le/fichier/") (autoload run-prolog "prolog" "Start a Prolog sub-process." t) (autoload prolog-mode "prolog" "Major mode for Prolog programs." t) (autoload mercury-mode "prolog" "Major mode for Mercury programs." t) (setq prolog-system gnu) (setq auto-mode-alist (append (("\\.pl$". prolog-mode) ("\\.m$". mercury-mode)) auto-mode-alist)) This mode provides syntax highlighting + interpreter access. Christophe Garion IN112 IN112 Mathematical Logic 9/ 31
20 Easy to use The command line interpreter allows to: navigate into queries history with and dynamically complete a predicate name with Christophe Garion IN112 IN112 Mathematical Logic 10/ 31
21 Easy to use The command line interpreter allows to: navigate into queries history with and dynamically complete a predicate name with From Emacs: history access with M-p and M-p a predicate, a region or a buffer can be evaluated predicate definitions can be retrieved predicate template insertion with C-c C-n... Christophe Garion IN112 IN112 Mathematical Logic 10/ 31
22 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 11/ 31
23 Interpret a program From interpreter:?- [ /home/tof/cours/in112/exempleprolog/ancestors.pl ]. compiling /home/tof/cours/in112/exempleprolog/ancetres.pl for byte code... /home/tof/cours/in112/exempleprolog/ancetres.pl compiled, 12 lines read bytes written, 62 ms (2 ms) yes do not forget the final. filename protection with Prolog answers yes: the predicate consult/1 is evaluated! beware when reloading programs, verify with listing the predicates definitions Christophe Garion IN112 IN112 Mathematical Logic 12/ 31
24 Interpret a program From interpreter:?- [ /home/tof/cours/in112/exempleprolog/ancestors.pl ]. compiling /home/tof/cours/in112/exempleprolog/ancetres.pl for byte code... /home/tof/cours/in112/exempleprolog/ancetres.pl compiled, 12 lines read bytes written, 62 ms (2 ms) yes do not forget the final. filename protection with Prolog answers yes: the predicate consult/1 is evaluated! beware when reloading programs, verify with listing the predicates definitions From Emacs, open the file and C-c C-b. Christophe Garion IN112 IN112 Mathematical Logic 12/ 31
25 Query evaluation Query evaluation:?- ancestor(jack,mary). true? Christophe Garion IN112 IN112 Mathematical Logic 13/ 31
26 Query evaluation Query evaluation:?- ancestor(jack,mary). true? The? symbol signifies that Prolog waits for a user command: ; to ask for the next solution (backtracking) a RETURN to ask for all solutions to stop Christophe Garion IN112 IN112 Mathematical Logic 13/ 31
27 Query evaluation Query evaluation:?- ancestor(jack,mary). true? The? symbol signifies that Prolog waits for a user command: ; to ask for the next solution (backtracking) a RETURN to ask for all solutions to stop In our case, after ; : Fatal Error: local stack overflow (size: 8192 Kb, environment variable used: LOCALSZ) Christophe Garion IN112 IN112 Mathematical Logic 13/ 31
28 Query evaluation After having corrected the program:?- ancestor(w,mary). W = jack? a W = louise no Christophe Garion IN112 IN112 Mathematical Logic 14/ 31
29 Query evaluation After having corrected the program:?- ancestor(w,mary). W = jack? a W = louise no Evaluation with failure:?- ancestor(john,jack). no Christophe Garion IN112 IN112 Mathematical Logic 14/ 31
30 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 15/ 31
31 Arithmetics Arithmetics is available in GNU Prolog. +, *, -, / min, max =:=, =/= (cf. next slides) <, >, =<, >=... All those operators are infix. Christophe Garion IN112 IN112 Mathematical Logic 16/ 31
32 Arithmetics Arithmetics is available in GNU Prolog. +, *, -, / min, max =:=, =/= (cf. next slides) <, >, =<, >=... All those operators are infix. N.B. (important) The operands of those operators must be evaluable. Christophe Garion IN112 IN112 Mathematical Logic 16/ 31
33 Unification, assignment, equality: try it! Unification operator: = X = Y. X = Y, f(y) = Z. f(x) = g(y). f(x) \= g(a). Christophe Garion IN112 IN112 Mathematical Logic 17/ 31
34 Unification, assignment, equality: try it! Unification operator: = Assignment operator: is X = Y. X = Y, f(y) = Z. f(x) = g(y). f(x) \= g(a). X is 2. X is (2 + 3). X is Y. Y = 2, X is Y. Christophe Garion IN112 IN112 Mathematical Logic 17/ 31
35 Unification, assignment, equality: try it! Unification operator: = Assignment operator: is X = Y. X = Y, f(y) = Z. f(x) = g(y). f(x) \= g(a). X is 2. X is (2 + 3). X is Y. Y = 2, X is Y. Terms equality operator: == X == X. X == Y. X \== Y. 2 == (1 + 1). Christophe Garion IN112 IN112 Mathematical Logic 17/ 31
36 Unification, assignment, equality: try it! Unification operator: = Assignment operator: is X = Y. X = Y, f(y) = Z. f(x) = g(y). f(x) \= g(a). X is 2. X is (2 + 3). X is Y. Y = 2, X is Y. Terms equality operator: == Arithmetic equality: =:= X == X. X == Y. X \== Y. 2 == (1 + 1). 2 =:= 2. 2 =:= (1 + 1). 2 =:= 3. 2 =\= 3. Christophe Garion IN112 IN112 Mathematical Logic 17/ 31
37 Unification, assignement: example Question How to define a fact/2 predicate which represents the factorial function? Christophe Garion IN112 IN112 Mathematical Logic 18/ 31
38 Unification, assignement: example Question How to define a fact/2 predicate which represents the factorial function? Using logic: Factorial definition fact(0, 1) x y fact(x 1, y) fact(x, y x) Christophe Garion IN112 IN112 Mathematical Logic 18/ 31
39 Unification, assignement: example fact-1.pl fact(0,1). fact(n,y * N) :- fact(n - 1,Y). Christophe Garion IN112 IN112 Mathematical Logic 19/ 31
40 Unification, assignement: example fact-1.pl fact(0,1). fact(n,y * N) :- fact(n - 1,Y). Trying with 0!:?- fact(0,x). X = 1? ; Fatal Error: global stack overflow (size: Kb, environment variable used: GLOBALSZ) Christophe Garion IN112 IN112 Mathematical Logic 19/ 31
41 Unification, assignement: example fact-1.pl fact(0,1). fact(n,y * N) :- fact(n - 1,Y). Explanation (with trace., remove trace mode with notrace.): 1 1 Redo: fact(0,1)? 2 2 Call: fact(0-1,_48)? 3 3 Call: fact(0-1-1,_78)? 4 4 Call: fact( ,_108)? 5 5 Call: fact( ,_138)?... Christophe Garion IN112 IN112 Mathematical Logic 19/ 31
42 Unification, assignement: example fact-2.pl fact(0,1). fact(n,y * N) :- N > 0, fact(n - 1, Y). Christophe Garion IN112 IN112 Mathematical Logic 20/ 31
43 Unification, assignement: example fact-2.pl fact(0,1). fact(n,y * N) :- N > 0, fact(n - 1, Y). Trying 0!:?- fact(0,x). X = 1? ; no Christophe Garion IN112 IN112 Mathematical Logic 20/ 31
44 Unification, assignement: example fact-2.pl fact(0,1). fact(n,y * N) :- N > 0, fact(n - 1, Y). Trying 3!:?- fact(3,x). no Christophe Garion IN112 IN112 Mathematical Logic 20/ 31
45 Unification, assignement: example fact-2.pl fact(0,1). fact(n,y * N) :- N > 0, fact(n - 1, Y). Explanation (with trace.): 1 1 Call: fact(3,_16)? 2 2 Call: 3>0? 2 2 Exit: 3>0? 3 2 Call: fact(3-1,_48)? 4 3 Call: 3-1>0? 4 3 Exit: 3-1>0? Call: >0? 8 5 Fail: >0? 7 4 Fail: fact( ,_158)? 5 3 Fail: fact(3-1-1,_103)? 3 2 Fail: fact(3-1,_48)? 1 1 Fail: fact(3,_16)? Christophe Garion IN112 IN112 Mathematical Logic 20/ 31
46 Unification, assignement: example fact-2.pl fact(0,1). fact(n,y * N) :- N > 0, fact(n - 1, Y). Explanation (why fact(0,1) is not used):? = 0. no Christophe Garion IN112 IN112 Mathematical Logic 20/ 31
47 Unification, assignement: example fact-3.pl fact(0,1). fact(n, Y * N) :- N > 0, M = N - 1, fact(m, Y). Christophe Garion IN112 IN112 Mathematical Logic 21/ 31
48 Unification, assignement: example fact-3.pl fact(0,1). fact(n, Y * N) :- N > 0, M = N - 1, fact(m, Y). Trying 3!:?- fact(3,x). fact(3,x). no Christophe Garion IN112 IN112 Mathematical Logic 21/ 31
49 Unification, assignement: example fact-3.pl fact(0,1). fact(n, Y * N) :- N > 0, M = N - 1, fact(m, Y). Explanation (with trace.): 1 1 Call: fact(3,_16)? 2 2 Call: 3>0? 2 2 Exit: 3>0? 3 2 Call: fact(3-1,_48)? 4 3 Call: 3-1>0? 4 3 Exit: 3-1>0? Fail: >0? 7 4 Fail: fact( ,_158)? 5 3 Fail: fact(3-1-1,_103)? 3 2 Fail: fact(3-1,_48)? 1 1 Fail: fact(3,_16)? Christophe Garion IN112 IN112 Mathematical Logic 21/ 31
50 Unification, assignement: example fact-3.pl fact(0,1). fact(n, Y * N) :- N > 0, M = N - 1, fact(m, Y). Explanation (why fact(0,1) is not used):?- M = 3-1. M = 3-1 yes Christophe Garion IN112 IN112 Mathematical Logic 21/ 31
51 Unification, assignement: example fact-4.pl fact(0,1). fact(n, Y * N) :- N > 0, M is N - 1, fact(m, Y). Christophe Garion IN112 IN112 Mathematical Logic 22/ 31
52 Unification, assignement: example fact-4.pl fact(0,1). fact(n, Y * N) :- N > 0, M is N - 1, fact(m, Y). Trying 3!:?- fact(3,x). X = 1*1*2*3? ; no Christophe Garion IN112 IN112 Mathematical Logic 22/ 31
53 Unification, assignement: example fact-4.pl fact(0,1). fact(n, Y * N) :- N > 0, M is N - 1, fact(m, Y). Trying 3!:?- fact(3,x). X = 1*1*2*3? ; no fact-5.pl (finally!) fact(0,1). fact(n, Y) :- N > 0, M is N - 1, fact(m, X), Y is X * N. Christophe Garion IN112 IN112 Mathematical Logic 22/ 31
54 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 23/ 31
55 Lists representation Lists are basic data structures. Building a new list by induction: Syntax (list) empty list: [] or the list is composed of: an element, the head of the list a list, the tail of the list The list is then represented by [head tail]. Christophe Garion IN112 IN112 Mathematical Logic 24/ 31
56 Lists representation Lists are basic data structures. Building a new list by induction: Syntax (list) empty list: [] or the list is composed of: an element, the head of the list a list, the tail of the list The list is then represented by [head tail]. A list containing known elements is represented with the, : [a, b, c]. Christophe Garion IN112 IN112 Mathematical Logic 24/ 31
57 Lists representation Lists are basic data structures. Building a new list by induction: Syntax (list) empty list: [] or the list is composed of: an element, the head of the list a list, the tail of the list The list is then represented by [head tail]. Examples to evaluate: [T Q] = [a, b, c]. [T, Q] = [a, b, c]. [T, Q, R] = [a, b, c]. [T Q] = [a]. [T] = [a]. Christophe Garion IN112 IN112 Mathematical Logic 24/ 31
58 Operations on lists Avalaible operations on lists: member/2 (e.g. member(x, [a,b,c]).) append/3 (e.g. append([d, e], [a,b,c], X).) reverse/2 last/2 length/2 sort/2... Christophe Garion IN112 IN112 Mathematical Logic 25/ 31
59 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 26/ 31
60 Negation by failure Negation does not exist in Prolog: only Horn clauses are used! Christophe Garion IN112 IN112 Mathematical Logic 27/ 31
61 Negation by failure Negation does not exist in Prolog: only Horn clauses are used! Syntax (negation by failure) \+ (goal) This operator represents the fact that Prolog cannot prove goal. Christophe Garion IN112 IN112 Mathematical Logic 27/ 31
62 Negation by failure Negation does not exist in Prolog: only Horn clauses are used! Syntax (negation by failure) \+ (goal) This operator represents the fact that Prolog cannot prove goal. Try the following examples: \+(X == Y). \+(member(a, [b,c])). Christophe Garion IN112 IN112 Mathematical Logic 27/ 31
63 NBF: the ancestors example Add the following predicate: X is not a direct ancestor of Y if X is an ancestor of Y and X is not a parent of Y. Christophe Garion IN112 IN112 Mathematical Logic 28/ 31
64 NBF: the ancestors example Add the following predicate: X is not a direct ancestor of Y if X is an ancestor of Y and X is not a parent of Y. ancestor.pl not_direct_ancestor(x, Y) :- ancestor(x, Y), \+(parent(x, Y)). Try it! Christophe Garion IN112 IN112 Mathematical Logic 28/ 31
65 NBF is not logical negation! In classical logic: = A B B A Christophe Garion IN112 IN112 Mathematical Logic 29/ 31
66 NBF is not logical negation! In classical logic:... but not with NBF! = A B B A Try the following definition for not_direct_ancestor: ancestor.pl not_direct_ancestor(x, Y) :- \+(parent(x, Y)), ancestor(x, Y). Christophe Garion IN112 IN112 Mathematical Logic 29/ 31
67 Outline 1 Prolog: getting started! 2 Interpreting and querying 3 Unification and assignement 4 Lists 5 Negation by failure 6 Misc. Christophe Garion IN112 IN112 Mathematical Logic 30/ 31
68 Misc. listing is used to obtain a predicate definition or all program predicates definition. ex: listing(ancestor). Christophe Garion IN112 IN112 Mathematical Logic 31/ 31
69 Misc. listing is used to obtain a predicate definition or all program predicates definition. ex: listing(ancestor). Normally, a predicate should be defined contiguously. You can add the following line at the beginning of the file: :- discontiguous(pred/n). where pred is the predicate. Christophe Garion IN112 IN112 Mathematical Logic 31/ 31
70 Misc. listing is used to obtain a predicate definition or all program predicates definition. ex: listing(ancestor). Normally, a predicate should be defined contiguously. You can add the following line at the beginning of the file: :- discontiguous(pred/n). where pred is the predicate. If a predicate is defined in more than one file, you should add the following in all files preambles: :- multifile(pred/n). Christophe Garion IN112 IN112 Mathematical Logic 31/ 31
IN112 Mathematical Logic
Institut Supérieur de l Aéronautique et de l Espace IN112 Mathematical Logic Lab session on Prolog Christophe Garion DMIA ISAE Christophe Garion IN112 IN112 Mathematical Logic 1/ 31 License CC BY-NC-SA
More informationSD314 Outils pour le Big Data
Institut Supérieur de l Aéronautique et de l Espace SD314 Outils pour le Big Data Functional programming in Python Christophe Garion DISC ISAE Christophe Garion SD314 Outils pour le Big Data 1/ 35 License
More informationLogic Programming Languages
Logic Programming Languages Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical inferencing process to
More informationModule 7. Knowledge Representation and Logic (Rule based Systems) Version 2 CSE IIT, Kharagpur
Module 7 Knowledge Representation and Logic (Rule based Systems) Lesson 18 Rule based Systems - II 7.2.5 Programs in PROLOG These minimal notes on Prolog show only some of its flavor. Here are facts plays(ann,fido).
More informationIntroduction to predicate calculus
Logic Programming Languages Logic programming systems allow the programmer to state a collection of axioms from which theorems can be proven. Express programs in a form of symbolic logic Use a logical
More informationChapter 16. Logic Programming Languages
Chapter 16 Logic Programming Languages Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming The Origins of
More informationChapter 16. Logic Programming Languages ISBN
Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming
More informationQuick n Dirty Prolog Tutorial
CSc 245 Introduction to Discrete Structures Quick n Dirty Prolog Tutorial (McCann) Last Revised: February 2014 Background: Prolog, whose name is from the phrase PROgramming in LOGic, is a special purpose
More informationBacktracking. Ch. 5 Controlling Backtracking. Backtracking. Backtracking Example. Example. Example
Backtracking Ch. 5 Controlling Backtracking Backtracking is the attempt to (re)satisfy a goal by exploring alternative ways to satisfy it. Chronological backtracking is backtracking in which we always
More informationLogic Languages. Hwansoo Han
Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Logic Programming Language Paradigm Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic
More information3 Lists. List Operations (I)
3 Lists. List Operations (I) The list is the simplest yet the most useful Prolog structure. A list is a sequence of any number of objects. Example 3.1: L = [1, 2, 3], R = [a, b, c], T = [john, marry, tim,
More informationdocumenting programs, including: A traditional, command line interactive top level.
Computational Logic Developing Programs with a Logic Programming System 1 Our Development Environment: The Ciao System We use the (ISO-Prolog subset of the) Ciao multiparadigm programming system. In particular,
More informationProlog. Intro to Logic Programming
Prolog Logic programming (declarative) Goals and subgoals Prolog Syntax Database example rule order, subgoal order, argument invertibility, backtracking model of execution, negation by failure, variables
More informationThe Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms
The Logic Paradigm Joseph Spring 7COM1023 Programming Paradigms 1 Discussion The Logic Paradigm Propositional and Predicate Logic See also notes and slides on PP website Horn Clauses Definition, Examples
More informationCS 360: Programming Languages Lecture 10: Logic Programming with Prolog
CS 360: Programming Languages Lecture 10: Logic Programming with Prolog Geoffrey Mainland Drexel University Section 1 Administrivia Midterm Tuesday Midterm is Tuesday, February 14! Study guide is on the
More informationProlog Programming. Lecture Module 8
Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of
More informationNotes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions The AI War How machines should learn: inductive or deductive? Deductive: Expert => rules =>
More informationINTRODUCTION TO PROLOG
INTRODUCTION TO PROLOG PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/44 STRUCTURE OF A PROLOG PROGRAM Where, declaratively, Haskell expresses a computation as a system
More informationDeclarative Programming Prolog CS360
Declaratie Programming Prolog CS360 Terms Numerical literals String literals Ø By default, any string that starts is all lowercase Ø Use single quotes for anything else Atoms Ø Essentially, strings Ø Also,
More informationTopic B: Backtracking and Lists
Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct
More informationCS 321 Programming Languages and Compilers. Prolog
CS 321 Programming Languages and Compilers Prolog Prolog PROgramming LOGic Algorithm = Logic + Control Logic programming deals with computing relations rather than functions. To understand Prolog one must
More informationLecture 11: Feb. 10, 2016
CS323: AI (Hands on with Prolog) Spring 2016 Lecturer: K.R. Chowdhary Lecture 11: Feb. 10, 2016 : Professor of CS (VF) Disclaimer: These notes have not been subjected to the usual scrutiny reserved for
More informationIntroduction to Prolog
Introduction to Prolog David Woods dwoods@scss.tcd.ie Week 3 - HT Declarative Logic The Prolog programming language is, at its theoretical core, a declarative language. This is unlike more commonly used
More informationChapter 16. Logic Programming Languages ISBN
Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming
More informationPROLOG PROgramming in LOGic
PROLOG PROgramming in LOGic 1 Knowledge-Based Information Systems (Relational) database systems are very efficient in the handling of data. Information is data together with a suitable interpretation.
More informationProlog-2 nd Lecture. Prolog Predicate - Box Model
Prolog-2 nd Lecture Tracing in Prolog Procedural interpretation of execution Box model of Prolog predicate rule How to follow a Prolog trace? Trees in Prolog use nested terms Unification Informally Formal
More informationDerived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses
Prolog Programming Derived from PROgramming in LOGic (1972) Good at expressing logical relationships between concepts Prolog and LISP - two most popular AI languages Execution of a Prolog program is a
More informationWeb Architecture AN OVERVIEW
Web Architecture AN OVERVIEW General web architecture Historically, the client is a web browser But it can be also A mobile application A desktop application Other server applications Internet Server(s)
More informationBrief Introduction to Prolog
CSC384: Intro to Artificial Intelligence Brief Introduction to Prolog Prolog Programming for Artificial Intelligence by Ivan Bratko. Prolog is a language that is useful for doing symbolic and logic based
More informationUsing Prolog as a CAS
Using Prolog as a CAS Kharkiv Pedagogical University A. Stolyarevska July 2002 References 1) Robinson J.A. A machine-oriented logic based on the resolution principle. J. ACM, 12, 23-41. 2) Colmerauer A.
More informationLING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong Today's Topics SWI-Prolog installed? We will start to write grammars today Quick Homework 8 SWI Prolog Cheatsheet At the prompt?- 1. halt. 2. listing. listing(name).
More informationPROGRAMMING IN HASKELL. Chapter 2 - First Steps
PROGRAMMING IN HASKELL Chapter 2 - First Steps 0 Glasgow Haskell Compiler GHC is the leading implementation of Haskell, and comprises a compiler and interpreter; The interactive nature of the interpreter
More informationCOMP2411 Lecture 20: Logic Programming Examples. (This material not in the book)
COMP2411 Lecture 20: Logic Programming Examples (This material not in the book) There are several distinct but often equivalent ways to think about logic programs 1. As computing logical consequences of
More informationProgramming Paradigms
PP 2017/18 Unit 6 Prolog Basics 1/42 Programming Paradigms Unit 6 Prolog Basics J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2017/18 Unit 6 Prolog Basics 2/42 Outline
More informationLOGIC AND DISCRETE MATHEMATICS
LOGIC AND DISCRETE MATHEMATICS A Computer Science Perspective WINFRIED KARL GRASSMANN Department of Computer Science University of Saskatchewan JEAN-PAUL TREMBLAY Department of Computer Science University
More informationThe Idea Underlying Logic Programming. CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Logic Programming
The Idea Underlying CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Department of Computer Science and Engineering University of Minnesota Lectures in Fall
More informationDraw a diagram of an empty circular queue and describe it to the reader.
1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the
More informationProlog Introduction. Gunnar Gotshalks PI-1
Prolog Introduction PI-1 Physical Symbol System Hypothesis A physical symbol system has the necessary and sufficient means for general intelligent action. Allen Newell and Herbert A. Simon PI-2 Physical
More informationProlog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts
Prolog IFT 6802 Introduction to Prolog Par Jean Vaucher (& Laurent Magnin) A programming language based on the formalism and the concepts of formal logic. PROgrammation LOGique Robinson (resolution) Kowalski
More informationAn introduction to logic programming with Prolog
An introduction to logic programming with Prolog Dr. Constantinos Constantinides Department of Computer Science and Software Engineering Concordia University A running example: A family genealogy tree
More informationCS 360: Programming Language Concepts Lecture 15 Logic Programming
Reference: Ch. 12.1-12.5 CS 360: Programming Language Concepts Lecture 15 Logic Programming I. Logic Programming (Generally) What is logic programming? A logic program is a collection of declarations,
More informationChapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy
Topics Chapter 16 Logic Programming Summary (resolution, unification, Prolog search strategy ) Disjoint goals The cut operator Negative goals Predicate fail Debugger / tracer Lists 2 Resolution Resolution
More informationChapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation
Topics Chapter 16 Logic Programming Proving Theorems Resolution Instantiation and Unification Prolog Terms Clauses Inference Process Backtracking 2 Predicate Calculus and Proving Theorems A use of propositions
More informationRuby AN OVERVIEW. Luigi De Russis Dipartimento di Automatica e Informatica Politecnico di Torino
Ruby AN OVERVIEW Luigi De Russis Dipartimento di Automatica e Informatica Politecnico di Torino luigi.derussis@polito.it What is Ruby? Ruby is a dynamic, open source programming language with a focus on
More informationProgramming Languages 2nd edition Tucker and Noonan
Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does a dog have if you call its tail a leg? A: Four. Calling a tail a leg doesn t make it one. Abraham
More informationDay02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12
Day02 A Young W. Lim 2017-10-07 Sat Young W. Lim Day02 A 2017-10-07 Sat 1 / 12 Outline 1 Based on 2 Introduction (2) - Basic Elements Basic Elements in C Programming Young W. Lim Day02 A 2017-10-07 Sat
More informationR13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.
R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is
More informationWhat are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)).
What are Operators? - 1 Functors Introduce operators to improve the readability of programs Operators syntactic sugar Based on Clocksin & Mellish Sections 2.3, 5.5 O-1 O-2 The arithmetic expression:» x
More informationFundamentals of Prolog
Fundamentals of Prolog Prof. Geraint A. Wiggins Centre for Cognition, Computation and Culture Goldsmiths College, University of London Contents Summary of Lecture 1 What makes a good Prolog program? What
More informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationIntroduction Prolog Activity! Prolog. Dr. Mattox Beckman. University of Illinois at Urbana-Champaign Department of Computer Science
Prolog Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Outline Introduction Objectives Logic Prolog Prolog Queries Builtin Structures Activity! Activity Objectives
More informationTopic 1: Introduction to Knowledge- Based Systems (KBSs)
Topic 1: Introduction to Knowledge- Based Systems (KBSs) 1.5 Introduction to Logic Programming (Prolog) 32 Simple example: Algorithm for checking sorted list? We all know how to check if a list is sorted:
More informationHistory Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability
History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,
More informationIntroduction to Functional Programming and basic Lisp
Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to
More informationThe current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday.
The current topic: Prolog! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values Logic programming: Prolog! Introduction
More informationProlog. Logic Programming vs Prolog
Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming
More informationMIDTERM EXAM (Solutions)
MIDTERM EXAM (Solutions) Total Score: 100, Max. Score: 83, Min. Score: 26, Avg. Score: 57.3 1. (10 pts.) List all major categories of programming languages, outline their definitive characteristics and
More informationOperators (2A) Young Won Lim 10/2/13
Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationIntroduction to Prolog by
to Prolog by a talk given to The Linux Supporters Group Adelaide July 2009 Slide 1 Choice Points in Prolog Slide 2 Prolog s run-time stack does not function as procedural language stacks do. It isn t even
More informationCSE 452: Programming Languages. Prolog Statements. Loading the Knowledge Base. Logical Programming Languages Part 2
CSE 452: Programming Languages Logical Programming Languages Part 2 Prolog Statements Prolog statements consist of facts, rules, and queries. Example of facts (written as headless Horn clauses) male(tony).
More informationAnnouncements. The current topic: Prolog. Logic programming. Logic programming. Lab 2 has been marked.
The current topic: Prolog! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values Logic programming: Prolog Next up: Introduction
More informationLING/C SC/PSYC 438/538. Lecture 15 Sandiway Fong
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong Did you install SWI Prolog? SWI Prolog Cheatsheet At the prompt?- Everything typed at the 1. halt. prompt must end in a period. 2. listing. listing(name).
More informationResolution (14A) Young W. Lim 6/14/14
Copyright (c) 2013-2014. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free
More informationsimplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or
simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion simple and/or composition of goals hides complex control patterns not easily represented by traditional
More informationMAT 106: Trigonometry Brief Summary of Function Transformations
MAT 106: Trigonometry Brief Summary of Function Transformations The sections below are intended to provide a brief overview and summary of the various types of basic function transformations covered in
More informationPrototyping a Social Network. AngularJS: Firebase integration with AngularFire
Prototyping a Social Network AngularJS: Firebase integration with AngularFire Pizza++ 2 Pizza++ Feature Set Find top pizzas to eat near me Post pizzas Rate pizzas Review (comment) pizzas Discuss about
More informationDefining Binary & Unary Operators DO-1
Defining Binary & Unary Operators DO-1 English-French Dictionary 1 Can use compound terms to represent a dictionary» list is a structure that contains an entry followed by the rest of the list» For example
More informationMotivations. Luigi De Russis. Why Ruby (on Rails)?
Motivations Luigi De Russis 2 Disclaimer YES course-specific value open mind NO general value extremism 3 4 Course requirements Goal and context 5 Goal design and implement a Social Network site 6 credits
More informationCS A331 Programming Language Concepts
CS A331 Programming Language Concepts Lecture 10 Alternative Programming Languages (Functional LISP Declarative - PROLOG) March 24, 2014 Sam Siewert Functional PL Concepts Based on Lambda Calculus Output
More information10. Logic Programming With Prolog
Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000 10. Logic Programming With Overview Logic Programming Logic Programming Logic programming is a form of declarative programming A
More informationExercises on the Fundamentals of Prolog
1 Introduction Exercises on the Fundamentals of Prolog These exercises are intended to help reinforce material taught in the lectures of CIS335 course in Prolog. They do not contribute any marks to the
More information}Optimization Formalisms for recursive queries. Module 11: Optimization of Recursive Queries. Module Outline Datalog
Module 11: Optimization of Recursive Queries 11.1 Formalisms for recursive queries Examples for problems requiring recursion: Module Outline 11.1 Formalisms for recursive queries 11.2 Computing recursive
More informationSome material adapted from Upenn cmpe391 slides and other sources
Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationIntroduction to Android
Introduction to Android Ambient intelligence Alberto Monge Roffarello Politecnico di Torino, 2017/2018 Some slides and figures are taken from the Mobile Application Development (MAD) course Disclaimer
More information}Optimization. Module 11: Optimization of Recursive Queries. Module Outline
Module 11: Optimization of Recursive Queries Module Outline 11.1 Formalisms for recursive queries 11.2 Computing recursive queries 11.3 Partial transitive closures User Query Transformation & Optimization
More informationLogical reasoning systems
Logical reasoning systems Theorem provers and logic programming languages Production systems Frame systems and semantic networks Description logic systems CS 561, Session 19 1 Logical reasoning systems
More informationIntroduction and first application. Luigi De Russis. Rails 101
Introduction and first application Luigi De Russis 2 About Rails Ruby on Rails 3 Framework for making dynamic web applications created in 2003 Open Source (MIT License) for the Ruby programming language
More informationChapter 5. Pure PROLOG. Foundations of Logic Programming
Chapter 5 1 Outline vs. logic programming Lists in Adding Arithmetics to Adding the Cut to 2 Syntax of Pure Prolog p(x,a) :- q(x), r(x,yi). p(x, a) q(x), r(x,y i ) % Comment Ambivalent syntax: p(p(a,b),
More informationOperators (2A) Young Won Lim 10/5/13
Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationFirst-Order Logic (FOL)
First-Order Logic (FOL) FOL consists of the following parts: Objects/terms Quantified variables Predicates Logical connectives Implication Objects/Terms FOL is a formal system that allows us to reason
More informationGAS Tutorial - 6. Expression
GAS Tutorial - 6. Expression Young W. Lim 2016-03-03 Wed Young W. Lim GAS Tutorial - 6. Expression 2016-03-03 Wed 1 / 15 Outline 1 Expressions Young W. Lim GAS Tutorial - 6. Expression 2016-03-03 Wed 2
More informationLecture Notes on Prolog
Lecture Notes on Prolog 15-317: Constructive Logic Frank Pfenning Lecture 15 October 24, 2017 1 Introduction Prolog is the first and still standard backward-chaining logic programming language. While it
More informationDatabases in Python. MySQL, SQLite. Accessing persistent storage (Relational databases) from Python code
Databases in Python MySQL, SQLite Accessing persistent storage (Relational databases) from Python code Goal Making some data 'persistent' When application restarts When computer restarts Manage big amounts
More informationCS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College. Scheme
CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College 1 Scheme Overview Scheme Scheme is a block-structured, lexically-scoped, properly tail-recursive dialect of Lisp
More informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional
More information15-122: Principles of Imperative Computation
15-122: Principles of Imperative Computation Lab 0 Navigating your account in Linux Tom Cortina, Rob Simmons Unlike typical graphical interfaces for operating systems, here you are entering commands directly
More informationzebra puzzle continued recap Prolog concepts family relations
zebra puzzle continued recap Prolog concepts family relations 1 recapping the Zebra puzzle 2 ****** the facts ****** There are 5 houses, occupied by politicallyincorrect gentlemen of 5 different nationalities,
More informationA language is a subset of the set of all strings over some alphabet. string: a sequence of symbols alphabet: a set of symbols
The current topic:! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values! Logic programming: Prolog! Introduction! Rules,
More informationPROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions
PROGRAMMING IN HASKELL CS-205 - Chapter 6 - Recursive Functions 0 Introduction As we have seen, many functions can naturally be defined in terms of other functions. factorial :: Int Int factorial n product
More informationReferences. Topic #16: Logic Programming. Motivation. What is a program? Prolog Program Structure
References Topic #16: Logic Programming CSE 413, Autumn 2004 Programming Languages Slides from CSE 341 S. Tanimoto See Chapter 16 of the text Read 16.1, 16.4, 16.5, 16.6 (skip 16.6.7) Skim 16.7, 16.8 http://www.cs.washington.edu/education/courses/413/04au/
More informationProlog. ATutorialIntroduction. James Lu Jerud J. Mead. Computer Science Department Bucknell University Lewisburg, PA 17387
Prolog ATutorialIntroduction James Lu Jerud J. Mead Computer Science Department Bucknell University Lewisburg, PA 17387 1 Contents 1 Introduction 1 2 Easing into Prolog 2 2.1 Logic Programming.........................................
More informationCMSC 331 Final Exam Section 0201 December 18, 2000
CMSC 331 Final Exam Section 0201 December 18, 2000 Name: Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for
More informationLecture 16: Logic Programming in Prolog
Lecture 16: Logic Programming in Prolog COMP 524 Programming Language Concepts Stephen Olivier March 26, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of
More informationWhat is Prolog? - 1. A Prolog Tutorial. What is Prolog? - 2. Prolog Programming. » Declaring some facts about objects and their relationships
What is Prolog? - 1 Prolog is an example of a logic programming language Invented by Alain Colmeraurer in 1972 A Prolog Tutorial Based on Clocksin and Mellish Chapter 1 The version implemented at the University
More informationImplementação de Linguagens 2016/2017
Implementação de Linguagens Ricardo Rocha DCC-FCUP, Universidade do Porto ricroc @ dcc.fc.up.pt Ricardo Rocha DCC-FCUP 1 Logic Programming Logic programming languages, together with functional programming
More informationProgramming Language Concepts, cs2104 Lecture 01 ( )
Programming Language Concepts, cs2104 Lecture 01 (2003-08-15) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2002-08-15 S. Haridi, CS2104, L01 (slides: C. Schulte, S. Haridi) 1
More informationLearning Rules. Learning Rules from Decision Trees
Learning Rules In learning rules, we are interested in learning rules of the form: if A 1 A 2... then C where A 1, A 2,... are the preconditions/constraints/body/ antecedents of the rule and C is the postcondition/head/
More informationProgramming Paradigms
PP 2017/18 Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut 1/38 Programming Paradigms Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut J. Gamper Free University of Bozen-Bolzano
More informationCILOG User Manual Version 0.14
CILOG User Manual Version 0.14 David Poole Department of Computer Science, University of British Columbia, Vancouver, B.C. Canada V6T 1Z4 Email: poole@cs.ubc.ca URL: http://www.cs.ubc.ca/spider/poole November
More information