Who is a desencendant of the queenmother

Assignment Help Computer Engineering
Reference no: EM131305257

CS-205 Declarative Programming Assignment

Question 1: Recursion, Lists and Accumulating Parameters

(a) Write the following program and compile it:

% Program: ROYAL

parent(queenmother,elisabeth).             parent(elisabeth,charles).

parent(elisabeth,andrew).                     parent(elisabeth,anne).

parent(elisabeth,edward).                     parent(diana,william).

parent(diana,harry).                             parent(sarah,beatrice).

parent(anne,peter).                              parent(anne,zara).

parent(george,elisabeth).                      parent(philip,charles).

parent(philip,andrew).                           parent(philip,edward).

parent(charles,william).                         parent(charles,harry).

parent(andrew,beatrice).                       parent(andrew,eugene).

parent(mark,peter).                              parent(mark,zara).

parent(william,georgejun).                     parent(kate,georgejun).

parent(kate,charlotte).

Define the following predicates on the persons in the program ROYAL.

(1) the_royal_females/1 (a list of all female members of the Royal Family)

(2) the_royal_males/1 (a list of all male members of the Royal Family)

(3) the_royal_family/1 (a list of all members of the Royal Family)

(4) mother/2

(5) has_child/1.

(6) ancestor/2 (use recursion).

(7) descendant/2 (use recursion or (6)).

Translate the following questions into Prolog queries and try them out:

(8) Who is the mother of Beatrice?

(9) Who has a child (one or more)?

(10) Who is a desencendant of the Queenmother?

(b) Use predicates of question (a) to define predicates sibling/2 and aunt/2 (w.r.t. the Royal Family). [Query: Who are the siblings of charles?]

(c) Write a predicate palindrome_list(L) which checks whether L is a palindromic list (i.e., reads the same forwards and backwards). Examples are [a,b,c,b,a] and [12,a,5,a,12]. The base cases are when the list is empty or a singleton. The general case is to check that the first element is the same as the last element and (recursively) the remaining part of the list is palindromic. To achieve this write a predicate last_element(L,X,R) which instantiates X to the last element of L and R to L with X removed. The easiest way to de?ne this is to use append.

(d) An example of a recursive predicate and a tail recursive version using an accumulating parameter.

i. The square of the Euclidean distance between two vectors xi and yi is i=1n(xi - yi)*(xi - yi). Write a recursive predicate euclidsqr(X,Y,ED) which returns the value in ED when X and Y are lists representing vectors of the same length.

ii Now write a tail recursive predicate euclidsqr_acc(X,Y,A,ED) to compute the same function using the accumulating parameter A to store intermediate calculations. (Look at sum_a in example prolog code).

Question 2: Backtracking Solution of Futoshiki Puzzle

Here is a Futoshiki puzzle downloaded from the internet (popular in many news-papers).

The aim is to place digits 1-4 in the empty cells so that each row and column contains distinct digits and the constraints speci?ed by the inequality signs are all satisfied. You are to write a generate and test backtracking program in Prolog to solve this puzzle.

(a) Define the predicate member_rem(E,L,R) which chooses an element E from list L leaving remainder R.

1760_Figures.png

(b) Using the above define gen_list_n(N,D,L) which generates a list L of N distinct elements from the list D where the length of D is ≥ N.

gen_n(0, _,[]).

gen_n (N, D, [X|Xs]) :-

N > 0, N1 is N - 1,

 . . . .

gen_n(N1, D1, Xs).

Define gen4(L) to generate a list of 4 distinct digits from 1-4.

(c) To check that two list of numbers X, Y are different at each entry (i.e, Xi differs from Yi for all i) define a predicate distinct_in_entries(X,Y). As elements of the lists are numbers you use =\= to check for inequality.

(d) Now you can generate a possible solution [R1, R2, R3, R4] where Ri are rows of 4 distinct numbers from 1-4 and all the columns consist of distinct numbers as follows: generate R1 (using gen4), then R2 and check R1 and R2 are distinct at all entries; generate R3 and check this is distinct in entries with R1 and R2 and so on. Call this predicate gen_poss_soln([R1, R2, R3, R4]). So e.g., it will produce [[1, 2, 3, 4], [2, 1, 4, 3], [3, 4, 1, 2], [4, 3, 2, 1]] as an output.

 (e) Finally define solve ([R1, R2, R3, R4]) using generate and test by generating a possible solution, [R1, R2, R3, R4], and then testing each of the in-equalities. Notice that the only constraints in R1 are on R11 and R12 (R11 > R12) so you only need say R1 = [R11, R12, _, _]. You should deal with the other rows and constraints in a similar manner.

