You are on page 1of 21

SIR PADAMPAT SINGHANIA UNIVERSITY Udaipur

CS 302: Artificial Intelligence Lab Manual

1

Contents

1. 2. 3. 4.

Lab Rules………………………………………………………….3 About Turbo Prolog……………………………………………...4 Initiation……………………………………………………….…15 List of experiments………………………………………………19

2

Marking criteria. Weightage: Internal: 20 marks External: 30 marks 3 . Write input test data/ or program that are used to test program objective to see whether program is achieving the given objective or not. This section specifies the complete description of the including problem analysis. Conclusion: 3. 2. 4. The experiments should be completed and get checked by the concerned teacher in the lab on or before the date of submission. describe the results in few lines Write complete conclusion whether what the student has learned from this experiment. method used. In this section write the complete errorless source code. a) Experiment completion b) Lab file (neatness and regularity) c) Viva (from time to time) d) Exam (end term): experiment + viva 5. 2. Every experiment must be included in the file in following format. input description. The content of the whole lab is attached in this document. Output: 5. Source Code: 3.LAB rules (for students) 1. Aim: In this section write complete objective of the program you are going to make in the lab. fundamental concept and desired output format. The student must have the full printed content page right from the first day of the lab in their lab files. 1. Input: 4. After which the experiment will not be signed.

A. trough this article. Kowalski et A. 1970: R. But his goal was not to create a new programing language. So he managed to study the researches of R. First. to look for the rules of wich the goal is the conclusion. then i will give you the basics of the language. To obtain a simple poerful and fonctionnal program. Warren. Roussel et A. So. used the model of A. Roussel.D. and the Prolog tool was developed. The birth of Prolog: In France. on his side. with R. A piece of history The logic programing in few dates: • • • • 1930: Jaques Herbrand achieve his theory about the calculation of the predicates. It's easy to use because the Prolog is a logical programming language. He only wanted to be able to describe. 1. and he used thes theories as the base for the first theoric model of Prolog. Kowalski about the resolution methods. P. thanks to P.H. Colmerauer use the logic as a programing language. Finally. The Prolog is a logic programing language based on two mains mechanisms: the backtracking and the unification. by taking the conditions of this rules as new under goal. Colmerauer began to be interested in the way to make deductions from some texts. i will tell you about the history of Prolog. So. i will try to make you understand the best i can the method to write a program with Prolog. 1972: The first Prolog interpretor is born at the University of Marseille. Colmerauer. redo 4 . a environment to a computer in order that this one could answer to some questions on the environment. you only need to give a sample of facts and rules. he made Prolog interpretor wich was coded in Fortan.they made an embryo of such a system. The backtracking is the fact to go from the wanted goal. en 1970. then. thanks to D. 1977: The first Prolog compiler apperas at the University of Edimburg.About Turbo Prolog Introduction The Prolog is a well known language in the domain of the Artificial Intelligence. in french. i will present to you a very useful tool for those who wish to begin with Prolog: Borland Turbo Prolog. Kowalski. Colmerauer and with the help of some fellow-members from the University of Edimburg.

