Re: determinism

Gregory Bourassa <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Daniel,

Does your solution not return one solution to the caller before it ascertains whether or not the goal is really deterministic?

This program is a bit simplistic and it actually tries G three times; but it only returns a solution if G is really deterministic.

det(G) :- retractall( success ), call(G), backtrack_only_once, !, fail.

det(G) :- success, call(G).

backtrack_only_once :- success.

backtrack_only_once :- not( success ), assertz( success ), !, fail.

Regards.

Gregory Bourassa

On Mon Feb 12 12:11 , Daniel Diaz sent:

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.

>

You can do it using a global variable to count solutions. Stop when the

second is reached.

det(Goal) :-

det1(Goal).

det(_) :-

g_read(det_count, 1).

det1(Goal) :-

g_assign(det_count, 0),

call(Goal),

g_inc(det_count, Count), % increment and return the counter

Count = 2, % cut if 2nd solution is reached (else fail)

!,

fail.

Hope this helps

--

Ce message a ete verifie par MailScanner

pour des virus ou des polluriels et rien de

suspect n'a ete trouve.

_______________________________________________

Users-prolog mailing list

[email protected]

http://lists.gnu.org/mailman/listinfo/users-prolog

_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.