1 Prolog’s Lists, Negation and Imperative Control Flow COMP 144 Programming Language Concepts Spring 2003 The University of North Carolina at Chapel Hill.

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.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
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).
INTRODUCTION TO PROLOG. PROLOG BASICS Atoms - most primitive terms that the language manipulates start with lower case letter includes strings (‘inside.
1 Logic Programming with Prolog: Resolution, Unification, Backtracking COMP 144 Programming Language Concepts Spring 2003 Stotts, Hernandez-Campos Modified.
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/
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
Programming Languages Third Edition
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 26: Introduction to Logic Programming with Prolog COMP 144 Programming Language.
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.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Logic Programming Languages
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
CS 321 Programming Languages and Compilers Prolog part 2.
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.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Introduction to Logic Programming with Prolog (Section 11.3)
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.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
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.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Programming Languages Third Edition Chapter 4 Logic Programming.
CS 152: Programming Language Paradigms March 5 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
1 CS Programming Languages Class 19 November 2, 2000.
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
For Friday No reading Prolog Handout 2. Homework.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
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”
1 Announcements We are almost done grading HW1 HW2 due today Download SWI Prolog! HW3 (Prolog) will be posted today, due on February 29 th Spring 16 CSCI.
Announcements Rainbow grades up HW1, Quiz 1-2 in HW Server Deadline for HW3 (Prolog) is extended to Monday, March 7 th. Submit in HW Server A few notes.
C. Varela1 Logic Programming (PLP 11, CTM 9.3) Prolog Imperative Control Flow: Backtracking, Cut, Fail, Not Lists, Append Carlos Varela Rennselaer Polytechnic.
Logic Programming Lecture 2: Unification and proof search.
Copyright © 2009 Elsevier Chapter 11 :: Logic Languages And other online sources (see links on schedule page) Michael L. Scott Based on Programming Language.
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.
Recursive stack-based version of Back-chaining using Propositional Logic
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
CS 3304 Comparative Languages
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 14, 2017
Logic Programming with Prolog: Resolution, Unification, Backtracking
Chapter 11 :: Logic Languages
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Prolog Concepts.
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Chapter 12 :: Logic Languages
Presentation transcript:

1 Prolog’s Lists, Negation and Imperative Control Flow COMP 144 Programming Language Concepts Spring 2003 The University of North Carolina at Chapel Hill Stotts, Hernandez-Campos Modified by Charles Ling for CS2209b, UWO Use with Permission

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 Cut causes the unification stack to be frozen…Cut causes the unification stack to be frozen…

10 Cut and the stack… Cut and the stack… (a) P: rochester (c) Y: tandoori (b) Z: blue K: 147 New stack base for backtracking Cut !

11 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.

12 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))

13 Backward Chaining in Prolog Backward chaining follows a classic depth-first backtracking algorithmBackward chaining follows a classic depth-first backtracking algorithm ExampleExample –Goal: Snowy(C) Snowy(C)

14 Infinite Regression Goal

15 Reading Assignment ReadRead –Rest of Scott Sect Guide to Prolog Example, Roman BartákGuide to Prolog Example, Roman Barták –Go through all the examples –