home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / prolog / 1537 < prev    next >
Encoding:
Text File  |  1992-08-14  |  2.1 KB  |  65 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!mcsun!Germany.EU.net!ira.uka.de!chx400!bernina!neptune!nugget.inf.ethz.ch!marti
  3. From: marti@nugget.inf.ethz.ch (Robert Marti)
  4. Subject: Re: transitive and symetric relations
  5. Message-ID: <1992Aug14.162919.6025@neptune.inf.ethz.ch>
  6. Sender: news@neptune.inf.ethz.ch (Mr News)
  7. Nntp-Posting-Host: nugget.inf.ethz.ch
  8. Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH), Zurich, CH
  9. References: <SWK.92Aug10220513@seymour.mlb.semi.harris.com> <189@syllogi.syllogic.nl> <1992Aug13.111745.17980@odin.diku.dk> <7199@skye.ed.ac.uk>
  10. Date: Fri, 14 Aug 1992 16:29:19 GMT
  11. Lines: 52
  12.  
  13. In article <7199@skye.ed.ac.uk>, ken@aiai.ed.ac.uk (Ken Johnson) writes:
  14. |> In article <1992Aug13.111745.17980@odin.diku.dk> torbenm@diku.dk (Torben
  15. |> AEgidius Mogensen) writes:
  16. |> #  A correct formulation of the transitive clause is
  17. |> #
  18. |> #  distance(X,Z,D) :-
  19. |> #    distance_fact(X,Y,D1),
  20. |> #    distance(Y,Z,D2),
  21. |> #    D is D1 + D2.
  22. |> This may loop indefinitely.
  23.  
  24. Agreed.
  25.  
  26.  
  27. |> For instance, suppose you invoked it with
  28. |>          ?- distance(london,paris,X).
  29. |> when `paris' was not mentioned in any distance fact.
  30.  
  31. Hardly, as seen below.  (Note that since there is no distance_fact
  32. in the program, your precondition is fulfilled.  Also, the dynamic
  33. declaration may not be necessary in your flavor of Prolog.)
  34.  
  35. ----- Begin Included Transscript -----
  36.   mint[254]: prolog
  37.   SICStus 2.1 #5: Tue May 12 12:04:21 MET DST 1992
  38.   | ?- [user].
  39.   | :- dynamic distance_fact/3.
  40.   | distance(X,Z,D) :-
  41.        distance_fact(X,Y,D1),
  42.        distance(Y,Z,D2),
  43.        D is D1 + D2.
  44.   | {user consulted, 40 msec 672 bytes}
  45.  
  46.   yes
  47.   | ?- distance(london,paris,X).
  48.  
  49.   no
  50.   | ?- ^D
  51. ------ End Included Transscript ------
  52.  
  53. However, the goal  ?- distance(london,paris,X)  leads to an infinite
  54. loop in Prolog if you can deduce both the facts
  55.   distance_fact(london,paris,_)
  56. and
  57.   distance_fact(paris,london,_)
  58. from your program.
  59.  
  60. -- 
  61. Robert Marti                    |  Phone:    +41 1 254 72 60
  62. Informationssysteme             |  FAX:      +41 1 262 39 73
  63. ETH-Zentrum                     |  E-Mail:   marti@inf.ethz.ch
  64. CH-8092 Zurich, Switzerland     |
  65.