PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012.

Size: px
Start display at page:

Download "PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012."

Transcription

1 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 Use an editor to input the following program named family: parent( pam, bob ). parent( tom, bob ). parent( tom, liz ). parent( bob, ann ). parent( bob, pat ). parent( pat, jim ). The program developed a relation as the family tree in fig. 1. pam bob tom liz Enter the IF-Prolog environment, where you can see the prompt?-, get the Prolog program by enter consult(family). ann pat Then you can have query on the family relation as follows: Answer from Prolog:?- parent ( bob, pat ). yes?- Study the following I-O carefully: jim figure 1 A family tree. Input parent ( liz, pat ). parent ( tom, ben ). parent ( X, liz). parent ( bob, X ). parent ( X, Y). Output X = tom X = ann; X = pat X = pam Y = bob; X = tom Y = bob; X = tom Y = liz; parent(y, jim), parent(x, Y)... X = bob Y = pat Basic elements of Prolog Clause. i. A Prolog program consists of clauses. Each clause terminates with a period (.). Each of these clauses declares one fact, e.g. the parent-child relation. i In general, a relation is defined as the set of all its instances. PROLOG page 1

2 Rules. i. It specifies things that are true if the same condition is satisfied. e.g. To formulate the logical statement, X and Y, Y is an offspring of X if X is a parent of Y. The following Prolog clause is used. i Each rule have : ( means for all ) offspring (Y, X) :- parent (X, Y). a) condition part (on RHS as body ). b) conclusion part (on LHS as head ). Two more examples i. X and Y, X is the mother of Y if X is a parent of Y and X is a female. Formulate the statement by the following PROLOG statements, mother(x, Y) :- parent(x, Y), female(x). X and Y, X is a sister of Y if (1) both X and Y have the same parent, and (2) X is a female. Formulate the statement by the following PROLOG statements, sister( X, Y) :- parent ( Z, X), parent ( Z, Y), female ( X). Recursive rule definition. Defining a rule based on a definition of itself defined before. e.g. X and Z, X is a predecessor of Z if X is a parent of Z or Y (1) X is a parent of Y, and (2) Y is a predecessor of Z. ( means there exists, means such that ) Formulate the logical statement as predecessor ( X, Z) :- parent ( X, Z). predecessor ( X, Z) :- parent ( X, Y), predecessor ( Y, Z). PROLOG page 2

3 Here is a complete program family: parent( pam, bob). parent( tom, bob). parent( tom, liz). parent( bob, ann). parent( bob, pat). parent( pat, jim). female( pam). male( tom). male( bob). female( liz). female( ann). female( pat). male( jim). offspring( Y, X) :- parent( X, Y). mother( X, Y) :- parent( X, Y), female( X). grandparent( X, Z) :- parent( X, Y), parent( Y, Z). sister( X, Y) :- parent( Z, X), parent( Z, Y), female(x), different( X, Y). predecessor( X, Z) :- parent( X, Z). predecessor( X, Z) :- parent( X, Y), predecessor( Y, Z). % Pam is a parent of Bob % Pam is female % Tom is male % Y is an offspring of X if % X is a parent of Y % X is the mother of Y if % X is a parent of Y and % X is female % X is a grandparent of Z if % X is a parent of Y and % Y is a parent of Z % X is a sister of Y if % X and Y have the same parent and % X is female and % X and Y are different % Rule pr1 : X is predecessor of Z % Rule pr2 : X is predecessor of Z How does Prolog answer questions? --- Backtracking To answer a question, Prolog tries to satisfy all the goals. ( To satisfy a goal means to demonstrate the goal logically follows from the facts and rules in the program.) Prolog backtracks to the original goal in order to try an alternative way to derive the top goal. e.g. Given the question for the program family:?- predecessor ( tom, pat). 1st : X = tom, Z = pat 2nd : Rule 1 t true. Backtrack rule 2. 3rd : Match with parent (tom, bob). 4th : Recursive search for predecessor ( bob, pat). 5th : match with rule 1, i.e. parent ( bob, pat). ** Answer found ----> yes. PROLOG page 3

4 The complete execution trace is shown in fig. 2. by rule pr1 parent(tom, pat) predecessor(tom, pat) figure 2 Execution trace Declarative and Procedural meaning of programs by rule pr2 parent(tom, Y) predecessor(y, pat) The declarative meaning is concerned with the relations defined by the program, i.e. determining WHAT the output of the program is. The procedural meaning is concerned with the relations actually evaluated by the Prolog system, i.e. determining HOW the output is obtained. SYNTAX AND MEANING Data objects Constants (i.e. atoms and number) data objects i. Strings can consist of the following characters: simple objects structure upper-case letters A, B,..., Z lower-case letters a, b,..., z digits 0, 1, 2,..., 9 special characters such as + - * / < > = :. & _ ~ atoms constants numbers variables Atoms can be constructed in 3 ways: Strings of letters. starting with a lower-case letter. e.g. x y, miss_jones Figure 3 Data objects in Prolog Strings of special characters. without predefined meaning e.g. the string :- cant be used. Strings of characters. enclosed in single quotes. e.g. 'Mom', 'Sarah Jones' i Numbers in Prolog Integer: to Real: t used very much, only decimal point form is used Variables i. Starting with an upper-case letter or an underscored character. e.g. X, Result, _x23 PROLOG page 4

