🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
5 messages
5 total messages Started by Scott Sloka Sun, 24 Jan 1993 02:11
Help: making a binary predicate reversibly equal
#2410
Author: Scott Sloka
Date: Sun, 24 Jan 1993 02:11
13 lines
962 bytes
Howdy.  My name is Scott Sloka and I am an AI enthusiast at the University of
Waterloo.  I have a list of facts such as: nextto(a,b) and I would like
nextto(a,b) to be equivalent to nextto(b,a).  This does not work:

nextto(X,Y):-nextto(Y,X).

because an endless loop is set up.  I am just beginning Prolog programming
because I am doing a project on abstraction and I would like to include this
parameter switch equalization in my routines for some of my predicates.  Any
pointers would be greatly appreciated.  Thanks in advance.

		-Scott
Re: Help: making a binary predicate reversibly equal
#2414
Author: Matthew Crocker
Date: Mon, 25 Jan 1993 13:03
14 lines
1115 bytes
if your database has nextto(a,b), nextto(c,d) etc. then use a different
predicate to define the symmetric version of the relation. I.e.

next-to(A,B) :- nextto(A,B).
next-to(A,B) :- nextto(B,A).

Matt.

-------Dr. Matthew Crocker-----------------------------------------
 Dept. of Artificial Intelligence  | Phone: DAI: +44 -31 650 2702 
   Centre for Cognitive Science    |        CCS: +44 -31 650 4432
     University of Edinburgh       |        FAX: +44 -31 226 2730
         80 South Bridge           | E-mail: M.Crocker@ed.ac.uk or,
   Edinburgh, Scotland, EH1 1HN    |         mwc@aisb.ed.ac.uk
Re: Help: making a binary predicate reversibly equal
#2412
Author: Jens Wunderwa
Date: Mon, 25 Jan 1993 15:13
21 lines
1391 bytes
In article <C1C63u.J6n@watserv1.uwaterloo.ca> jssloka@monet.uwaterloo.ca (Scott Sloka) writes:
>
>   Howdy.  My name is Scott Sloka and I am an AI enthusiast at the University of
>   Waterloo.  I have a list of facts such as: nextto(a,b) and I would like
>   nextto(a,b) to be equivalent to nextto(b,a).  This does not work:
>
>   nextto(X,Y):-nextto(Y,X).
>
>   because an endless loop is set up.  I am just beginning Prolog programming
>   because I am doing a project on abstraction and I would like to include this
>   parameter switch equalization in my routines for some of my predicates.  Any
>   pointers would be greatly appreciated.  Thanks in advance.
>
>		   -Scott

Just define

nextto_sym(X,Y) :- nextto(X,Y).
nextto_sym(X,Y) :- nextto(Y,X).

Ciao Jens
Re: Help: making a binary predicate reversibly equal
#2417
Author: Scot Dyer
Date: Mon, 25 Jan 1993 19:12
36 lines
2040 bytes
% From: jssloka@monet.uwaterloo.ca (Scott Sloka)
% Subject: Help: making a binary predicate reversibly equal
% 
% Howdy.  My name is Scott Sloka and I am an AI enthusiast at the University of
% Waterloo.

Howdy.

%            I have a list of facts such as: nextto(a,b) and I would like
% nextto(a,b) to be equivalent to nextto(b,a).  This does not work:
% 
% nextto(X,Y):-nextto(Y,X).
% 
% because an endless loop is set up.  I am just beginning Prolog programming
% because I am doing a project on abstraction and I would like to include this
% parameter switch equalization in my routines for some of my predicates.  Any
% pointers would be greatly appreciated.  Thanks in advance.

This is a real common problem for beginners.  You need _two_ predicates, one
to handle the symmetry of the relation, and the other to provide the basic
facts.  Try something like:

	nextto( X, Y ) :- nextto_fact( X, Y ).
	nextto( X, Y ) :- nextto_fact( Y, X ).

	nextto_fact( a, b ).
	% and whatever other 'facts' are involved.

%                 -Scott
	-- Scot
+------------------------+-----------------------------------------------+
|Scot Dyer_Rivenburgh    | "Land of song," said the warrior bard,	 |
|dyer@eagle.sharebase.com| "Though all the world betrays thee,		 |
+------------------------+  One sword, at least, thy rights shall guard, |
|(He's right, you know.) |  One faithful harp shall praise thee."	 |
+------------------------+-----------------------------------------------+
Re: Help: making a binary predicate reversibly equal
#2420
Author: Ken Johnson
Date: Tue, 26 Jan 1993 11:08
45 lines
1403 bytes
In article <C1C63u.J6n@watserv1.uwaterloo.ca> jssloka@monet.uwaterloo.ca
(Scott Sloka) writes:

#  I have a list of facts such as: nextto(a,b) and I would like nextto(a,b)
#  to be equivalent to nextto(b,a). 


This is a common problem. The usual solution is

next_to(A,B) :-
	next_to_fact(A,B).

next_to(A,B) :-
	next_to_fact(B,A).


next_to_fact(e,r).
next_to_fact(i,o).
next_to_fact(o,p).
next_to_fact(q,w).
next_to_fact(r,t).
next_to_fact(t,y).
next_to_fact(u,i).
next_to_fact(w,e).
next_to_fact(y,u)


Example run

| ?- next_to(q,w).

yes
| ?- next_to(w,q).

yes
| ?- next_to(a,b).
no


-- 
Son, all the pretty, intelligent, healthy     #    I have discovered of this
young women are taken. It's a basic rule of   #    basic rule of the universe
the universe, and if you don't like it, go    #    a most remarkable proof,
somewhere else.        -- my dad  1906-1992   #    which this .signature is too
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads