Welcome! Log In Create A New Profile

Advanced

Assignment 2 Question 2(c)

Posted by DJ_Paulo 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 2 Question 2(c)
July 10, 2012 10:26AM
Hi all

I don't know if I'm just being dumb, but I'm not understanding question 2(c):

"Write a procedure satisfy(P,L) that receives a binary predicate symbol P and returns the list L of all terms X for which P(X,Y) succeeds for some Y."

Please can someone explain what is actually being asked here?

Thanks
Paulo
avatar Re: Assignment 2 Question 2(c)
July 10, 2012 10:51AM
First of I think the question might be stated slightly incorrectly. Also, this is my interpretation of what is being asked so don't complain if it turns out to be wrong.

So image you have the following facts:

fact(x1, y1).
fact(x2, y2).
fact(x3, y3).
fact(x4, y4).
% fact(xn, yn) etc.

You must write a procedure:

satisfy(fact, L)

that returns:

L = [x1, x2, x3, x4]

Now, the question says "for some Y" and not "for all Y" (meaning it does not care what the value of Y is), which the above does. This means that you need to specify the Y part, but I don't see how you can do this with satisfy(fact, L). I think you will need something like satisfy(fact, Y, L) to specify the Y part.

My assumption might be completely wrong as this is the first time I have used Prolog.
Re: Assignment 2 Question 2(c)
July 10, 2012 12:03PM
Thanks MotaBoy

I hope you're right. I won't hold it against you if you're not because I have no clue myself smiling smiley

Cheers
Paulo
avatar Re: Assignment 2 Question 2(c)
July 10, 2012 12:19PM
Here is a slighly better example of what I think "for some Y" means:

for all Y:

fact(green, dog).
fact(blue, cat).
fact(red, dog).
fact(yellow, cat).
fact(green, cat).

satisfy(fact, L).

Result:

L = [green, blue, red, yellow, green]



...and for some Y:

satisfy(fact, cat, L).

Result:

L = [blue, yellow, green]
Re: Assignment 2 Question 2(c)
July 10, 2012 12:49PM
That does make sense "for some Y", but as you said, it requires an extra variable which the original procedure structure "satisfy(P,L)" does not cater for.
If the question used a real life example, I think it would have been easier to figure out what is actually being asked.
avatar Re: Assignment 2 Question 2(c)
July 10, 2012 01:04PM
It might be that there is some other way to pass the Y variable to the precedure using just "satisfy(P,L)", but I have come up with a solution yet.
Re: Assignment 2 Question 2(c)
July 11, 2012 07:54AM
I think I have found the set of predicates to use in the textbook.
Just need to figure out which one would be best suited to answering the question.
avatar Re: Assignment 2 Question 2(c)
July 11, 2012 10:34AM
I managed to get two versions ( satisfy(P, L) & satisfy(P,Y, L) )working with the stuff from (I think) chapter 6 (built-in predicates?). I'm still not sure about this whole "for some Y" business. Any ideas so far DJ_Paulo?
Sorry, only registered users may post in this forum.

Click here to login