5 i The lexical scope of variable name is one clause, i.e. if the same name occurs in two clauses, it signifies two different variables. Structures i. Structured objects are objects that have several components. The components themselves can, in turn, be structures. i e.g. date( Day, may, 1983). iv. The figure in fig. 4 shows the relations of points, segments and triangles. v. To formulate in Prolog: P1 = point( 1, 1) P2 = point( 2, 3) S = seg( point( 1, 1), point( 2, 3)) T = triangle( point( 4, 2), point( 6, 4), point( 7, 1)) vi. The corresponding tree representation is shown in fig P2 = (2,3) (4, 2) (6, 4) P1 = (1,1) (7, 1) Figure 4 Some simple geometric objects T P1 = point S = seg 1 1 point point T = triangle point point point Figure 5. Tree representation of the objects in Figure 4. MATCHING Given 2 terms, we say that they match if : i. they are identical, or the variables in both terms can be instantiated to objects in such a way that after the substitution of variables by these objects the terms become identical. Thus, matching is a process that takes as input two terms and checks whether they match. PROLOG page 5

6 The general rules to decide whether two terms, S and T, match are as follows: i. If S and T are constants, then S and T match only if they are the same object. If S is a variable and T is anything, then they match, and S is instantiated to T. Conversely, if T is a variable then T is instantiated to S. i If S and T are structures then they match only if a) S and T have the same principal functor, and b) all their corresponding components match. The resulting instantiation is determined by the matching of the components. e.g. Defining structures for recognizing horizontal and vertical line segments. vetical( seg( point( X, Y1), point( X, Y2))). horizontal( seg( point( X1, Y), point( X2, Y))). Conjunction and Disjunction In general, a question to the Prolog system is a list of goals separated by commas. A comma between goals thus detes the conjunction of goals (AND) Prolog also accepts the disjunction of goals (OR). It is lower in order of precedence, and deted by separated with the semicolon. e.g. translate( Number, Word) :- Number = 1, Word = one; Number = 2, Word = two; Number = 3, Word = three. *** Example: monkey and banana A Monkey is at the door and the banana is hang on from the ceiling the room. The state of the world is determined by The position of monkey in the room. Is the monkey on the box or on the floor? The position of the box. Does the monkey have the banana? Four types of movement by the monkey: grasp banana, climb box, push box, walk around Sample Prolog program to find the solution. % move( State1, Move State2): making Move in State1 results in State2; % a state is represented by a term: % state( MonkeyHorizontal, MonkeyVertical, BoxPosition, HasBanana) move( state( middle, onbox, middle, hast), % Before move grasp, % Grasp banana state( middle, onbox, middle, has) ). % After move move( state( P, onfloor, P, H), climb, state( P, onbox, P, H) ). % Climb box PROLOG page 6

7 move( state( P1, onfloor, P1, H), push( P1, P2), state( P2, onfloor, P2, H) ). move( state( P1, onfloor, B, H), walk( P1, P2), state( P2, onfloor, B, H) ). % Push box from P1 to P2 % Walk from P1 to P2 % canget( State): monkey can get banana in State canget( state( _, _, _, has) ). % can 1 : Monkey already has it canget( State1) :- % can 2 : Do some work to get it move( State1, Move, State2), % Do something canget( State2). % Get it w Given the initial state to see if there is a solution as follows,?- canget( state( atdoor, onfloor, atwindow, hast)). state( atdoor, onfloor, atwindow, hast) walk( atdoor, P2) state( P2, onfloor, atwindow, hast) climb backtrack push( P2, P2 ) P2 = atwindow state( atwindow, onbox, atwindow, hast) No move possible state( P2, onfloor, P2, hast) climb state( P2, onbox, P2, hast) grasp P2 = middle state( middle, onbox, middle, has) Figure 6 The monkey s search for the banana. The search starts at the top de and proceeds downwards, as indicated. Alternative moves are tried in the left-to-right order. Backtracking occurred once only. Danger of indefinite looping Considering the following clause in a program: p :- p. The question?- p. will cause Prolog entering an indefinite loop. Ather example of indefinite looping i. Reorder the Monkey and Banana thus the walk clause appears first. PROLOG page 7

