Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91904542

Have any Question?


Related Questions in Computer Engineering

Recall the successor notation for representing natural

Recall the successor notation for representing natural numbers as terms in Prolog. In this notation, "0" stands for the number zero, "s (0)" stands for one, "s (s (0))" stands for two, and so on. (a) Based on the success ...

What are the typical types of risk faced by a firm explain

What are the typical types of risk faced by a firm? Explain each type of risk in details.

Assume that these data are seven random observations taken

Assume that these data are seven random observations taken from a larger population whose values are normally distributed. (even if this assumption makes little sense) Using this assumption, coupled with prior computatio ...

Explain a business process you are familiar with describe

Explain a business process you are familiar with. Describe how a computer-based information system is related (or used) in this business process. Explain how a computer-based information systems can improve the efficienc ...

Can someone explain to me how stooge works in the most

Can someone explain to me how Stooge works in the most simplified way. Because am having a hard time understanding it. There was an example on youtube that goes like this: if you are given a small array of numbers that w ...

Question suppose that a car is moving through a suburban

Question : Suppose that a car is moving through a suburban environment that has a wireless channel with a coherence time of 10 ms and a coherence bandwidth of 600 kHz. The bit rate of the signal being used is 50 kbps. Ch ...

A biostatistician is investigating the timenbspt to death

A biostatistician is investigating the time,  T , to death of a mouse exposed to a newly developed pesticide. He finds that the pdf of T is given by the following formula  f(t) = 15t 2 e -5t3 . Which of the following sta ...

1 under what circumstances is it advantageous for a company

1. Under what circumstances is it advantageous for a company competing in foreign markets to concentrate its value chain activities in a select few locations? Under what circumstances is it advantageous for a company com ...

The solution of this exercise please 37 creating an

The solution of this exercise please: 3.7 (Creating an Autocomplete Form) Create a simple search form using a search input element in which the user can enter a search query. Using the Firefox web browser, test the form ...

Question suppose the streets in a city are laid out in a

Question : Suppose the streets in a city are laid out in a perfect grid with avenues A through Z running parallel east-west, and First through Tenth Streets running parallel north-south. Give a count of the number of sho ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As