0
votes

I'm trying to test out recursion in prolog. Based on the KB and conditional statements below, I tried to make a recursive call and wanted to use the one specifically for "eastOf(X,Y) :- westOf(X,Z),eastOf(Z,Y)" The query I am using is "eastOf(ave,yonge)" which should use that recursive call and state that X is ave, Y is yonge and Z is collegePark. However the proglog program i am using current (ECliPSe) iss giving me this error "*** Overflow of the local/control stack! You can use the "-l kBytes" (LOCALSIZE) option to have a larger stack. Peak sizes were: local stack 11024 kbytes, control stack 120048 kbytes"

Find below my .pl file

eastOf(collegePark,yonge).
eastOf(sushi,eaton).
eastOf(X,Y) :- westOf(Y,X). 
eastOf(X,Y) :- westOf(X,Z), eastOf(Z,Y).

westOf(ellington,yonge). 
westOf(ryerson,sushi).
westOf(ave,collegePark).
westOf(X,Y) :- eastOf(Y,X).
westOf(X,Y) :- eastOf(X,Z), westOf(Z,Y).
2
The predicate eastOf(X,Y) :- westOf(X,Z), eastOf(Z,Y). isn't a good rule. It says that X is east of Y if X is west of Z and Z is east of Y. That's not necessarily true. - lurker
Could you provide an example for when this isn't true? - MJJLAM
Sure: Denver, CO is west of New York, NY, and New York, NY, is east of Chicago, IL, but Denver, CO, is NOT east of Chicago, IL. - lurker
So from that predicate it is actually finding that X is north of Y not actually east? Is that correct? - MJJLAM
No, that's not even conclusive. You can't deduce north or south from an east or west relationship, unless you're referring to an unusual, non-spherical geometry. If you are just talking about east and west, and you ignore the fact that A can be either east of B or west of B depending upon which way around the globe you go, then you can say that if A is east of B, and B is east of C, then A is east of C. - lurker

2 Answers

1
votes
eastOf(X,Y) :- westOf(Y,X).

westOf(X,Y) :- eastOf(Y,X).

The infinite loop has occurred in the combination of these two predicates. Even if stack size is large, size over occurs. I change your program as follows.

eastOf_data(collegePark,yonge).
eastOf_data(sushi,eaton).
eastOf(X,Y) :- westOf_data(Y,X). 
eastOf(X,Y) :- westOf_data(X,Z), eastOf_data(Z,Y).

westOf_data(ellington,yonge). 
westOf_data(ryerson,sushi).
westOf_data(ave,collegePark).
westOf(X,Y) :- eastOf_data(Y,X).
westOf(X,Y) :- eastOf_data(X,Z), westOf_data(Z,Y).
1
votes

I think you meant to use eastOf(yonge,collegePark) as your first statement. Right now it never finds an atomic statement starting with either 'ave' or 'yonge', and keeps looping between eastOf(X,Y) :- westOf(Y,X) and westOf(X,Y) :- eastOf(Y,X).