8 Then the execution of our original goal of the previous section,?- canget( state( atdoor, onfloor, atwindow, hast)). would cause an indefinite looping. (Why? The monkey will only walk around.) Program variations through reordering of clauses and goals. Consider the four versions of the predecessor program. pred1( X, Z) :- pred2( X, Z) :- parent( X, Z). parent( X, Y), pred1( X, Z) :- pred2( Y, Z). parent( X, Y), pred2( X, Z) :- pred1( Y, Z). parent( X, Z). pred3( X, Z) :- pred4( X, Z) :- parent( X, Z). pred4( X, Y), pred3( X, Z) :- parent( Y, Z). pred3( X, Y), pred4( X, Z) :- parent( Y, Z). parent( X, Z). All pred1, pred2 and pred3 can reach a solution. The pred4 is hopeless. LIST The list is a simple data structure widely used in n-numeric programming. e.g. [ann, tennis, tom, skiing] A list consists of two things i. the first term, called the head of the list. the remaining part of the list, called the tail. The head can be any Prolog object; the tail has to be a list. In If-Prolog, a list can be regarded as an empty list or a structure whose functor is dot., and that has two arguments: the head and the tail. Thus, the general principle for structuring data objects in Prolog also applies to lists of any length. It can be illustrated by the following example. e.g.?- List1 = [a,b,c], List2 = '.'(a, '.'(b, '.'(c, []))). List1 = [a,b,c] List2 = [a,b,c]?- Hobbies = '.'( tennis, '.'( music, [])), Hobbies = [ skiing, food], L = [ ann, [ tennis, music], tom, [skiing, food]]. Hobbies = [ tennis, music] Hobbies = [ skiing, food] L = [ ann, [ tennis, music], tom, [skiing, food]] PROLOG page 8

9 Prolog provides ather tational extension, the vertical bar, which separates the head and the tail. The tation is L = [a Tail] Operations on lists include i. checking whether an object is an element of a list, i.e. membership. concatenation of two lists, (Unions of sets) i adding or deleting an object to or from a list. iv. checking whether a list is a sublist of ather. v. generate permutate of a list Membership member( X, L). where X is an object and L is a list. The goal member( X, L) is true if X occurs in L. Example Truth value member( b, [ a, b, c]) member( b, [ a, [b, c]]) member( [b, c], [a, [b, c]]) The relationship of member would be, X is a member of L if either (1) X is the head of L, or (2) X is the member of the tail of L Thus to formulate the statement in Prolog, member( X, [X Tail]). member( X, [Head Tail]) :- member( X, Tail). Concatenation True False True conc( L1, L2, L3). where L1 and L2 are two lists and L3 is their concatenation. Example Truth value conc( [a,b], [c,d], [a,b,c,d]) conc( [a,b], [c,d], [a,b,a,c,d]) True False Defining in Prolog conc( [], L, L). conc( [X L1], L2, [X L3]) :- conc( L1, L2, L3). e.g.?- conc( [a, [b, c], d], [a, [], b], L). L = [a, [b, c], d, a, [], b]?- conc( L1, L2, [a, b, c]). L1 = [] L2 = [a, b, c]; L1 = [a] L2 = [b, c]; PROLOG page 9

10 L1 = [a, b] L2 = [c]; L1 = [a, b, c] L2 = [];?- Redefine member1 using conc as member1( X, L) :- conc(_, [X, _], L). Adding an item To add an item to a list, it is easiest to put the new item in front of the list so that resulting list becomes. Thus it is defined as, [X L] where X is the new object and L is original list. add( X, L, [X L]). Deleting an item del( X, L, L1). where L is the original list, X is the object to be deleted, L1 is the resulting list. There are two cases, i. X is the head of the list. The result is simply the tail. X is in the tail. The result is deleted from the tail (recursive), add the present head. Definition in Prolog. del( X, [X Tail], Tail). del( X, [Y Tail], [Y Tail1]) :- del( X, Tail, Tail1). e.g.?- del( a, [a, b, a, a], L). L = [b, a, a]; L = [a, b, a]; L = [a, b, a];?- del( a, L, [1, 2, 3]). L = [a, 1, 2, 3]; L = [1, a, 2, 3]; L = [1, 2, a, 3]; L = [1, 2, 3, a];?- PROLOG page 10