there only remain to unify the found facts with the required goal.that tey contain. so the interpretor will not interprete the content of these beacons. Now let us close this presentation and see the basics of Prolog. There are several predefined types: symbol A symbol is a succession of characters which must begin with a lower case character. a fact and a rule) by giving to the variables . and write a program with it is easy. the symbol must be encapsulated with two double quotes ("").2. Examples of symbols : example an-other-example again_a_symbol 5 . 2. it is used to indicate to the program the questions or the internal goals to solve */ NB:In Prolog the beacons /* and */ are used to isolate the comments. or to put some blank spaces in it. the "domains" section allows us to define the types which will be used in the program. The structure of a program Any Program written with Prolog must respect a well defined structure. In order to be able to make a symbol begin by an upper case character. The basics 2. The unification is the fact to try to make two assertions equals(generaly.1. It is especially used to build some systems on the natural languages or some expert systems. some values. Finally.the search recursively. Here is this structure: domains /* here will be declared the types which will be used in the program */ predicates /* here will be put the primitives of the predicates which will be used in the rules */ clauses /* here will be written the facts (or assumptions) and the rules which are our program */ goals /* this section is optional. It is a clear and a readable language for any user. The domains In Prolog. and so build a base with all the facts found. 2.

positive(3). father(pierre.1e-307 et +/. An other type of predicate would be. For example. Example : 'c'."A_symbol_with_upper_case" "a symbol with blank spaces" integer The integers are all the integer numbers between -32768 and +32767 real The reals are the real numbers between +/.3. the decimal separator is the dot character (. the lists are also available. In the predicates section of a Prolog written program. The predicates The predicates express a relation between their arguments. the predicates are the "functions". would indicate if 3 is positive or not. emma) indicate that a relation exists between pierre et emma. these are the clauses. 6 . In Prolog.87 Remark : In Prolog. A char is always written between two simple quotes (' '). this relation is father. i'll show you an example of types declarations. domains my_int = integer /* définition of a simple type my_int which is of the type integer */ list_string = string* /* the character '*' after the type to indicate that a list is defined. To help you to understand.) char These are all the character. or a property of one of these. look the predicate father. This predicate. Example : "hello world". the non predefined predicates are declared like the following example: predicates father(symbol.symbol) /* father takes two parameters of symbol type */ positive(integer) /* positive takes one parameter of the integer type */ There remains only the definition of the rules of the predicates and the facts. In short. in Prolog. here a string list */ 2.1e+308 Examples of reals : 4 -97456 42. for example. A string is always written between two double quotes (" "). string These are the character strings.

so we will use these abbreviations: IF :AND . grand_father(X. emma) /* this fact affirms taht pierre is emma's father */ a fact is always true. This set of clauses forms the knowledge base which will be used by the program to reason. The conclusion is proven only if all the conditions are true.4. each clause (fact or rule) ends with a dot. At the time of the call of a predicate. Progressively with its demonstrations. marie). we have declared the predicates father and grand_father. A fact is a relation between two or more objects. so it look for the rules and the facts associated to this predicate and will solve all that is necessary. Few rules must be followed to write a good program with Prolog: • • • at least one clause must be written for a declarated predicate. and give as answer all the solutions of the question asked at the beginning. all the clauses concernng a same predicate must be gathered.2.Z) AND father(Z. A rule has a specific form which is: conclusion IF condition(s). The clauses The clauses is a set of facts and rules.Y). AND and OR are very often used. Example: father(pierre.Y) IF father(X. father(paul. A rule can have several conditions. OR . Example: Let us consider that. symbol) clauses father(jean. so we will use the keywords AND and OR to separate them. in the predicates section. there are the clauses: predicates father(symbol. the keywords IF. Prolog will try to solve it. 7 . paul). symbol) grand_father(symbol. A rule is a conditional relation. Prolog makes go up the results of all its demonstrations.

It also possible to work with some variables in the rules in order to modify them.). X is the grand_father of Y if X is the father of Z and that Z is the father of Y. In Prolog. it will make all the solutions go up. let us translate the rule grand_father. The external goals are taped in the "dialog" windows of the interpretor(for example Borland Turbo Prolog 2. a simple program : the fathers. . the creation of a dynamic data base. marie) /* ask the program if jean is the father of marie */ father(X. I will present to you what are the goals and what is their utility. The clause linked to grand_father is a rule.Comments: In this example. Ther exists two types of goals.6. The internal goals are often used to carry out some operations that must be done before to call an external goal(like the initialisation of a graphic interface. So X. nom) clauses 8 . An external goal is a call to our program.Y et Z). 2. Now. Now. The internal goals can't print a result on the screen nor ni to make go up the solutions of the problem. all the clauses linked to the predicate father are facts because they are sont unconditional. The goals The goals allow people to question the program.. if they exist */ 2. The internal goals are written in the goals section of the program. marie) /* ask the program if marie has one or several fathers and give all the solutions */ The use of the variable allow Prolog to make all the solution go up. the internal goals and the external goals. Several simple examples In this section. father(jean. I will show you how to make this in the example sextion at the en of this chapter.Y and Z can take all the values in their definition domain fixed in the predicates section(here symbol).5. any symbol beginning with an upper case character is considered as a variable. You will notice the use of some symbols beginning with an upper case character(X. i will present to you several examples of programs written in Prolog in order to illustrate what i have introduced to you before. Examples of external goals father(jean. Prolog will solve this goal. X) /* allow us to know all the children of jean. and it will print a result if it exists.0).. domains nom = symbol predicates father(nom.

marie) No Goal: father(jean. so the sum of A and B is assigned at the variable Result. integer) clauses add(A. paul) The program answers: Yes So jean is the father of paul. Besides. so the program can't fing any solution.O "Goal:" is the prompt when the program is runing. in the base of facts. integer. Now some other goals and answers.Result = A + B. Launch the program and call the predicate add. 4. a simple program with some manipulation of variable predicates add(integer. valentin). and it prints their count. paul). it prints each of them in the order it found them in the base of facts. Goal: father(jean. paul) In Borland Turbo Prolog 2. jean is not defined as being the father of marie. Goal: father(jean. father(marc. so it can't find any solution. marie). father(marc. claude).father(jean. father(marc. X) No Solution Goal: father(marc. I will show you how to proceed with an example. Finally. Result) :. father(jean. Res) Res=7 1 Solution the operator = used in the rule is the assignment operator. Let us launch the program and input the following goal: father(jean. fiona). Prolog and the negation In Prolog. marc has 3 children. the predefined predicate "not" can be applied on a rule called in a condition. To use the rule add and recover the result. X) X=fiona X=valentin X=marie 3 Solutions lola and jérome are not in the base of facts of the program. you need to use an extra argument and this last one must be a variable because there is no function in Prolog. and so no possibility to return a result. 9 . lola) No Goal: father(jérome. B. Goals: add(3.

An important remark. In this last case. the character '|' separate the head of the list of its tail.3] is an integer list which contains the integers 1. symbol) clauses friend(pierre. louis). friend(jean. A list is empty. all the elements from a same list must have the same type. not(friend(X. Examples: .e] ] ] ] [a | [b | [c | [d | [e] ] ] ] ] 10 . In Prolog. 2 and 3.e] and cut it recursively: [a | [b. [a] is a list with the symbol 'a'. Prolog. When using the "not". Examples: [] is the empty list. its type must be declared in the domains section of the program.2] can be cut into [1|[2]] 1 is the first element of the list. its elements are separated with a comma. in order to be the friend of gaetan. louis)).d. Examples: domains li = integer * /*li is a list of integers*/ ls = symbol * /*ls is a list of symbols*/ name = symbol ln = name * /*ln is a list of names. X must be a friend of paul and must not be a friend of louis.e] ] ] [a | [b | [c | [d.paul). Before using a list in Prolog. [1. paul).predicates friend(symbol.Let's consider the list [a. pierre).2.d. you must take a precaution: the conditions which allow the unification must be placed before those on which the "not" is applied. the recursivity and the lists The recursivity and the lists provide to Prolog a powerfull tool of reasonning.[1.friend(X. friend(pierre.c. Here. and i will give you an example of recursive function which use the lists. X) :. any list can be cut into a head and a tail.c. . friend(gaetan. friend(jean. or it contains at least one element.d. then [2] is the the tail of the list.b. anne). I will explain to you in short the principle of the lists. but also a list of symbolsbecause name is a symbol*/ The syntax is simple: identifier_of_the_type = type_of_the_elements * The star indicates that we use a list.e] ] [a | [b | [c.

the program does nothing. the "\n" is used to print a new line. Here. Tf the list contains only one element. If the list is empty. aff([X|Y]) :. For that.write(X."\n"). The first clause(aff([]).[a | [b | [c | [d | [e | [] ] ] ] ] ] So. the program prints it. here. But in a program. This principle is valid if you want to recover the n first elements of a list. the program call the predicate aff on the tail of the list. Then. the program does nothing. i will just give you the mathematical functions which exit in Prolog: + Addition . it prints its first element by using a predefined predicate very useful (write).Soustraction Absolute X div Integer division of X by abs(X) Y value of X Y X mod Remainder of the integer Square root sqrt(X) dividion of X by Y of X 11 * Multiplication / Division . if the list is empty. For example.write(X."\n"). we can recover the data like we wish it. Here. here is the interest of the recursivity.Y|Z]. each element of the list can be recovered. Y the second.write(X._|Z]) :. Another remark. the program to print the content of a list of integer domains li = integer * /*li is a list of integers*/ predicates aff(li) clauses aff([]). Also an element can be ignored: Example: domains li = integer * predicates aff_un_sur_deux(li) clauses aff_un_sur_deux([]). the call the predicate aff_un_sur_deux on the tail of the list (Z).) is the break condition of the recursive program. If the liste contains more than one element. X is the first element. the program prints the first one (X). it is possible to recover the two first elements. In order to close this chapter. the use of the variables is very important because thanks to the variables. by cutting this list."\n"). after having printed the head of the list. ignore the second (use of '_'). aff_un_sur_deux(Z). aff_un_sur_deux(X|[]]) :. aff_un_sur_deux([X. we will not recover with the hand all these elements. the list must be cut like: [X. aff(Y). and Z is the tail of the list. But if the list is not empty.

0(in the continuation of this chapter. tan(X).1. All the main tools are integrated in TP: • • • • • an editor. a menu to navigate from an element to another. It is a complete development environment for Prolog developers. an interpretor. Presentation Borland Turbo Prolog 2.0 3. arctan(X) (here X must be a value in Radians) exp(X). a window "trace". log(X) 3. and to do some settings. i will use the abbreviation TP) has been launched by Borland in 1986.Y cos(X). dedicated for the trace mode. A preview of TP: 12 . a dialog window to print the output of the program. ln(X). sin(X). How to use Borland Turbo Prolog 2.

Save the content of the editor to a specific file that you will choose.3. a selection window will appear. used to recall the previous goal. Now. The menus and the keybord short cuts In this section. The menu of TP contains six objects but only three of them are useful to begin: The "Files" menu With this menu you will be able to manage your files in the TP environment. "Run" launch the interpretation of the program. the list of the keybord short cuts that is useful to know: Short cut Alt + F Alt + E Alt + R Alt + X F2 F3 F8 Open the "Files" menu. Load the content of a file in the editor. else it will be overwritten. The editor 13 . "Edit" is used to go in the editor window. Action 3. so we can edit the program. Launch the interpretationof the program. and put the focus on the "Dialog" window. There are the most useful actions: Object of the menu Load New file Save Write to Quit Action load a file by giving its name. Save the current file. If you input *.2. The "Edit" and "Run" menus These two objects are not really menus. Save the current file. Create a new file and close the current one. In runing mode only.Let's begin the visit of TP with the menus and the short cuts.pro. i will present to you the menus and the keybord short cuts which are useful for any beginner in Prolog. 3. then go in the dialog window and wait for an external goal. Put the focus on the "Editor" window. Quit TP. Quit TP. It will be created if it doesn't exists.

14 . the "Dialog" window will be active. Press the enter key. it will keep this indentation. This editor which allows the free deplacement of the cursor. let a blank space and declare a predicate. When you launch the interpretation of your program.4. For example. and the result of this clause will be printed in the "trace" window. How to use the trace mode The trace mode is useful when you want to know how exactly your program run. So you will be able to enter an external goal to call your pragram. open the predicates section with the keyword "predicates". Press the enter key again. the program will wait for you to press the F10 key in order to move a step forward. without any blank space at the beginning of the line. the cursor will be placed on the current clause. So. Finally. The interpretor The interpretor is used to interprete the program. is useful because when you indent your code by putting a blank space at the beginning of a line. The results of this last one will be printed in the dialog window. you only need to put the keyword trace at the beginning of your program. 3. Please remark that the cursor kept the blank space that you put at the beginning of the previous line. when you will lauch your program.The "Editor" is the tool in which the code of the program is printed.5. To activate the trace mode. 3. for each executed instruction.

Classes). to load in the that rules you have entered. required(Course.NextCourse) :20. prereq(dataStructs.NextCourse).prereq(Course. required(Course. In a terminal window.progLangs).graphics).progLangs). Make sure you include the period at the end.prolog in your favorite text editor. What responses do you get? Why? 9. prereq(introCS. 10. 17. 3.SomeOtherCourse). 7. prereq(dataStructs. prereq(dataStructs. The questions that you find intermixed throughout the lab are for you to think about. prereq(dataStructs. Note that introCS is not considered as a prerequisite to progLangs. Whenever you get a prompt for more answers.ai). Enter the following queries into Prolog. 11. 13.graphics). and type pl to start up Prolog. 8.X). Inside Prolog.graphics). 5.dataStructs). change to the appropriate directory where you stored the above program. 15 . 2. we will create a new predicate called required which will take this into account.progLangs). prereq(introCS. enter a semicolon (. and enter and save the following facts. Create the program prog1. prereq(dataStructs.) to see if there are any more. 15. 19. Part 1: Compiling and running a program 1. Now try entering required(X. 14. prereq(introCS.NextCourse) :. prereq(linAlg. prereq(dataStructs. prereq(Course. 16.NextCourse). prereq(linAlg.Initiation Exercise to be practiced during 1st and 2nd days of lab.classes). The following tasks have to be done in order to get accustomed to the prolog programming. 6.required(SomeOtherCourse. 12.linAlg).prolog']. Add the following rules to the bottom of your program: 18. 4. type ['prog1. Why? To correct this. Ask in lab or in class if the answers aren't in clear. prereq(introCS.dataStructs).

Tracing through the program may help. the variable is bound to match the other. 16 . 9.progLangs). Prolog tries to find all rules and facts to match that query. b. At each stopping point. trace. required(introCS. Then try to run the query again: required(introCS.progLangs).Does this solve the problem? Why? What does the comma (.progLangs). to get Prolog out of debug mode.progLangs). type nodebug. a fact or a head (left side) of a rule matches a goal if all three of the following conditions are true: a. When the query is done. prereq(introCS.NextCourse) :. Try changing the rules for required to the following and see what happens when you try the query required(X. 2. If at least one of them is a variable. When Prolog gets to the point where it can't match a goal. How is this consistent with the above statements? 3. enter the following query: required(introCS. Both have the same predicate. 5. hit enter to continue. You will sometimes see a variable with an underscore in front of it. enter the following at a Prolog prompt: 7. 4.NextCourse). The order in which you enter in Prolog rules can be important.dataStructs). like _G463.prereq(Course. More specifically. For example. You may have to occasionally click back on the terminal window and hit the semicolon if it seems that the debugger is stuck. Enter the following queries and examine the results. Matching terms from the query and the fact (or rule head) are equal. and tries a different choice. Both have the same number of terms following the predicate. 8. You'll see Prolog work its way through the possibilities. Whenever you enter a query (also referred to as a goal). c. This indicates that Prolog has picked a default name for an as-of-yet unbound variable. required(Course. What kind of backtracking did Prolog have to do to answer this question? 6.) mean in the rule above? Part 2: How Prolog does it: matching and backtracking 1. To see a trace of Prolog's work. it backtracks to the point where a choice had to be made.

(Note that Prolog sometimes gives warnings about "singleton variables. member(X. is used nowhere else in the rule. 3. H2 | T]).[H1. appendTo([H | T1].[5. member(2.r. 11. X | _]). countTo(4. and an underscore is probably more appropriate. H3 | T]).3]). countTo(4. for separating information out of lists.[_. Find it and fix it. 4. 10.3]).appendTo(T1. countTo(3.[H1. countTo(1.2]).[1.2. H2.2. Prolog has a member predicate that is used to test if a given value is the member of a list.L2. 5. Try the following queries: 7. and see what it does: append([a. Prolog provides pattern matching. We'll create a predicate called appendTo.g. The predicate append is built into Prolog. 11. Try the following example. H2 | T]). [1. but there's a mistake in it. countTo(2. 13. 18. Try the following: 17.3]).2. 8. countTo(2. Load in your code.3. then enter the following query: countTo(4. 6.L2.2.L.[5. countTo(4.[H1.[1.) 16.b]. appendTo([].10.SomeOtherCourse). Let's do it.[1.[1. What do you see? Why? What purpose does the underscore (_) serve? 12. 15.prereq(Course.4]).L).3.T1).3.NextCourse) :required(SomeOtherCourse." This means that you have a variable that exists in only one place. countTo(4.[H | T3]) :. Prolog has lists in much the same fashion as Scheme and SML.NextCourse).Answer). required(Course.x]. countTo(2. 17 . A list is written with similar syntax to SML (e. which does exactly the same thing as append but we've defined it ourselves. Start editing a new Prolog program. 9.[q.2. Part 3: Lists in Prolog 1.4]).4]). The following code is a headstart.[H | T]).2. but you could easily define it yourself. and enter in the following: 2. much like SML. 14.[1]).

You might find it useful to read the help info on these predicates.M). 4. X =:= 12. mystery([]. = is a predicate just like any other and can be written like =(X. 21. 3.T). 1=2. X = 3*4. X = 12.prolog. 9. But the infix notation is standard and more readable. [X | _]). Try these out: 2 is 1+1. X is 12. 6. help(is).19. Try out this query. X = 3*4.2). 1+1 =:= 2. [H | T]) :. Similarly. Try out the following queries to see what you get: 2. X is 3*4. memberOf(X. 5. Try: help(=:=).N) :. N is M+1. help(=). 20. X=Y. which is not the same as the symbol "3". 18 .X=zaphod. 1+1 is 2. Y=X.0).memberOf(H. X = 3*4. X=2.mystery(T. X =:= 3*4. 1+2=3. Here's a broken headstart for you to clean up. X = 3*4. "1+2" is an expression. What does the following mystery predicate do? Why? 8. 7. 2 =:= 1+1. Part 4: Prolog Mathematical Operators 1. Submit your code in a file called memberOf. Technically. mystery([_|T]. memberOf(X. There are thus two more ways of representing equality in Prolog. write our own memberOf predicate.

X = [2. should produce X = [1. 1] .3. X = [1.4. 1. perm([1. Try out this creative use of the append predicate: L=[1.5].Part 5: Now You're Getting 1. See if you can use this idea to create a predicate perm. 2. X = [2. 3] . 1. 2] . X = [3. L).2. which produces all permutations of an input list. 1] . 2.X). 2] . 3.2. For example. X = [3.append( V . 3] . no 19 . 2. [H|T] . 3.3].

an uppercase alphabet or a digit. 2. Write prolog code to replace the occurrences of a specific word by another word throughout a specified file.bham. Write prolog code to convert a given string into a list of constituting characters. Write prolog code for the purpose of ignoring space character from the input stream. 2. female(Y). wife_of(X.cs. Lists 1. 6.Y). Write a prolog program (containing facts and rules) to answer queries regarding Students and courses. male(X). Write prolog code to merge two sequentially ordered lists into one ordered output list. 2. Nehru. 8. Write prolog code to find nth element of a given list.Y). Write prolog code for deleting the first occurrence of an object from a list. (e. Input and output 1.ac. Write prolog code for finding the last_object of an input list. 4. and check if the answer is yes or no. 7. Write prolog code for finding a set which is result of the union of two given sets. 4.html facts and rules: predicate logic. Write prolog code to repeatedly input a character and decide if the same is a lower case alphabet. Write prolog code for writing the elements of a list N per line. Also count the number of characters within the given string and compare the value thus obtained with the value returned by the use of the built in predicate str_len. Write prolog code to find the length of an input list. 3. 1. 3. Write prolog code for typing in a desired question. Write prolog code to append list2 to list1 and bind the result to list3. 2. 5. Write prolog code for checking a specific object to be a member of a given list.g predicates father(X.List of Experiments Study the following link: http://www. Write a prolog program (containing facts and rules) to answer queries regarding family tree of Pt. reading a user typed-in symbol as an answer. String manipulations 1. 20 .uk/%7Epjh/prolog_course/iso_manual/iso_manual.

and that N = E + 1. Since there are 8 letters to be solved. Clearly. 3.R. Write prolog code to check if a given year is leap or not. with x coordinate being the successive rows and the corresponding y-coordinate are the respective integer values of a list. we can simply explore the 10*9*. Write prolog code to calculate the values of sine. Thus MONEY < 19998 and hence M = 1. Write prolog code to find the factorial of a positive integer. General Assignments 1. 2.E. 4. 21 .S. Since M is already bound to 1. A little insight can simplify things. Using these insights to reduce the number of solutions that must be explored.S and Y represents a different digit. Now we have SEND + 1ORE = 1ONEY. Each of the letters D.. A little more thought shows that S must be bound to 8 or 9. statements Write prolog code to add the members of a given list. Again SEND < 9999 and now 1ORE < 1999 so 1ONEY < 11998. Write prolog code to find GCD. Write prolog code for plotting a graph.3.M. This could well be too slow. Moreover. LCM of a given number. Arithmetic and relational expressions.E.N.O. then using the module graph made above plot a graph. when each letter is mapped to its corresponding digit the equation SEND + MORE = MONEY holds. varying from 0o to 360o in the steps of 30o. Assemble the calculated values in a list. "Send more money" is a well-known puzzle.Y]) that solves this puzzle by binding the correct digits to each of the variables in the list. 6.M. write a Prolog predicate soln([D. 5.R. 7. O must be bound to 0.. SEND < 9999 and MORE < 9999.N.O.*3 mappings of letters to digits.