🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4275

Re: elementary problem (I hope)

#4275
From: Richard O'keefe
Date: Mon, 12 Mar 1990 00:54
74 lines
2918 bytes
In article <1990Mar9.095655.4191@bath.ac.uk>
ccsdgdc@gdr.bath.ac.uk (Douglas Clark) writes:
>A user has been asking me how to write synonyms in Prolog.
>Being ignorant I have no idea.
>It is obvious why the natural

>father(X) :- male(X).
>male(X) :- father(X).
>father(fred).

>fails.  But I cannot find a substitute that works.  Some way of eliminating
>the repetitive backtracking.  Help would be appreciated.

Er, what repetitive backtracking?  The code exhibited must go into an
infinite loop without ever delivering any answers:
	?- father(tom)
    =>	?- male(tom)
    =>	?- father(tom)
and away we go.  

Do you really believe that "father" and "male" are synonyms?  Strange world.

If you have two predicates p and q such that p iff and only if q, then all
you have to do is to pick one of them, say p, and decide to take it as basic.
What you do is include the axiom
	q(X) :- p(X).
If this is the only clause for q, then p and q cannot possibly differ at
any point.  YOU DON'T NEED TO DO ANYTHING TO P TO MAKE THIS SO.

It's a good idea to make the definition of p self-contained, so whenever
you would have called q in the definition of p, make it call p instead.
That isn't strictly necessary.

In this particular example, to make sure that father/1 and male/1 have
exactly the same set of answers, and that fred is a father, it suffices
to write

	male(X) :- father(X).		% make male, father equivalent

	father(fred).			% define father

In article <1990Mar10.120125.12992@Neon.Stanford.EDU>, 
feldman@Neon.Stanford.EDU (Todd J. Feldman) writes:
> How about:
 
> father(X):-
> 	not(tried(male(X))),
> 	assert(tried(male(X))),
> 	male(X).
> male(X):-
> 	not(tried(father(X))),
> 	assert(tried(father(X))),
> 	father(X).

This does not work at all if you ask a question with a variable in it.
Suppose I ask
	?- male(fred), male(X).
Given the fact father(fred), this should succeed with X = fred.

The greatest problem with Feldman's approach is its use of the data base.

	father(fred).
	father(X) :- subgoal_of(father(X)), !, fail.
	father(X) :- male(X).

	male(X) :- subgoal_of(male(X)), !, fail.
	male(X) :- father(X).

doesn't leave a lot of dangerous mess around behind it.  It has problems
of its own.  (See discussions of the "loop check problem".)  An approach
which might work rather nicely would be to use extension tables.

But the simplest approach is just not to put the loop there in the first
place.
Technical Details
Message-ID: <2972@goanna.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok
References: <1990Mar9.095655.4191@bath.ac.uk> <1990Mar10.120125.12992@Neon.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok
From: ok@goanna.oz.au (Richard O'keefe)
Newsgroups: comp.lang.prolog
Subject: Re: elementary problem (I hope)
Message-ID: <2972@goanna.oz.au>
Date: 12 Mar 90 00:54:24 GMT
References: <1990Mar9.095655.4191@bath.ac.uk> <1990Mar10.120125.12992@Neon.Stanford.EDU>
Organization: Comp Sci, RMIT, Melbourne, Australia
Lines: 74