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

  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