🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #3276

reply to quickie

#3276
From: Jason Trenouth
Date: Tue, 19 Apr 1988 16:24
38 lines
1513 bytes
In reply to Ian Dickenson's posed "quickie":

        exactly_one(X, Y) :-
            contains(X, Y),
            p(Y),
            bagof(Y1,
                  (
                    contains(X, Y1),
                    \+(Y1 = Y),		% Assuming N unifications are better
                    q(Y1)		% than one call to "q".
                  ),
                  Ys).

The algorithm computes at worst:

	N calls to "p" (where N is the number of Ys "contain"ed in X); and

	N*(N-1) calls to "q".

By adding a lemma creation predicate (i.e. asserting) for "q" inside
the "bagof" call we could achieve linearity in full calls to "q".

[Anyone else?]

Chow.

	_______________________________________
	|                                     |
	| Jason Trenouth                      |
	|  Computer Science Department        |
	|   University of Exeter              |
	|    Devon EX4 4PT                    |
	|     United Kingdom                  |
	|                                     |
	| JANET:  jtr@uk.ac.exeter.cs         |
	| UUCP:   jtr@expya.uucp              |
	| BITNET: jtr%uk.ac.exeter.cs@ukacrl  |
	|_____________________________________|
Technical Details
Message-ID: <427@expya.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!ukc!warwick!expya!jtr

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!ukc!warwick!expya!jtr
From: jtr@expya.UUCP (Jason Trenouth)
Newsgroups: comp.lang.prolog
Subject: reply to quickie
Message-ID: <427@expya.UUCP>
Date: 19 Apr 88 16:24:55 GMT
Reply-To: jtr@expya.UUCP (Jason Trenouth)
Organization: Computer Science Dept. - University of Exeter. UK
Lines: 38