[a,b,c,d] 15/9/2013. [a,b,c,d] List. List. List. List is one of the most important Prolog data structures.
|
|
- Alexander Phillips
- 6 years ago
- Views:
Transcription
1 is one of the most important Prolog data structures. A list is an ordered sequence of zero or more terms written between square brackets and separated by commas. [a,b,c,d] September 1 st Session 2013/2014 (A131) Wan Hussain Wan Ishak School of Computing UUMCollege of Arts and Sciences Universiti Utara Malaysia (P) (F) (E) hussain@uum.edu.my (U) Lecture notes, Operators and Arithmetic Arithmetic Constructing Expressions Processing Character Strings and Structures [a,b,c,d] Elements The elements of a list can be any kind of Prolog terms, including other lists. [1,2,3,4] [a1,a2,a3] [sawi, kangkung] [kucing(comel), kucing(hitam)] [[satu,dua],[tiga,empat]] 1
2 The empty list is written: [] Please note one element list [a] is not equivalent to the atom a.? [a]=a. no The list can be divided into head and tail by the symbol. [H T] Thefirstelementistheheadandtherestarethetail. [a [b,c,d,e]] can be constructed or decomposed through unification. Unify with [a,b,c] = X [X,b,Z] = [a,y,c] [[a,b],c] = [X,Y] Result X = [a,b,c] X = a, Y = b, Z = c X = [a,b], Y = c [a(b),c(x)] = [Z,c(a)] X = a, Z = a(b) [a [b,c,d,e]] The tail of a list is always a list, the head of a list is an element. Everynonemptylisthasaheadandatail. [a,b,c,d] =[a [b,c,d]] [a]=[a []] More examples Built-in predicates Unify with Result [X Y] = [a,b,c,d] X = a, Y = [b,c,d] [X Y] = [a] X = a, Y = [] [X,Y Z] = [a,b,c] X = a, Y = b, Z = [c] [X,Y,Z A] = [a,b,c] X = a, Y = b, Z = c, A = [] [X,Y Z] = [a W] X = a, W = [Y Z] Predicate append/3 length/2 member/2 member/3 remove/3 removeall/3 reverse/2 Function join or split lists get the length of a Prolog list get or check a member of a list get or check a member of a list and its position remove an element from a list remove all occurrences of an item from a list check or get the reverse of a list 2
3 append/3 append(first, Second, Whole) member/3 member(element,, Position) Join list Splitting list?-append([a,b],[c,d],whole). Whole =[a,b,c,d]?-append([a,b],second,[a,b,c,d]). Second =[c,d]?-append(first,[c,d],[a,b,c,d]). First =[a,b] Element position Get Element at given position?- member(c, [a,b,c,d], Position). Position=3;?- member(element, [a,b,c,d], 2). Element=b length/2 member/3(more example): length(term, Length)?- length([a,b,c,d], Length). Length=4 Get the element and its position?- member(element, [a,b,c,d], Position). Element =a, Position = 1; Element =b, Position = 2; Element =c, Position = 3; Element =d, Position = 4; member/2 remove/3?-member(a, [a,b,c,d]). remove(element,, Remainder) member(element, )?- member(element, [a,b,c,d]). Element = a ; Element = b ; Element = c ; Element = d ; Takeout an element Element missing?????- remove(b,[a,b,c,d], Remainder). Remainder =[a,c,d];?- remove(element,[a,b,c,d],[a,b,d]). Element=c; 3
4 remove/3(more example): Reverse/2?- remove(element, [a,b,c,d], Remainder). Element=a, Remainder =[b,c,d]; Element=b, Remainder =[a,c,d]; Element=c, Remainder =[a,b,d]; Element=d, Remainder =[a,b,c]; What element can be removed Reverse the list Causes error reverse(, Revlist)?- reverse([a,b,c,d], Revlist). Revlist =[d,c,b,a]?- reverse(, [d,c,b,a]). =[a,b,c,d] ; Error 4, Heap Space Full, Trying ewrite/1 removeall/3 - Exercise What is the output? removeall(item,, Remainder)?-append([ab],[b,c,d], X).?-reverse([b,c,d],R),append([ab],R,X).?- reverse([b,c,d], R), member(f, R, 1), remove(f, R, B), append([ab], B, X). removeall/3 (Example): Remove all repeated elements Remove all elements that match with the first element?- removeall(a, [a,b,a,b,a], Remainder). Remainder =[b,b]?- removeall(item, [a,b,a,b,a], Remainder). Item =a, Remainder =[b,b]?- removeall(item, [b,a,b,a], Remainder). Item =b, Remainder =[a,a] append/3 length/2 member/2 member/3 remove/3 removeall/3 reverse/2 How to define or construct the predicates? How they are working/how they manipulate the list? 4
5 append/3 addon/3 addon(first, Second, Whole) Definition: addon([],x,x). addon([h T1],X,[H T2]):- addon(t1,x,t2). stoptherecursion addelement into thelist 3 append/3 addon/3 From 2, (2.1) addon([],[c],t2). Call (1) addon([],x,x). true []=] Stop at 3 rule (1). Rule (2) will not execute. (1) addon([],x,x). addon/3 (2) addon([h T1],X,[H T2]):- (2.1) addon(t1, X, T2). X=[c] append/3 addon/3?-addon([a,b],[c],w). (1) addon([],x,x). addon/3 (2) addon([h T1],X,[H T2]):- (2.1) addon(t1, X, T2).?- addon([a,b],[c],w). W =[a,b,c] 1 (2) addon([a [b]],[c],[a T2]):- (2.1) addon([b],[c],t2). [a [b,c]] T2 = [b,c] (1) addon([],x,x). addon/3 (2) addon ([H T1],X,[H T2]):- (2.1) addon (T1, X, T2). 1 Call (1) addon([],x,x). Call (2) addon([h T1],X,[H T2]). Call (2.1) addon(t1,x,t2). false [a,b]\=[] addon([b],[c],t2). go to 2 true [a,b]=[h T1] [c]=x W=[H T2] H=a T1=[b] X=[c] W=[a T2] T2=_ 2 (2) (2.1) 3 (1) addon([b []],[c],[b T2]):- addon([],[c],t2). addon([],[c],[c]). [b [c]] T2 = [c] append/3 addon/3 From 1, (2.1) addon([b],[c],t2). (1) addon([],x,x). addon/3 (2) addon([h T1],X,[H T2]):- (2.1) addon(t1, X, T2). length/2 noofterms/2 noofterms(term, Length) Call (1) addon([],x,x). false [b]\=[] 2 Call (2) addon([h T1],X,[H T2]). true [b]=[h T1] H=b [c]=x T1=[] W=[H T2] X=[c] Call (2.1) addon(t1,x,t2). W=[b T2] T2=_ addon([],[c],t2). go to 3 Definition: noofterms([],0). noofterms([h Tail],K):- noofterms(tail,j), KisJ+1. stoptherecursion calculatethelength 5
6 length/2 noofterms/2 noofterms/2 (1) noofterms([],0). length/2 noofterms/2 noofterms/2 (1) noofterms([],0). 1?-noOfTerms([a,b,c],T). Call (1) noofterms([],0). Call (2) noofterms([h Tail],K). Call (2.1) noofterms(tail,j). (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), false [a,b,c]\=[] true [a,b,c]=[h Tail] T=K H=a Tail=[b,c] T=K=_ 4 From 3, (2.1) noofterms([],j). Call (1) noofterms([],0). true []=[] J=0 (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), Prologwill now return to 3 to execute 2.2. Followed by 2 and 1. noofterms([b,c],j). go to 2 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.) 2 length/2 noofterms/2 From 1, (2.1) noofterms([b,c],j). Call (1) noofterms([],0). Call (2) noofterms([h Tail],K). Call (2.1) noofterms(tail,j). (1) noofterms([],0). noofterms/2 (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), false [b,c]\=[] true [b,c]=[h Tail] J=K noofterms([c],j). go to 3 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.) H=b Tail=[c] J=K=_? - noofterms([a,b,c],t). 1 (2) noofterms([a [b,c]],k):- K=3 (2.1) noofterms([b,c],j), J=2 (2.2) 2 K is J + 1. (2) noofterms([b [c]],k):- K=2 (2.1) noofterms([c],j), J=1 (2.2) 3 K is J + 1. (2) noofterms([c []],K):- (2.1) noofterms([],j), (2.2) 4 K (1) is J noofterms([],0) (2.2) K is J + 1. K is K is (1) noofterms([],0). noofterms/2 (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), K=1 J=0 In console T = 3 K is length/2 noofterms/2 From 2, (2.1) noofterms([c],j). Call (1) noofterms([],0). Call (2) noofterms([h Tail],K). Call (2.1) noofterms(tail,j). (1) noofterms([],0). noofterms/2 (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), false [c]\=[] true [c]=[h Tail] J=K noofterms([],j). go to 4 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.) H=c Tail=[] J=K=_ noofterms([a [b,c]],k). K is noofterms([b [c]],k) J = K = 2 K is noofterms([c []],K). J = K = 1 K is noofterms([],0). J = K = 0 6
7 member/2 is_in/2 remove/3 take_out/3 is_in(element, ) Definition: is_in(x,[x T]). is_in(x,[h T]):- is_in(x, T). checkifthe ElementisHeadofthe list ifnot,traverse therest ofthelist(tail) take_out (Element,, Remainder) Definition: take_out (X,[X R],R). element found take_out (X,[F R],[F S]):- take_out (X,R,S). traverse the list,atthe same time create new list is_in(x,[a,b,c]). reverse/2 overturn/2 overturn(, Revlist) X = a Return X = a is_in(x,[b,c]). Definition: overturn(,rev):- overturn2(,[],rev). X = b is_in(x,[c]). Return X = b X = c is_in(x,[]). Return X = c overturn2([h T],Z,W):- overturn2(t,[h Z],W). theelementposition overturn2([],x,x). is_in(c,[a,b,c]). Character Strings Three ways to represent a string of characters in Prolog: c \= a is_in(c,[b,c]). As an atom atoms are compact but hard to takeapart or manipulate. C \= b is_in(c,[c]). As a list of ASCII codes can use standard list processing techniques on them. c = c Return is_in(c,[]). As a list of one-character atoms - can use standard list processing techniques on them. 7
8 Character Strings Use write/1 with double quotes.?-write( abc ). [97,98,99] Character Strings Example(Prolog codes): splitnprint(ayat):- name(ayat,ayat), write_str(ayat). write_str([h T]):- put(h), write_str(t). write_str([]). Output:?- splitnprint(ahmad). ahmad Character Strings Use put/1 or putb/1. write_str([h T]):- put(h), write_str(t). write_str([]). Character Strings (Exercise) Write acode/rule toprintoutasfollows:?- print_splits("prolog"). p rolog pr olog pro log prol og prolo g prolog print_split([],word). write_str([]). Character Strings Convert between an atom or number and a byte list - name/2. name(atomic, )?- name(makan,). = [109,97,107,97,110]?- name(atomic, [109,97,107,97,110]). Atomic = makan Character Strings (Exercise) Write a code/rule to check whether the word end with s or not:?- end_with_s("flowers").?- end_with_s("car"). no?- end_with_s("cars"). print_splits(word):- print_split(word,word). print_split([_ T],Word):- append(h,t, Word), write_str(h), write(` `), write_str(t),nl, print_split(t, Word). write_str([h T]):- put(h), write_str(t). end_with_s():- length(, L), member(115,, L). 8
9 Operators Notation Data structure in Prolog: functor(arg1, arg2,, argn). Functor can become operator example: eat(ali,rice). Functor Canbewritten as: Linguistic Operator ali eat rice. Linguistic Operator Precedence value for operator Thevaluebetween The precedence value can influence the structure meaning: low precedence meaning high priority. operator with 33 is given higher priority compare to35. operator with 33 will be first executed. Operators Notation Types of operators Operator Example Infix Prefix +(3,4) Postfix 8 factorial Linguistic Operator Precedence Value Thevaluebetween The precedence value can influence the structure meaning: low precedence meaning high priority. operator with 33 is given higher priority compare to 35. operator with 33 will be first executed. Linguistic Operator Operator can be defined using op/3. op/3 - Declares an operator with a given type and precedence. op(precedence, Type, Name) Integer Name of the operator Atom or list of atoms Linguistic Operator Precedence Value Example use display/1 To view the standard syntax Change the precedence value Error Wrongly use operator?- op(35,xfx,is_in).?- op(33,fx,room).?- display(apple is_in room kitchen). is_in(apple,room(kitchen))?- op(36,fx,room).?- display(apple is_in room kitchen).! ! Error 42 : Syntax Error! Goal : eread(_11848,_11850)?- display(room kitchen is_in house). room(is_in(kitchen,house)) Defining operator is_in and room 9
10 Linguistic Operator Precedence Value Example Using Linguistic Operator Examine?- op(35,xfx,is_in).?- op(33,fx,room).?- display(apple is_in room kitchen). is_in(apple,room(kitchen)) Standard Syntax % Rules if binatang(x) and makan(x,ikan) then kucing(x). if(then(and(binatang(_13214),makan(_13214,ikan)), kucing(_13214)))?- op(36,fx,room).?- display(room kitchen is_in house). room(is_in(kitchen,house)) Linguistic Operator Defining Type Ifthe precedencevalue isthesame Prologwillreadeitherfrom lefttoright or righttoleftbased onthetype. Type for operator Types fx fy xf yf xfx xfy yfx Meaning non-associative prefix operator right associativeprefix operator non-associative postfix operator left associativepostfix operator non-associative infix operator right associativeinfix operator left associativeinfix operator prefix postfix infix Arithmetic 2 Operation + 1 =? Arithmetic how we do calculation in Prolog. Use predicate is/2 not =/2. Using Linguistic Operator Example cth.pl % Linguistic operators :- op(800, fx, if), op(700, xfx, then), op(300, xfy, or), op(200, xfy, and). % Facts binatang(comel). binatang(tompok). makan(comel,ikan). Makan(tompok,ikan). mengiau(comel). mengiau(tompok). % Rules if binatang(x) and makan(x,ikan) then kucing(x). Arithmetic Operation is/2 takes an arithmetic expression on its right, evaluates it, and unifies the result with its argument on the left. Format: X is X is 9. A = 1, X is A is <argument > is <arithmetic expression>. 10
11 Arithmetic Operation Wrong expression: 2+1is3. Typeerror-notintheright format. Arithmetic Operation Other arithmetic functions supported in LPA Prolog 2is1+X Instantiationerror valueofxis unknown. Arithmetic Operation Different with is/2 and =/2 : is/2 evaluate its right argument and unifies it with itsargumentontheleft docalculation. =/2 is to test if both arguments on the left and right are unify do unification. Arithmetic Operators The precedence of operators: Xis1 2*5^2/8+6 Equivalent to X is (1 (((2 * (5 ^ 2))/ 8)+ 6)) Where ^ is performed first, then*and/, and finally+ and-. Arithmetic Operators Common arithmetic operators(infix operators) Operator & Symbol Example & Output + Addition X is Subtraction X is * Multiplication X is 3 * 2. 6 / Floating-point division X is 3 / // Integer division X is 3 // 2. 1 Using Arithmetic Operators?- papar(5) printout(n):- 2. printout(1, N) printout(n, N) printout(x, N):- 7. printout_num(x), 8. nl, 9. NewX is X + 1, 10. printout(newx, N) printout_num(0) printout_num(x):- 15. write(x), 16. NewX is X - 1, 17. printout_num(newx). 11
12 Constructing Expression Different between Prolog an other programming languages is: Other programming language evaluate arithmetic expression s whenever they occur Prolog evaluates them only in specific places. Practical Calculation When using expressions in Prolog, we are mixing the styles of encoding knowledge. Normal syntax: Canbewrittenas:? X is ?-sum(2, 3, X). Constructing Expression of built-in Predicates that evaluate expressions. R is Ex Evaluates Ex and unifies result with R Ex1 =:= Ex2 test if the results of two expressions are equal Ex1 =\= Ex2 test if the results of two expressions are not equal Ex1 > Ex2 Ex1 < Ex2 test if the result of one expression is greater than another test if the result of one expression is less than another Ex1 >= Ex2 test if one expression is greater than or equal to another Ex1 =< Ex2 test if one expression is less than or equal to another Practical Calculation doublevalue(x, Z):- ZisX*X. areaofsquare(p, L, Area):- Area is P*L. Exercise Explain which of the following succeed, fail, or raise error conditions, and why: 1.?- 5 is ?- 5 =:= ?- 5 = ?- 5 is 2 + What. 5.?- 4+1 = ?- 4+1 is ?- 4+1 =:= ?- What is ?- What =:= ?- What is ?- What = ?- What =\=
Wan Hussain Wan Ishak
September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More informationWan Hussain Wan Ishak
February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More informationWan Hussain Wan Ishak
September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More informationLecture 9: A closer look at terms
Lecture 9: A closer look at terms Theory Introduce the == predicate Take a closer look at term structure Introduce strings in Prolog Introduce operators Exercises Exercises of LPN: 9.1, 9.2, 9.3, 9.4,
More informationTeaching. Module. Wan Hussain Wan Ishak
Teaching Module Wan Hussain Wan Ishak September Session 2011/2012 (A111) School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9284786 (F) 04-9284753 (E) hussain@uum.edu.my
More informationLecture 9. Exercises. Theory. Solutions to exercises LPN 8.1 & 8.2. Patrick Blackburn, Johan Bos & Kristina Striegnitz
Lecture 9 Exercises Solutions to exercises LPN 8.1 & 8.2 Theory Solution to Exercise 8.1 Suppose we add the noun ``men'' (which is plural) and the verb ``shoot''. Then we would want a DCG which says that
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 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 informationLogic Programming (PLP 11) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing
Logic Programming (PLP 11) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing Carlos Varela Rennselaer Polytechnic Institute February 9, 2015 C. Varela 1 Arithmetic Goals N>M N
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 informationLogic Programming (PLP 11.3) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing
Logic Programming (PLP 11.3) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing Carlos Varela Rennselaer Polytechnic Institute February 3, 2011 C. Varela 1 Arithmetic Goals N>M N
More informationMore Planning and Prolog Operators
More Planning and Prolog Operators Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 16 22/11/04 22/11/04 AIPP Lecture 16: More Planning and Operators 1 Planning continued Contents
More informationSTACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:
STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The
More informationDefining Binary & Unary Operators
Defining Binary & Unary Operators DO-1 English-French Dictionary 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 informationInput & Output. York University Department of Computer Science and Engineering. York University- CSE V. Movahedi 08_IO
Input & Output York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 08_IO 1 Read and write terms Overview Read and write characters Reading English sentences
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard
More informationLogic Programming Prolog: Arithmetic, Equalities, Operators, I/O. (PLP 11) Databases: assert, retract. (CTM 9.6)
Logic Programming Prolog: Arithmetic, Equalities, Operators, I/O. (PLP 11) Databases: assert, retract. (CTM 9.6) Carlos Varela Rennselaer Polytechnic Institute November 24, 2015 C. Varela 1 Arithmetic
More informationDepartment of Computer Science
Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and
More informationDefining! Binary & Unary! Operators!
Defining! Binary & Unary! Operators! DO-1 English-French Dictionary! Can use compound terms to represent a dictionary! > list is a structure that contains an entry followed by the rest of the list! > For
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 informationConstants and Variables
DATA STORAGE Constants and Variables In many introductory courses you will come across characteristics or elements such as rates, outputs, income, etc., measured by numerical values. Some of these will
More informationScheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax
Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is
More informationUNIT 3 OPERATORS. [Marks- 12]
1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationSome Applications of Stack. Spring Semester 2007 Programming and Data Structure 1
Some Applications of Stack Spring Semester 2007 Programming and Data Structure 1 Arithmetic Expressions Polish Notation Spring Semester 2007 Programming and Data Structure 2 What is Polish Notation? Conventionally,
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 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 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 informationInformation technology Programming languages Prolog Part 1: General core
INTERNATIONAL STANDARD ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 3 Published 2017-07 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
More informationInformatics Ingeniería en Electrónica y Automática Industrial
Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical
More informationOperators in java Operator operands.
Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,
More informationPROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012.
PROLOG Prolog is a programming language for symbolic, n-numeric computations. It is specially well suited for solving problems that involve objects and relation between objects. First simple Prolog Program
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationLecture 19: Functions, Types and Data Structures in Haskell
The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming
More informationThere are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:
Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
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 informationUnit-2 (Operators) ANAND KR.SRIVASTAVA
Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion
More informationWan Hussain Wan Ishak
September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More information15/9/2013. Defining Fact. Defining Fact. Defining Rule. Syntax. Rule-clausethatdependonotherfacts. Example:
Defining Fact Facts to describe the relationship between objects. To represent specific knowledge. Alor Setar is a capital of Kedah capital_of(alor_setar, kedah). state(kedah, alor_setar). is_in(alor_setar,
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 2018-2019 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/b-c+d*e-a*c If a=4, b=c=2,
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 2017 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/b-c+d*e-a*c If a=4, b=c=2,
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 informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationWhat s the problem? fib(1,1). fib(2,1). fib(n,x) :- N>2, N1 is N-1, N2 is N-2, fib(n1,x2), fib(n2,x2).
39 What s the problem? A Fibonacci Implementation fib(1,1). fib(2,1). fib(n,x) :- N>2, N1 is N-1, N2 is N-2, fib(n1,x2), fib(n2,x2). List Concatenation conc([],l,l). conc([x L1], L2, [X L3]) :- conc(l1,l2,l3).
More informationPROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions
PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions 0 Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x 2 x {1...5}} The set {1,4,9,16,25}
More informationFormal Languages and Automata Theory, SS Project (due Week 14)
Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string
More informationProlog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E
Intelligent Systems and HCI D703E Lecture : More Prolog Paweł Pietrzak Prolog (cont d) 1 Remark The recent version of SWI- Prolog displays true and false rather than and no Using multiple clauses Different
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationPrepared by: Shraddha Modi
Prepared by: Shraddha Modi Introduction Operator: An operator is a symbol that tells the Computer to perform certain mathematical or logical manipulations. Expression: An expression is a sequence of operands
More information02157 Functional Programming Lecture 2: Functions, Basic Types and Tuples
Lecture 2: Functions, Basic Types and Tuples nsen 1 DTU Informatics, Technical University of Denmark Lecture 2: Functions, Basic Types and Tuples MRH 13/09/2012 Outline A further look at functions, including
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
More informationWan Hussain Wan Ishak
February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationFundamentals of Programming CS-110. Lecture 3
Fundamentals of Programming CS-110 Lecture 3 Operators Operators Operators are words or symbols that cause a program to do something to variables. OPERATOR TYPES: Type Operators Usage Arithmetic + - *
More information09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION
DATA STRUCTURES AND ALGORITHMS 09 STACK APPLICATION REVERSE POLISH NOTATION IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES
More informationCOMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006
OMP 9416, session 1, 2006 p. 1 Datalog OMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 2 Atoms, integers and variables The fact "person(socrates).", the fact "sum(2,3,y)." and the rule "mortal(x)
More informationOperators & Expressions
Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.
More informationIntroduction to Programming, Aug-Dec 2006
Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components
More informationPROgramming in LOGic PROLOG Recursion, Lists & Predicates
PROgramming in LOGic PROLOG Recursion, Lists & Predicates CSC9Y4 1 Recursion Recursion in Prolog means placing in the body of a rule a call to the predicate which occurs in the head of the rule. Here is
More informationIntroduction to Prolog
Introduction to Prolog York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 03_Prolog 1 Overview Introduction & Preliminaries Syntax Characters Constants
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More informationObjects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003
Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void
More informationA Java program contains at least one class definition.
Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public
More informationOperators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)
Operators Representing and storing primitive data types is, of course, essential for any computer language. But, so, too, is the ability to perform operations on data. Java supports a comprehensive set
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationData Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1
Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Stack Operations on a stack Representing stacks Converting an expression
More informationProlog - 3 Prolog search trees + traces
Prolog - 3 Prolog search trees + traces 1 Review member(a, [A B]). member(a, [B C]) :- member (A,C). goal-oriented semantics: can get value assignment for goal member(a,[b C]) by showing truth of subgoal
More informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
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 informationHaskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.
Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationControl Flow February 9, Lecture 7
Chapter 6 Control Flow February 9, Lecture 7 Expressions A simple object Literal constant Named variable Constant Or a function applied to arguments For built-in functions we use the term operator (like
More informationSML A F unctional Functional Language Language Lecture 19
SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list
More informationGO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.
http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
More informationCMSC 331 Final Exam Section 0201 December 18, 2000
CMSC 331 Final Exam Section 0201 December 18, 2000 Name: nswers 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
More informationLecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011
Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions
More informationJava Programming Fundamentals. Visit for more.
Chapter 4: Java Programming Fundamentals Informatics Practices Class XI (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT (Comp.Sc.)
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationCOP4020 Programming Languages. Logical programming with Prolog Prof. Xin Yuan
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan Topics Logic programming with Prolog COP4020 Spring 2013 2 Definitions: Prolog Terms Terms are symbolic expressions that are
More informationMicroprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)
Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming) Learning any imperative programming language involves mastering a number of common concepts: Variables: declaration/definition
More informationThe object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog
Lecture 8 Meta-level predicates and operators Contents Object level vs. meta level Controlling flow of computation Checking and dismantling expressions Comparison operators The object level in Prolog Prolog
More informationAn Interesting Way to Combine Numbers
An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly
More informationComputer Programming CS F111
Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print
More informationC Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff
C Programming Language 1 C C is better to use than assembly for embedded systems programming. You can program at a higher level of logic than in assembly, so programs are shorter and easier to understand.
More informationLECTURE 17. Expressions and Assignment
LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)
More informationConnection between Lists and Terms. Prolog-Lecture 2. Unifying Lists. Unifying Lists. Steps to a Recursive Predicate. List Predicates.
Prolog-Lecture 2 Iqbal Mohomed Connection between Lists and Terms [H T] is just syntactic sugaring for the term.(h,t)?-.(h,t) = [a,b,c]. H = a T = [b, c] ; The dot operator or functor. corresponds to cons
More informationWan Hussain Wan Ishak
February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com
More informationIntroduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms
Introduction Problem Solving on Computer Data Structures (collection of data and relationships) Algorithms 1 Objective of Data Structures Two Goals: 1) Identify and develop useful high-level data types
More informationCHAD Language Reference Manual
CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,
More informationDKT 122/3 DIGITAL SYSTEM 1
Company LOGO DKT 122/3 DIGITAL SYSTEM 1 BOOLEAN ALGEBRA (PART 2) Boolean Algebra Contents Boolean Operations & Expression Laws & Rules of Boolean algebra DeMorgan s Theorems Boolean analysis of logic circuits
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationCSE 3302 Programming Languages Lecture 8: Functional Programming
CSE 3302 Programming Languages Lecture 8: Functional Programming (based on the slides by Tim Sheard) Leonidas Fegaras University of Texas at Arlington CSE 3302 L8 Spring 2011 1 Functional Programming Languages
More informationData Structures and Computation
Chapter 3 Data Structures and Computation 3.1. ARITHMETIC Here are some examples of how to do arithmetic in Prolog:.?- Y is 2+2. 4?- ~is 3+3. ~ Z 6~3571428 ~ ~ + (3.9 / 2.1). The 1~iii t4i predicate is
More informationChapter 6. Predefined Predicates
Advanced Logic Programming https://sewiki.iai.uni-bonn.de/teaching/lectures/alp/2017/ Chapter 6. Predefined Predicates Updated: 12 June, 2017 Reorganized entire chapter Input and output Exception handling
More informationResearch Report AI A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia
Research Report AI 1989 02 A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia Athens, Georgia 30602 U.S.A. A Numerical Equation Solver
More informationOverview. Declarative Languages. operation of del. Deleting an element from a list. functions using del. inserting elements with del
Overview Declarative Languages D7012E: Arithmetic and Backtracking Fredrik Bengtsson Some standard functions Operators Arithmetic The eight queens problem Controlling backtracking cut Deleting an element
More information