11 In general, the operation of inserting X at any place in some list List giving BiggerList can be defined by the clause: insert( X, List, BiggerList) :- del( X, BiggerList, List). Sublist sublist( L1, L2). where L1 is the sublist of L2. Example Truth value sublist( [c,d,e], [a,b,c,d,e]) sublist( [c,e], [a,b,c,d,e]) The relation can be formulated as: S is a sublist of L if (1) L can be decomposed into 2 lists, L1 and L2, and (2) L2 can be decomposed into 2 lists, S and L3. Thus, in Prolog sublist( S, L) :- conc( L1, L2, L), conc( S, L3, L2). True False e.g.?- sublist( S, [a,b,c]). Permutation S = []; S = [a]; S = [a, b]; S = [a, b, c]; S = [b];... permutation( L1, L2). where L2 is a permutation of L1 and vice versa. To formulate the relation, depending on the first list, there are two cases: i. The first list is empty. The second list must also be empty. The first list is t empty. The first list has the form [X L], and a permutation of such a list can be constructed: first premute L obtaining L1 and then insert X at any position into L1. To formulate in Prolog, permutation( [], []). permutation( [X L], P) :- permutation( L, L1), insert( X, L1, P). Operator tation For arithmetic operations, say 2 * a + b * c. PROLOG page 11

12 Prolog handles it as ordinary clause +( *( 2, a), *( b, c)). Nevertheless, Prolog allows both tations. Prolog program can define new operators as infix ones in special kinds of clauses, sometimes called directives. In IF-PROLOG, the operator has can be defined by the directive: :- op( 600, xfy, has). It tells Prolog that we want to use has as an operator, whose precedence is 600 and its type is xfy, i.e. infix. e.g. Program can define has and supports which allows clauses like which are equivalent to peter has information. floor supports table. has( peter, information). supports( floor, table). REM. Three operator types: Infix. e.g. a + b. Prefix. e.g. +( a, b). Postfix. e.g. (a, b)+. Notation of x, y and f in the operator definition, f indicates the position of the operator. x represents an argument whose precedence must be strictly lower than that of the operator. y represents an argument whose precedence is lower or equal to that of the operator Arithmetic Prolog has the following basic arithmetic operation. +, -, *, /, div and mod (integer division and modulo) The evaluation of an arithmetic operation is forced by the predefined operator, is. e.g.?- X = X = yes?- X is X = 3. yes.?- Relational operators: >, <, >=, =<, =:=, =\= PROLOG page 12

13 The set of predefined operators are follows :- op( 1200, xfx, ':-'). :- op( 1200, fx, [:-,?-]). :- op( 1100, xfy, ';'). :- op( 1000, xfy, ','). :- op( 700, xfx, [=, is, <, >, =<, >=, =\=, =:=]). :- op( 500, yfx, [+, -]). :- op( 500, fx, [+, -, t]). :- op( 400, yfx, [*, /, div]). :- op( 300, xfx, mod). Example Result 2277*37 > yes =:= yes = A = B + 2 A = 2 B = 2 born( Name, Year), Year > = 1950, The names of people born between 1950 & 1960 Year < = e.g. Given two positive integers, X and Y, their greatest common divisor D, can be found according to 3 cases: i. if X = Y, D = X, if X < Y, D = the greatest common divisor of X and Y-X. i if Y < X, D = the greatest common divisor of Y and X-Y. To formulate in Prolog: gcd( X, X, X). gcd( X, Y, D) :- X < Y, Y1 is Y - X, gcd( X, Y1, D). gcd( X, Y, D) :- Y < X, X1 is X - Y, gcd(x1, Y, D). e.g. Finding the length of a list, length( [], 0). length( [_ Tail], N) :- length( Tail, N1), N is 1 + N1. Example : Example programs using structures The family in fig. 7 can be stored in the database by the clause. e.g. family( person( tom, fox, date( 7, may, 1950), works(bbc,15520)), person( ann, fox, date( 9, may, 1951), unemployed), [ person( pat, fox, date( 5, may, 1973), unemployed), person( jim, fox, date( 5, may, 1973), unemployed)]). PROLOG page 13

14 family( person( david, brown, date( 7, may, 1950), works(bbc,15520)), person( mary, brown, date( 9, may, 1951), unemployed), [ person( may, brown, date( 5, may, 1973), unemployed), person( john, brown, date( 5, may, 1973), unemployed)]). husband( X) :- family( X, _, _). wife( X) :- family( _, X, _). child( X) :- family( _, _, Children), member( X, Children). % X is a husband % X is a wife % X is a child member( X, [X L]). member( X, [Y L]):- member( X, L). exists( Person) :- husband( Person); wife( Person); child( Person). % Any person in the database dateofbirth( person( _, _, Date, _), Date). salary( person( _, _, _, works( _, S)), S). % Salary of working person salary( person( _, _, _, unemployed), 0). % Salary of unemployed total( [], 0). % Empty list of people total( [Person List], Sum) :- salary( Person, S), % S : salary of first person total( List, Rest), % Rest : sum of salaries of others Sum is S + Rest. Write down the answer to the following queries: Query exists( person( Name, Surname, _, _) ). Answer child(x), dateofbirth( X, date( _, _, 1981) ). wife( person( Name, Surname, _, works( _, _) ) ). exists( person( Name, Surname, date( _, _, Year), unemployed) ), Year < exists( Person), dateofbirth( Person, date( _, _, Year)), Year < 1950, salary( Person, Salary), Salary < PROLOG page 14

