Wan Hussain Wan Ishak
|
|
- Dana Holt
- 5 years ago
- Views:
Transcription
1
2 September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) (E) hussain@uum.edu.my (U)
3 Lecture notes List, Operators and Arithmetic Arithmetic Constructing Expressions List Processing Character Strings and Structures
4 List List 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]
5 List
6 List [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]]
7 List The empty list is written: [] Please note one element list [a] is not equivalent to the atom a.? [a] = a. no
8 List List can be constructed or decomposed through unification. Unify with [a,b,c] = X [X,b,Z] = [a,y,c] [[a,b],c] = [X,Y] [a(b),c(x)] = [Z,c(a)] Result X = [a,b,c] X = a, Y = b, Z = c X = [a,b], Y = c X = a, Z = a(b)
9 List More examples Unify with [X Y] = [a,b,c,d] Result 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]
10 List The list can be divided into head and tail by the symbol. [H T] The first element is the head and the rest are the tail. Example: [a [b,c,d,e]]
11 List [a [b,c,d,e]] The tail of a list is always a list, the head of a list is an element. Every nonempty list has a head and a tail. [a,b,c,d] = [a [b,c,d]] [a] = [a []]
12 List Manipulation Built-in predicates 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
13 List Manipulation append/3 Syntax: Example: append(first, Second, Whole) 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]
14 List Manipulation length/2 Syntax: Example: length(term, Length)?- length([a,b,c,d], Length). Length = 4
15 List Manipulation member/2 Syntax: Example:?- member(a, [a,b,c,d]). yes member(element, List)?- member(element, [a,b,c,d]). Element = a ; Element = b ; Element = c ; Element = d ;
16 List Manipulation member/3 Syntax: member(element, List, Position) Example: Element position?- member(c, [a,b,c,d], Position). Position = 3 ; Get Element at given position?- member(element, [a,b,c,d], 2). Element = b
17 List Manipulation member/3 (more example):?- member(element, [a,b,c,d], Position). Element = a, Position = 1 ; Get the element and its position Element = b, Position = 2 ; Element = c, Position = 3 ; Element = d, Position = 4 ;
18 List Manipulation remove/3 Syntax: remove(element, List, Remainder) Example: 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 ;
19 List Manipulation remove/3 (more example):?- 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] ; What element can be removed Element = d, Remainder = [a,b,c] ;
20 List Manipulation removeall/3 Syntax: removeall(item, List, Remainder)
21 List Manipulation 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]
22 List Manipulation Reverse/2 Syntax: Example: Reverse the list Causes error reverse(list, Revlist)?- reverse([a,b,c,d], Revlist). Revlist = [d,c,b,a]?- reverse(list, [d,c,b,a]). List = [a,b,c,d] ; Error 4, Heap Space Full, Trying ewrite/1
23 List Manipulation - Exercise What is the output??- 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).
24 List Constructing Predicates 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?
25 List Constructing Predicates append/3 addon/3 Syntax: addon(first, Second, Whole) Definition: addon ([],X,X). addon ([H T1],X,[H T2]):- addon (T1, X, T2). stop the recursion add element into the list
26 List Constructing Predicates append/3 addon/3 (1) addon ([],X,X). addon/3?- addon([a,b],[c],w). (2) addon ([H T1],X,[H T2]):- (2.1) addon (T1, X, T2). Ep. 1 Call (1) addon([],x,x). false [a,b]\=[] Call (2) addon([h T1],X,[H T2]). true [a,b]=[h T1] [c]=x Call (2.1) addon(t1,x,t2). W=[H T2] addon([b],[c],t2). go to Ep. 2 H=a T1=[b] X=[c] W=[a T2] T2=_
27 List Constructing Predicates append/3 addon/3 (1) addon ([],X,X). addon/3 From Ep.1, (2.1) addon([b],[c],t2). (2) addon ([H T1],X,[H T2]):- (2.1) addon (T1, X, T2). Ep. 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 Ep. 3
28 List Constructing Predicates append/3 addon/3 (1) addon ([],X,X). addon/3 From Ep.2, (2.1) addon([],[c],t2). (2) addon ([H T1],X,[H T2]):- (2.1) addon (T1, X, T2). Ep. 3 Call (1) addon([],x,x). true []=] Stop at Ep. 3 rule (1). Rule (2) will not execute. X=[c]
29 List Constructing Predicates?- addon([a,b],[c],w). W =[a,b,c] (1) addon ([],X,X). addon/3 (2) addon ([H T1],X,[H T2]):- (2.1) addon (T1, X, T2). Ep. 1 (2) addon([a [b]],[c],[a T2]):- (2.1) addon([b],[c],t2). [a [b,c]] T2 = [b,c] Ep. 2 (2) (2.1) addon([b []],[c],[b T2]):- addon([],[c],t2). [b [c]] T2 = [c] Ep. 3 (1) addon([],[c],[c]).
30 List Constructing Predicates length/2 noofterms/2 Syntax: noofterms(term, Length) Definition: noofterms([],0). noofterms([h Tail],K):- noofterms(tail,j), K is J + 1. stop the recursion calculate the length
31 List Constructing Predicates length/2 noofterms/2 noofterms/2 (1) noofterms([],0).?- noofterms([a,b,c],t). (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), (2.2) K is J + 1. Ep. 1 Call (1) noofterms([],0). false [a,b,c]\=[] Call (2) noofterms([h Tail],K). true [a,b,c]=[h Tail] Call (2.1) noofterms(tail,j). T=K noofterms([b,c],j). go to Ep. 2 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.) H=a Tail=[b,c] T=K=_
32 List Constructing Predicates length/2 noofterms/2 noofterms/2 (1) noofterms([],0). Ep. 2 From Ep.1, (2.1) noofterms([b,c],j). Call (1) noofterms([],0). false [b,c]\=[] (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), (2.2) K is J + 1. Call (2) noofterms([h Tail],K). true [b,c]=[h Tail] Call (2.1) noofterms(tail,j). J=K H=b Tail=[c] J=K=_ noofterms([c],j). go to Ep. 3 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.)
33 List Constructing Predicates length/2 noofterms/2 noofterms/2 (1) noofterms([],0). Ep. 3 From Ep.2, (2.1) noofterms([c],j). Call (1) noofterms([],0). false [c]\=[] (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), (2.2) K is J + 1. Call (2) noofterms([h Tail],K). true [c]=[h Tail] Call (2.1) noofterms(tail,j). J=K H=c Tail=[] J=K=_ noofterms([],j). go to Ep. 4 Call (2.2) pending. (At the moment Sub goal 2.2 will not be called.)
34 List Constructing Predicates length/2 noofterms/2 noofterms/2 (1) noofterms([],0). From Ep.3, (2.1) noofterms([],j). (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), (2.2) K is J + 1. Ep. 4 Call (1) noofterms([],0). true []=[] J=0 Prolog will now return to Ep. 3 to execute 2.2. Followed by Ep. 2 and Ep. 1.
35 List Constructing Predicates (1) noofterms([],0). noofterms/2? - 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) K is J + 1. (2.2) 4 K (1) is J noofterms([],0) (2) noofterms([h Tail],K):- (2.1) noofterms(tail,j), (2.2) K is J + 1. K=1 J=0 In console T = 3 yes (2.2) (2.2) K is J + 1. K is J + 1. (2.2) K is J + 1. (2.2) K is J + 1. K is K is K is 0 + 1
36 List Constructing Predicates noofterms([a [b,c]],k). J = K = 2 K is noofterms([b [c]],k) J = K = 1 K is noofterms([c []],K). J = K = 0 K is noofterms([],0).
37 List Constructing Predicates member/2 is_in/2 Syntax: is_in (Element, List) Definition: is_in (X,[X T]). is_in (X,[H T]):- is_in(x, T). check if the Element is Head of the list if not, traverse the rest of the list (Tail)
38 List Constructing Predicates is_in(x,[a,b,c]). X = a Return X = a is_in(x,[b,c]). Return X = b X = b is_in(x,[c]). Return X = c X = c is_in(x,[]).
39 List Constructing Predicates is_in(c,[a,b,c]). c \= a is_in(c,[b,c]). C \= b is_in(c,[c]). c = c Return yes is_in(c,[]).
40 List Constructing Predicates remove/3 take_out/3 Syntax: take_out (Element, List, 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, at the same time create new list
41 List Constructing Predicates reverse/2 overturn/2 Syntax: overturn (List, Revlist) Definition: overturn (List,RevList):- overturn2(list,[],revlist). overturn2([h T],Z,W):- overturn2(t,[h Z],W). the element position overturn2([],x,x).
42 Character Strings Three ways to represent a string of characters in Prolog: As an atom atoms are compact but hard to take apart or manipulate. As a list of ASCII codes can use standard list processing techniques on them. As a list of one-character atoms - can use standard list processing techniques on them.
43 Character Strings Use write/1 with double quotes. Example:?- write( abc ). [97,98,99]
44 Character Strings Use put/1 or putb/1. Example: write_str([h T]):- put(h), write_str(t). write_str([]).
45 Character Strings Convert between an atom or number and a byte list - name/2. Syntax: name(atomic, List) Example:?- name(makan,list). List = [109,97,107,97,110]?- name(atomic, [109,97,107,97,110]). Atomic = makan
46 Character Strings Example (Prolog codes): splitnprint(ayat):- name(ayat,ayatlist), write_str(ayatlist). write_str([h T]):- put(h), write_str(t). write_str([]). Output:?- splitnprint(ahmad). ahmad
47 Character Strings (Exercise) Write a code/rule to print out as follows:?- print_splits("prolog"). p rolog pr olog pro log prol og prolo g prolog yes print_splits(word):- print_split(word,word). print_split([],word). print_split([_ T],Word):- append(h,t, Word), write_str(h), write(` `), write_str(t),nl, print_split(t, Word). write_str([]). write_str([h T]):- put(h), write_str(t).
48 Character Strings (Exercise) Write a code/rule to check whether the word end with s or not :?- end_with_s("flowers"). yes?- end_with_s("car"). no?- end_with_s("cars"). yes end_with_s(list):- length(list, L), member(115, List, L).
49 Operators Notation Data structure in Prolog: functor(arg1, arg2,, argn). Functor can become operator example: eat(ali,rice). Can be written as: Functor Linguistic Operator ali eat rice.
50 Operators Notation Types of operators Operator Example Infix Prefix +(3,4) Postfix 8 factorial
51 Linguistic Operator Operator can be defined using op/3. op/3 - Declares an operator with a given type and precedence. Syntax: Name of the operator op(precedence, Type, Name) Integer Atom or list of atoms
52 Linguistic Operator Precedence value for operator The value between The precedence value can influence the structure meaning: low precedence meaning high priority. Example: operator with 33 is given higher priority compare to 35. operator with 33 will be first executed.
53 Linguistic Operator Precedence Value The value between The precedence value can influence the structure meaning: low precedence meaning high priority. Example: operator with 33 is given higher priority compare to 35. operator with 33 will be first executed.
54 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). yes?- op(33,fx,room). yes?- display(apple is_in room kitchen). is_in(apple,room(kitchen))?- op(36,fx,room). yes Defining operator is_in and 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))
55 Linguistic Operator Precedence Value Example?- op(35,xfx,is_in). yes?- op(33,fx,room). yes?- op(36,fx,room). yes?- display(apple is_in room kitchen). is_in(apple,room(kitchen))?- display(room kitchen is_in house). room(is_in(kitchen,house))
56 Linguistic Operator Defining Type If the precedence value is the same Prolog will read either from left to right or right to left based on the type. Type for operator Types fx fy xf yf xfx xfy yfx Meaning non-associative prefix operator right associative prefix operator non-associative postfix operator left associative postfix operator non-associative infix operator right associative infix operator left associative infix operator prefix postfix infix
57 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).
58 Using Linguistic Operator Examine % Rules if binatang(x) and makan(x,ikan) then kucing(x). Standard Syntax if(then(and(binatang(_13214),makan(_13214,ikan)), kucing(_13214)))
59 Arithmetic 2 Operation + 1 =? Arithmetic how we do calculation in Prolog. Use predicate is/2 not =/2.
60 Arithmetic Operation is/2 takes an arithmetic expression on its right, evaluates it, and unifies the result with its argument on the left. Example: Format: X is X is 9. A = 1, X is A is <argument > is <arithmetic expression>.
61 Arithmetic Operation Wrong expression: is 3. Type error - not in the right format. 2 is 1 + X Instantiation error value of X is unknown.
62 Arithmetic Operation Different with is/2 and =/2 : is/2 evaluate its right argument and unifies it with its argument on the left do calculation. =/2 is to test if both arguments on the left and right are unify do unification.
63 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
64 Arithmetic Operation Other arithmetic functions supported in LPA Prolog
65 Arithmetic Operators The precedence of operators: Example: X is 1 2 * 5 ^ 2 / Equivalent to Where ^ is performed first, then * and /, and finally + and -. X is (1 (((2 * (5 ^ 2)) / 8) + 6))
66 Using Arithmetic Operators Example:?- 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).
67 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.
68 Constructing Expression List of built-in Predicates that evaluate expressions. R is Ex Ex1 =:= Ex2 Ex1 =\= Ex2 Ex1 > Ex2 Ex1 < Ex2 Ex1 >= Ex2 Ex1 =< Ex2 Evaluates Ex and unifies result with R test if the results of two expressions are equal test if the results of two expressions are not equal test if the result of one expression is greater than another test if the result of one expression is less than another test if one expression is greater than or equal to another test if one expression is less than or equal to another
69 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 =\= 2+3.
70 Practical Calculation When using expressions in Prolog, we are mixing the styles of encoding knowledge. Normal syntax: Can be written as:? X is ?- sum(2, 3, X).
71 Practical Calculation Example: doublevalue(x, Z):- Z is X * X. areaofsquare(p, L, Area):- Area is P * L.
[a,b,c,d] 15/9/2013. [a,b,c,d] List. List. List. List is one of the most important Prolog data structures.
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
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 (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 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 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 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 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 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 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 informationLogic Programming. Using Data Structures Part 2. Temur Kutsia
Logic Programming Using Data Structures Part 2 Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria kutsia@risc.uni-linz.ac.at Contents Recursive Comparison
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationCombining Lists & Built-in Predicates
Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 6 11/10/04 11/10/04 AIPP Lecture 6: Built-in Predicates 1 Collecting Results Last time we
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 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 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 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 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 informationRecursion, Structures, and Lists
Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 4 04/10/04 30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists 1 The central ideas of Prolog
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 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 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 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 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 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 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 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 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 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 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 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 informationFunctional Programming in Haskell Part I : Basics
Functional Programming in Haskell Part I : Basics Madhavan Mukund Chennai Mathematical Institute 92 G N Chetty Rd, Chennai 600 017, India madhavan@cmi.ac.in http://www.cmi.ac.in/ madhavan Madras Christian
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 informationCSc 372 Comparative Programming Languages
CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg
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 informationProlog examples continued
Prolog examples continued arithmetic functions translating a simple Lisp function modelling an addition circuit puzzle solving 1 arithmetic functions we keep arithmetic functions as functions for convenience:?-
More informationLecture 11: Feb. 10, 2016
CS323: AI (Hands on with Prolog) Spring 2016 Lecturer: K.R. Chowdhary Lecture 11: Feb. 10, 2016 : Professor of CS (VF) Disclaimer: These notes have not been subjected to the usual scrutiny reserved for
More informationCSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona
1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists
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 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 informationCode No: R Set No. 1
Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional
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 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 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 Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation
More informationScheme: Expressions & Procedures
Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University
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 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 information