Comp 307: Artificial Intelligence Lecture 3:1 COMP307 Assignment 1 is handed out. Tutorial this week: – Prolog: lists – Help with Q1, Q2.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.
Formal Models of Computation Part II The Logic Model
8 Queens. Problem: Placing 8 queens on a chessboard such that they don’t attack each other Three different Prolog programs are suggessted as solutions.
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Chapter Three: Lists, Operators, Arithmetic 1. Chapter three: 3.1Representation of lists 3.2Some operations on lists 2.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Logic Programming Chapter 15 Part 2. Prolog Lists The list is Prolog’s basic data structure Lists are a series of Prolog terms, separated by commas Each.
1 COMP313A Programming Languages Logic Programming (3)
Prolog Programming for Artificial Intelligence Three edition 2001
1 Prolog III. 2 Lists [ ] is the empty list. [x, 2+2, [a, b, c]] is a list of three elements. The first element in the list is its “head”. The list with.
Comp 307 Lecture 4:1 Prolog I, II Prolog was taught as a procedural language Control structures: if, while, recursion Data structures: structured terms,
Lecture 8 of Computer Science II Recursions Instructor: Mr.Ahmed Al Astal.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
Comp. Eng. II: Intro. to Prolog1 CoE Software Lab II (2SBo6) , Semester 2, Who I am: Andrew Davison WiG Lab Office
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.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
CIA2326 Week3: Prolog: List Processing Lee McCluskey First term:
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
Python Tutorial Lecture for EE562 Artificial Intelligence for Engineers 1.
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.
LANGUAGE TRANSLATORS: WEEK 3 LECTURE: Grammar Theory Introduction to Parsing Parser - Generators TUTORIAL: Questions on grammar theory WEEKLY WORK: Read.
Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, = 3, so 3 is an odd positive integer.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
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 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
MB: 5 March 2001CS360 Lecture 41 Programming in Logic: Prolog Lists and List Operations Readings: Sections 3.1 & 3.2.
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
Full Logic Programming. Data structures Pure LP allows only to represent relations (=predicates) To obtain full LP we will add functors (=function symbols)
COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705) x2316
COMP307 Artificial Intelligence Xiaoying Gao Victoria University of Wellington Lecture 2:1 
Lists in Prolog Sections 3.1, 3.2. Lists n List = sequence of values –[1, 2, 3, 4, 5] –[bob, brian, cathy, mark, david, loretta] –[birds(4, calling),
Lisp "List Processing". Lisp history John McCarthy developed the basics behind Lisp during the 1956 Dartmouth Summer Research Project on Artificial Intelligence.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
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.
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
LISP LISt Processing. History & Overview b b One of the oldest high level programming languages. b b First developed in 1958 by John McCarthy. b b Later.
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Section 16.5, 16.6 plus other references
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
CS 326 Programming Languages, Concepts and Implementation
Tutorial Lecture for EE562 Artificial Intelligence for Engineers
LISP LISt Processing.
Acc 290 Education on your terms/tutorialrank.com.
الخطوة الثالثة الاختيار.
Prolog Lists.
Prolog Lists.
Recursion, Higher-order-functions
LISP LISt Processing.
LISP LISt Processing.
Prolog III Lists 8-Jul-19.
Presentation transcript:

Comp 307: Artificial Intelligence Lecture 3:1 COMP307 Assignment 1 is handed out. Tutorial this week: – Prolog: lists – Help with Q1, Q2

Prolog Materials SWI-Prolog Manual: 2.1, 2.5, … edit a file using emacs or other editor: myfile.pl command line “prolog” or “swi-prolog” (or use it in emacs see 2.5) load a file and compile ?-[myfile]. Learning Prolog online course Prolog books: The Art of Prolog (Sterling), Prolog by Example (Helder Coelho, Jose C. Cotta) Prolog programming for Artificial Intelligence (Ivan Bratko) Comp 307: Artificial Intelligence Lecture 3:2

Comp 307: Artificial IntelligenceLecture 2:3 Recursion in Prolog factorial(0, 1):-!. factorial(N, X):- N1 is N-1, factorial(N1, X1), X is N * X1. |?-factorial(4, X). X=24. Base case: do something Normal case: change the arguments call the same clause using different arguments do one step

Comp 307: Artificial Intelligence Lecture 3:4 Prolog (II) Data Structures – Structure – List

Comp 307: Artificial Intelligence Lecture 3:5 Data Objects Simple Objects Structures ConstantsVariables Atoms Numbers

Comp 307: Artificial Intelligence Lecture 3:6 Structured terms (Structured Objects) person(john, smith, date_birth(1, may, 1968)). course(comp307, lectures(hm104, sharon)). picture(rectangle(10, 20)). picture(rectangle(width(10), height(20))). picture(rectangle(top_left(100, 100), 10, 20)). Structure: functor(components) components can be other structures Structured terms can be used to represent objects, trees, and other data structures.

Comp 307: Artificial Intelligence Lecture 3:7 List examples names(comp307, [john, mary, helen]). seat_plan(comp307, [[john, mary, helen], [jim, tim]]). marks([80.5, 90, 95]). marks([john, 80], [mary, 90], [helen, 95]). list_example([1, 2, 3, a, b, [c, d]]). list_example([ ]) picture([rectangle(top_left(100, 100), 10, 20), circle(center(10, 10), 50)]).

Comp 307: Artificial Intelligence Lecture 3:8 List List is a sequence of any numbers of terms. List is a special structure.(Head, Tail) [a, b, c, d].(a, [b, c, d]).(a,.(b,.(c,.(d, [ ])))) The length of the list is not fixed Sequential access only Can only add/delete elements to/from the beginning of a list The elements of the list – can be anything (even other lists), – can be different type

Comp 307: Artificial Intelligence Lecture 3:9 [Head|Tail] [Head|Tail].(Head, Tail) Head is the first element of the list, Tail is the rest of the list (Tail is a list itself). [Head|Tail] [a, b, c] Head=a, Tail=[b, c] [Head|Tail] [b,c] Head=b, Tail=[c] [Head|Tail] [c] Head=c, Tail=[] [Head|Tail] [ ] do not match [Head] [e] Head =e [Head] [ ] do not match

Comp 307: Artificial Intelligence Lecture 3:10 Tail recursion to handle lists |?-print_list([a, b, c]). print_list([]). print_list([H|T]):- write(H), print_list(T).

Comp 307: Artificial Intelligence Lecture 3:11 Tail Recursion to handle lists ?- member(1, [1, 2, 3]). ?- member(3, [1, 2, 3]). member(X,[X|_]). member(X,[_|Tail]) :- member(X,Tail).

Comp 307: Artificial Intelligence Lecture 3:12 Using list to collect result: tail recursion (U-bend) |?-list_scaleup1([40, 60, 80], X). list_scaleup1(L, LL):- new_list_scaleup1(L, [], LL). new_list_scaleup1([], L, L). new_list_scaleup1([H|T], L, LL):- HH is H+10, new_list_scaleup1(T, [HH|L], LL).

Comp 307: Artificial Intelligence Lecture 3:13 Using list to collect result: Tail recursion (U-bend) % intersection1(+Xs, +Ys, -FinalRes) intersection1(Xs, Ys, Zs) :- new_intersection1(Xs, Ys, [], Zs). new_intersection1([], _, Zs, Zs). new_intersection1([X|Xs], Ys, Z1s, Z2s) :- member(X, Ys), new_intersection1(Xs, Ys, [X|Z1s], Z2s). new_intersection1([X|Xs], Ys, Z1s, Z2s) :- \+member(X, Ys), new_intersection1(Xs, Ys, Z1s, Z2s).

Comp 307: Artificial Intelligence Lecture 3:14 Recursion and lists |?-list_length([a, b, c], X). list_length([], 0). list_length([Head|Tail], X):- list_length(Tail, X1), X is X1 +1.

Comp 307: Artificial Intelligence Lecture 3:15 Using List to collect results: recursion (rope-ladder) |?-list_scaleup([40, 60, 80], X). list_scaleup([], []). list_scaleup([H|T], L):- list_scaleup(T, TT), HH is H+10, L=[HH|TT]. list_scaleup([], []). list_scaleup([H|T], [HH|TT]):- HH is H+10, list_scaleup(T, TT).

Comp 307: Artificial Intelligence Lecture 3:16 Using List to collect results: recursion (rope-ladder) |?-intersection([a, b, c], [b, c, d], X). % intersection(+Xs, +Ys, -Result) intersection([], _, []). intersection([X|Xs], Ys, [X|Zs]) :- member(X, Ys), !, intersection(Xs, Ys, Zs). intersection([X|Xs], Ys, Zs) :- \+ member(X, Ys), intersection(Xs, Ys, Zs).