Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- From: mearvk <mearvk@xxxxxxxxx>
- Date: Fri, 12 Oct 2007 17:49:23 -0700
On Oct 12, 6:03 pm, bart demoen <b...@xxxxxxxxxxxxxx> wrote:
On Fri, 12 Oct 2007 15:29:45 -0700, mearvk wrote:
The following file generates the error below:
[START FILE]
instanceOf(X,X).[...]
instanceOf(produce,cucumber).
instanceOf(meats,steaks).[...]
instanceOf(meats,beef).
instanceOf(beef,hamburger).
instanceOf(A,B):- instanceOf(C,B), instanceOf(A,C), A\==B, B\==C, A
\==C.
[END FILE]
?- instanceOf(meats,hamburger).
ERROR: Out of local stack
This is a recurring problem when trying to define a relation in terms of
some base cases and a rule that constructs more out of the base cases.
[inductive definitions, but if you are not mathematically inclined, you
can ignore this]
Here is a rule of thumb:
make the base cases (from instanceOf(X,X) to instanceOf(beef,hamburger))
into facts with a different name, like
base_instanceOf(X,X).
...
base_instanceOf(beef,hamburger).
because that's what they are: that's what you know basically about
instanceOf without any inference.
Then define
instanceOf(A,B) :-
base_instanceOf(A,B).
instanceOf(A,B) :-
base_instanceOf(A,C),
base_instanceOf(C,B),
+ any conditions you think are appropriate.
Sure like hell, this want solve all your problems with this thing, but it
is a start.
BTW, if you are interested in understanding what it going on, don't get
distracted by posts telling you that you could use tabling from XSB (or
other systems): that just opens a new layer of things to get acquainted
with and it does not explain by itself the previous layer.
Cheers
Bart Demoen- Hide quoted text -
- Show quoted text -
All right I changed my setup to fit your recommendations. Thanks :-)
base_instanceOf(X,X).
base_instanceOf(produce,tomato).
base_instanceOf(produce,lettuce).
base_instanceOf(produce,cabbage).
base_instanceOf(produce,potatoe).
base_instanceOf(produce,apple).
base_instanceOf(produce,cucumber).
base_instanceOf(meat,steak).
base_instanceOf(meat,sausage).
base_instanceOf(meat,ham).
base_instanceOf(meat,salami).
base_instanceOf(meat,beef).
base_instanceOf(beef,hamburger).
instanceOf(A,A).
instanceOf(A,B):- base_instanceOf(A,B).
instanceOf(A,B):- base_instanceOf(C,B), base_instanceOf(A,C).
This works. But the next question is how can I recursively define an
instance of thing to be an instance of another thing at an arbitrary
depth? This code only solves for depth 2. A subset of a subset. (meat
beef > hamburger) It'd be much nicer if I could do this recursivelyfor any depth. (food > organic > dead > cooked > meat > hamburger).
Any ideas/hints?
Thanks!
.
- Follow-Ups:
- Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- From: sbaker8688
- Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- References:
- Trying to setup a hierarchy of classes of things (SWI prolog)
- From: mearvk
- Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- From: bart demoen
- Trying to setup a hierarchy of classes of things (SWI prolog)
- Prev by Date: Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- Next by Date: Re: Newbie question on discrete distribution of random numbers
- Previous by thread: Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- Next by thread: Re: Trying to setup a hierarchy of classes of things (SWI prolog)
- Index(es):