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

  Create the following symbolic equations

Create the following symbolic equations.

  Write a void function definition for a function

Write a void function definition for a function called add_tax. The function add_tax has two formal parameters taxrate.

  What are the services within the print services role

What are some of the management activities you can accomplish with ServerManagerCmd.exe. What are the services within the Print Services role. How do you add counter, using different sections of the Performance Monitor, in order to configure monitori..

  Printing of fibonacci series

Write down a program which utilized a loop to determine the first seven values of Fibonacci number sequence explained by the following formula.

  Express what is a keyword in a programming language

Why explantion of a variable is considered to be an important.

  Write a simple java application

Write a simple Java application which calculates the power dissipation in a simple circuit. Your application should ask the user to enter the voltage and resistance values of the circuit.

  Handling the error

Alter your program so that it consider the arguments provided at the command line are integers. If there are no arguments, print the message.

  Problem on backtracking algorithm

Your program should print out the maze after each cell is visited, showing which cells have already been visited. Finally, your program must print out a message indicating whether the exit was found or that no route to the exit could be found

  What do you think that the future holds for the virtual

write a 200- to 300-word short-answer response to the followingwhat do you think that the future holds for virtual

  Question 1 explain the terms technique and tool and then

question 1 explain the terms technique and tool and then describe some of the techniques and tools that you used in

  Design the function definitions of pixel class constructor

Write the function definitions of the Pixel class constructor adn CurrentStatus member functions.

  List the five criteria for systems project selection

List the five criteria for systems project selection. What does COTS stand for? Define tangible costs and benefits. Give an example of each one. When is break-even analysis useful? List the five steps in interview preparation.

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