Prolog program to implement the russian multiplication

Assignment Help Computer Engineering
Reference no: EM131149077

Assignment 1:

Important: The main purpose of this assignment is to develop your skills regarding the use of built-in predicates in Prolog, the control of backtracking and the way in which Prolog can be used for simple arithmetic procedures.

Please note that you need to submit screen shots (using fn+prt sc for Windows in most instances) of results for questions where a program/procedure or query is required. This will assist us to see whether you obtained the correct results and if not, try to point out where you went wrong.

Your programs should also be robust. This means that it should check whether all the input arguments for a specific procedure are legal. For example, if you know you are working with integers, an input of the constant that is not an integer is not acceptable.

Important note: It is not advisable that you search for Prolog solutions to the questions in this assignment on the internet. You may find a solution to a specific problem but that will not assist you in acquiring the necessary skills for mastering this programming paradigm.

Question 1

(a) Write a Prolog procedure to split a given list into two separate lists, one containing integers and the other one real numbers. All other items in the given list should be ignored.

(b) Briefly discuss the difference between green cuts and red cuts.

Question 2:

(a) Write a procedure filter(List,PredName,Result) that removes all the elements X in List for which PredName(X) fails, and returns the resulting list in Result. The predicate PredName/1 should be defined when calling the procedure filter.

Let test be defined as test(N):- atomic(N).

?- filter([a,b,-6,7,A,-1,0,B],test,L). L = [a,b,-6,7,-1,0],

Hint: Use the Prolog built-in predicate =..

(b) Write a procedure map(List,PredName,Result) that applies the predicate PredName(Arg,Res) to all the elements in List, and returns the result in the list Result.

Let test be defined as test(N,R):- R is N^3.

?- map([3,5,-2],test,L).

L = [27,125,-8] (6)

Question 3

Use the database you defined for question 1 of assignment 1 to determine the following using setof, bagof or findall:
(a) How many different kinds of birds are listed in the database? (4)
(b) How many birds defined in the database include insects in their diet? (5)
(c) How many different sizes of bird are defined in the database? (4)

Lists can be used to represent sets in Prolog. Write the following Prolog procedures using the Prolog built-in predicates setof, bagof or findall.

(a) The procedure intersection(A,B,L) returns the intersection L of sets A and B,i.e. the set L contains all elements that belong to A and to B. (5)

(b) The procedure complement(A,U,C) returns the complement L of set A given the universal set U (A is a subset of U). The complement of set A consists of all those elements that belong to U but not to A. (6)

Question 4

Consider the following set of Prolog clauses concerning big cats in the National Parks in South Africa.
leopard(X):-
not lion(X), not cheetah(X).
lion(simba). lion(mufasa). lion(scar).

Sometimes Prolog returns unexpected results, e.g. if the query leopard(sylvester) is entered using the information given above, Prolog retuns yes. (For those of you not familiar with Sylvester the lion: he was declared a habitual criminal after escaping twice from one of our national parks. His new home is the Addo Elephant Park in the Eastern Cape.)

(a) Explain why this happens.
(b) What assumption causes the phenomenon mentioned above?

Question 5

Construct a table listing the symbols that can be used to compare two terms X and Y and state the meaning of each. (For your own benefit, make sure you understand the meaning of each.)

Question 6
The way in which cryptarithmetic puzzles can be solved in Prolog is discussed in section 4.4 of Bratko. Use the guidelines given by Bratko to solve the following puzzle:
CROSS + ROADS = DANGER.

Question 7

The Russian Multiplication problem can be defined as follows: Say you want to multiply x with y giving z. The problem is solved using the following iterative loop:

With each iteration, x gets the value x/2 and y gets the value y*2. If x is even, the y-entry is ignored. If x is odd, y is added to a running total. The loop terminates when x = 0.

For example: Calculate z = 24 * 52.

 

x

 

y

 

Calculation of total (T)

 

Total

 

24

 

52

 

 

0

 

12

 

104

 

 

0

 

6

 

208

 

 

0

 

3

 

416

 

T = T + 416

 

416

 