15 family( Husband, Wife, Children), total(husband, Wife Children], Income). CONTROLLING BACKTRACKING ~ CUT Studying the following sample program, f( X, 0) :- X < 3. % Rule 1 f( X, 2) :- 3 =< X, X < 6. % Rule 2 f( X, 4) :- 6 =< X. % Rule 3 When the following question is posed,?- f(1,y), 2 < Y. Y becomes instantiated to 0 and violate the second condition input in question, However, Prolog tries through backtracking two useless alternatives X Figure 7 A double-step function Preventing useless backtracking, the technique of cut is used, with the symbol! indicating it. For the previous example, the program can be changed to, f( X, 0) :- X < 3,!. f( X, 2) :- X < 6,!. f( X, 4). For the question f( 1, Y), 2 < Y after finding the second condition does t hold at the first rule, it tries backtracking and then the backtracking is cut. rule 1 Y = 0 f(1, Y), 2 < Y rule 2 Y = 2 rule 3 Y = 4 1 < 3, 2< 0 3 1, 1 < 6, 2 < 2 6 1, 2 < 4 CUT 2 < 0 e.g. Computing maximum max( X, Y, X) :- X >= Y. max( X, Y, Y) :- X < Y. Figure 8 At the point marked CUT we already kw that the rules 2 and 3 are bound to fail. These two rules are mutually exclusive, thus formulate in a more ecomic way, max( X, Y, X) :- X >= Y,!. max( X, Y, Y). PROLOG page 15

16 e.g. Single-solution membership member( X, [X L]). member( X, [Y L]) :- member( X, L). This is n-deterministic : if X occurs several times then any occurrence can be found. The following is a deterministic one, member( X, [X L]) :-! member( X, [Y L]) :- member( X, L). To clarify this definition, consider a clause of the form: H :- B 1, B 2,..., B m,!,..., B n. Let us assume that this clause was invoked by a goal G that matches H. i. At the moment that the cut is encountered, the system has already found some solution of the goals B 1,..., B m becomes frozen and all possible remaining alternatives are discarded. The parent goal G w becomes committed to this clause: any attempt to match G with the head of some other clause is precluded. i Backtracking will still be possible within the goal list after!. Negation as Failure That something is t true can be said in Prolog by using a special goal, fail, which always fails, thus forcing the parent goal to fail. e.g. To formulate Mary likes all animals but snakes. likes( mary, X) :- snake( X),!, fail. likes( mary, X) :- animal(x). e.g. Defining the difference relation. If Goal succeeds then t (Goal) fails otherwise t (Goal) succeeds. t( P) :- P,!, fail; true. Problems with cut and negation Advantages of using cut: i. With cut we can often improve the efficiency of the program. The idea is to explicitly tell Prolog t to try other alternatives because they are bound to fail. Using cut we can specify mutually exclusive rules; so we can express rules of the form: a) if condition P then conclusion Q, b) otherwise conclusion R Disadvantage of using cut: Lose the valuable correspondence between the declarative and procedural meaning of programs. PROLOG page 16

17 Remark: If there is cut in the program, we can change the order of clauses and goals, and this will only affect the efficiency or termination of the program, t the declarative meaning. On the other hand, with using cut, a change in order of clause will change the declarative meaning. 1. p :- a, b p :- c % means p <==> (a & b) v c 2. p :- a,!, b p :- c % means p <==> (a & b) v (~a & c) Predefined IF/PROLOG procedures Sample Program: :- op(100, xfy, reports_to). iptool :- write('to finish, type in: stop.\n'), write('type in terms like: X reports_to Y.\n'), repeat, write(:),tab(1), read(term), interpreter(term). interpreter(stop) :-!. interpreter(x reports_to Y) :-!, asserta(x reports_to Y), fail. interpreter(_) :-!, write('"x reports_to Y." expected, try again:\n'), fail. read - It reads the next term from the CURRENT input stream. write - It writes term(s) to the current output streaming according to current operator declarations, with quotes ( ) omitted. repeat i. It always succeeds. Remember that IF/Prolog returns to the last successful solved clause and attempts to find ather solution. i If repeat was the last successful clause in a procedure in effect it has an infinite number of solutions and an infinite sequence of backtracking choices is generated. iv. To exit from a loop caused by repeat, the following clauses must either succeed, or a cut must be executed to that the backtrack point at repeat is removed. PROLOG page 17

Artificial Intelligence Course Sharif University of Technology

