Question: Logic Programming 4. Logic Programming [Total: 25 marks] In this question, we consider the Prolog program below. The rules (shown in bold type) are incomplete

Logic Programming

Logic Programming 4. Logic Programming [Total: 25 marks] In this question, we

4. Logic Programming [Total: 25 marks] In this question, we consider the Prolog program below. The rules (shown in bold type) are incomplete link (mary,peter). link (john, peter). link (mary, amy) link (john, david) link (amy, bob). friend (x.Y) :- . . list friends (X,L) :- . 4(a) [5 marks] The fact link (john,peter) means that john and peter are friends We want to make each link bidirectional, e.g., peter and john are friends However, we do not want to add additional facts like link (peter, john) in the above program Write the rule(s) for friend (X, Y) in order to solve this problem. [10 marks] 4(b) Write the rule(s) for list_friends (X,L) such that L represents the list of all friends of X. Consider the following queries. Guess the result of each query in a Prolog interpreter list friends (john, L) list friends (amy, L) Result 4(c) [10 marks] We recommend X and Y to be friends if they are not friends but they have at least one common friend Write the rule(s) for recommend (X, Y) Consider the following queries. Guess the result of each query in a Prolog interpreter recommend (john, amy) recommend (david, john) ue Result END OF THE PAPERnn 4. Logic Programming [Total: 25 marks] In this question, we consider the Prolog program below. The rules (shown in bold type) are incomplete link (mary,peter). link (john, peter). link (mary, amy) link (john, david) link (amy, bob). friend (x.Y) :- . . list friends (X,L) :- . 4(a) [5 marks] The fact link (john,peter) means that john and peter are friends We want to make each link bidirectional, e.g., peter and john are friends However, we do not want to add additional facts like link (peter, john) in the above program Write the rule(s) for friend (X, Y) in order to solve this problem. [10 marks] 4(b) Write the rule(s) for list_friends (X,L) such that L represents the list of all friends of X. Consider the following queries. Guess the result of each query in a Prolog interpreter list friends (john, L) list friends (amy, L) Result 4(c) [10 marks] We recommend X and Y to be friends if they are not friends but they have at least one common friend Write the rule(s) for recommend (X, Y) Consider the following queries. Guess the result of each query in a Prolog interpreter recommend (john, amy) recommend (david, john) ue Result END OF THE PAPERnn

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!