1

 

832

 

T = T + 832

 

1248

 

0

 

 

 

1248

Write a Prolog program to implement the Russian Multiplication Problem.

Question 8

Assume that your database currently contains the following facts:

What are the effects of the following queries?

(a) ?- p(X),q(X,Y),r(Y,Z).
(b) ?- p(X),!,q(X,Y),r(Y,Z).
(c) ?- p(X),q(X,Y),!,r(Y,Z).
(d) ?- p(X),once(q(X,Y)),r(Y,Z).

Reference no: EM131149077

Questions Cloud

What does the term risk free interest mean and why do we use : What does the term risk-free interest mean, and why do we usually use the U.S. Treasury bill yield as the risk-free rate?
What yield to maturity is the bond offering : Yield to Maturity A 5.65 percent coupon bond with 18 years left to maturity is offered for sale at $1,035.25. What yield to maturity is the bond offering?
Using an amortization schedule calculate his payoff amount : Let's say that the restaurant owner in Problem 4 above decides to go with the amortized loan option and after having paid 2 payments decides to pay off the balance. Using an amortization schedule calculate his payoff amount.
What is the serving size stated on the label : What is the "serving size" stated on the label? Does this serving size match the portion you typically consume of this food in one sitting? Is it bigger or smaller than what you typically consume?
Prolog program to implement the russian multiplication : Write a Prolog procedure to split a given list into two separate lists, one containing integers and the other one real numbers. All other items in the given list should be ignored.
Under which of the three options will the owner pay : Under which of the three options will the owner pay the least interest and why
Determines number of occurrences of a given letter in string : In this last checkpoint, you will write a new program that determines the number of occurrences of a given letter in a string. To do so, you are only allowed to use the replace() and len() functions.
What is your intuition about the validity : Who are the key "players" in the politics of the world's fisheries? In other words, who has a stake in fisheries?  What is your intuition about the validity or "truth" of the viewpoint expressed in the article
What is the cost of the equipment that she purchased today : Jane Bryant has just purchased some equipment for her beauty salon. She plans to pay the following amounts at the end of the next five years: $8,250, $8,500, $8,750, $9,000, and $10,500. If she uses a discount rate of 10 percent, what is the cost of ..

Reviews

Write a Review

Computer Engineering Questions & Answers

  Give some guidelines for effective communication

give some guidelines for effective communication. Detail all the written documentation, reports and communications methods used during the life cycle of a project.

  Most interesting part of dhs cyber security page and why

Go to the following website and review it. Write a one page paper (double spaced) on what you think is the most interesting part of the DHS Cyber Security page and why

  How to create a quality management plan

Listing the  business and IT risks specific to developing and operating a web site to sell appliances over the Internet.

  Developing the c++ code

Write down a C++ code in order to execute the following application: If you press on “Sum” button, summation of all the multiple of 4 numbers greater than 0 and less than 100 will be found and the result will be displayed in result edit box.

  Describes a function named insidecircle

Describes a function named insideCircle

  Do clear data from my maskedtextbox named "mtbpac"

I am using Visual Basic.NET with Microsoft Visual Studio 2005. I have a project with a User Control that I have created. I have a button that I named Clear. I require to clear the data from my maskedtextbox named "mtbPAC".

  Generate a context diagram of the system

Generate a context diagram of the system

  Describe the pillars of electronic commerce

Identify and describe the three pillars of electronic commerce - What is the "value chain"? Contrast the traditional value chain with the customer-oriented value chain.

  Preparing a copy of hard drive

After we have the target media prepared and assembled along with all our tools assembled for investigation we should now make a copy of hard drive.

  Write a reflective essay of 750-1000 words on the

write a reflective essay of 750-1000 words on the historical development of policing and the unique challenges faced

  Find there are still some left over in standard enumeration

find that there are still some left over in our standard enumeration. Does this mean that there are more Turing machines than programs?

  Assembly program to find out the price of a car rental

Write down an Assembly program in order to find out the price of a car rental. The car being rented costs $45 per day and frequent renters get a $15 discount on the total bill.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd