logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Vasim KhanPhilosophy
(5/5)

878 Answers

Hire Me
expert
Jim TavareLaw
(5/5)

541 Answers

Hire Me
expert
Anup GodaraAccounting
(5/5)

674 Answers

Hire Me
expert
Sarandeep GuptaGeneral article writing
(5/5)

598 Answers

Hire Me
Others
(5/5)

Draw the Prolog tree for the computation below: like in the examples we discussed

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

6. (20pt) Consider the following Prolog facts and rules: 

append([], Y, Y).

append ( [H I X] Y, I Z] ) : - append(X, Y, Z) .

member (X, [X I _] ) .

member (X, [-IT]) :- member(X, T).

member2(X, L) append(P, [X I _] , L), not (member2(X, P)). 

The member predicate returns all elements of a list when used as shown below (left). To produce each element only once, we can use member2; see below (middle). Note further that member2 produces unique elements in the order of their first occurrence. 

?- member(X, [a,b,c,b,a]) .           ?- member2(X, [a,b,c,b,a]).                    ?- member3(X, [a,b,c,b,a]).

X = a ;                                          X = a ;                                                     X = c ;

X = b ;                                          X = b ;                                                    X = b ; 

X = c ;                                         X = c ;                                                       X = a ; 

 X = a ;                                        false.                                                        false.

 X = a ;

false. 

(a) (lOpt) Write a new predicate member3 which, when used as above, produces unique elements in the order of their last occurrence, as seen above (right).

(b) (lOpt) Draw the Prolog tree for the computation below: like in the examples we discussed, you need to show, on each brach, the rule used and the substitution (if any), the branches not attempted because of cuts (! - indicate which cut prevented which branch), and the output produced (solutions and the false).

?- member3(X, [a,b,a]).

X = b ;

X = a ;

false. 

 

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme