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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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