home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sunic!dkuug!diku!torbenm
- From: torbenm@diku.dk (Torben AEgidius Mogensen)
- Newsgroups: comp.lang.prolog
- Subject: Re: transitive and symetric relations
- Message-ID: <1992Aug13.111745.17980@odin.diku.dk>
- Date: 13 Aug 92 11:17:45 GMT
- References: <SWK.92Aug10220513@seymour.mlb.semi.harris.com> <189@syllogi.syllogic.nl>
- Sender: torbenm@freke.diku.dk
- Distribution: comp.lang.prolog
- Organization: Department of Computer Science, U of Copenhagen
- Lines: 29
-
- fdb@syllogic.nl (Frank de Bruijn) writes:
-
- >swk@seymour.mlb.semi.harris.com (Song W. Koh) writes:
-
- >>[I'm a] 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.
-
- >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).
- >distance(X,Z,D):- distance_fact(X,Y,D1), distance_fact(Y,Z,D2), D is D1 + D2 .
-
- This will not work: it will not find distances of points that require
- paths more than two long. A correct formulation of the transitive
- clause is
-
- distance(X,Z,D):- distance_fact(X,Y,D1), distance(Y,Z,D2), D is D1 + D2.
-
- So be sure to get your answers right before you flame someone for
- asking the obvious.
-
- Torben Mogensen (torbenm@diku.dk)
-