🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #80

Re: transitive and symetric relations

#80
From: Frank de Bruijn
Date: Tue, 11 Aug 1992 06:59
46 lines
2180 bytes
swk@seymour.mlb.semi.harris.com (Song W. Koh) writes:

>Is there an FAQ for this group?  Could someone send me a copy?

no FAQ that I'm aware of

>prolog beginner.  I am having trouble describing transitive and
>symetric relations without stack overflows.  Things like:

>distance(X,Y,D) :- distance(Y,X,D).

I see, are you blind, or just too lazy to read a decent textbook on
PROLOG? Even the "not so good books" describe this.

roughly: if you query for the distance between a and b, but facts to that
end do not exist - neither distance(a,b,D) nor distance(b,a,D) - then your
rule will cause an endless loop of recursive calls that will cause the stacks
to overflow.

The standard solution is to use a different predicate name for the distance
facts. (It has always struck me as a bit of a diappointment though)

distance(X, Y, D):- distance_fact(X, Y, D).
distance(X, Y, D):- distance_fact(Y, X, D).

If you find this disappointing then you'll have to build a meta-interpreter
that allows you to declare relations and their properties as well as facts.

Such a meta-interpreter could handle the symmetry, transitivity, etc. of all
relations declared as such. One implementation technique that can be used in
such a meta-interpreter is to examine the goal stack for an earlier call-frame
that matches the current call frame. This works, but it's costly.........
... Read the chapters on meta-interpreters in various textbooks

>and

>distance(X,Z,D) :- distance(X,Y,D1), distance(Y,Z,D2), D is D1 + D2.

similar standard solution:
distance(X,Z,D):- distance_fact(X,Y,D1), distance_fact(Y,Z,D2), D is D1 + D2 .

>Thanks in advance.
do your homework next time

Frank W.G.M. de Bruijn,
LP Consultant, Syllogic Corp, Houten, the Netherlands.
Technical Details
Message-ID: <189@syllogi.syllogic.nl>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!syllogi!fdb
References: <SWK.92Aug10220513@seymour.mlb.semi.harris.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!syllogi!fdb
From: fdb@syllogic.nl (Frank de Bruijn)
Newsgroups: comp.lang.prolog
Subject: Re: transitive and symetric relations
Message-ID: <189@syllogi.syllogic.nl>
Date: 11 Aug 92 06:59:41 GMT
References: <SWK.92Aug10220513@seymour.mlb.semi.harris.com>
Distribution: comp.lang.prolog
Organization: Syllogic B.V., Houten, the Netherlands
Lines: 46