Artificial Intelligence Course Sharif University of Technology Artificial Intelligence Course Sharif University of Technology Outline Data objects Matching Declarative meaning of Prolog programs Procedural meaning Example: monkey and banana Order of clauses and goals

More information

Syntax and Meaning of Prolog Programs

Syntax and Meaning of Prolog Programs Chapter 2 Syntax and Meaning of Prolog Programs Data Objects Matching Declarative meaning of Prolog programs Procedural meaning Example : monkey and banana Order of clauses and goals The relation between

More information

PROLOG programming for artificial intelligence

PROLOG programming for artificial intelligence Prolog Prolog.1 Textbook and Software Title PROLOG programming for artificial intelligence Author Ivan Bratko Get the software windows Home users: download from the course site Install software to preferred

More information

A Sample Prolog Session

A Sample Prolog Session A Sample Prolog Session 1 The Monkey Banana program Below is the program as shown in Figure 2.14[1]. % Figure 2.14 A program for the monkey and banana problem. % move( State1, Move, State2): making Move

More information

Prolog. Textbook and Software. Title PROLOG programming for artificial intelligence

Prolog. Textbook and Software. Title PROLOG programming for artificial intelligence Tutorial : Prolog Prolog Prolog.1 Textbook and Software Title PROLOG programming for artificial intelligence Author Ivan Bratko Get the software windows Download PL.zip from the course site Extract the

More information

Logic Programming and PROLOG (III)

Logic Programming and PROLOG (III) Logic Programming and PROLOG (III) Dr. Antonio L. Bajuelos Note: The most of the information of these slides was extracted and adapted from Bratko s book, Prolog Programming for Artificial Intelligence".

More information

Last Week COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Recursion The Ancestor Relation

Last Week COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Recursion The Ancestor Relation COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Dr. Annabel Latham Ashton Building Room 2.05 http://www.csc.liv.ac.uk/~alatham/comp219.html Last Week Prolog programs comprised

More information

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010 Prolog Programming Chapter 2 Syntax and Meaning of Prolog Programs 1/16/2010 1 Chapter 2 Syntax and Meaning of Prolog Programs Data Objects Matching Declarative meaning of Prolog programs Procedural meaning

More information

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog COMP219: Artificial Intelligence Lecture 6: Recursion in Prolog 1 Overview Last time Introduction to Prolog: facts, rules, queries; family tree program Today: Recursive rules in Prolog; writing and evaluating

More information

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation Topics Chapter 16 Logic Programming Proving Theorems Resolution Instantiation and Unification Prolog Terms Clauses Inference Process Backtracking 2 Predicate Calculus and Proving Theorems A use of propositions

More information

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses

Derived 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 information

What are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)).

What 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 information

Operators (2A) Young Won Lim 10/2/13

