Chapter Three: Lists, Operators, Arithmetic CS 461.

Slides:



Advertisements
Similar presentations
Part 1 The Prolog Language Chapter 3 Lists, Operators, Arithmetic
Advertisements

3. Lists, Operators, Arithmetic. Contents Representation of lists Some operations on lists Operator notation Arithmetic.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
Chapter Three: Lists, Operators, Arithmetic 1. Chapter three: 3.1Representation of lists 3.2Some operations on lists 2.
Line Efficiency     Percentage Month Today’s Date
Unit Number Oct 2011 Nov 2011 Dec 2011 Jan 2012 Feb 2012 Mar 2012 Apr 2012 May 2012 Jun 2012 Jul 2012 Aug 2012 Sep (3/4 Unit) 7 8 Units.
Chapter Three: Lists, Operators, Arithmetic 1. © Patrick Blackburn, Johan Bos & Kristina Striegnitz Important things about lists  List elements are enclosed.
ProjectImpactResourcesDeadlineResourcesDeadline Forecast Plan Time Resources Risk 001xx 002xx 003xx 004xx 005xx 006xx 007xx TotalXX Example 1: Portfolio.
Gantt Chart of Progress FY
Windows Server 2008 R2 Oct 2009 Windows Server 2003
Jan 2016 Solar Lunar Data.

Analyzing patterns in the phenomena
Q1 Jan Feb Mar ENTER TEXT HERE Notes
Jul Aug Sept Oct Nov Dec Jan Feb Mar Apr May Jun

Project timeline # 3 Step # 3 is about x, y and z # 2
Average Monthly Temperature and Rainfall
2017 Safety Group 1 – 5 Year Program Timeline Guide


Mammoth Caves National Park, Kentucky
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Timeline PowerPoint Template

2013 VFC PRESIDENT’S REPORT
Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
Jul Aug Sept Oct Nov Dec Jan Feb Mar Apr May Jun
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Gantt Chart of Progress FY
Free PPT Diagrams : ALLPPT.com


Wireless Local Number Portability Timeline - Phase 2
Step 3 Step 2 Step 1 Put your text here Put your text here
Calendar Year 2009 Insure Oklahoma Total & Projected Enrollment
MONTH CYCLE BEGINS CYCLE ENDS DUE TO FINANCE JUL /2/2015
Jan Sun Mon Tue Wed Thu Fri Sat
2019 Safety Group 1 – 5 Year Program Timeline Guide

©G Dear 2008 – Not to be sold/Free to use
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ITEM 1 ITEM 2 ITEM 3
Electricity Cost and Use – FY 2016 and FY 2017

SC SC SC WS SC S HIS Background document Seminar document
Unemployment in Today’s Economy
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com


Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
2016 Safety Group 1 – 5 Year Program Timeline Guide
Text for section 1 1 Text for section 2 2 Text for section 3 3
Project timeline # 3 Step # 3 is about x, y and z # 2
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
Rev. 2 Wireless Local Number Portability and Pooling Phase 2 Implementation Guideline INDUSTRY 2002 SERVICE PROVIDER JAN FEB MAR APR MAY JUN JUL AUG SEP.
2012 Safety Group 1 – 5 Year Program Timeline Guide
Wireless Local Number Portability Timeline - Phase 2

Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Pilot of revised survey
Rev. 2 Wireless Local Number Portability and Pooling Phase 2 Implementation Guideline INDUSTRY 2002 SERVICE PROVIDER JAN FEB MAR APR MAY JUN JUL AUG SEP.
Presentation transcript:

Chapter Three: Lists, Operators, Arithmetic CS 461

3.2 Some operations on lists 1.Concatenation 2.Adding an item 3.Deleting an item

Concatenation conc(L1,L2,L3) L1 and L2 are two lists and L3 is their concatenation. conc([a,b],[c,d],[a,b,c,d]) True conc([a,b],[c,d],[a,b,a,c,d]) False

Concatenation (cont.) Definition of conc: empty (1)If the first argument is empty, then the second and third arguments must be the same list conc([],L,L). non-empty list (2)If the first argument of conc is non-empty list, then it has a head and tail and must look like this [X|L1] the result of concatenation of L1 and L2 is the list [X|L3] where L3 is the concatenation of L1 and L2 conc([X|L1],L2,[X|L3]):- conc(L1,L2,L3).

5 2. Concatenation (Example) conc([],L,L). conc([X|L1],L2,[X|L3]):- conc(L1,L2,L3). ?- conc([a,b,c],[1,2,3],L) L= [a,b,c,1,2,3] ?-conc([a,[b,c],d],[a,[],b],L) L = [a, [b, c], d, a, [], b].

6 2. Concatenation (Example) conc([],L,L). conc([X|L1],L2,[X|L3]):- conc(L1,L2,L3). ?- conc(L1,L2,[a,b,c]) (decompose) L1 = [], L2 = [a, b, c] ; L1 = [a], L2 = [b, c] ; L1 = [a, b], L2 = [c] ; L1 = [a, b, c], L2 = [] ;

7 2. Concatenation (Example) conc([],L,L). conc([X|L1],L2,[X|L3]):- conc(L1,L2,L3). ?-conc(Before,[may|After], [jan,feb,mar,apr,may,jun,jul,aug,sep,oct,n ov,dec]). Before = [jan, feb, mar, apr], After = [jun, jul, aug, sep, oct, nov, dec] How can we find the months that precedes and follows a given month in a list ?

Class exercise (1) conc([],L,L). conc([X|L1],L2,[X|L3]):- conc(L1,L2,L3). Write a goal, using conc, to delete the last three elements from the list L producing another list L1. HINT : L is a concatenating of L1 and another three elements list

Answer: ?- L = [1,2,3,4,5], conc(L1,[_,_,_],L). L = [1, 2, 3, 4, 5], L1 = [1, 2]

10 Concatenation Definition of member using conc: We can program the membership relation using conc: member1(X,L):- conc(L1,[X|L2],L). X is a member of list L if L can be decopmosed into two lists so that the second one has X as its head. member1(X,L):- conc(_,[X|_],L). member1(X,L):- conc(L1,[X|L2],L). member1(X,L):- conc(_,[X|_],L). ?- member1( b,[a,b,c]).

11 Adding an item Simply to put an item in front of a list: [X|L] Definition of add: The procedure can be written explicitly as the fact: add(X,L,[X,L]). Example ?-add(z,[a,b,c],NewList).

Delete an item Deleting an item X from list L, can be programmed as a relation: Del(X,L,L1). Where L1 is equal to L with the item X removed.

Delete an item The del definition : We have two cases : 1)If X is the head of the list, then the result after deletion will be the tail of the list. del(X,[X|Tail], Tail). 2) If X is in the tail then it is deleted from there: del(X,[X|Tail], Tail). del(X, [Y|Tail], Tail1) :- del(X, Tail, Tail1).

14 2. Deletion (Example) del(X,[X|Tail], Tail). del(X, [Y|Tail], Tail1) :- del(X, Tail, Tail1). ?- del(a,[a,b,a,a],L). L = [b, a, a] ; L = [a] ; L = [] ;