[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: determinism

From: Alexandre Saidi
Subject: Re: determinism
Date: Mon, 12 Feb 2007 19:34:28 +0100
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

This may help :

- go/2 takes G and T. It copies G to G1 (no shared variable), calls G1 (hence G) and if success, next/3 will decide.
- next/3 retries G (hence G1) but if there is a solution different from the first call (in go/2), then cuts and conludes on a failure.
Otherwise, next/3 takes the only solution into T.
- more_than_one is here to write some blabla.
Other 'write(...)' are also there for a trace.
 Try it with :
go(p0(X), T).  
go(p1(X), T).
go(p2(X), T).
go(p3(X), T).

Only go(p0(X), T). succeeds. Others will write things but fail.

PS : there is no try with an nonexistent predicat; you may set the appropriate flag and try with that case also.


go(G, T) :- copy_term(G,G1), call(G1), next(G,G1,T).
next(G,G1,T) :- G, G \== G1, !, more_than_one(G,G1,T).
next(_G,G1,T) :- T=G1, write('case  one solution\n').	% succeed, only one solution.
more_than_one(_G,_G1,_T) :- write('case with more than one solution \n'), fail.

% ex for G with 0, 1 and more solutions.
p0(_):- fail.	% zero solution for p0

p1(1).	% one solution predicate

p2(1).	% Two solutions for p2

p3(1).	% 3 (or more) soultions
michel levy a écrit :
Could you help to write this program :
det(T,G) succeeds if and only if G succeeds once and only once and give the T answer.
1) I don't want the solution below by findall, because I want to try at most two back tracks on G.
det(T,G) :- findall(T,G,L),length(L,1)

2) I know already call_det but it's not the solution because G can have choice points, but only one answer.


Aleksander S. Saidi
Maître de Conférences
Ecole Centrale de Lyon
Département Mathématiques-Informatique
Mél : address@hidden
Tél :, Fax :

Attachment: Alexandre.Saidi.vcf
Description: Vcard

reply via email to

[Prev in Thread] Current Thread [Next in Thread]