Operators (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 information

Overview. Declarative Languages. operation of del. Deleting an element from a list. functions using del. inserting elements with del

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

Lecture 9: A closer look at terms

Lecture 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 information

Operators (2A) Young Won Lim 10/5/13

Operators (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 information

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy Topics Chapter 16 Logic Programming Summary (resolution, unification, Prolog search strategy ) Disjoint goals The cut operator Negative goals Predicate fail Debugger / tracer Lists 2 Resolution Resolution

More information

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006

COMP 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 information

Lecture 11: Feb. 10, 2016

Lecture 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 information

Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E

Prolog (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 information

Topic B: Backtracking and Lists

Topic B: Backtracking and Lists Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct

More information

Backtrack control. Chapter 5

Backtrack control. Chapter 5 Chapter 5 Backtrack control Prolog will automatically backtrack to satisfy a goal. This relieves the programmer of the burden of putting in backtrack explicitly. On the negative side, this might lead to

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme 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 information

Prolog Programming. Chapter 5. Controlling Backtracking : 1/16/2010

Prolog Programming. Chapter 5. Controlling Backtracking : 1/16/2010 Prolog Programming Chapter 5 Controlling Backtracking : 1/16/2010 1 Chapter 5 Controlling Backtracking Preventing backtracking Examples using cut Negation as failure Problems with cut and negation 2 5.1

More information

Prolog Programming. Lecture Module 8

Prolog Programming. Lecture Module 8 Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of

More information

More Planning and Prolog Operators

More 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 information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

An introduction to logic programming with Prolog

An introduction to logic programming with Prolog An introduction to logic programming with Prolog Dr. Constantinos Constantinides Department of Computer Science and Software Engineering Concordia University A running example: A family genealogy tree

More information

Lecture 9. Exercises. Theory. Solutions to exercises LPN 8.1 & 8.2. Patrick Blackburn, Johan Bos & Kristina Striegnitz

Lecture 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 information

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler. Name: Midterm Exam PID: This is a closed-book exam; you may not use any tools besides a pen. You have 75 minutes to answer all questions. There are a total of 75 points available. Please write legibly;

More information

Logic Languages. Hwansoo Han

Logic Languages. Hwansoo Han Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...

More information

Recursion, Structures, and Lists

Recursion, 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 information

Prolog. Logic Programming vs Prolog

Prolog. Logic Programming vs Prolog Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming

More information

INTRODUCTION TO PROLOG

INTRODUCTION 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 information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

3 Lists. List Operations (I)

3 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 information

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3.

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. 1 Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. Satisfying goals 2 Prolog A standard free Prolog can be downloaded from http://www.swi-prolog.org

More information

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday.

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday. The current topic: Prolog! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values Logic programming: Prolog! Introduction

More information

Brief Introduction to Prolog

Brief Introduction to Prolog CSC384: Intro to Artificial Intelligence Brief Introduction to Prolog Prolog Programming for Artificial Intelligence by Ivan Bratko. Prolog is a language that is useful for doing symbolic and logic based

More information

Backtracking. Ch. 5 Controlling Backtracking. Backtracking. Backtracking Example. Example. Example

Backtracking. Ch. 5 Controlling Backtracking. Backtracking. Backtracking Example. Example. Example Backtracking Ch. 5 Controlling Backtracking Backtracking is the attempt to (re)satisfy a goal by exploring alternative ways to satisfy it. Chronological backtracking is backtracking in which we always

More information

Prolog. Intro to Logic Programming

Prolog. 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 information

CSE 20 DISCRETE MATH. Winter

CSE 20 DISCRETE MATH. Winter CSE 20 DISCRETE MATH Winter 2017 http://cseweb.ucsd.edu/classes/wi17/cse20-ab/ Final exam The final exam is Saturday March 18 8am-11am. Lecture A will take the exam in GH 242 Lecture B will take the exam

More information

UNIT 2 A. I. LANGUAGES-2: PROLOG

UNIT 2 A. I. LANGUAGES-2: PROLOG UNIT 2 A. I. LANGUAGES-2: Structure Page Nos. 2.0 Introduction 42 2.1 Objectives 43 2.2 Foundations of Prolog 43 2.3 Notations in Prolog for Building Blocks 46 2.4 How Prolog System Solves Problems 50

More information

Wan Hussain Wan Ishak

Wan 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 information

PROLOG PROgramming in LOGic

PROLOG PROgramming in LOGic PROLOG PROgramming in LOGic 1 Knowledge-Based Information Systems (Relational) database systems are very efficient in the handling of data. Information is data together with a suitable interpretation.

More information

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

PROgramming 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 information

Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Functional & Logic Programming - Backtracking October, 01

Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Backtracking. Functional & Logic Programming - Backtracking October, 01 Functional & Logic Programming - October, 01 already seen how to control execution ordering the clauses and goals can affect the speed of execution and the order of evaluation of the clauses now going

More information

Defining Binary & Unary Operators

Defining 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 information

Logic Programming Paradigm

Logic Programming Paradigm Logic Programming Paradigm Sample Courseware Logic Programming Paradigm Logic programming offers a formalism for specifying a computation in terms of logical relations between entities. A logic program

More information

Software Paradigms (Lesson 6) Logic Programming

Software Paradigms (Lesson 6) Logic Programming Software Paradigms (Lesson 6) Logic Programming Table of Contents 1 Introduction... 2 2 Facts... 3 3 Predicates (Structured Terms)... 4 3.1 General Structures... 4 3.2 Predicates (Syntax)... 4 3.3 Simple

More information

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 Sketchpad Graphics Language Reference Manual Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 October 20, 2013 1. Introduction This manual provides reference information for using the SKL (Sketchpad

More information

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong Today's Topics SWI-Prolog installed? We will start to write grammars today Quick Homework 8 SWI Prolog Cheatsheet At the prompt?- 1. halt. 2. listing. listing(name).

More information

Logik für Informatiker: PROLOG Part 3: SLD Trees

Logik für Informatiker: PROLOG Part 3: SLD Trees Logik für Informatiker: PROLOG Part 3: SLD Trees Andreas Karwath & Wolfram Burgard (original slides by Peter Flach) 1 SLD Resolution and SLD Trees 2 Resolution in Prolog based on definite clause logic

More information

Introduction to Prolog

Introduction to Prolog Introduction to Prolog David Woods dwoods@scss.tcd.ie Week 3 - HT Declarative Logic The Prolog programming language is, at its theoretical core, a declarative language. This is unlike more commonly used

More information

IFAD. VDMTools Validated. Design through Modelling. Overview of VDM -SL/++ IFAD. IFAD A/S Forskerparken 10 DK-5230 Odense M Denmark.

IFAD. VDMTools Validated. Design through Modelling. Overview of VDM -SL/++ IFAD. IFAD A/S Forskerparken 10 DK-5230 Odense M Denmark. VDMTools Validated Design through Modelling Overview of VDM -SL/++ www.ifad.dk A/S Forskerparken 10 DK-5230 Odense M Denmark 1 VDM-SL ISO Standard 1996 for flat language Different module proposals A de-facto

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

More information

Operational Semantics

Operational Semantics 15-819K: Logic Programming Lecture 4 Operational Semantics Frank Pfenning September 7, 2006 In this lecture we begin in the quest to formally capture the operational semantics in order to prove properties

More information

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg 1 Logic Programming True facts: If I was born in year B, then in year Y on my birthday I turned Y-B years old I turned

More information

Defining! Binary & Unary! Operators!

Defining! 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 information

Defining Binary & Unary Operators DO-1

Defining 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 information

Problem Solving and Search

Problem Solving and Search Problem Solving and Search Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam [ http://www.illc.uva.nl/~ulle/teaching/pss/ ] Ulle Endriss 1 Table of Contents Lecture 1:

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 6 Prolog Basics 1/42 Programming Paradigms Unit 6 Prolog Basics J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2017/18 Unit 6 Prolog Basics 2/42 Outline

More information

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop CAP 5602 Summer, 2011 Lesson 4: Loops The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop 1. The cut The cut (!) is a way of controlling backtracking. If a rule contains a

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

First-Order Logic (FOL)

First-Order Logic (FOL) First-Order Logic (FOL) FOL consists of the following parts: Objects/terms Quantified variables Predicates Logical connectives Implication Objects/Terms FOL is a formal system that allows us to reason

More information

Expr Language Reference

Expr Language Reference Expr Language Reference Expr language defines expressions, which are evaluated in the context of an item in some structure. This article describes the syntax of the language and the rules that govern the

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

More information

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89 Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the

More information

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

It 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 information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

CSE 20 DISCRETE MATH. Fall

CSE 20 DISCRETE MATH. Fall CSE 20 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Final exam The final exam is Saturday December 16 11:30am-2:30pm. Lecture A will take the exam in Lecture B will take the exam

More information

Introduction to predicate calculus

Introduction to predicate calculus Logic Programming Languages Logic programming systems allow the programmer to state a collection of axioms from which theorems can be proven. Express programs in a form of symbolic logic Use a logical

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Reviews. Arithmetic Operators (2)

Reviews. Arithmetic Operators (2) Introduction to Prolog Useful references: Clocksin, W.F. and Mellish, C.S., Programming in Prolog: Using the ISO Standard (5th edition), 2003. Bratko, I., Prolog Programming for Artificial Intelligence

More information

Data types for mcrl2

Data types for mcrl2 Data types for mcrl2 Aad Mathijssen April 5, 2018 We provide a syntax for the standard data types of the mcrl2 language. This syntax is intended to be a practical mix between standard mathematical notation

More information

Last Week. Today. Prolog: recursion examples. Recursion in Prolog. CSC326 Programming Languages (Week 12,Friday)

Last Week. Today. Prolog: recursion examples. Recursion in Prolog. CSC326 Programming Languages (Week 12,Friday) Last Week CSC326 Programming Languages (Week 12,Friday) Yilan Gu guyilan@ecf.toronto.edu http://www.cs.toronto.edu/~yilan/326f09/ More on Prolog reasoning mechanism Operators Lists Today Recursion in Prolog

More information

Prolog-2 nd Lecture. Prolog Predicate - Box Model

Prolog-2 nd Lecture. Prolog Predicate - Box Model Prolog-2 nd Lecture Tracing in Prolog Procedural interpretation of execution Box model of Prolog predicate rule How to follow a Prolog trace? Trees in Prolog use nested terms Unification Informally Formal

More information

UNIT- 3 Introduction to C++

UNIT- 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 information

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog CS 360: Programming Languages Lecture 10: Logic Programming with Prolog Geoffrey Mainland Drexel University Section 1 Administrivia Midterm Tuesday Midterm is Tuesday, February 14! Study guide is on the

More information

Wan Hussain Wan Ishak

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 information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. 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 information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

In this chapter you ll learn:

In this chapter you ll learn: Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading on

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x).

Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x). Logic Programming Logic Programming = ex) factorial program query fac(1,1) fac(n-1,m) fac(n,n m)?- fac(5,120). yes?- fac(5,x). X=120 cf) in procedural programming x=1; for (i=1;i

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4

More information

Input & 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 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 information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd 19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading

More information

CHAD Language Reference Manual

CHAD 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 information

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There 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 information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut 1/38 Programming Paradigms Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut J. Gamper Free University of Bozen-Bolzano

More information