Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 PAPERnnStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started