1 Lecture 16: Prolog’s Lists, Negation and Imperative Control Flow (Section 11.3) CSCI 431 Programming Languages Fall 2002 A modification of slides developed.

Slides:



Advertisements
Similar presentations
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10: Cuts and Negation Theory –Explain how to control Prolog`s backtracking behaviour with.
Advertisements

Chapter 11 :: Logic Languages
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Declarative Programming Lists in PROLOG Autumn 2014.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
1 Prolog’s Lists, Negation and Imperative Control Flow COMP 144 Programming Language Concepts Spring 2003 The University of North Carolina at Chapel Hill.
Side effects in Prolog Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
C. Varela1 Logic Programming (PLP 11.3) Prolog Imperative Control Flow: Backtracking Cut, Fail, Not Carlos Varela Rennselaer Polytechnic Institute September.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lists, Operators, Arithmetic Notes for Ch.3 of Bratko For CSCE 580 Sp03 Marco.
Prolog Ross (Tate). Filling in the Blanks Rather than reverse((a,b)) returns (b,a) Rather than reverse((a,b)) returns (b,a) What X makes reverse((a,b),
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 28: Prolog’s Lists, Negation and Imperative Control Flow COMP 144 Programming Language.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
1 Lecture 11: Semantic Analysis (Section ) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos.
Formal Models of Computation Part II The Logic Model
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
Introduction to Logic Programming with Prolog (Section 11.3)
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Prolog Programming. 2 DATA STRUCTURES IN PROLOG PROGRAMMING TECHNIQUES CONTROL IN PROLOG CUTS.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
1 Lecture 5: Syntax Analysis (Section 2.2) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos at UNC.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
CS 603: Programming Languages Lecture 25 Spring 2004 Department of Computer Science University of Alabama Joel Jones.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
CS 403: Programming Languages Lecture 18 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
C H A P T E R N I N E Logic Programming Part 2 Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
C. Varela1 Logic Programming (PLP 11, CTM 9.3) Prolog Imperative Control Flow: Backtracking, Cut, Fail, Not Lists, Append Carlos Varela Rennselaer Polytechnic.
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
Copyright © 2009 Elsevier Chapter 11 :: Logic Languages And other online sources (see links on schedule page) Michael L. Scott Based on Programming Language.
Prolog Programming.
Chapter 12 :: Logic Languages
Recursive stack-based version of Back-chaining using Propositional Logic
Prolog Concepts.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Carlos Varela Rensselaer Polytechnic Institute November 17, 2017
Carlos Varela Rensselaer Polytechnic Institute November 28, 2017
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Chapter 11 :: Logic Languages
CS 3304 Comparative Languages
Prolog Lists.
Prolog Programming (Volume 2)
Chapter 12 :: Logic Languages
Chapter 3: Prolog (Lists, Arithmetic, Operators)
Chapter 12 :: Logic Languages
Prolog Lists.
Programming Techniques
Carlos Varela Rennselaer Polytechnic Institute November 22, 2016
Programming Languages 2nd edition Tucker and Noonan
Prolog Concepts.
Prolog Based on: Chapter 12 of PLP “Seven languages in seven weeks”
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Chapter 12 :: Logic Languages
Presentation transcript:

1 Lecture 16: Prolog’s Lists, Negation and Imperative Control Flow (Section 11.3) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill

2 Lists ConstructorsConstructors –[] Empty list constant –. Constructor functor ExampleExample –.(a,.(b,.(c, []))) –[a, b, c] (syntactic sugar) Tail notation:Tail notation: –[a | [b, c]] –[a, b | [c]] Head::a Tail::[a]

3 Lists Examples No notion of input or output parameters

4 Tic-Tac-Toe Example 3x3 grid3x3 grid Two Players:Two Players: –X (computer) –O (human) Fact x(n) indicates a movement by XFact x(n) indicates a movement by X –E.g. x(5), x(9) Fact o(n) indicates a movement by OFact o(n) indicates a movement by O –E.g. o(1), o(6)

5 Tic-Tac-Toe Example Winning conditionWinning condition

6 Tic-Tac-Toe Example Strategy: good moves Ordered List of Choices     

7 Tic-Tac-Toe Example       Winning Split X

8 Imperative Control Flow The cut Prolog has a number of explicit control flow featuresProlog has a number of explicit control flow features ! Known as the cut! Known as the cut –This is a zero-argument predicate that always succeeds –It commits the interpreter to the unification made between the parent goal and the left-hand side of the current rules ExampleExample member(X, [X|T]). member(X, [H|T]) :- member(X, T). member(X, [X|T]) :- !. member(X, [H|T]) :- member(X, T). member may succeed n times member may succeed at most one time If this rule succeeded, do not try to use the following ones

9 Imperative Control Flow AlternativeAlternative member(X, [X|T]). member(X, [H|T]) :- not(X=H), member(X, T). How does not work?How does not work? not(P) :- call(P), !, fail. not(P). –call attempts to satisfy the goal P. –fail always fails.

10 Prolog Database Manipulation Two built-in predicates can be used to modify the database of known factsTwo built-in predicates can be used to modify the database of known facts assert(P) adds a new fact.assert(P) adds a new fact. –E.g. assert(parent(kevin, john)) retract(P) removes a known fact.retract(P) removes a known fact. –E.g. retract(parent(kevin, john))