(f) The solver solve will find the solution for a 4x4 Futoshiki problem in a reasonable time, but if you scaled it up in an obvious manner for 5x5 problems it would be too inefficient. So produce a more efficient version of solve which splits up the generate and test tasks. Call this solve_in_steps ([R1, R2, R3, R4]) and this time, generate R1 first and test any constraints you can, just involving row 1 (in this case its only R11 > R12), then generate R2 and apply the constraints on any variables in R1 and R2 and so on. This approach should be able to cope with 5x5 problems (though there are many other improvements you can make to speed up the solver).

Reference no: EM131305257

Questions Cloud

Describe the design for a between subjects experiment : Identify another factor (a confounding variable) that might explain why some employees participated in the fitness program and why those same employees have fewer sick days.
What does it mean that equities may have rallied too much : What are equities?- What does it mean that "equities may have rallied too much"?- If equities have rallied too much, why would buying puts be a good idea?
Discuss about the humor and persuasion : Discuss about the Humor and Persuasion .our paper should delineate three or more aspects of the effectiveness of humor and indicate at least three risks of attempting to use humor in persuasion. Your paper should include previous theories of persua..
Compare the pros and cons of buying a put option : Compare the pros and cons of buying a put option versus selling a stock if you are worried that the price of the stock might decline.
Who is a desencendant of the queenmother : CS-205 Declarative Programming Assignment. Translate the following questions into Prolog queries and try them out: Who is the mother of Beatrice? Who has a child (one or more)? Who is a desencendant of the Queenmother
What is the intrinsic value of the put option : What is the intrinsic value of the call option that expires in April and has a $95 strike price?- What is the intrinsic value of the put option that expires in January and has a $105 strike price?
Discuss about the cultural influence in business psychology : Discuss about the Cultural Influence in Business Psychology.Mark Jones, a Production Manager, has been transferred from the manufacturing plant in his hometown of Chicago to his company's overseas manufacturing plant in Osaka, Japan.
Create a pl-sql procedure to print out the reservation : Write a PL/SQL function that given a reservation ID, returns the name of guest who made that reservation. If there is no such reservation in the database, return null. Please call this function with input reservation ID 1, and print out the return..
What does a bullish approach mean : What does a "bullish approach" mean? Why does the data on options purchases indicate that traders were taking a bullish approach?

Reviews

len1305257

12/8/2016 3:48:35 AM

The work has to be the group’s own work. Your solution is to be submitted electronically as two files. One for each question. (Please do not zip!) Use the CS-205 Assignments page on Blackboard for submission. Solution ?le format: .pl if accepted otherwise .txt. Embed results as comments in these files. Sufficient results should be given to test your code. Please register as a group on blackboard asap. Include group number, name(s) and student number(s) on the first page.

Write a Review

Computer Engineering Questions & Answers

  Which design strategy would you recommend for construction

The agency wants to keep a database of its own property listings and also wants to have access to the citywide multiple listings service used by all real estate agents. Which design strategy would you recommend for the construction of this system? ..

  Sections of currency conversion development documentation

The Currency Conversion application is a menu-driven program that allows users to select one of five international currency types, input the amount of a foreign currency, and then convert the foreign currency to dollars. The program displays the e..

  How to generate the computer code

I have not seen them yet, but the wave appears to be toward a complete English ability to write down computer programs.

  List the hexadecimal code for each instruction

Consider the MARIE program below. a) List the hexadecimal code for each instruction. b) Draw the symbol table. c) What is the value stored in the AC when the program terminates?

  Write an illustration of a nested if structure and build it

write a 200- to 300-word short-answer response to the followinga create an example of a nested if structure and build

  Is allocate and free memory belong to the process

System calls to allocate and free memory belong to the Process control operating system service category. The producer-consumer problem refers to the sharing of a buffer of size n among two jobs

  Is this an ethical question or just a matter of office

as a new systems analyst at premier financial services you are getting quite an education. youreport to mary the it

  Calculate matrix-vector product using mpi processes

Implement a parallel algorithm that calculates matrix-vector product using MPI processes, What is the cause of the difference? What are the advantages and disadvantages of two approaches?

  Change in behavior that occurs as a result of experience

Give an instance of such a "lesson" that helped you to improve your job performance. Try to generalize this isolated experience of yours into a "training method" that would help others to improve their performance as well.

  How to increase scara system security in advance way

Writing research paper of 3 to 4 pages. How to increase SCARA system security in advance way and taking examples to increase the SCADA system security?

  Write a program that demonstrates the coin class

Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up.

  Is platos view of knowledge more closely aligned

Heraclitus concluded that everything is "becoming", or that everything is in a state of flux. Parmenides concluded reality is Being, one thing which is motionless, eternal etc. Compare their conclusions with the ideas of Plato in the divided line ..

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